Obtain memory usage and class for GPU variable
조회 수: 6 (최근 30일)
이전 댓글 표시
How can I get the amount of memory space (bytes) and the class (single/double/int) of a GPU variable? 'whos' doens't provide what I need. E.g.:
A=rand(1000,gpuArray);
infoA=whos('A');
gives: infoA =
name: 'A'
size: [1000 1000]
bytes: 108
class: 'gpuArray'
global: 0
sparse: 0
complex: 0
nesting: [1x1 struct]
persistent: 0
but i still don't know how many bytes of GPU memory A is taking and whether A is a single / double etc.
댓글 수: 0
채택된 답변
추가 답변 (1개)
Edric Ellis
2016년 5월 3일
편집: Edric Ellis
2016년 5월 3일
Unfortunately, whos only reports the memory usage on the CPU of a gpuArray. For non-sparse gpuArray data, you can compute the number of bytes consumed like so:
dataType = classUnderlying(A);
switch dataType
case 'double'
bytesPerElem = 8;
case 'single'
bytesPerElem = 4;
case 'logical'
bytesPerElem = 1;
otherwise
bytesPerElem = str2double(regexprep(dataType, '[a-z]', '')) / 8;
end
if ~isreal(A)
bytesPerElem = 2 * bytesPerElem;
end
totalBytes = bytesPerElem * numel(A);
참고 항목
카테고리
Help Center 및 File Exchange에서 GPU Computing in MATLAB에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!