[arrayfire] 183/284: FEAT Add getActiveBackend function
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Sun Feb 7 18:59:31 UTC 2016
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to branch debian/experimental
in repository arrayfire.
commit 56f9140d880b5816817aa8e3bd78c114492de56b
Author: Shehzan Mohammed <shehzan at arrayfire.com>
Date: Fri Jan 8 23:21:01 2016 -0500
FEAT Add getActiveBackend function
---
docs/details/backend.dox | 9 +++++++++
include/af/backend.h | 20 ++++++++++++++++++++
src/api/c/device.cpp | 6 ++++++
src/api/cpp/device.cpp | 7 +++++++
src/api/unified/device.cpp | 6 ++++++
test/backend.cpp | 15 +++++++++++++++
6 files changed, 63 insertions(+)
diff --git a/docs/details/backend.dox b/docs/details/backend.dox
index 4d9cdf6..146cc14 100644
--- a/docs/details/backend.dox
+++ b/docs/details/backend.dox
@@ -71,5 +71,14 @@ The return value specifies which backend the array was created on.
=======================================================================
+\defgroup unified_func_getactivebackend getActiveBackend
+
+\brief Get's the backend enum for the active backend
+
+\ingroup unified_func
+\ingroup arrayfire_func
+
+=======================================================================
+
@}
*/
diff --git a/include/af/backend.h b/include/af/backend.h
index 93d8d8d..0342ef0 100644
--- a/include/af/backend.h
+++ b/include/af/backend.h
@@ -55,6 +55,17 @@ AFAPI af_err af_get_available_backends(int* backends);
AFAPI af_err af_get_backend_id(af_backend *backend, const af_array in);
#endif
+#if AF_API_VERSION >= 33
+/**
+ \param[out] backend takes one of the values of enum \ref af_backend
+ from the backend that is currently set to active
+ \returns \ref af_err error code
+
+ \ingroup unified_func_getactivebackend
+ */
+AFAPI af_err af_get_active_backend(af_backend *backend);
+#endif
+
#ifdef __cplusplus
}
#endif
@@ -101,5 +112,14 @@ AFAPI int getAvailableBackends();
AFAPI af::Backend getBackendId(const array &in);
#endif
+#if AF_API_VERSION >= 33
+/**
+ \returns \ref af_backend which is the backend is currently active
+
+ \ingroup unified_func_getctivebackend
+ */
+AFAPI af::Backend getActiveBackend();
+#endif
+
}
#endif
diff --git a/src/api/c/device.cpp b/src/api/c/device.cpp
index 8f33299..d782211 100644
--- a/src/api/c/device.cpp
+++ b/src/api/c/device.cpp
@@ -53,6 +53,12 @@ af_err af_get_backend_id(af_backend *result, const af_array in)
return AF_SUCCESS;
}
+af_err af_get_active_backend(af_backend *result)
+{
+ *result = (af_backend)getBackend();
+ return AF_SUCCESS;
+}
+
af_err af_init()
{
try {
diff --git a/src/api/cpp/device.cpp b/src/api/cpp/device.cpp
index 3b1609b..5e4b0f7 100644
--- a/src/api/cpp/device.cpp
+++ b/src/api/cpp/device.cpp
@@ -42,6 +42,13 @@ namespace af
return result;
}
+ af::Backend getActiveBackend()
+ {
+ af::Backend result = (af::Backend)0;
+ AF_THROW(af_get_active_backend(&result));
+ return result;
+ }
+
void info()
{
AF_THROW(af_info());
diff --git a/src/api/unified/device.cpp b/src/api/unified/device.cpp
index f7e9556..fbd8e32 100644
--- a/src/api/unified/device.cpp
+++ b/src/api/unified/device.cpp
@@ -35,6 +35,12 @@ af_err af_get_backend_id(af_backend *result, const af_array in)
return CALL(result, in);
}
+af_err af_get_active_backend(af_backend *result)
+{
+ *result = unified::AFSymbolManager::getInstance().getActiveBackend();
+ return AF_SUCCESS;
+}
+
af_err af_info()
{
return CALL_NO_PARAMS();
diff --git a/test/backend.cpp b/test/backend.cpp
index 7b8dbdd..4bb5cdf 100644
--- a/test/backend.cpp
+++ b/test/backend.cpp
@@ -21,11 +21,26 @@
using std::string;
using std::vector;
+const char *getActiveBackendString()
+{
+ af_backend active = (af_backend)0;
+ af_get_active_backend(&active);
+
+ switch(active) {
+ case AF_BACKEND_CPU : return "AF_BACKEND_CPU";
+ case AF_BACKEND_CUDA : return "AF_BACKEND_CUDA";
+ case AF_BACKEND_OPENCL: return "AF_BACKEND_OPENCL";
+ default : return "AF_BACKEND_DEFAULT";
+ }
+}
+
template<typename T>
void testFunction()
{
af_info();
+ printf("Active Backend Enum = %s\n", getActiveBackendString());
+
af_array outArray = 0;
dim_t dims[] = {32, 32};
ASSERT_EQ(AF_SUCCESS, af_randu(&outArray, 2, dims, (af_dtype) af::dtype_traits<T>::af_type));
--
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