Sparse gpuArray accumulation in for-loop
1 view (last 30 days)
Show older comments
I met a problem 'Out of memory' in Sparse gpuArray accumulation in my for-loop.
The following code is in a function. I need to accumulate the result 'KernelCurrent' of every loop into the grobal gpuArray Sparse 'Kernel'. In this function, 'KernelCurrent' is also a gpuArray Sparse and has the same size as 'Kernel'; (Size: 262144×262144)
I have tested all the other line of code in this function, which showed that the 'Out of memory' problem is caused by the operation of addition(accumulation). The storage memories requested for both 'Kernel' and 'KernelCurrent' is exactly less than the 'AvailableMemory' of the gpuDevice.
Kernel = gpuArray(sparse(num_row, num_col))
for
.
.
.
KernelCurrent = Result_oneLoop; % 'KernelCurrent' has the same size as 'Kernel'
Kernel = Kernel + KernelCurrent; % Causing the 'Out of mamory' problem
end
The gpuDevice that I can access:
Are there alternative method of coding for solving this problem ? Thanks in advance!
2 Comments
Accepted Answer
Matt J
on 10 Oct 2019
Edited: Matt J
on 10 Oct 2019
I would guess that your Kernel matrix is becoming less and less sparse as you accumulate until its memory consumption is growing beyond the GPU's capacity. Add the line below and re-run to check.
Kernel = gpuArray(sparse(num_row, num_col))
for
.
.
.
KernelCurrent = Result_oneLoop;
Kernel = Kernel + KernelCurrent;
percent_density=nnz(Kernel)/numel(Kernel)*100, %<---- Add this
end
How large does the percent_density become before the "Out of memory" occurs?
More Answers (0)
See Also
Categories
Find more on GPU Computing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!