[arrayfire] 265/284: BUGFIX: max_bytes were being set incorrectly in MemoryManager
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Sun Feb 7 18:59:40 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 fc7553df8377ee6c4b7f25878aaf6bf0727bcf6b
Author: Pavan Yalamanchili <pavan at arrayfire.com>
Date: Tue Feb 2 14:31:34 2016 -0500
BUGFIX: max_bytes were being set incorrectly in MemoryManager
---
src/backend/MemoryManager.cpp | 21 +++++++++++++++------
src/backend/MemoryManager.hpp | 2 ++
src/backend/cpu/memory.cpp | 4 +++-
src/backend/cuda/memory.cpp | 8 ++++++--
src/backend/opencl/memory.cpp | 8 ++++++--
5 files changed, 32 insertions(+), 11 deletions(-)
diff --git a/src/backend/MemoryManager.cpp b/src/backend/MemoryManager.cpp
index 8142628..d82436e 100644
--- a/src/backend/MemoryManager.cpp
+++ b/src/backend/MemoryManager.cpp
@@ -19,6 +19,7 @@
namespace common
{
+const size_t ONE_GB = 1 << 30;
MemoryManager::MemoryManager(int num_devices, unsigned MAX_BUFFERS, bool debug):
mem_step_size(1024),
max_buffers(MAX_BUFFERS),
@@ -32,17 +33,25 @@ MemoryManager::MemoryManager(int num_devices, unsigned MAX_BUFFERS, bool debug):
}
if (this->debug_mode) mem_step_size = 1;
- static const size_t oneGB = 1 << 30;
for (int n = 0; n < num_devices; n++) {
- size_t memsize = getMaxMemorySize(n);
+ // Calling getMaxMemorySize() here calls the virtual function that returns 0
+ // Call it from outside the constructor.
+ memory[n].max_bytes = ONE_GB;
+ memory[n].total_bytes = 0;
+ memory[n].lock_bytes = 0;
+ memory[n].lock_buffers = 0;
+ }
+}
+
+void MemoryManager::setMaxMemorySize()
+{
+ for (unsigned n = 0; n < memory.size(); n++) {
// Calls garbage collection when:
// total_bytes > memsize * 0.75 when memsize < 4GB
// total_bytes > memsize - 1 GB when memsize >= 4GB
// If memsize returned 0, then use 1GB
- memory[n].max_bytes = memsize == 0 ? oneGB : std::max(memsize * 0.75, (double)(memsize - oneGB));
- memory[n].total_bytes = 0;
- memory[n].lock_bytes = 0;
- memory[n].lock_buffers = 0;
+ size_t memsize = this->getMaxMemorySize(n);
+ memory[n].max_bytes = memsize == 0 ? ONE_GB : std::max(memsize * 0.75, (double)(memsize - ONE_GB));
}
}
diff --git a/src/backend/MemoryManager.hpp b/src/backend/MemoryManager.hpp
index 8bb9941..faae7fa 100644
--- a/src/backend/MemoryManager.hpp
+++ b/src/backend/MemoryManager.hpp
@@ -63,6 +63,8 @@ class MemoryManager
public:
MemoryManager(int num_devices, unsigned MAX_BUFFERS, bool debug);
+ void setMaxMemorySize();
+
void *alloc(const size_t bytes);
void unlock(void *ptr, bool user_unlock);
diff --git a/src/backend/cpu/memory.cpp b/src/backend/cpu/memory.cpp
index cf7e1ba..8a89cb1 100644
--- a/src/backend/cpu/memory.cpp
+++ b/src/backend/cpu/memory.cpp
@@ -56,7 +56,9 @@ size_t MemoryManager::getMaxMemorySize(int id)
MemoryManager::MemoryManager() :
common::MemoryManager(getDeviceCount(), MAX_BUFFERS, AF_MEM_DEBUG || AF_CPU_MEM_DEBUG)
-{}
+{
+ this->setMaxMemorySize();
+}
void *MemoryManager::nativeAlloc(const size_t bytes)
diff --git a/src/backend/cuda/memory.cpp b/src/backend/cuda/memory.cpp
index f5dc6ca..6a947c6 100644
--- a/src/backend/cuda/memory.cpp
+++ b/src/backend/cuda/memory.cpp
@@ -91,7 +91,9 @@ size_t MemoryManager::getMaxMemorySize(int id)
MemoryManager::MemoryManager() :
common::MemoryManager(getDeviceCount(), MAX_BUFFERS, AF_MEM_DEBUG || AF_CUDA_MEM_DEBUG)
-{}
+{
+ this->setMaxMemorySize();
+}
void *MemoryManager::nativeAlloc(const size_t bytes)
{
@@ -126,7 +128,9 @@ size_t MemoryManagerPinned::getMaxMemorySize(int id)
MemoryManagerPinned::MemoryManagerPinned() :
common::MemoryManager(1, MAX_BUFFERS, AF_MEM_DEBUG || AF_CUDA_MEM_DEBUG)
-{}
+{
+ this->setMaxMemorySize();
+}
void *MemoryManagerPinned::nativeAlloc(const size_t bytes)
{
diff --git a/src/backend/opencl/memory.cpp b/src/backend/opencl/memory.cpp
index 7054e96..01c93bb 100644
--- a/src/backend/opencl/memory.cpp
+++ b/src/backend/opencl/memory.cpp
@@ -89,7 +89,9 @@ size_t MemoryManager::getMaxMemorySize(int id)
MemoryManager::MemoryManager() :
common::MemoryManager(getDeviceCount(), MAX_BUFFERS, AF_MEM_DEBUG || AF_OPENCL_MEM_DEBUG)
-{}
+{
+ this->setMaxMemorySize();
+}
void *MemoryManager::nativeAlloc(const size_t bytes)
{
@@ -128,7 +130,9 @@ size_t MemoryManagerPinned::getMaxMemorySize(int id)
MemoryManagerPinned::MemoryManagerPinned() :
common::MemoryManager(getDeviceCount(), MAX_BUFFERS, AF_MEM_DEBUG || AF_OPENCL_MEM_DEBUG),
pinned_maps(getDeviceCount())
-{}
+{
+ this->setMaxMemorySize();
+}
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