Code optimization with GPU

1 次查看(过去 30 天)
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

采纳的回答

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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 GPU Computing in MATLAB 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by