From 8b5b58e77ffe51f70a0d7121bbe9e3101ef63d71 Mon Sep 17 00:00:00 2001 From: pradeep Date: Sun, 18 Sep 2016 22:17:39 +0530 Subject: [PATCH] Check and load a functional backend Though libraries of a given backend can be present on the target machine, there can be scenarios where a compatible hardware device is not available. In such cases, backend loader checks if current selected backend has a device ready for use. If no appropriate device exists, the next backend in the priority list is checked for same criteria. This process is repeated until a working backend is found. In the event that no functional backend is found, the program throws a runtime error. --- arrayfire/library.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/arrayfire/library.py b/arrayfire/library.py index ff09f051d..aeeb03c7e 100644 --- a/arrayfire/library.py +++ b/arrayfire/library.py @@ -490,9 +490,23 @@ def __init__(self): except: pass + c_dim4 = c_dim_t*4 + + out = c_dim_t(0) + dims = c_dim4(10, 10, 10, 10) + + for key, value in self.__clibs: + err = value.af_randu(ct.pointer(out), 4, ct.pointer(dims), 0) + if (err == ERR.NONE.value): + if (self.__name != key): + self.__name = key + break + else: + self.__name = None + pass + if (self.__name is None): - raise RuntimeError("Could not load any ArrayFire libraries.\n" + - more_info_str) + raise RuntimeError("Could not load any ArrayFire libraries.\n" + more_info_str) def get_id(self, name): return self.__backend_name_map[name]