curfil  ..
 All Classes Functions Variables Typedefs Friends Groups Pages
cuda_general.hpp
1 #ifndef __CUV_GENERAL_HPP__
2 #define __CUV_GENERAL_HPP__
3 
4 #include <cuda_runtime_api.h>
5 #include <stdexcept>
6 
7 #ifndef CUDA_TEST_DEVICE
8 # define CUDA_TEST_DEVICE 0
9 #endif
10 
11 namespace cuv {
12 
16 static inline void checkCudaError(const char *msg) {
17  cudaError_t err = cudaGetLastError();
18  if (cudaSuccess != err) {
19  throw std::runtime_error(std::string(msg) + ": " + cudaGetErrorString(err));
20  }
21 }
22 
23 // use this macro to make sure no error occurs when cuda functions are called
24 #ifdef NDEBUG
25 # define cuvSafeCall(X) \
26  if(strcmp(#X,"cudaThreadSynchronize()")!=0){ X; cuv::checkCudaError(#X); }
27 #else
28 # define cuvSafeCall(X) X; cuv::checkCudaError(#X);
29 #endif
30 
31 }
32 
33 #endif