Is there a way to run this loop in gpu and will it consume lesser time compared to parallel cpu computation time?

N=50;
for n=1:8
b=rand(300,103);
w=rand(300,1);
[Q,R]=qr(b,0);
A(:,:,n);=R
end

댓글 수: 8

I don't want to put this as an answer to your question because it might seem like an obvious point: have you tried using gpuArray data to see if things go faster? Something as simple as b=rand(300,103,'gpuArray') would get you started.
First place...is the code working ?
Yeah, at final step we converted A to 3d array back to 2d array. Gpu Array direct usage is little slow since the loop above mentioned, contains for-loop to compute multiplication of every column of matrix A.
But you're not doing a multiplication, you're doing a QR decomposition. Decomposing a 300-by-103 matrix should be sufficient computation that you get an advantage using the GPU, even when you're doing it 8 times.
yes, you are right but i have code like this now
D=rand(300,52)+i*rand(300,52);
B =rand(300,36);
F=rand(300,36)+i*rand(300,36);
A=zeros(300,103);
for n=1:36
for m=1:52
A(1:300,m)=B(1:300,n).*D(1:300,m);
end
for m=1:51
A(1:300,52+m)=-B(1:300,n).*D(1:300,m).*F(1:300,n).';
end
A=[real(A);imag(A)];
[Q,R]=qr(A,0);
AA(:,:,n)=R
end
I am not sure what should be done in this case, eventhough i do a gpuarray its taking a same time to that of the normal cpu . Is there a way to compute the whole main for loop in one shoot in gpu ?
Okay, well this
for m=1:52
A(1:300,m)=B(1:300,n).*D(1:300,m);
end
is equivalent to this
A = B(1:300,n).*D;
If you have enough memory you could even vectorize the outer loop since this
for n=1:36
for m=1:52
A(1:300,m)=B(1:300,n).*D(1:300,m);
end
end
is equivalent to this
A = reshape(B,size(B,1),1,size(B,2)) .* D;
and then you'd access A page-by-page, like
[Q,R] = qr(A(:,:,n),0);
Could I be able to access it at once, instead of using page by page
%code
for n=1:36
[Q(:,:,n),R(:,:,n)]=qr(A2(:,:,n),0);
end
I wanted this to happen without for loop. Here A2, is 600*103*36,
R needs to be of the size 103*103*36 and
Q of the size 600*103*36
Any answer would be appreciated. Kindly do reply

댓글을 달려면 로그인하십시오.

답변 (1개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2018년 3월 20일

댓글:

2018년 4월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by