I need to do this without for loop(For Gpu computing)
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
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.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で GPU Computing in MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!