Memory leaks in simple MEX function

2 ビュー (過去 30 日間)
Ayal
Ayal 2013 年 8 月 15 日
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):
#include "mex.h"
#include "gpu/mxGPUArray.h"
void mexFunction(int nlhs, mxArray *plhs[],
int nrhs, mxArray const *prhs[])
{
mxInitGPU();
const mxGPUArray * inp=mxGPUCreateFromMxArray(prhs[0]);
const mxGPUArray * ms=mxGPUCreateFromMxArray(prhs[1]);
const double * inpPtr=(const double*) mxGPUGetDataReadOnly(inp);
const double * masksPtr=(const double*) mxGPUGetDataReadOnly(ms);
mxGPUArray * out=mxGPUCopyFromMxArray(prhs[2]);
double * outPtr=(double* ) mxGPUGetData(out);
plhs[0] = mxGPUCreateMxArrayOnGPU(out);
mxGPUDestroyGPUArray(inp);
mxGPUDestroyGPUArray(ms);
mxGPUDestroyGPUArray(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]);
dumdum=MexMemoryTrack(foo2,foo3,foo);
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.
  2 件のコメント
Jill Reese
Jill Reese 2013 年 8 月 15 日
What version of MATLAB are you using?
Ayal
Ayal 2013 年 8 月 15 日
2013a

サインインしてコメントする。

回答 (1 件)

Jill Reese
Jill Reese 2013 年 8 月 16 日
編集済み: Jill Reese 2013 年 8 月 16 日
There is a known memory leak in R2013a only. If possible, I would apply the patch associated with external bug report 954239 to see if it helps in your situation.
Best,
Jill
  1 件のコメント
Ayal
Ayal 2013 年 8 月 27 日
Sadly, this did not solve the problem. I deleted my own answer because it was way off. So far it seems to me like Matlab just doesn't clear the GPU memory when it's overwritten. This is a problem similar to one I've read about - when calling Matlab functions from within a MEX, memory isn't overwritten, but re-allocated.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGPU 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