[arrayfire] 142/248: Added function to get available backends
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Tue Nov 17 15:54:17 UTC 2015
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to branch dfsg-clean
in repository arrayfire.
commit 0c90cce7c38b5c53e5ab4004eef2ce04d5ba1658
Author: Shehzan Mohammed <shehzan at arrayfire.com>
Date: Tue Oct 20 17:38:51 2015 -0400
Added function to get available backends
---
docs/details/backend.dox | 22 ++++++++++++++++++++++
include/af/backend.h | 15 +++++++++++++++
include/af/defines.h | 3 ++-
src/api/c/device.cpp | 12 ++++++++++++
src/api/cpp/device.cpp | 7 +++++++
src/api/unified/device.cpp | 6 ++++++
src/api/unified/symbol_manager.cpp | 20 +++++++++++++++-----
src/api/unified/symbol_manager.hpp | 3 +++
8 files changed, 82 insertions(+), 6 deletions(-)
diff --git a/docs/details/backend.dox b/docs/details/backend.dox
index c136cff..f318588 100644
--- a/docs/details/backend.dox
+++ b/docs/details/backend.dox
@@ -28,5 +28,27 @@ backends loaded successfully.
=======================================================================
+\defgroup unified_func_getavailbackends getAvailableBackends
+
+\brief Returns an integer indicating the backends loaded successfully.
+
+The number returned denotes the backends available according to the table:
+
+Return Value | Backends Available
+-------------|-----------------------
+0 | None
+1 | CPU
+2 | CUDA
+3 | CPU and CUDA
+4 | OpenCL
+5 | CPU and OpenCL
+6 | CUDA and OpenCL
+7 | CPU, CUDA and OpenCL
+
+\ingroup unified_func
+\ingroup arrayfire_func
+
+=======================================================================
+
@}
*/
diff --git a/include/af/backend.h b/include/af/backend.h
index c828fb6..dcdb195 100644
--- a/include/af/backend.h
+++ b/include/af/backend.h
@@ -30,6 +30,14 @@ AFAPI af_err af_set_backend(const af_backend bknd);
*/
AFAPI af_err af_get_backend_count(unsigned* num_backends);
+/**
+ \param[out] backends is the OR sum of the backends available.
+ \returns \ref af_err error code
+
+ \ingroup unified_func_getavailbackends
+ */
+AFAPI af_err af_get_available_backends(int* backends);
+
#ifdef __cplusplus
}
#endif
@@ -52,5 +60,12 @@ AFAPI void setBackend(const Backend bknd);
*/
AFAPI unsigned getBackendCount();
+/**
+ \returns OR sum of the backends available
+
+ \ingroup unified_func_getavailbackends
+ */
+AFAPI int getAvailableBackends();
+
}
#endif
diff --git a/include/af/defines.h b/include/af/defines.h
index bb8e58a..dc36a27 100644
--- a/include/af/defines.h
+++ b/include/af/defines.h
@@ -325,11 +325,12 @@ typedef enum {
AF_FIF_RAW = 34 ///< FreeImage Enum for RAW Camera Image File
} af_image_format;
+// These enums should be 2^x
typedef enum {
AF_BACKEND_DEFAULT = 0, ///< Default backend order: OpenCL -> CUDA -> CPU
AF_BACKEND_CPU = 1, ///< CPU a.k.a sequential algorithms
AF_BACKEND_CUDA = 2, ///< CUDA Compute Backend
- AF_BACKEND_OPENCL = 3, ///< OpenCL Compute Backend
+ AF_BACKEND_OPENCL = 4, ///< OpenCL Compute Backend
} af_backend;
// Below enum is purely added for example purposes
diff --git a/src/api/c/device.cpp b/src/api/c/device.cpp
index cd5bd57..751b377 100644
--- a/src/api/c/device.cpp
+++ b/src/api/c/device.cpp
@@ -44,6 +44,18 @@ af_err af_get_backend_count(unsigned* num_backends)
return AF_SUCCESS;
}
+af_err af_get_available_backends(int* result)
+{
+#if defined(AF_CPU)
+ *result = AF_BACKEND_CPU;
+#elif defined(AF_CUDA)
+ *result = AF_BACKEND_CUDA;
+#elif defined(AF_OPENCL)
+ *result = AF_BACKEND_OPENCL;
+#endif
+ return AF_SUCCESS;
+}
+
af_err af_init()
{
try {
diff --git a/src/api/cpp/device.cpp b/src/api/cpp/device.cpp
index dffeb19..d137ddc 100644
--- a/src/api/cpp/device.cpp
+++ b/src/api/cpp/device.cpp
@@ -27,6 +27,13 @@ namespace af
return temp;
}
+ int getAvailableBackends()
+ {
+ int result = 0;
+ AF_THROW(af_get_available_backends(&result));
+ return result;
+ }
+
void info()
{
AF_THROW(af_info());
diff --git a/src/api/unified/device.cpp b/src/api/unified/device.cpp
index 6a11e04..dccb2e8 100644
--- a/src/api/unified/device.cpp
+++ b/src/api/unified/device.cpp
@@ -22,6 +22,12 @@ af_err af_get_backend_count(unsigned* num_backends)
return AF_SUCCESS;
}
+af_err af_get_available_backends(int* result)
+{
+ *result = AFSymbolManager::getInstance().getAvailableBackends();
+ return AF_SUCCESS;
+}
+
af_err af_info()
{
return CALL_NO_PARAMS();
diff --git a/src/api/unified/symbol_manager.cpp b/src/api/unified/symbol_manager.cpp
index 31e2abd..fda482e 100644
--- a/src/api/unified/symbol_manager.cpp
+++ b/src/api/unified/symbol_manager.cpp
@@ -10,6 +10,7 @@
#include "symbol_manager.hpp"
#include <algorithm>
#include <string>
+#include <cmath>
using std::string;
using std::replace;
@@ -130,20 +131,24 @@ AFSymbolManager& AFSymbolManager::getInstance()
}
AFSymbolManager::AFSymbolManager()
- : activeHandle(NULL), defaultHandle(NULL), numBackends(0)
+ : activeHandle(NULL), defaultHandle(NULL), numBackends(0), backendsAvailable(0)
{
// In reverse order of priority. The last successful backend loaded will be
// the most prefered one.
- static const int order[] = {AF_BACKEND_CPU,
- AF_BACKEND_OPENCL,
- AF_BACKEND_CUDA};
+ static const int order[] = {AF_BACKEND_CPU, // 1
+ AF_BACKEND_OPENCL, // 4
+ AF_BACKEND_CUDA}; // 2
+
+ static const int index[] = {-1, 0, 2, -1, 1}; // Nothing at position 0, 3
for(int i = 0; i < NUM_BACKENDS; ++i) {
- int backend = order[i] - 1;
+ int backend = index[order[i]];
bkndHandles[backend] = openDynLibrary(backend);
if (bkndHandles[backend]) {
activeHandle = bkndHandles[backend];
numBackends++;
+ backendsAvailable += std::pow(2, backend);
+ printf("BA %d %d\n", backend, backendsAvailable);
}
}
// Keep a copy of default order handle
@@ -166,6 +171,11 @@ unsigned AFSymbolManager::getBackendCount()
return numBackends;
}
+int AFSymbolManager::getAvailableBackends()
+{
+ return backendsAvailable;
+}
+
af_err AFSymbolManager::setBackend(af::Backend bknd)
{
if (bknd==AF_BACKEND_DEFAULT) {
diff --git a/src/api/unified/symbol_manager.hpp b/src/api/unified/symbol_manager.hpp
index 34bae58..94a2b38 100644
--- a/src/api/unified/symbol_manager.hpp
+++ b/src/api/unified/symbol_manager.hpp
@@ -29,6 +29,8 @@ class AFSymbolManager {
unsigned getBackendCount();
+ int getAvailableBackends();
+
af_err setBackend(af::Backend bnkd);
template<typename... CalleeArgs>
@@ -64,6 +66,7 @@ class AFSymbolManager {
LibHandle activeHandle;
LibHandle defaultHandle;
unsigned numBackends;
+ int backendsAvailable;
};
#if defined(OS_WIN)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/arrayfire.git
More information about the debian-science-commits
mailing list