'Out of memory on device' error for GPU
40 views (last 30 days)
When trying to replace a value in an existing large GPU array A, e.g. like this:
I get the error:
"Error using gpuArray/subsasgn
Out of memory on device. To view more detail about available memory on the GPU, use 'gpuDevice()'. If the problem persists, reset the GPU by calling 'gpuDevice(1)'."
I don't understand since I would not expect any additional GPU memory required for this operation. However, some closer investigation revealed that the amount of free GPU memory to enable even the simple operation above is roughly equal to the memory taken by A itself.
In cases like this, working with large variables, this means that at all times a huge chunk of GPU memory needs to remain available. Quite inefficient. Any explanation / solution for this issue would be very welcome, thanks!
I'm using Matlab 2016a
Here's the output from gpuDevice:
Name: 'Tesla K20c'
MaxThreadBlockSize: [1024 1024 64]
MaxGridSize: [2.1475e+09 65535 65535]
Edric Ellis on 3 May 2016
Edited: Edric Ellis on 3 May 2016
This behaviour is related to what MATLAB calls "in-place optimization". There's some background in this entry in Loren's blog. Basically, MATLAB treats assignment of the form:
A(x) = B;
as equivalent to a function call a bit like this:
A = subsasgn(A, substruct('()', x), B);
To avoid duplicating A, the in-place optimization must take place. Unfortunately, this doesn't happen when executing the commands at the command-line, but it does happen inside functions. So, for example, on my GPU device which has 6GB of RAM, the following two commands error at the command-line, but succeed inside a function:
A = gpuArray.zeros(1, 2e9, 'uint16');
A(1) = 2;