Unavoidable memory leaks in MEX
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu GPU Computing finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!