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

3 visualizaciones (últimos 30 días)
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 comentarios
Srinidhi Ganeshan
Srinidhi Ganeshan el 31 de Mzo. de 2018
Editada: Srinidhi Ganeshan el 31 de Mzo. de 2018
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.

Iniciar sesión para comentar.

Respuesta aceptada

Joss Knight
Joss Knight el 1 de Abr. de 2018
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 comentario
Srinidhi Ganeshan
Srinidhi Ganeshan el 2 de Abr. de 2018
Thank you for your answer. But as you said, this is slower approach.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre GPU Computing en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by