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!