Clear Filters
Clear Filters

Memory leak occurring when repeatedly performing matrix left division on GPU

24 views (last 30 days)
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):
for l=1:10000000000000
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.

Accepted Answer

Joss Knight
Joss Knight on 19 May 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.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!