[arrayfire] 42/75: Changes to make sure cpu backend does not enqueue too many functions.
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Mon Feb 29 08:01:15 UTC 2016
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 e1abe128ae19b769c1b48855df3306d87afcc847
Author: Pavan Yalamanchili <pavan at arrayfire.com>
Date: Mon Feb 22 12:27:44 2016 -0500
Changes to make sure cpu backend does not enqueue too many functions.
This fix synchronizes when the queue hits 25 functions or when
the memory used is approaching the device limit.
---
src/backend/MemoryManager.cpp | 4 ++--
src/backend/cpu/memory.cpp | 21 +++++++++++++++--
src/backend/cpu/queue.hpp | 52 +++++++++++++++++++++++++++----------------
3 files changed, 54 insertions(+), 23 deletions(-)
diff --git a/src/backend/MemoryManager.cpp b/src/backend/MemoryManager.cpp
index 0879e98..379c2e2 100644
--- a/src/backend/MemoryManager.cpp
+++ b/src/backend/MemoryManager.cpp
@@ -257,7 +257,7 @@ void MemoryManager::printInfo(const char *msg, const int device)
unit = "MB";
}
- std::cout << " | " << std::right << std::setw(14) << kv.first << " "
+ std::cout << "| " << std::right << std::setw(14) << kv.first << " "
<< " | " << std::setw(7) << std::setprecision(4) << size << " " << unit
<< " | " << std::setw(9) << status_mngr
<< " | " << std::setw(9) << status_user
@@ -277,7 +277,7 @@ void MemoryManager::printInfo(const char *msg, const int device)
}
for (auto &ptr : kv.second) {
- std::cout << " | " << std::right << std::setw(14) << ptr << " "
+ std::cout << "| " << std::right << std::setw(14) << ptr << " "
<< " | " << std::setw(7) << std::setprecision(4) << size << " " << unit
<< " | " << std::setw(9) << status_mngr
<< " | " << std::setw(9) << status_user
diff --git a/src/backend/cpu/memory.cpp b/src/backend/cpu/memory.cpp
index 8837e27..b4b1b45 100644
--- a/src/backend/cpu/memory.cpp
+++ b/src/backend/cpu/memory.cpp
@@ -112,13 +112,30 @@ void printMemInfo(const char *msg, const int device)
template<typename T>
T* memAlloc(const size_t &elements)
{
- return (T *)getMemoryManager().alloc(elements * sizeof(T), false);
+ T *ptr = nullptr;
+
+ try {
+ ptr = (T *)getMemoryManager().alloc(elements * sizeof(T), false);
+ } catch(...) {
+ getQueue().sync();
+ ptr = (T *)getMemoryManager().alloc(elements * sizeof(T), false);
+ }
+ return ptr;
}
void* memAllocUser(const size_t &bytes)
{
- return getMemoryManager().alloc(bytes, true);
+ void *ptr = nullptr;
+
+ try {
+ ptr = getMemoryManager().alloc(bytes, true);
+ } catch(...) {
+ getQueue().sync();
+ ptr = getMemoryManager().alloc(bytes, true);
+ }
+ return ptr;
}
+
template<typename T>
void memFree(T *ptr)
{
diff --git a/src/backend/cpu/queue.hpp b/src/backend/cpu/queue.hpp
index 6d32b85..2f32b4d 100644
--- a/src/backend/cpu/queue.hpp
+++ b/src/backend/cpu/queue.hpp
@@ -8,6 +8,7 @@
********************************************************/
#include <util.hpp>
+#include <memory.hpp>
//FIXME: Is there a better way to check for std::future not being supported ?
#if defined(AF_DISABLE_CPU_ASYNC) || (defined(__GNUC__) && (__GCC_ATOMIC_INT_LOCK_FREE < 2 || __GCC_ATOMIC_POINTER_LOCK_FREE < 2))
@@ -48,32 +49,45 @@ typedef async_queue queue_impl;
namespace cpu {
/// Wraps the async_queue class
-class queue {
+class queue
+{
public:
- queue()
- : sync_calls( __SYNCHRONOUS_ARCH == 1 || getEnvVar("AF_SYNCHRONOUS_CALLS") == "1") {}
-
- template <typename F, typename... Args>
- void enqueue(const F func, Args... args) {
+ queue()
+ :
+ count(0),
+ sync_calls( __SYNCHRONOUS_ARCH == 1 || getEnvVar("AF_SYNCHRONOUS_CALLS") == "1")
+ {}
- if(sync_calls) { func( args... ); }
- else { aQueue.enqueue( func, args... ); }
+ template <typename F, typename... Args>
+ void enqueue(const F func, Args... args)
+ {
+ count++;
+ if(sync_calls) { func( args... ); }
+ else { aQueue.enqueue( func, args... ); }
#ifndef NDEBUG
- sync();
+ sync();
+#else
+ if (checkMemoryLimit() || count >= 25) {
+ sync();
+ }
#endif
+ }
- }
- void sync() {
- if(!sync_calls) aQueue.sync();
- }
+ void sync()
+ {
+ count = 0;
+ if(!sync_calls) aQueue.sync();
+ }
- bool is_worker() const {
- return (!sync_calls) ? aQueue.is_worker() : false;
- }
+ bool is_worker() const
+ {
+ return (!sync_calls) ? aQueue.is_worker() : false;
+ }
-private:
- const bool sync_calls;
- queue_impl aQueue;
+ private:
+ int count;
+ const bool sync_calls;
+ queue_impl aQueue;
};
}
--
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