[arrayfire] 122/284: Synchronize when AF_SYNCHRONOUS_CALLS is set to 1
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Sun Feb 7 18:59:25 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 1cbffbbbca2aa94b6c01daed167b36534831273a
Author: Umar Arshad <umar at arrayfire.com>
Date: Wed Dec 30 10:09:15 2015 -0500
Synchronize when AF_SYNCHRONOUS_CALLS is set to 1
---
.gitignore | 1 +
CMakeLists.txt | 1 +
src/api/unified/CMakeLists.txt | 1 +
src/api/unified/symbol_manager.cpp | 19 ----------
src/api/unified/symbol_manager.hpp | 2 ++
src/backend/cpu/Array.hpp | 2 +-
src/backend/cpu/CMakeLists.txt | 1 +
src/backend/cpu/debug_cpu.hpp | 2 +-
src/backend/cpu/platform.cpp | 6 ++--
src/backend/cpu/platform.hpp | 6 ++--
src/backend/cpu/queue.hpp | 42 +++++++++++++++++++++++
src/backend/cuda/CMakeLists.txt | 1 +
src/backend/cuda/debug_cuda.hpp | 10 ++++--
src/backend/cuda/platform.cpp | 6 ++++
src/backend/cuda/platform.hpp | 3 ++
src/backend/opencl/CMakeLists.txt | 1 +
src/backend/opencl/debug_opencl.hpp | 7 +++-
src/backend/opencl/kernel/convolve.hpp | 1 +
src/backend/opencl/platform.cpp | 6 ++++
src/backend/opencl/platform.hpp | 2 ++
src/util.cpp | 40 +++++++++++++++++++++
src/{backend/opencl/debug_opencl.hpp => util.hpp} | 16 ++++-----
22 files changed, 136 insertions(+), 40 deletions(-)
diff --git a/.gitignore b/.gitignore
index 948b596..d032d3d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -11,3 +11,4 @@ GPATH
include/af/version.h
src/backend/version.hpp
docs/details/examples.dox
+/TAGS
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ea92cbe..fda2703 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -110,6 +110,7 @@ IF(BUILD_SIFT)
ENDIF(BUILD_SIFT)
INCLUDE_DIRECTORIES(
+ "${CMAKE_CURRENT_SOURCE_DIR}/src"
"${CMAKE_CURRENT_SOURCE_DIR}/include"
"${CMAKE_CURRENT_SOURCE_DIR}/src/backend"
"${CMAKE_CURRENT_SOURCE_DIR}/src/api/c"
diff --git a/src/api/unified/CMakeLists.txt b/src/api/unified/CMakeLists.txt
index a4843bb..b6980d6 100644
--- a/src/api/unified/CMakeLists.txt
+++ b/src/api/unified/CMakeLists.txt
@@ -15,6 +15,7 @@ FILE(GLOB cpp_sources
SOURCE_GROUP(api\\cpp\\Sources FILES ${cpp_sources})
FILE(GLOB common_sources
+ "../../util.cpp"
"../c/util.cpp"
"../c/err_common.cpp"
"../c/type_util.cpp"
diff --git a/src/api/unified/symbol_manager.cpp b/src/api/unified/symbol_manager.cpp
index 1139f99..bc1f14b 100644
--- a/src/api/unified/symbol_manager.cpp
+++ b/src/api/unified/symbol_manager.cpp
@@ -42,25 +42,6 @@ inline string getBkndLibName(const int backend_index)
return LIB_AF_BKND_PREFIX + LIB_AF_BKND_NAME[i] + LIB_AF_BKND_SUFFIX;
}
-inline std::string getEnvVar(const std::string &key)
-{
-#if defined(OS_WIN)
- DWORD bufSize = 32767; // limit according to GetEnvironment Variable documentation
- string retVal;
- retVal.resize(bufSize);
- bufSize = GetEnvironmentVariable(key.c_str(), &retVal[0], bufSize);
- if (!bufSize) {
- return string("");
- } else {
- retVal.resize(bufSize);
- return retVal;
- }
-#else
- char * str = getenv(key.c_str());
- return str==NULL ? string("") : string(str);
-#endif
-}
-
/*flag parameter is not used on windows platform */
LibHandle openDynLibrary(const int bknd_idx, int flag=RTLD_LAZY)
{
diff --git a/src/api/unified/symbol_manager.hpp b/src/api/unified/symbol_manager.hpp
index f4cf913..eb33c20 100644
--- a/src/api/unified/symbol_manager.hpp
+++ b/src/api/unified/symbol_manager.hpp
@@ -11,6 +11,8 @@
#include <af/defines.h>
#include <string>
#include <stdlib.h>
+#include <util.hpp>
+
#if defined(OS_WIN)
#include <Windows.h>
typedef HMODULE LibHandle;
diff --git a/src/backend/cpu/Array.hpp b/src/backend/cpu/Array.hpp
index adb72dc..e0709d3 100644
--- a/src/backend/cpu/Array.hpp
+++ b/src/backend/cpu/Array.hpp
@@ -21,7 +21,7 @@
#include <algorithm>
#include <vector>
#include <platform.hpp>
-#include <async_queue.hpp>
+#include <queue.hpp>
// cpu::Array class forward declaration
namespace cpu
diff --git a/src/backend/cpu/CMakeLists.txt b/src/backend/cpu/CMakeLists.txt
index b0ab17a..bf72a8a 100644
--- a/src/backend/cpu/CMakeLists.txt
+++ b/src/backend/cpu/CMakeLists.txt
@@ -107,6 +107,7 @@ source_group(api\\c\\Headers FILES ${c_headers})
source_group(api\\c\\Sources FILES ${c_sources})
FILE(GLOB cpp_sources
+ "../../util.cpp"
"../../api/cpp/*.cpp"
)
diff --git a/src/backend/cpu/debug_cpu.hpp b/src/backend/cpu/debug_cpu.hpp
index b1d8e17..cbcdc22 100644
--- a/src/backend/cpu/debug_cpu.hpp
+++ b/src/backend/cpu/debug_cpu.hpp
@@ -9,7 +9,7 @@
#pragma once
#include <platform.hpp>
-#include <async_queue.hpp>
+#include <queue.hpp>
#include <err_cpu.hpp>
#ifndef NDEBUG
diff --git a/src/backend/cpu/platform.cpp b/src/backend/cpu/platform.cpp
index 98cfad4..6ae63a9 100644
--- a/src/backend/cpu/platform.cpp
+++ b/src/backend/cpu/platform.cpp
@@ -17,6 +17,7 @@
#include <string>
#include <defines.hpp>
#include <version.hpp>
+#include <queue.hpp>
#ifdef _WIN32
#include <limits.h>
@@ -249,8 +250,9 @@ int getActiveDeviceId()
static const int MAX_QUEUES = 1;
-async_queue& getQueue(int idx) {
- static std::array<async_queue, MAX_QUEUES> queues;
+
+queue& getQueue(int idx) {
+ static std::array<queue, MAX_QUEUES> queues;
return queues[idx];
}
diff --git a/src/backend/cpu/platform.hpp b/src/backend/cpu/platform.hpp
index 1057552..0cd42ae 100644
--- a/src/backend/cpu/platform.hpp
+++ b/src/backend/cpu/platform.hpp
@@ -11,9 +11,9 @@
#include <string>
-class async_queue;
-
namespace cpu {
+ class queue;
+
int getBackend();
std::string getInfo();
@@ -30,5 +30,5 @@ namespace cpu {
void sync(int device);
- async_queue& getQueue(int idx = 0);
+ queue& getQueue(int idx = 0);
}
diff --git a/src/backend/cpu/queue.hpp b/src/backend/cpu/queue.hpp
new file mode 100644
index 0000000..6e5cd71
--- /dev/null
+++ b/src/backend/cpu/queue.hpp
@@ -0,0 +1,42 @@
+/*******************************************************
+ * Copyright (c) 2016, ArrayFire
+ * All rights reserved.
+ *
+ * This file is distributed under 3-clause BSD license.
+ * The complete license agreement can be obtained at:
+ * http://arrayfire.com/licenses/BSD-3-Clause
+ ********************************************************/
+
+#include <util.hpp>
+#include <async_queue.hpp>
+
+#pragma once
+
+namespace cpu {
+
+/// Wraps the async_queue class
+class queue {
+public:
+ queue()
+ : sync_calls( getEnvVar("AF_SYNCHRONOUS_CALLS") == "1") {}
+
+ template <typename F, typename... Args>
+ void enqueue(const F func, Args... args) {
+
+ if(sync_calls) { func( args... ); }
+ else { aQueue.enqueue( func, args... ); }
+ }
+ void sync() {
+ if(!sync_calls) aQueue.sync();
+ }
+
+ bool is_worker() const {
+ return (!sync_calls) ? aQueue.is_worker() : false;
+ }
+
+private:
+ const bool sync_calls;
+ async_queue aQueue;
+};
+
+}
diff --git a/src/backend/cuda/CMakeLists.txt b/src/backend/cuda/CMakeLists.txt
index bb8fca0..ee7b86f 100644
--- a/src/backend/cuda/CMakeLists.txt
+++ b/src/backend/cuda/CMakeLists.txt
@@ -178,6 +178,7 @@ FILE(GLOB c_headers
)
FILE(GLOB c_sources
+ "../../util.cpp"
"../../api/c/*.cpp"
)
diff --git a/src/backend/cuda/debug_cuda.hpp b/src/backend/cuda/debug_cuda.hpp
index 084d12f..f542495 100644
--- a/src/backend/cuda/debug_cuda.hpp
+++ b/src/backend/cuda/debug_cuda.hpp
@@ -51,8 +51,12 @@
#else
-#define POST_LAUNCH_CHECK() do { \
- CUDA_CHECK(cudaPeekAtLastError()); \
- } while(0) \
+#define POST_LAUNCH_CHECK() do { \
+ if(cuda::synchronize_calls()) { \
+ CUDA_CHECK(cudaStreamSynchronize(cuda::getStream(cuda::getActiveDeviceId()))); \
+ } else { \
+ CUDA_CHECK(cudaPeekAtLastError()); \
+ } \
+ } while(0) \
#endif
diff --git a/src/backend/cuda/platform.cpp b/src/backend/cuda/platform.cpp
index 76b336c..a263bea 100644
--- a/src/backend/cuda/platform.cpp
+++ b/src/backend/cuda/platform.cpp
@@ -21,6 +21,7 @@
#include <cstdio>
#include <cstring>
#include <err_cuda.hpp>
+#include <util.hpp>
using namespace std;
@@ -393,6 +394,11 @@ void sync(int device)
setDevice(currDevice);
}
+bool synchronize_calls() {
+ static bool sync = getEnvVar("AF_SYNCHRONOUS_CALLS") == "1";
+ return sync;
+}
+
}
af_err afcu_get_stream(cudaStream_t* stream, int id)
diff --git a/src/backend/cuda/platform.hpp b/src/backend/cuda/platform.hpp
index 7b64968..20862fb 100644
--- a/src/backend/cuda/platform.hpp
+++ b/src/backend/cuda/platform.hpp
@@ -50,6 +50,9 @@ int setDevice(int device);
void sync(int device);
+// Returns true if the AF_SYNCHRONIZE_CALLS environment variable is set to 1
+bool synchronize_calls();
+
cudaDeviceProp getDeviceProp(int device);
struct cudaDevice_t {
diff --git a/src/backend/opencl/CMakeLists.txt b/src/backend/opencl/CMakeLists.txt
index 86ba1b2..223752c 100644
--- a/src/backend/opencl/CMakeLists.txt
+++ b/src/backend/opencl/CMakeLists.txt
@@ -152,6 +152,7 @@ FILE(GLOB backend_headers
)
FILE(GLOB backend_sources
+ "../../util.cpp"
"../*.cpp"
)
source_group(backend\\Headers FILES ${backend_headers})
diff --git a/src/backend/opencl/debug_opencl.hpp b/src/backend/opencl/debug_opencl.hpp
index 74b3f7c..b4126f9 100644
--- a/src/backend/opencl/debug_opencl.hpp
+++ b/src/backend/opencl/debug_opencl.hpp
@@ -16,5 +16,10 @@
#include <iostream>
#define CL_DEBUG_FINISH(Q) Q.finish()
#else
-#define CL_DEBUG_FINISH(Q)
+#define CL_DEBUG_FINISH(Q) \
+ do { \
+ if(synchronize_calls()) { \
+ Q.finish(); \
+ } \
+ } while (false);
#endif
diff --git a/src/backend/opencl/kernel/convolve.hpp b/src/backend/opencl/kernel/convolve.hpp
index 035f4c2..6d1d7de 100644
--- a/src/backend/opencl/kernel/convolve.hpp
+++ b/src/backend/opencl/kernel/convolve.hpp
@@ -52,6 +52,7 @@ void convolve_nd(Param out, const Param signal, const Param filter, ConvolveBatc
case 3: conv3<T, accType, expand>(param, out, signal, filter); break;
}
+ CL_DEBUG_FINISH(getQueue());
bufferFree(param.impulse);
}
diff --git a/src/backend/opencl/platform.cpp b/src/backend/opencl/platform.cpp
index 1301af9..57726d2 100644
--- a/src/backend/opencl/platform.cpp
+++ b/src/backend/opencl/platform.cpp
@@ -41,6 +41,7 @@
#include <map>
#include <errorcodes.hpp>
#include <err_opencl.hpp>
+#include <util.hpp>
using std::string;
using std::vector;
@@ -556,6 +557,11 @@ void removeDeviceContext(cl_device_id dev, cl_context ctx)
}
}
+bool synchronize_calls() {
+ static bool sync = getEnvVar("AF_SYNCHRONOUS_CALLS") == "1";
+ return sync;
+}
+
}
using namespace opencl;
diff --git a/src/backend/opencl/platform.hpp b/src/backend/opencl/platform.hpp
index 154d84b..84cb7b8 100644
--- a/src/backend/opencl/platform.hpp
+++ b/src/backend/opencl/platform.hpp
@@ -115,4 +115,6 @@ void removeDeviceContext(cl_device_id dev, cl_context ctx);
void sync(int device);
+bool synchronize_calls();
+
}
diff --git a/src/util.cpp b/src/util.cpp
new file mode 100644
index 0000000..5607292
--- /dev/null
+++ b/src/util.cpp
@@ -0,0 +1,40 @@
+/*******************************************************
+ * Copyright (c) 2016, ArrayFire
+ * All rights reserved.
+ *
+ * This file is distributed under 3-clause BSD license.
+ * The complete license agreement can be obtained at:
+ * http://arrayfire.com/licenses/BSD-3-Clause
+ ********************************************************/
+
+/// This file contains platform independent utility functions
+#include <string>
+#include <cstdlib>
+
+#if defined(OS_WIN)
+#include <Windows.h>
+typedef HMODULE LibHandle;
+#else
+#include <dlfcn.h>
+#endif
+
+using std::string;
+
+string getEnvVar(const std::string &key)
+{
+#if defined(OS_WIN)
+ DWORD bufSize = 32767; // limit according to GetEnvironment Variable documentation
+ string retVal;
+ retVal.resize(bufSize);
+ bufSize = GetEnvironmentVariable(key.c_str(), &retVal[0], bufSize);
+ if (!bufSize) {
+ return string("");
+ } else {
+ retVal.resize(bufSize);
+ return retVal;
+ }
+#else
+ char * str = getenv(key.c_str());
+ return str==NULL ? string("") : string(str);
+#endif
+}
diff --git a/src/backend/opencl/debug_opencl.hpp b/src/util.hpp
similarity index 59%
copy from src/backend/opencl/debug_opencl.hpp
copy to src/util.hpp
index 74b3f7c..e1cd85a 100644
--- a/src/backend/opencl/debug_opencl.hpp
+++ b/src/util.hpp
@@ -1,5 +1,5 @@
/*******************************************************
- * Copyright (c) 2014, ArrayFire
+ * Copyright (c) 2016, ArrayFire
* All rights reserved.
*
* This file is distributed under 3-clause BSD license.
@@ -7,14 +7,10 @@
* http://arrayfire.com/licenses/BSD-3-Clause
********************************************************/
+/// This file contains platform independent utility functions
+
+#include <string>
+
#pragma once
-#include <err_opencl.hpp>
-#include <stdio.h>
-#include <errorcodes.hpp>
-#ifndef NDEBUG
-#include <iostream>
-#define CL_DEBUG_FINISH(Q) Q.finish()
-#else
-#define CL_DEBUG_FINISH(Q)
-#endif
+std::string getEnvVar(const std::string &key);
--
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