Code optimization with GPU

1 visualizzazione (ultimi 30 giorni)
POHL Michel
POHL Michel il 16 Gen 2021
Commentato: Joss Knight il 16 Gen 2021
Hi everyone, I have the following line of codes which I would like to parallelize on the GPU :
U = zeros(q, M, q, 'gpuArray');
for j=1:q
U(j,:,j) = my_line_vector;
end
Is there any way to suppress the loop?
Thes are the lines of code that run the slowest in my program.
Thank you in advance
Michel

Risposta accettata

Joss Knight
Joss Knight il 16 Gen 2021
Modificato: Joss Knight il 16 Gen 2021
I = reshape(gpuArray.eye(q),q,1,q);
U = I.*my_line_vector;
  4 Commenti
POHL Michel
POHL Michel il 16 Gen 2021
Thank you, it works!
I did not know that the element wise product worked with matrices with different size.

Accedi per commentare.

Più risposte (0)

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by