Borrar filtros
Borrar filtros

two - loop with GPU

1 visualización (últimos 30 días)
Anh
Anh el 3 de Abr. de 2013
I just have GPU on my desktop with matlab R2012b I plotted a Gaussian profile using two - loop on CPUas below:
for n=1:1:N
for m=1:1:N
x(n)=n*ds-L/2;
y(m)=m*ds-L/2;
G(n,m)=exp(-((x(n)^2)+(y(m)^2)))/(w^2);
end
end
I read somewhere that GPU does not support index like that, I even tried but it not work either. Is there any way possible to do the same thing on GPU?
Thank so much
  2 comentarios
James Lebak
James Lebak el 5 de Abr. de 2013
It seems like it should be possible to do this on the GPU. Can you tell us what variables were on the GPU, and what happened when it failed to work? Did you receive an error message, or did MATLAB compute an incorrect answer?
Anh
Anh el 15 de Abr. de 2013
All variables were on GPU (N, ds, N). I got the message: Undefined function 'colon' for input arguments of type 'gpuArray' Even one "For loop", if N is on GPU, it not work either. I know there is one way we can deal with "For loop" of an array by using gpuArray.colon.(...), but I have loop inside the loop to create a matrix G(n,m), so I don't know how to solve this problem.

Iniciar sesión para comentar.

Respuestas (1)

James Lebak
James Lebak el 23 de Abr. de 2013
Yes, 1:gpuArray(N) for scalar N doesn't work in MATLAB R2013a. Try the following:
x=gpuArray.colon(1,N)*ds-L/2;
y=gpuArray.colon(1,N)*ds-L/2;
G = exp(-((x.*x).'*gpuArray.ones(1,N)+gpuArray.ones(N,1)*(y.*y)))./(w^2);
This vectorizes the calculation of x and y and calculates all the elements in the matrix at once, which should be much more efficient on the GPU than using a loop.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by