Unavoidable memory leaks in MEX
이전 댓글 표시
I'm trying to write a MEX running some CUDA code (can't use feval). Unfortunately, no matter what I do, I can't avoid the memory leaks.
I give, as a parameter to the function, a gpuArray of 0-s. I tried making the prhs non-constant, so I could overwrite it:
double * outPtr=(double* ) mxGetData(prhs[2]);
The data is a gpuArray, so It should be stored on the GPU, but when I pass outPtr as a parameter to a CUDA kernel, I get an error (CUDA-related).
so, overwriting didn't work, I tried:
mxGPUArray * tmp=mxGPUCopyFromMxArray(prhs[2]);
double * outPtr=(double* ) mxGPUGetData(tmp);
and then
plhs[0]=mxGPUCreateMxArrayOnGPU(tmp);
which causes memory leaks on the GPU. I suspect the memory on the GPU isn't freed later when I clear/overwrite the variable in plhs[0].
I tried many things, but none of them solved this problem. I even tried making a persistent variable "out", and destroying it at the beginning of the MEX code (I figured maybe if I explicitly told MATLAB to clear it, instead of expecting MATLAB to clear it as soon as I overwrite it). But it seems mxArrayDestroy doesn't clear memory on GPU.
So, Is there ANY way for me to free the space stored in plhs[0] when I'm done with it?
I am using MATLAB 2013a
댓글 수: 3
Jill Reese
2013년 8월 26일
Ayal, you asked a very similar question recently and I suggested that you try applying the patch for a known memory leak with GPU computing in R2013a. Was that one of the things that you tried which didn't work?
Best,
Jill
Ayal
2013년 8월 26일
Ayal
2013년 8월 27일
답변 (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!