Memory leak occurring when repeatedly performing matrix left division on GPU

7 visualizaciones (últimos 30 días)
Im working on a project that at its core relies on peforming many matrix left division operations in a regression problem. In order improve the speed of the program I have been attempting to get this matrix left division to run on the GPU. However whenever I peform this operation my local memory begins to rapidly fill until the system runs out of memory and matlab crashes. The GPUs (NVIDIA GeForce RTX 3060 Laptop GPU) memory however is unaffected. The code that I'm trying to run is effectively as follows (this code causes memory leaks when run on my system):
A=gpuArray(rand(10000,12));
b=gpuArray(rand(10000,1));
for l=1:10000000000000
x=A\b;
end
It should also be noted that the GPU version of my code runs significantly slower than the CPU version.
Any help with this issue would be appreciated, thank you.

Respuesta aceptada

Joss Knight
Joss Knight el 19 de Mayo de 2024
Thank you very much for reporting this. This appears to be a bug in MATLAB's gpuArray support for overdetermined solves. For now you should replace your calls to mldivide with the equivalent use of qr:
[Q,R] = qr(A);
x = R\(Q'*b);
Without knowing exactly why you are calling mldivide repeatedly I can't be sure of other advice, but other strategies might be:
  • If you have multiple right-hand-sides (b) you should solve for them all at once by concatenating them into a single b matrix.
  • If you have multiple system matrices (A) you could use pagemldivide.
  • Use the CPU since it's faster anyway
On a laptop GPU I am not surprised if the GPU is not faster than the CPU for double precision, especially when you only have a single right-hand-side. If accuracy is not a big issue for you, you could try solving the problem in single precision instead of double. In double your mobile 3060 GPU is 64x slower than in single.
  1 comentario
Harry
Harry el 20 de Mayo de 2024
Thank you very much this solved the issue, thank you also for the advice in improving program speed.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre GPU Computing en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by