gpt4 book ai didi

matlab - 为什么复杂的 Matlab gpuArray 占用的内存是它应该占用的内存的两倍?

转载 作者:太空宇宙 更新时间:2023-11-03 19:36:56 24 4
gpt4 key购买 nike

我注意到大型复杂数组在 GPU 上占用的内存是 CPU 上的两倍。

这是一个最小的例子:

%-- First Try: Complex Single
gpu = gpuDevice(1);
m1 = gpu.FreeMemory;
test = complex(single(zeros(600000/8,1000))); % 600 MByte complex single
whos('test')
test = gpuArray(test);
fprintf(' Used memory on GPU: %e\n', m1-gpu.FreeMemory);

现在我对一个不复杂的两倍大的数组做同样的事情:

%-- Second Try:, Single
gpu = gpuDevice(1);
m1 = gpu.FreeMemory;
test = single(zeros(600000/4,1000)); % 600MB MByte real single
whos('test')
test = gpuArray(test);
fprintf(' Used memory on GPU: %e\n', m1-gpu.FreeMemory);

输出是:

 Name          Size                  Bytes  Class     Attributes    
test 75000x1000 600000000 single complex
Used memory on GPU: 1.200095e+09

Name Size Bytes Class Attributes
test 150000x1000 600000000 single
Used memory on GPU: 6.000476e+08

在 CPU 上,两个数组都是 600MB - 在 GPU 上,复杂数组使用 1.2 GByte。我使用 Matlab 2013a 在两个显卡上对此进行了测试:GeForce GTX 680 和 Tesla K20。

我怎样才能避免这种情况?这是 Matlab 中的错误吗?

最佳答案

这是在 MATLAB central 上回答的.总结一下 MathWorks 开发人员 Edric Ellis 的回答:

  • gpu.FreeMemory 可能不是可用 GPU 内存的准确度量,因为 MATLAB 在使用完内存后不会立即释放内存。 gpu.AvailableMemory 是可用内存的更准确度量。

  • 将复杂数据传入/传出 GPU 仍然需要 2 倍的内存,因为格式转换是在 GPU 上完成的。具体而言,CPU 主机内存中的复数数组以实部/虚部分成 2 个单独的向量存储,而 GPU 设备上的复数数组以交错格式存储。

在 R2017a 上测试,我确认:

  • gpu.FreeMemory 切换到 gpu.AvailableMemory 确实解决了引发原始问题的报告内存使用情况的差异。

  • 使用 8 GB GPU 内存,正在复制...

    • 6 GB 实数组:成功
    • 6 GB 复杂数组:“设备内存不足”错误
    • 6 个独立的 1 GB 复杂数组:成功

关于matlab - 为什么复杂的 Matlab gpuArray 占用的内存是它应该占用的内存的两倍?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22843743/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com