目前由于某种原因cudaMalloc将errno设置为17,尽管返回了cudaSuccess。我一直在搜索互联网,但我的谷歌foo并没有给我带来任何启示,所以我决定要求堆栈溢出的人。
这是我的输出
ERROR: What is not going down, ERRSTR: Success, ERRNO 0
ERROR: What is going on here?, ERRSTR: File exists, ERRNO 17
这是我的代码(至少有一些代码)
//headers
#define CheckError(MESSAGE) do { fprintf(stderr,"ERROR: %s, ERRSTR: %s, ERRNO %i\n",MESSAGE,strerror(errno),errno); } while(0);
#define CudaSafeCall( err ) __cudaSafeCall( err, __FILE__, __LINE__ )
#define ARRAY_LENGTH ( 1000000 )
#define ARRAY_ELEMENT_SIZE ( sizeof(int) )
#define ARRAY_SIZE ( (size_t)ARRAY_ELEMENT_SIZE * ARRAY_LENGTH )
inline void __cudaSafeCall( cudaError err, const char *file, const int line )
{
if ( cudaSuccess != err )
{
fprintf( stderr, "cudaSafeCall() failed at %s:%i : %s\n",
file, line, cudaGetErrorString( err ) );
exit( -1 );
}
return;
}
int main(int argc,char* argv[])
{
..... Other Code ......
int *device_array;
CheckError("What is not going on here.");
CudaSafeCall(cudaMalloc((void**)&device_array,ARRAY_SIZE));
CheckError("What is going on here?");
..... Other Code ......
}
有没有人知道这里会发生什么?现在ARRAY_SIZE设置为4百万,但是当它是400时会出现同样的问题。
答案 0 :(得分:1)
如果前一个函数没有返回任何错误,您似乎假设errno
必须为零。
事实并非如此。
如果前一个功能成功, errno
不需要设置为零。
仅当呼叫的返回值指示错误时,其值才有意义
和
允许成功的函数改变错误。
在您的情况下,上一个函数(无论是什么,在本例中可能是cudaMalloc
或某个由cudaMalloc
库例程调用的系统函数)都是成功的。因此errno
变量的内容并不重要。