Effacer les filtres
Effacer les filtres

How to improve code for gpu?

1 vue (au cours des 30 derniers jours)
Mantas Vaitonis
Mantas Vaitonis le 16 Juin 2018
Commenté : Mantas Vaitonis le 17 Juin 2018
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 commentaire
Mantas Vaitonis
Mantas Vaitonis le 17 Juin 2018
Nevermind, did find the solution by myself :)

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur GPU Computing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by