MATLAB Answers

cyan
1

Memory issue with eig function and GPU Array

Asked by cyan
on 3 Jun 2019
Latest activity Commented on by cyan
on 4 Jun 2019
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.

  0 Comments

Sign in to comment.

1 Answer

Answer by Edric Ellis
on 4 Jun 2019
 Accepted Answer

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 Comment

Than you very much. The latest version fix the issue.

Sign in to comment.