I wrote a mex function and noticed that every time I run it, more and more memory disappears from my GPU, even though I overwrite the previous results every time. In my attempts find the source of the problem, I wrote the following code (file is called MexMemoryTrack):
void mexFunction(int nlhs, mxArray *plhs,
int nrhs, mxArray const *prhs)
const mxGPUArray * inp=mxGPUCreateFromMxArray(prhs);
const mxGPUArray * ms=mxGPUCreateFromMxArray(prhs);
const double * inpPtr=(const double*) mxGPUGetDataReadOnly(inp);
const double * masksPtr=(const double*) mxGPUGetDataReadOnly(ms);
mxGPUArray * out=mxGPUCopyFromMxArray(prhs);
double * outPtr=(double* ) mxGPUGetData(out);
plhs = mxGPUCreateMxArrayOnGPU(out);
I run it using:
foo=gpuArray.zeros([3 3 10000 18]);
foo2=gpuArray.randn([7 7 10000 20]);
foo3=gpuArray.randn([5 5 18 20]);
if I put this code in a loop, all my memory ends up disappearing and I get an "out of memory" error. I can't figure out why. This is a very simple code. I either overwrite data or destroy it using mxGPUDestroyGPUArray.
why would I keep losing memory? clearing dumdum after each execution doesn't help I am using Matlab 2013a and Visual Studio 2010 for compiling.