卸载使用CUDA内存的mex文件时,MATLAB崩溃 [英] MATLAB crashes when unloading mex file which has used CUDA memory

查看:289
本文介绍了卸载使用CUDA内存的mex文件时,MATLAB崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我使用一个使用CUDA的matlab(Linux 64bit)中的MEX文件。代码编译和执行很好,但是当我想卸载mex(例如重新编译它或matlab退出时),matlab立即崩溃,没有任何消息和空转储。



我可以把它减少到最小的工作示例:



MEX cpp文件:

  #include< stdint.h> 
#includemex.h

externCvoid cudaTest();

void mexFunction(
int nlhs,mxArray * plhs [],
int nrhs,const mxArray * prhs [])
{
cudaTest ;
}

CUDA使用NVCC编译的文件:

  void cudaTest(){

float * d_test = NULL;
cudaMalloc((void **)& d_test,10000 * sizeof(float));

cudaFree(d_test);
}

虽然我的真实程序总是崩溃,总是可再现。有时它会崩溃有时不..

解决方案

我认为这解决了我的问题:



http://www.mathworks.de/matlabcentral/answers/45307


I have been trying to figure this out for quite some time.

I use a MEX file in matlab (Linux 64bit) which uses CUDA. The code compiles and executes fine but when I want to unload the mex (e.g. to recompile it or when matlab exits), matlab crashes immediately without any message and with an empty dump.

I was able reduce it to a minimal working example:

MEX cpp File:

#include <stdint.h>
#include "mex.h"

extern "C" void cudaTest();

void mexFunction(
                int nlhs, mxArray *plhs[],
                int nrhs, const mxArray *prhs[])
{
    cudaTest();
}

CUDA File compiled with NVCC:

void cudaTest() {

    float* d_test = NULL;
    cudaMalloc((void**) &d_test, 10000 * sizeof(float));

    cudaFree(d_test);
}

While with my real program it always crashes, with this minimal example it is not always reproducible. Sometimes it does crash sometimes not..

解决方案

I think this solved my problem:

http://www.mathworks.de/matlabcentral/answers/45307

这篇关于卸载使用CUDA内存的mex文件时,MATLAB崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆