Unavoidable memory leaks in MEX

1 visualizzazione (ultimi 30 giorni)
Ayal
Ayal il 26 Ago 2013
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 Commenti
Ayal
Ayal il 26 Ago 2013
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 il 27 Ago 2013
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...

Accedi per commentare.

Risposte (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by