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 Center および File ExchangeGPU Computing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by