Unavoidable memory leaks in MEX

조회 수: 3 (최근 30일)
Ayal
Ayal 2013년 8월 26일
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
Ayal
Ayal 2013년 8월 26일
Jill - I asked a little bit more here (for a possible alternative), but you are correct - the questions are very similar. I didn't notice your answer (and come to think of it, it's likely I accidentally thought the e-mail update I got was about my own answer). I will try to have someone apply the patch (i'm using a computer in the university...) This doesn't look like the problem I've been having (the error for being out of memory seems different - like the memory problem is not with the GPU's memory, but is brought on by the use of the GPU)
But i'll give it a try. Thanks!
Ayal
Ayal 2013년 8월 27일
Unfortunatly, that didn't help, altough I had the exact version (6.2) of the parallel computing toolbox, so I guess someone might benefit from it...

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile 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!

Translated by