[arrayfire] 221/248: Add getBackendId function to get backend info of an array

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Tue Nov 17 15:54:29 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 da4d2ccc8b8b9ee8f1a73eda6a43b85fc0e45a06
Author: Shehzan Mohammed <shehzan at arrayfire.com>
Date:   Tue Nov 10 13:16:10 2015 -0500

    Add getBackendId function to get backend info of an array
    
    * Use this function when checking arrays in unified backend
---
 docs/details/backend.dox           | 12 ++++++++++++
 include/af/backend.h               | 18 ++++++++++++++++++
 src/api/c/device.cpp               |  9 +++++++++
 src/api/cpp/device.cpp             |  8 ++++++++
 src/api/unified/device.cpp         |  7 +++++++
 src/api/unified/symbol_manager.cpp |  5 +++--
 6 files changed, 57 insertions(+), 2 deletions(-)

diff --git a/docs/details/backend.dox b/docs/details/backend.dox
index f318588..fafa453 100644
--- a/docs/details/backend.dox
+++ b/docs/details/backend.dox
@@ -50,5 +50,17 @@ Return Value | Backends Available
 
 =======================================================================
 
+\defgroup unified_func_getbackendid getBackendId
+
+\brief Get's the backend enum for an array
+
+This will return one of the values from the \ref af_backend enum.
+The return value specifies which backend the array was created on.
+
+\ingroup unified_func
+\ingroup arrayfire_func
+
+=======================================================================
+
 @}
 */
diff --git a/include/af/backend.h b/include/af/backend.h
index dcdb195..d402eed 100644
--- a/include/af/backend.h
+++ b/include/af/backend.h
@@ -38,6 +38,15 @@ AFAPI af_err af_get_backend_count(unsigned* num_backends);
  */
 AFAPI af_err af_get_available_backends(int* backends);
 
+/**
+   \param[out] backend takes one of the values of enum \ref af_backend
+   \param[in] in is the array who's backend is to be queried
+   \returns \ref af_err error code
+
+   \ingroup unified_func_getbackendid
+ */
+AFAPI af_err af_get_backend_id(af_backend *backend, const af_array in);
+
 #ifdef __cplusplus
 }
 #endif
@@ -45,6 +54,7 @@ AFAPI af_err af_get_available_backends(int* backends);
 #ifdef __cplusplus
 namespace af
 {
+class array;
 
 /**
    \param[in] bknd takes one of the values of enum \ref af_backend
@@ -67,5 +77,13 @@ AFAPI unsigned getBackendCount();
  */
 AFAPI int getAvailableBackends();
 
+/**
+   \param[in] in is the array who's backend is to be queried
+   \returns \ref af_backend which is the backend on which the array is created
+
+   \ingroup unified_func_getbackendid
+ */
+AFAPI af::Backend getBackendId(const array &in);
+
 }
 #endif
diff --git a/src/api/c/device.cpp b/src/api/c/device.cpp
index f72a6cd..d3ef95b 100644
--- a/src/api/c/device.cpp
+++ b/src/api/c/device.cpp
@@ -42,6 +42,15 @@ af_err af_get_available_backends(int* result)
     return AF_SUCCESS;
 }
 
+af_err af_get_backend_id(af_backend *result, const af_array in)
+{
+    try {
+        ArrayInfo info = getInfo(in);
+        *result = info.getBackendId();
+    } CATCHALL;
+    return AF_SUCCESS;
+}
+
 af_err af_init()
 {
     try {
diff --git a/src/api/cpp/device.cpp b/src/api/cpp/device.cpp
index d137ddc..bec0a60 100644
--- a/src/api/cpp/device.cpp
+++ b/src/api/cpp/device.cpp
@@ -7,6 +7,7 @@
  * http://arrayfire.com/licenses/BSD-3-Clause
  ********************************************************/
 
+#include <af/array.h>
 #include <af/device.h>
 #include <af/compatible.h>
 #include <af/traits.hpp>
@@ -34,6 +35,13 @@ namespace af
         return result;
     }
 
+    af::Backend getBackendId(const array &in)
+    {
+        af::Backend result = (af::Backend)0;
+        AF_THROW(af_get_backend_id(&result, in.get()));
+        return result;
+    }
+
     void info()
     {
         AF_THROW(af_info());
diff --git a/src/api/unified/device.cpp b/src/api/unified/device.cpp
index a9affa5..43559a0 100644
--- a/src/api/unified/device.cpp
+++ b/src/api/unified/device.cpp
@@ -28,6 +28,13 @@ af_err af_get_available_backends(int* result)
     return AF_SUCCESS;
 }
 
+af_err af_get_backend_id(af_backend *result, const af_array in)
+{
+    // DO NOT CALL CHECK_ARRAYS HERE.
+    // IT WILL RESULT IN AN INFINITE RECURSION
+    return CALL(result, in);
+}
+
 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 c29908a..7c650d4 100644
--- a/src/api/unified/symbol_manager.cpp
+++ b/src/api/unified/symbol_manager.cpp
@@ -202,8 +202,9 @@ bool checkArray(af_backend activeBackend, af_array a)
 {
     // Convert af_array into int to retrieve the backend info.
     // See ArrayInfo.hpp for more
-    int* a_ = reinterpret_cast<int*>(a);
-    return (*a_ >> 3) == activeBackend;
+    af_backend backend = (af_backend)0;
+    unified::AFSymbolManager::getInstance().call("af_get_backend_id", &backend, a);
+    return backend == activeBackend;
 }
 
 bool checkArrays(af_backend activeBackend)

-- 
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