MATLAB Answers

Memory issue with eig function and GPU Array

9 views (last 30 days)
cyan on 3 Jun 2019
Commented: 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;
user = memory;
% CPU calculation
mem_cpu = zeros(runs,1);
for idx = 1:runs
[VC_tmp, EC_tmp] = eig(AC(:,:,idx),'vector');
user = memory;
% plot and compare
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.

Accepted Answer

Edric Ellis
Edric Ellis on 4 Jun 2019
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
cyan on 4 Jun 2019
Than you very much. The latest version fix the issue.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!