Skip to content

Commit 8b5b58e

Browse files
committed
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.
1 parent 3537d10 commit 8b5b58e

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

arrayfire/library.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,9 +490,23 @@ def __init__(self):
490490
except:
491491
pass
492492

493+
c_dim4 = c_dim_t*4
494+
495+
out = c_dim_t(0)
496+
dims = c_dim4(10, 10, 10, 10)
497+
498+
for key, value in self.__clibs:
499+
err = value.af_randu(ct.pointer(out), 4, ct.pointer(dims), 0)
500+
if (err == ERR.NONE.value):
501+
if (self.__name != key):
502+
self.__name = key
503+
break
504+
else:
505+
self.__name = None
506+
pass
507+
493508
if (self.__name is None):
494-
raise RuntimeError("Could not load any ArrayFire libraries.\n" +
495-
more_info_str)
509+
raise RuntimeError("Could not load any ArrayFire libraries.\n" + more_info_str)
496510

497511
def get_id(self, name):
498512
return self.__backend_name_map[name]

0 commit comments

Comments
 (0)