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.
cufft is not part of the cuda runtime api. cufft is a separate library of functions. Since it's separate, it makes sense not to make cufft error enums dependent on the cuda runtime api library; such linkages hamper independent development of modules, codes, and libraries.
So when the book mentions CUDA calls, they are referring to the cuda runtime api, not the cufft library api.
Since the enumerated values returned from cufft library calls are independent of (and mostly orthogonal to) the enumerated values returned from the cuda runtime api, I don't think it's possible in any straightforward way to harmonize the two sets in a single macro. And since cuda calls and cufft calls may be intermingled in any piece of code, I can't think of an environmental way to do it. Someone else may come up with a clever approach, however.
If you want a cufft error enum to string parser, there is one in
/usr/local/cuda/samples/common/inc/helper_cuda.h
(assuming standard linux CUDA 5 install) that may be of interest. Pasting it in here for convenience:I use the following macro in my project: