help vectorize code for GPU

조회 수: 2 (최근 30일)
Octavian
Octavian 2015년 4월 5일
편집: Matt J 2015년 4월 5일
Dear All,
I have a for loop code snippet which in essence, involves 2D matrix or elementwise multiplication, and 2D matrix addition, for 2D sheets along the 3rd dimension in 3D double arrays. Here is what I mean:
for i=1:M
A(:,:,i)=B(:,:,i)* C(:,:,i);
D(:,:,i)=E(:,:,i).*F(:,:,i);
G(:,:,i)=H(:,:,i)+I(:,:,i);
end
Besides using parfor, is there a way to vectorize this code for GPU use to speed it (A-I are huge matrices).
Thank you, as always, Octavian

채택된 답변

Matt J
Matt J 2015년 4월 5일
편집: Matt J 2015년 4월 5일
I assume all the arrays shown are gpuArrays. You can use pagefun for creating A
A=pagefun(@mtimes, B,C);
There is also mtimesx ( Download ) on the File Exchange which optimizes this kind of thing for CPU variables.
The remaining operations are already internally vectorized, both for ordinary CPU array variables and gpuArrays. You can just do
D=E.*F;
G=H+I;

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 GPU Computing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by