MATLAB Answers

Obtain memory usage and class for GPU variable

21 ビュー (過去 30 日間)
Peter 2016 年 5 月 2 日
回答済み: Matt J 2021 年 3 月 1 日
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.:
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.


Edric Ellis
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;
bytesPerElem = str2double(regexprep(dataType, '[a-z]', '')) / 8;
if ~isreal(A)
bytesPerElem = 2 * bytesPerElem;
totalBytes = bytesPerElem * numel(A);
  1 件のコメント
Peter 2016 年 5 月 3 日
Thanks Edric!


その他の回答 (1 件)

Community Treasure Hunt

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

Start Hunting!

Translated by