I need to do this without for loop(For Gpu computing)

조회 수: 1 (최근 30일)
Srinidhi Ganeshan
Srinidhi Ganeshan 2018년 3월 31일
댓글: Srinidhi Ganeshan 2018년 4월 2일
I have these two problems in gpu computing in matlab
Suppose X=600*103*36 array
for n=1:36
[Q(:,:,n),R(:,:,n)]=qr(X(:,:,n));
end
I want to access all the pages at once for gpu computing. Is there a way to do ?
Problem 2:
From the above result,
suppose w is 600*36 matrix
for n=1:36
R1(:,:,n)=transpose(Q(:,:,n) )* w(600,n);
end
I wanted to make this loop without for loop for gpu computing.
Arrays here such as w, X are gpu arrays.
  댓글 수: 2
Srinidhi Ganeshan
Srinidhi Ganeshan 2018년 3월 31일
편집: Srinidhi Ganeshan 2018년 3월 31일
Mr. Walter Roberson, ThankYou for your reply :). But, in the link provided, I have to access Q values page by Page. But I wanted to access it in a stretch without for-loop for GPU Computing. I tried using reshape, pagefun, permute but till now I could not find a solution to do that without for loop.

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

채택된 답변

Joss Knight
Joss Knight 2018년 4월 1일
You can't do this, but I will take it as a further request for pagefun to support qr which will be coming in a future version of MATLAB.
The closest you can get is to form the block-diagonal matrix with your pages of X and solve qr for that. The results will be the equivalent block-diagonal elements of the output. Because your matrices are non-square, you would have to pad the columns with zeros.
function [Q,R] = pagefunQR(X)
m = size(X,1);
n = size(X,2);
p = size(X,3);
maxmn = max(m,n);
A = zeros(maxmn*p,'like',X);
for i = 1:p
strt = (i-1)*maxmn+1;
A(strt:strt+m-1,strt:strt+n-1) = X(:,:,i);
end
[Q, R] = qr(A);
for i = 1:p
strt = (i-1)*maxmn+1;
Q(1:maxmn,strt:strt+maxmn-1) = Q(strt:strt+maxmn-1,strt:strt+maxmn-1);
R(1:maxmn,strt:strt+maxmn-1) = R(strt:strt+maxmn-1,strt:strt+maxmn-1);
end
Q = reshape(Q(1:maxmn,:), maxmn, maxmn, p);
R = reshape(R(1:maxmn,:), maxmn, maxmn, p);
R = R(1:m,1:n,:);
end
Sadly, this approach is slower than just looping like you are doing. Plus it creates a huge pressure on memory.
  댓글 수: 1
Srinidhi Ganeshan
Srinidhi Ganeshan 2018년 4월 2일
Thank you for your answer. But as you said, this is slower approach.

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

추가 답변 (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