3D gpuArray vs cells of 2D gpuArrays major speed difference!
1 次查看(过去 30 天)
显示 更早的评论
Can anybody explain why these codes have drastically different runtimes?
I have a shared setup routine
clear all
y = gpuArray.rand(1000, 1000, 'single');
W = cell(1, 5);
WFull = gpuArray.zeros(1000, 1000, 5);
for j = 1:5
W{j} = gpuArray.rand(1000, 1000, 'single');
WFull(:,:,j) = W{j};
end
Version 1 (finishes in 1.4 seconds on my machine)
z = gpuArray.zeros(1000, 1000, 5);
tic
for i = 1:1000
for j = 1:size(W)
z(:,:,j) = W{j}*y;
end
end
toc
vs. Version 2 (finishes in 39 seconds on my machine... 27x times slower)
z = gpuArray.zeros(1000, 1000, 5);
tic
for i = 1:1000
for j = 1:size(WFull, 3)
z(:,:,j) = WFull(:,:,j)*y;
end
end
toc
Do you think that slicing large 3D gpuArrays is just really slow compared to looking up cell array values?
0 个评论
采纳的回答
Matt J
2013-5-24
编辑:Matt J
2013-5-24
Do you think that slicing large 3D gpuArrays is just really slow compared to looking up cell array values?
Yes, it is faster to look-up a cell than to pull a slice out of a 3D array, and that's true for normal arrays as well, as long as there is a small number of slices/cells. Of course, you should really be including the time needed to allocate memory to each W{j} in your comparison.
Another reason is that you have a syntax error in your for-loop over W{j}. It's only doing 1 loop iteration instead of 5,
>> for j=1:size(W), j, end
j =
1
This is biasing the comparison to some degree.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!