summaryrefslogtreecommitdiff
path: root/src/CuBaseLib/cucommon.h
diff options
context:
space:
mode:
authorJoe Zhao <ztuowen@gmail.com>2014-04-14 08:14:45 +0800
committerJoe Zhao <ztuowen@gmail.com>2014-04-14 08:14:45 +0800
commitcccccbf6cca94a3eaf813b4468453160e91c332b (patch)
tree23418cb73a10ae3b0688681a7f0ba9b06424583e /src/CuBaseLib/cucommon.h
downloadtnet-cccccbf6cca94a3eaf813b4468453160e91c332b.tar.gz
tnet-cccccbf6cca94a3eaf813b4468453160e91c332b.tar.bz2
tnet-cccccbf6cca94a3eaf813b4468453160e91c332b.zip
First commit
Diffstat (limited to 'src/CuBaseLib/cucommon.h')
-rw-r--r--src/CuBaseLib/cucommon.h46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/CuBaseLib/cucommon.h b/src/CuBaseLib/cucommon.h
new file mode 100644
index 0000000..6dc7e94
--- /dev/null
+++ b/src/CuBaseLib/cucommon.h
@@ -0,0 +1,46 @@
+#ifndef _CUCOMMON_H_
+#define _CUCOMMON_H_
+
+#include <iostream>
+#include <sstream>
+
+#include <cuda_runtime_api.h>
+
+#include "Error.h"
+
+
+
+#define cuSafeCall(fun) \
+{ \
+ int ret; \
+ if((ret = (fun)) != 0) { \
+ std::ostringstream os; \
+ os << "CUDA ERROR #" << ret << " " << __FILE__ ":" << __LINE__ << " " << __func__ << "()" << " '" << #fun << "' " << cudaGetErrorString((cudaError_t)ret); \
+ throw(MyException(os.str())); \
+ } \
+ cudaThreadSynchronize(); \
+}
+
+
+
+
+namespace TNet {
+
+ /** The size of edge of CUDA square block **/
+ static const int CUBLOCK = 16;
+
+ /** Number of blocks in which is split task of size 'size' **/
+ inline int n_blocks(int size, int block_size)
+ { return size / block_size + ((size % block_size == 0)? 0 : 1); }
+
+ /** Printing dim3 output operator **/
+ inline std::ostream& operator<<(std::ostream& os, dim3 arr) {
+ os << "[" << arr.x << "," << arr.y << "," << arr.z << "]";
+ return os;
+ }
+
+}
+
+
+
+#endif