错误检查函数
- 在调用CUDA运行时API时,调用ErrorCheck函数进行包装
- 参数
filename
一般使用__FILE__
;参数lineNumber
一般使用__LINE__
- 错误函数返回运行时API调用的错误代码
1
2
3
4
5
6
7cudaError_t ErrorCheck(cudaError_t error_code, const char* filename, int lineNumber){
if(error_code != cudaSuccess){
printf("CUDA error:\r\ncode=%d, name=%s, description=%s\r\nfile=%s, line=%d\r\n", error_code, cudaGetErrorName(error_code), cudaGetErrorString(error_code), filename, lineNumber);
return error_code;
}
return error_code;
}
检查核函数
捕捉调用核函数可能发生错误的方法:
1 | ErrorCheck(cudaGetLastError(), __FILE__, __LINE__); |