Code optimization with GPU

조회 수: 1 (최근 30일)
POHL Michel
POHL Michel 2021년 1월 16일
댓글: Joss Knight 2021년 1월 16일
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