blob: 6dc7e9484d8d8725dd2d045c6be79f6d009d223f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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
|