Memory increases on GPU while performing modification inplace

조회 수: 4 (최근 30일)
rinkert
rinkert 2021년 9월 21일
댓글: rinkert 2021년 10월 12일
When I allocate squeeze a 3D array to output a 2D array, my memory is increasing while I think I performing the modification inplace. That way I would expect that since the number of elements in the array does not incease, the memory used on the GPU does not increase.
However, I see something different in the task manager. What is going on?
  • MATLAB Version: 9.8.0.1538580 (R2020a) Update 6
  • Operating System: Microsoft Windows 10 Enterprise Version 10.0 (Build 18363)
  • NVidia GeForce RTX 3090
data = zeros(5632000, 128, 2, 'int16');
testSO(data);
function testSO(RF)
whos RF % int16 2.75 GB
size(RF); % 5632000x128x2
% GPU memory at beginning 1.2 GB
RF = gpuArray(RF); % 3.9 GB
RF = squeezingSuperFrames(RF); % 6.6 GB
end
function RF = squeezingSuperFrames(RF)
% concatenate pages of 3D array to create tall RF array
RF = reshape(permute(RF, [1 3 2]), [], size(RF, 2), 1);
end

답변 (2개)

Joss Knight
Joss Knight 2021년 10월 10일
MATLAB cannot perform this operation in place because data is a workspace variable. MATLAB has no way of knowing there won't be an error or user interrupt (Ctrl-C) during execution, so it takes a copy of data to ensure your workspace would not be corrupted.
  댓글 수: 3
Joss Knight
Joss Knight 2021년 10월 11일
Good point, I wasn't paying proper attention to when you were moving data to the GPU. As Matt points out, your culprit is permute.
MATLAB may be still holding onto the memory, but only because it is pooled, it is not preventing its use. This is a performance optimization. You can see that this memory is available for use by other MATLAB variables and operations by inspecting the AvailableMemory property in the output of gpuDevice.
rinkert
rinkert 2021년 10월 12일
Thanks for the pointer to AvailableMemory, that indeed showed that there is still memory available while nvidia-smi shows it up as in use.

댓글을 달려면 로그인하십시오.


Matt J
Matt J 2021년 10월 10일
reshape() does not result in data copying, but permute() does. It cannot be done in place, because it is reordering the data in memory.
  댓글 수: 3
Matt J
Matt J 2021년 10월 10일
편집: Matt J 2021년 10월 10일
The memory should be freed after the function call is complete. On my GPU (GTX 1080 Ti), this is what occurs. Maybe you should reset your GPU or even reboot the system to make sure your GPU didn't get stuck in some weird state.
rinkert
rinkert 2021년 10월 12일
yes indeed the memory is freed after the function call is completed. Seems like the memory is already available before, if I look at g=gpuDevice(); g.AvailableMemory before the function exits.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by