Memory leaks in simple MEX function
2 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
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
参考
カテゴリ
Help Center および File 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!