Skip to content

Commit

Permalink
unified: backend id fix (#3424)
Browse files Browse the repository at this point in the history
* fix: incorrect backend id bitshift. incorrect number of backends
* fix unified: convert backend_id to index with backend_index()


---------

Co-authored-by: Gallagher Donovan Pryor <gallagher@arrayfire.com>
  • Loading branch information
pv-pterab-s and Gallagher Donovan Pryor committed Aug 18, 2023
1 parent 30d9f0b commit 4e4a414
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/api/unified/symbol_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,16 +193,15 @@ AFSymbolManager::AFSymbolManager()
// In order of priority.
static const af_backend order[] = {AF_BACKEND_CUDA, AF_BACKEND_ONEAPI,
AF_BACKEND_OPENCL, AF_BACKEND_CPU};

LibHandle handle = nullptr;
af::Backend backend = AF_BACKEND_DEFAULT;
LibHandle handle = nullptr;
af::Backend backend = AF_BACKEND_DEFAULT;
// Decremeting loop. The last successful backend loaded will be the most
// prefered one.
for (int i = NUM_BACKENDS - 1; i >= 0; i--) {
int backend_index = order[i] >> 1U; // 2 4 1 -> 1 2 0
bkndHandles[backend_index] = openDynLibrary(order[i]);
if (bkndHandles[backend_index]) {
handle = bkndHandles[backend_index];
int bknd_idx = backend_index(order[i]);
bkndHandles[bknd_idx] = openDynLibrary(order[i]);
if (bkndHandles[bknd_idx]) {
handle = bkndHandles[bknd_idx];
backend = order[i];
numBackends++;
backendsAvailable += order[i];
Expand Down Expand Up @@ -242,7 +241,7 @@ af_err setBackend(af::Backend bknd) {
UNIFIED_ERROR_LOAD_LIB();
}
}
int idx = bknd >> 1U; // Convert 1, 2, 4 -> 0, 1, 2
int idx = backend_index(bknd);
if (instance.getHandle(idx)) {
getActiveHandle() = instance.getHandle(idx);
getActiveBackend() = bknd;
Expand Down

0 comments on commit 4e4a414

Please sign in to comment.