CUFFT Error Handling

I use the following macro to handle CUFFT errors:

#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 a 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 was somewhat configured without changing the functionality). The book says: "This method works for all CUDA calls, except for kernel calls." However, when using CUDA_CALL when calling the CUFFT routine, the compiler returns

 a value of type "cufftResult" cannot be used to initialize an entity of type "const cudaError_t". 

It seems that cufftResult and cudaError_t not immediately compatible.

Studying a bit more from this channel of the NVIDIA CUDA Library , it seems that cudaGetErrorString requires the input type cudaError_t .

My questions are as follows:

  • Is there a way to make cufftResult and cudaError_t compatible so that I can use CUDA_CALL in CUFFT routines and get the message string from the error code?
  • Is there any technical reason why another error occurs for the CUFFT library? :-)

Thanks.

EDIT AFTER OPENING OF ROBERT CROWELL

I changed the CufftSafeCall procedure 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 an error type string.

+3
source share
2 answers

cufft is not part of the cuda runtime api. cufft is a separate library of functions. Since it is separate, it makes sense not to make cufft error enumerations dependent on the cuda runtime api library; such relationships hinder the independent development of modules, codes, and libraries.

Therefore, when a book mentions CUDA calls, they refer to the runtime of the cuda api, and not to the cufft api library.

Since the enumerated values ​​are returned from cufft , the library calls are independent of the (and mostly orthogonal) enumerated values returned from the cuda runtime , I don’t think it is possible in a simple way to reconcile the two sets in one macro. And since cuda calls and cufft calls can be mixed in any piece of code, I can't think of an ecological way to do this. However, someone may come up with a smart approach.

If you want to list the cufft error for the parser, there is one in /usr/local/cuda/samples/common/inc/helper_cuda.h (assuming you installed the standard Linux CUDA 5), which may be of interest. Paste it here for convenience:

 #ifdef _CUFFT_H_ // cuFFT API errors static const char *_cudaGetErrorEnum(cufftResult error) { switch (error) { case CUFFT_SUCCESS: return "CUFFT_SUCCESS"; case CUFFT_INVALID_PLAN: return "CUFFT_INVALID_PLAN"; case CUFFT_ALLOC_FAILED: return "CUFFT_ALLOC_FAILED"; case CUFFT_INVALID_TYPE: return "CUFFT_INVALID_TYPE"; case CUFFT_INVALID_VALUE: return "CUFFT_INVALID_VALUE"; case CUFFT_INTERNAL_ERROR: return "CUFFT_INTERNAL_ERROR"; case CUFFT_EXEC_FAILED: return "CUFFT_EXEC_FAILED"; case CUFFT_SETUP_FAILED: return "CUFFT_SETUP_FAILED"; case CUFFT_INVALID_SIZE: return "CUFFT_INVALID_SIZE"; case CUFFT_UNALIGNED_DATA: return "CUFFT_UNALIGNED_DATA"; } return "<unknown>"; } #endif 
+3
source

My macro uses the following macro:

 // NOTE: include cufft to import '_cudaGetErrorEnum(cufftResult error)' #include <cufft.h> #include <helper_cuda.h> #define CHECK_CUFFT_ERRORS(call) { \ cufftResult_t err; \ if ((err = (call)) != CUFFT_SUCCESS) { \ fprintf(stderr, "cuFFT error %d:%s at %s:%d\n", err, _cudaGetErrorEnum(err), \ __FILE__, __LINE__); \ exit(1); \ } \ } 
0
source

All Articles