For safe (or error-checked) CUDA calls (to functions like cudaMemcpy
, cudaMalloc
, cudaFree
) we can define a wrapper, something like this:
#define cuSafe(ans) { gpuCuSafe((ans), __FILE__, __LINE__); }
inline void gpuCuSafe(cudaError_t code, const char *file, int line) {
if (code != cudaSuccess) {
fprintf(stderr,
"GPU ERROR: '%s' in file %s (line %d)\n",
cudaGetErrorString(code), /* <----< */
file,
line);
exit(EXIT_FAILURE);
}
}
These CUDA function calls return values of type cudaError_t
. We can call cudaGetErrorString(cudaError_t c)
to get the error string that might provide information to the users and developers of the program (an error string explaining the error is better than an error code).
In the cuRAND API Documentation, they use a similar approach to wrap curand
function calls. curand
functions return values of type curandStatus_t
.
I am looking for a function that return a string representing the returned curandStatus_t
value (could be CURAND_STATUS_INITIALIZATION_FAILED
, CURAND_STATUS_NOT_INITIALIZED
, etc), however, I couldn't find any function like that in the docs.
Just to be clear, what I want to be able to do is create a curandSafe
wrapper (similar to the cuSafe
example above)
#define curandSafe(ans) { gpuCuRandSafe((ans), __FILE__, __LINE__);}
inline void gpuCuRandSafe(curandStatus_t status, const char *file, int line) {
if (status != CURAND_STATUS_SUCCESS) {
fprintf(stderr,
"GPU curand ERROR in file %s (line %d)\n",
/*curandGetStatusString(status)*/ // OR SOMETHING LIKE THAT
file,
line);
exit(EXIT_FAILURE);
}
}
I am thinking about manually implementing it with a switch-case
, but would like to know if there is a built-in function for it, so it takes care of possible, new status codes.