Speed of code GPU

1 次查看(过去 30 天)
Tiki Tiki
Tiki Tiki 2018-8-9
评论: Tiki Tiki 2018-8-9
Hi everyone,
Can you help me optimize this code?
clear all
BatchSize = 100;
SP_Size = [32 32];
InputOverlap = rand(SP_Size(1)*SP_Size(2),BatchSize,'gpuArray');
Radius =4;
InputOverlap = reshape(InputOverlap,SP_Size(1),SP_Size(2),size(InputOverlap,2));
test_size2 = size (InputOverlap) ;
test_size = test_size2(1:2);
test_Overlap = InputOverlap;
test = zeros(test_size2,'gpuArray') ;
InputOverlap = [InputOverlap(:,1:Radius,:) InputOverlap InputOverlap(:,end+1-Radius:end,:)];
InputOverlap = [InputOverlap(1:Radius,:,:) ; InputOverlap ; InputOverlap(end+1-Radius:end,:,:) ];
t5 = tic;
parfor r=1:test_size(1)
InputOverlapTemp = InputOverlap;
temp = zeros(1,test_size(1),test_size2(3),'gpuArray');
Kmax = zeros(1,1,test_size2(3),'gpuArray');
for c=1:test_size(1)
Neighbour = InputOverlap(r:r+2*Radius,c:c+2*Radius,:);
Kmax(1,1,:) = max(max(Neighbour)) ;
temp(1,c,:) = ((test_Overlap(r,c,:)>= Kmax));
end
test(r,:,:) = temp;
end
time5 = toc(t5)
even I use GPU, but time simulation still big. Thank.
  1 个评论
Tiki Tiki
Tiki Tiki 2018-8-9
I've already written on CPU, and it takes nearly same time, so I couldnot see any advantage of GPU. in my code, if I donot use parfor, the time is even worse. So can you explain for my why I cannot speed up this code?
Thanks.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by