I'm using the following macro for CUFFT error handling:
#define cufftSafeCall(err) __cufftSafeCall(err, __FILE__, __LINE__)
inline void __cufftSafeCall(cufftResult err, const char *file, const int line)
{
if( CUFFT_SUCCESS != err) {
fprintf(stderr, "cufftSafeCall() CUFFT error in file <%s>, line %i.\n",
file, line);
getch(); exit(-1);
}
}
This macro does not return the message string from an error code. The book "CUDA Programming: a developer's guide to parallel computing with GPUs" suggests using the following macro
#define CUDA_CALL(call) { const cudaError_t err = (call); \
if(err != cudaSuccess) \
{ \
fprintf(stderr, "CUDA error in file '%s', line %d\n %s\nerror %d: %s\nterminating!\n",__FILE__, __LINE__,err, \
cudaGetErrorString(err)); \
cudaDeviceReset(); assert(0); \
} }
(note: it has been somewhat customized without altering the functionalities). The book says: "This technique works for all the CUDA calls except for the invocation of kernels." However, when using CUDA_CALL
on a CUFFT routine call, the compiler returns
a value of type "cufftResult" cannot be used to initialize an entity of type "const cudaError_t".
It seems then that cufftResult
and cudaError_t
are not immediately compatible.
Investigating a bit more, from this NVIDIA CUDA Library link, it seems that cudaGetErrorString
requires a cudaError_t
input type.
My questions are the following:
- Is there a way to make
cufftResult
andcudaError_t
be compatible, so that I can useCUDA_CALL
on CUFFT routines and receive the message string from an error code? - Is there any technical reason why implementing a different error for the CUFFT library? :-)
Thanks.
EDIT FOLLOWING ROBERT CROVELLA'S ANSWER
I have modified the CufftSafeCall routine as
inline void __cufftSafeCall(cufftResult err, const char *file, const int line)
{
if( CUFFT_SUCCESS != err) {
fprintf(stderr, "CUFFT error in file '%s', line %d\n %s\nerror %d: %s\nterminating!\n",__FILE__, __LINE__,err, \
_cudaGetErrorEnum(err)); \
cudaDeviceReset(); assert(0); \
}
}
to return also the error type string.