필터 지우기
필터 지우기

Memory leaks in simple MEX function

조회 수: 1 (최근 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 CenterFile Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by