[arrayfire] 245/284: BUGFIX Fix CUDA device management and free at destructor

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Sun Feb 7 18:59:38 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 163b5fbf8d51e7c3f7666b3a68cd21740b8284e6
Author: Shehzan Mohammed <shehzan at arrayfire.com>
Date:   Fri Jan 22 22:55:19 2016 -0500

    BUGFIX Fix CUDA device management and free at destructor
---
 src/backend/cuda/kernel/random.hpp | 15 ++++++++++++---
 src/backend/cuda/platform.cpp      |  5 ++++-
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/src/backend/cuda/kernel/random.hpp b/src/backend/cuda/kernel/random.hpp
index 4d960ae..96cf098 100644
--- a/src/backend/cuda/kernel/random.hpp
+++ b/src/backend/cuda/kernel/random.hpp
@@ -49,8 +49,18 @@ namespace kernel
 
         ~curandStateManager()
         {
-            //if(_state != NULL) memFree((char*)_state);
-            if(_state != NULL) CUDA_CHECK(cudaFree(_state));
+            try {
+                if (_state != NULL) {
+                    cudaError_t err = cudaFree(_state);
+                    if (err != cudaErrorCudartUnloading) {
+                        CUDA_CHECK(err);
+                    }
+                }
+            } catch (AfError err) {
+                if (err.getError() != AF_ERR_DRIVER) { // Can happen from cudaErrorDevicesUnavailable
+                    throw err;
+                }
+            }
         }
 
         unsigned long long getSeed() const
@@ -69,7 +79,6 @@ namespace kernel
             if(_state)
                 return _state;
 
-            //_state = (curandState_t*)memAlloc<char>(BLOCKS * THREADS * sizeof(curandState_t));
             CUDA_CHECK(cudaMalloc((void **)&_state, BLOCKS * THREADS * sizeof(curandState_t)));
             this->resetSeed();
             return _state;
diff --git a/src/backend/cuda/platform.cpp b/src/backend/cuda/platform.cpp
index 46b7303..744bf7e 100644
--- a/src/backend/cuda/platform.cpp
+++ b/src/backend/cuda/platform.cpp
@@ -425,7 +425,7 @@ int DeviceManager::setActiveDevice(int device, int nId)
     // Comes only when first is true. Set it to false
     first = false;
 
-    while(device < numDevices) {
+    while(true) {
         // Check for errors other than DevicesUnavailable
         // If success, return. Else throw error
         // If DevicesUnavailable, try other devices (while loop below)
@@ -435,12 +435,15 @@ int DeviceManager::setActiveDevice(int device, int nId)
             return old;
         }
         cudaGetLastError(); // Reset error stack
+#ifndef NDEBUG
         printf("Warning: Device %d is unavailable. Incrementing to next device \n", device);
+#endif
 
         // Comes here is the device is in exclusive mode or
         // otherwise fails streamCreate with this error.
         // All other errors will error out
         device++;
+        if (device >= numDevices) break;
 
         // Can't call getNativeId here as it will cause an infinite loop with the constructor
         nId = cuDevices[device].nativeId;

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