Cuda 袖口错误处理
我正在使用以下宏来处理CUFFT错误:Cuda 袖口错误处理,cuda,nvidia,cufft,Cuda,Nvidia,Cufft,我正在使用以下宏来处理CUFFT错误: #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() CUF
#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);
}
}
(注意:在不改变功能的情况下对其进行了一些定制)。这本书说:“这种技术适用于除内核调用之外的所有CUDA调用。”然而,当对CUFT例程调用使用CUDA\u调用时,编译器返回
a value of type "cufftResult" cannot be used to initialize an entity of type "const cudaError_t".
看来cufftResult
和cudaError\t
不能立即兼容
从这个链接进一步研究,似乎cudaGetErrorString
需要cudaError\t
输入类型
我的问题如下:
有没有办法使cufftResult
和cudaError\u t
兼容,这样我就可以在CUFFT例程上使用CUDA\u CALL
并从错误代码接收消息字符串
是否有任何技术原因导致对CUFFT库执行不同的错误?:-)李>
谢谢
根据罗伯特·克罗维拉的回答进行编辑
我已将袖口足球例行程序修改为
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); \
}
}
同时返回错误类型字符串。Cuft不是cuda运行时api的一部分。cufft是一个独立的函数库。因为它是独立的,所以不让Cuft错误枚举依赖于cuda运行时api库是有意义的;这种联系阻碍了模块、代码和库的独立开发
因此,当书中提到CUDA调用时,他们指的是CUDA运行时api,而不是cufft库api
由于枚举值库调用独立于枚举值api(并且大部分与枚举值api正交),因此我认为不可能以任何直接的方式在单个宏中协调这两个集合。由于cuda调用和cufft调用可能会在任何代码中混合使用,因此我想不出一种环保的方法来实现这一点。然而,其他人可能会想出一个聪明的方法
如果您想要一个cufft错误枚举到字符串解析器,那么在/usr/local/cuda/samples/common/inc/helper\u cuda.h
(假设标准linux cuda 5安装)中有一个可能是您感兴趣的。为方便起见,将其粘贴在此处:
#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
\ifdef\u CUFFT\H_
//cuFFT API错误
静态常量字符*_cudaGetErrorEnum(袖套结果错误)
{
开关(错误)
{
成功案例:
返回“CUFFT_SUCCESS”;
案例卡夫图无效:
返回“袖口计划无效”;
案例CUFFT_ALLOC_失败:
返回“CUFFT_ALLOC_失败”;
箱子袖口类型无效:
返回“袖口类型无效”;
case CUFT_无效_值:
返回“CUFFT\u无效值”;
案例袖口内部错误:
返回“CUFFT_内部错误”;
案例CUFFT_EXEC_失败:
返回“CUFFT_EXEC_失败”;
案例袖口安装失败:
返回“袖口安装失败”;
箱子袖口尺寸无效:
返回“袖口尺寸无效”;
案例袖口未对齐数据:
返回“袖口未对齐数据”;
}
返回“”;
}
#恩迪夫
我在项目中使用以下宏:
// 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); \
} \
}
//注意:包括要导入“\u cudaGetErrorEnum(cufftResult错误)”的cufft
#包括
#包括
#定义检查错误(调用){\
袖套结果错误\
如果((错误=(呼叫))!=CUFFT_成功){\
fprintf(标准,“袖口错误%d:%s在%s:%d\n”,错误,_cudaGetErrorEnum(错误)\
__文件(行)\
出口(1)\
} \
}
非常感谢您的回答。我已经相应地更新了我的帖子。你觉得怎么样?谢谢
// 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); \
} \
}