clear mex causes segmentation fault when using cuda RT API
显示 更早的评论
Hi all,
I have a mex function with CUDA code in it so that I can take advantage of my Quadro 4000 gpu (Driver version 4.2 / Runtime version 4.2) on my 64-bit linux machine.
Any time I make any call to a CUDA Runtime API function (cudaMalloc, cudaMemset, cudaMemcpy, etc.), I get a segmentation fault if I clear mex (or clear all).
Here is my simple .cu code:
#include "mex.h"
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
// Allocate and free one float on GPU memory
float *a = NULL;
cudaMalloc((void **)a, sizeof(float));
cudaFree(a);
// cudaDeviceReset();
}
After compiling the .cu to .cpp using nvcc and then making myMexFunction.mexa64 with mex, I call my function in MATLAB2012a:
>> myMexFunction;
>> clear all
>> Segmentation fault (core dumped)
One workaround I've found is calling "cudaDeviceReset()" at the end of my mex function. It doesn't seem like resetting the device every time I call my function should be necessary though.
Interestingly, calls to the Driver API have no such issues.
Has anyone encountered this before?
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 GPU CUDA and MEX Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!