[arrayfire] 214/284: Using device independent vector for cuda Pinned Memory Manager

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Sun Feb 7 18:59:34 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 904d3e0b8d8d85f07d650010662ba9cebf1c0c6b
Author: Shehzan Mohammed <shehzan at arrayfire.com>
Date:   Tue Jan 12 11:53:14 2016 -0500

    Using device independent vector for cuda Pinned Memory Manager
---
 src/api/c/imageio.cpp       |  5 +++--
 src/backend/cuda/memory.cpp | 21 +++++++--------------
 2 files changed, 10 insertions(+), 16 deletions(-)

diff --git a/src/api/c/imageio.cpp b/src/api/c/imageio.cpp
index 5471305..748ddbc 100644
--- a/src/api/c/imageio.cpp
+++ b/src/api/c/imageio.cpp
@@ -301,13 +301,14 @@ af_err af_save_image(const char* filename, const af_array in_)
             free_in = true;
         } else if(max_real < 256) {
             in = in_;
-        }
-        else if (max_real < 65536) {
+        } else if (max_real < 65536) {
             af_array c255 = 0;
             AF_CHECK(af_constant(&c255, 257.0, info.ndims(), info.dims().get(), f32));
             AF_CHECK(af_div(&in, in_, c255, false));
             AF_CHECK(af_release_array(c255));
             free_in = true;
+        } else {
+            in = in_;
         }
 
         // FI = row major | AF = column major
diff --git a/src/backend/cuda/memory.cpp b/src/backend/cuda/memory.cpp
index 69eb8f8..15786d9 100644
--- a/src/backend/cuda/memory.cpp
+++ b/src/backend/cuda/memory.cpp
@@ -59,6 +59,10 @@ public:
     }
 };
 
+// CUDA Pinned Memory does not depend on device
+// So we pass 1 as numDevices to the constructor so that it creates 1 vector
+// of memory_info
+// When allocating and freeing, it doesn't really matter which device is active
 class MemoryManagerPinned  : public common::MemoryManager
 {
     int getActiveDeviceId();
@@ -69,18 +73,7 @@ public:
     ~MemoryManagerPinned()
     {
         common::lock_guard_t lock(this->memory_mutex);
-        for (int n = 0; n < getDeviceCount(); n++) {
-            try {
-                cuda::setDevice(n);
-                this->garbageCollect();
-            } catch(AfError err) {
-                if(err.getError() == AF_ERR_DRIVER) { // Can happen from cudaErrorDevicesUnavailable
-                    continue;
-                } else {
-                    throw err;
-                }
-            }
-        }
+        this->garbageCollect();
     }
 };
 
@@ -116,11 +109,11 @@ static MemoryManager &getMemoryManager()
 
 int MemoryManagerPinned::getActiveDeviceId()
 {
-    return cuda::getActiveDeviceId();
+    return 0; // pinned uses a single vector
 }
 
 MemoryManagerPinned::MemoryManagerPinned() :
-    common::MemoryManager(getDeviceCount(), MAX_BUFFERS, MAX_BYTES, AF_MEM_DEBUG || AF_CUDA_MEM_DEBUG)
+    common::MemoryManager(1, MAX_BUFFERS, MAX_BYTES, AF_MEM_DEBUG || AF_CUDA_MEM_DEBUG)
 {}
 
 void *MemoryManagerPinned::nativeAlloc(const size_t bytes)

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