[arrayfire] 91/248: function to set active cuda device using native id

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Tue Nov 17 15:54:08 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 8dd257ba21918c381894c2392fd7f874d0a9bd38
Author: pradeep <pradeep at arrayfire.com>
Date:   Tue Sep 29 19:20:12 2015 -0400

    function to set active cuda device using native id
---
 include/af/cuda.h             | 28 ++++++++++++++++++++++++++++
 src/backend/cuda/platform.cpp | 18 ++++++++++++++++++
 src/backend/cuda/platform.hpp |  2 ++
 3 files changed, 48 insertions(+)

diff --git a/include/af/cuda.h b/include/af/cuda.h
index 7cc3cd6..5b5e25b 100644
--- a/include/af/cuda.h
+++ b/include/af/cuda.h
@@ -42,6 +42,18 @@ AFAPI af_err afcu_get_stream(cudaStream_t* stream, int id);
 AFAPI af_err afcu_get_native_id(int* nativeid, int id);
 #endif
 
+#if AF_API_VERSION >= 32
+/**
+   Set the CUDA device with given native id as the active device for ArrayFire
+
+   \param[in] nativeid native device id of the CUDA device
+   \returns \ref af_err error code
+
+   \ingroup cuda_mat
+ */
+AFAPI af_err afcu_set_native_id(int nativeid);
+#endif
+
 #ifdef __cplusplus
 }
 #endif
@@ -89,5 +101,21 @@ static inline int getNativeId(int id)
 }
 #endif
 
+#if AF_API_VERSION >= 32
+/**
+   Set the CUDA device with given native id as the active device for ArrayFire
+
+   \param[in] nativeId native device id of the CUDA device
+
+   \ingroup cuda_mat
+ */
+static inline void setNativeId(int nativeId)
+{
+    af_err err = afcu_set_native_id(nativeId);
+    if (err!=AF_SUCCESS)
+        throw af::exception("Failed to change active CUDA device to the device with given native id");
+}
+#endif
+
 }
 #endif
diff --git a/src/backend/cuda/platform.cpp b/src/backend/cuda/platform.cpp
index 4fe24c6..df9fa2a 100644
--- a/src/backend/cuda/platform.cpp
+++ b/src/backend/cuda/platform.cpp
@@ -272,6 +272,18 @@ int getDeviceNativeId(int device)
     return -1;
 }
 
+int getDeviceIdFromNativeId(int nativeId)
+{
+    DeviceManager& mngr = DeviceManager::getInstance();
+
+    int devId = 0;
+    for(devId = 0; devId < mngr.nDevices; ++devId) {
+        if (nativeId == mngr.cuDevices[devId].nativeId)
+            break;
+    }
+    return devId;
+}
+
 cudaStream_t getStream(int device)
 {
     return DeviceManager::getInstance().streams[device];
@@ -391,3 +403,9 @@ af_err afcu_get_native_id(int* nativeid, int id)
     *nativeid = cuda::getDeviceNativeId(id);
     return AF_SUCCESS;
 }
+
+af_err afcu_set_native_id(int nativeid)
+{
+    cuda::setDevice(cuda::getDeviceIdFromNativeId(nativeid));
+    return AF_SUCCESS;
+}
diff --git a/src/backend/cuda/platform.hpp b/src/backend/cuda/platform.hpp
index a893b01..b07ee97 100644
--- a/src/backend/cuda/platform.hpp
+++ b/src/backend/cuda/platform.hpp
@@ -79,6 +79,8 @@ class DeviceManager
 
         friend int getDeviceNativeId(int device);
 
+        friend int getDeviceIdFromNativeId(int nativeId);
+
         friend cudaStream_t getStream(int device);
 
         friend int setDevice(int device);

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