Code optimization with GPU

2 views (last 30 days)
POHL Michel
POHL Michel on 16 Jan 2021
Commented: Joss Knight on 16 Jan 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;
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

Accepted Answer

Joss Knight
Joss Knight on 16 Jan 2021
Edited: Joss Knight on 16 Jan 2021
I = reshape(gpuArray.eye(q),q,1,q);
U = I.*my_line_vector;

Sign in to comment.

More Answers (0)


Community Treasure Hunt

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

Start Hunting!

Translated by