필터 지우기
필터 지우기

How to improve code for gpu?

조회 수: 1 (최근 30일)
Mantas Vaitonis
Mantas Vaitonis 2018년 6월 16일
댓글: Mantas Vaitonis 2018년 6월 17일
Hello everybody. I am bit struggling with the following function for removing duplicate pairs when there is signal for the pair. I would like to move this function to GPU in order not to use for loop. The code is here:
if true
% code
end
clear;
tic
p1=[5 4 1 2 1]; idx2=[1 2 4 5];n3=[1 2 3 4 5];
p=gpuArray(p1);
idx=gpuArray(idx2);
n=gpuArray(n3);
[m,n2]=size(p);
t=p(p);
otherIdx=ones(size(idx),'gpuArray');
otherIdx1=otherIdx;
idx1=idx;
c=p(p);
for i=1:n2
if (c(i)==4)
k(i)=any(p(i)==idx1);
k1(i)=any(c(i)==idx1);
k2(i)=any(otherIdx1((c(i)==idx1)));
[idxx,otherIdxx]=arrayfun(@testas,k,k1,k2);
end
if any(p(i)==idx)
if any(c(i)==idx)
if otherIdx((c(i)==idx))==1
idx(c(i)==idx)=NaN;
otherIdx(p(i))=0;
% end
end
end
end
end
idx
toc
//////////////////////
function [idxx,otherIdxx]=testas(k,k1,k2)
if k==1
if k1==1
if k2==1
idxx=NaN;
otherIdxx=0;
end
end
end
end
Is arrayfun suitable for this case?
  댓글 수: 1
Mantas Vaitonis
Mantas Vaitonis 2018년 6월 17일
Nevermind, did find the solution by myself :)

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 GPU Computing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by