Memory issue with eig function and GPU Array

I'm running an iterative simulations in MATLAB where in each iteration the eigenvalue and eigenvector are solved. The result will be applied in the next iteration. SInce the matrix size is quite large (at least 5000x5000 complex number), I'm using the GPU array to accelerate the computation. It allows me gain almost 2 to 3 times of the speed which is great.
However, the memory used by Matlab will continuously increase after each call to "eig" function with GPU array. This does not happen will CPU array. The increment of the memory also scales with the matrix size. And my computer will become out-of-memory in less than 100 iterations that is not practice at all. I have tried to clear every variables and functions possible but the problem persists.
Here is a simplied code to represent the problem:
% create input matrix
mSize = 1000;
runs = 10;
AC = rand(mSize, mSize, runs).*exp(1i*2*pi*rand(mSize, mSize, runs));
AG = gpuArray(AC);
% GPU calculation
mem_gpu = zeros(runs,1);
for idx = 1:runs
[VG_tmp, EG_tmp] = eig(AG(:,:,idx));
clear VG_tmp EG_tmp G;
clear eig;
wait(gpuDevice);
user = memory;
mem_gpu(idx)=user.MemUsedMATLAB;
end
% CPU calculation
mem_cpu = zeros(runs,1);
for idx = 1:runs
[VC_tmp, EC_tmp] = eig(AC(:,:,idx),'vector');
user = memory;
mem_cpu(idx)=user.MemUsedMATLAB;
end
% plot and compare
figure(1);clf;
plot(1:runs,[mem_cpu,mem_gpu],'o-');
As you can see from the code, I have cleared all the gpuarrays as well as the eig function. The figure below is the comparison of the RAM usage after 10 iteration. The red curve is from GPU and the the blue curve is from CPU.
I am using Matlab 2017b and GPU is 'GeForce GTX 1080 Ti'.
The only way to clear this invisible memory is by restarting the Matlab, which I can not afford in this case.
Is it a bug in the eig implementation? Any idea how to fix it? Thank you.

 채택된 답변

Edric Ellis
Edric Ellis 2019년 6월 4일

1 개 추천

Using your reproduction steps, I was able to see the problem using R2017b, but this appears to be fixed in R2019a - so please try that version if you are able to.

댓글 수: 1

cyan
cyan 2019년 6월 4일
Than you very much. The latest version fix the issue.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Parallel Computing에 대해 자세히 알아보기

질문:

2019년 6월 3일

댓글:

2019년 6월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by