Effacer les filtres
Effacer les filtres

Speed up a for loop by utilizing a gpu

17 vues (au cours des 30 derniers jours)
tiwwexx
tiwwexx le 30 Juin 2022
Réponse apportée : tiwwexx le 30 Juin 2022
Hello, I'm trying to speed up the following for loop
for n=1:size(Q_test,3)
Q_test(:,:,n) = sigma(n) / 2 / mass(n) * Q_in(:,:,n);
end
I tried implementing this with all the above arrays being gpuArrays and running
Q_gpu = arrayfun(@scale_Q,sigmaE_gpu,mass_gpu,Q_gpu,size(Q_gpu,3));
function output = scale_Q(sigma,mass,Q_in,itterations)
output = zeros(size(Q_in),'single');
for n=1:itterations
output(:,:,n) = sigma(n) / 2 / mass(n) * Q_in(:,:,n);
end
end
but I get the error
"Error using gpuArray/arrayfun
Arrays have incompatible sizes for this operation."
% Error using gpuArray/arrayfun
% Arrays have incompatible sizes for this operation.
Any help would be appriciated!

Réponse acceptée

tiwwexx
tiwwexx le 30 Juin 2022
This solution was given by Jan here.
Q_gpu = reshape(0.5*sigmaE_gpu./mass_gpu,1,1,size(sigmaE_gpu,1)).*Q_gpu;

Plus de réponses (0)

Catégories

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

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by