我编写了我从MATLAB MEX文件中调用的CUDA代码 . 我没有使用任何MATLAB的GPU库或功能 . 我的代码只是接受C类型变量的CUDA代码而我只使用mex将 mwtypes 转换为C类型,然后调用独立的自编写CUDA代码 .
问题是,有时候,特别是在开发阶段,CUDA失败了(因为我犯了一个错误) . 大多数CUDA调用通常都被 gpuErrchk(cudaDoSoething(cuda)) ,defined as调用:
// Uses MATLAB functions but you get the idea.
#define gpuErrchk(ans) { gpuAssert((ans), __FILE__, __LINE__); }
inline void gpuAssert(cudaError_t code, const char *file, int line, bool abort=true)
{
if (code != cudaSuccess)
{
mexPrintf("GPUassert: %s %s %d\n", cudaGetErrorString(code), file, line);
if (abort){
//cudaDeviceReset(); //This does not make MATLAB release it
mexErrMsgIdAndTxt("MEX:myfun", ".");
}
}
}
虽然这可以按预期工作,但是会出现错误
GPUassert:遇到非法内存访问somefile.cu 208
在大多数情况下,MATLAB之后不会发布GPU . 这意味着即使我更改代码并重新编译,下一次调用代码也会导致错误:
GPUassert:所有支持CUDA的设备都忙或不可用somefile.cu firs_cuda_line
消除此错误的唯一方法是重新启动MATLAB . 这只是令人烦恼并阻碍了开发/测试过程 . 这不是我在开发Visual Studio时发生的事情 .
在错误提出之前和之后我都试过 cudaDeviceReset() ,但无济于事 .
What can I do/try to make MATLAB release the GPU after a GPU runtime error?