从网上抄来的几个处理错误的宏
// 应该是因为定义在了头文件里,所以用了static static void HandleError( cudaError_t err, const char *file, int line ) { if (err != cudaSuccess) { printf( "%s in %s at line %d\n", cudaGetErrorString( err ), file, line ); exit( EXIT_FAILURE ); } } #define HANDLE_ERROR( err ) (HandleError( err, __FILE__, __LINE__ )) #define HANDLE_NULL( a ) {if (a == NULL) { \ printf( "Host memory failed in %s at line %d\n", \ __FILE__, __LINE__ ); \ exit( EXIT_FAILURE );}}
// check cuda error inline void check(cudaError_t call, const char* file, const int line) { if (call != cudaSuccess) { std::cout << "cuda error: " << cudaGetErrorName(call) << std::endl; std::cout << "at file: " << file << ", line: " << line << std::endl; std::cout << cudaGetErrorString(call) << std::endl; } } #define CHECK(call) (check(call, __FILE__, __LINE__))