【问题标题】:matlab convn function GPU slower than CPU?matlab convn函数GPU比CPU慢?
【发布时间】:2014-08-15 03:48:01
【问题描述】:

我在两个 GPU 上测试 convn:Quadro 6000 和 Titan 都比 cpu 花费更长的时间。

可以在matlab中进行快速测试:

maxloop=1000;
for i=1:maxloop
   output2= convn(rand(320,1), rand([6,1,300]),'full');
end

for i=1:maxloop    
    goutput2= convn(gpuArray.rand(320,1),gpuArray.rand([6,1,300]), 'full');
end

CPU 需要 0.52 秒,Quadro 6000 需要 7 秒,Titan 需要 15 秒以上。

我测试过的内容:

1) 如果将 rand 输入更改为固定的预定义值并不会带来任何改进。

2) 预定义 GPU 输出 (goutput2) 并没有太大帮助。

四驱

泰坦

我确实运行了与第一个答案相同的测试:

Matlab Convolution using gpu

当 m=1000 时得到相同的结果; n=100; k=5;

经过的时间是 2.367453 秒。 %%%%GPU

经过的时间是 27.502952 秒。 %%%%CPU

我的问题是什么以及为什么我自己的测试代码在 GPU 上运行速度较慢?

【问题讨论】:

  • 阅读您链接到的答案,您相对较小的数据大小在 GPU 上无法很好地工作(可能是由于每次运行的设置成本)。
  • 您能否尝试使用this solution. 和此处-Measure and Improve GPU Performance. 中讨论的更可靠的基准测试技术

标签: matlab gpu


【解决方案1】:

乍一看像问题Matlab Convolution using gpu。但是在将数据大小从 [6,1,300] 增加到 [1000,1,1000] 之后,GPU 循环没有任何改善。所以这与数据的“大小”无关。

当我将数据从 [1000,1,1000] 重塑为 [1000,1000] 时,GPU 运行速度更快,CPU 运行速度比之前的测试慢。代码和时序如下:

clear all;

maxloop=1000;

r5=rand(5,1);
r1000=rand([1000,1,1000]); %3d array

for i=1:maxloop   
   cpu_output1= convn(r5, r1000,'full');  %3d cpu array
end

r1000=reshape(r1000,[1000,1000]);
for i=1:maxloop
   cpu_output2= convn(r5, r1000,'full'); %2d cpu array
end

gr5=gpuArray.rand(5,1);
gr1000=gpuArray.rand([1000,1,1000]);

for i=1:maxloop    
    gpu_output1= convn(gr5,gr1000, 'full'); %3d gpu array
end

gr3_1000=reshape(gr1000,[1000,1000]);
for i=1:maxloop    
    gpu_output2= convn(gr5,gr3_1000, 'full'); %2d gpu array
end

【讨论】:

    猜你喜欢
    • 2019-04-18
    • 2012-10-31
    • 2019-11-06
    • 1970-01-01
    • 2015-12-27
    • 1970-01-01
    • 2017-04-05
    • 2012-08-17
    • 1970-01-01
    相关资源
    最近更新 更多