Borrar filtros
Borrar filtros

for loop and data in GPU memory

2 visualizaciones (últimos 30 días)
Milos
Milos el 7 de Nov. de 2012
If the for loop is parallelizable, does the Parallel Computing Toolbox execute for loop in a parallel fashion when it is acting on data stored in GPU memory?
  2 comentarios
Jill Reese
Jill Reese el 8 de Nov. de 2012
It would be a bit easier to answer your question if you provided some sample code.
Thanks, Jill
Milos
Milos el 8 de Nov. de 2012
Suppose that f is a time-consuming function to compute, and that you want to compute its value on each element of array A and place the corresponding results in array B
A = gpuArray(X);
for i = 1:length(A)
B(i) = f(A(i));
end
Because the loop iteration can occur in parallel, this evaluation could complete much faster if for loop run in parallel on the GPU - in similar fashion like parfor loop is executed. My question is does this happen automatically or for loop is executed in the ordinary non-parallel fashion?

Iniciar sesión para comentar.

Respuesta aceptada

Jill Reese
Jill Reese el 9 de Nov. de 2012
The for loop is not performed in parallel when you write code like this:
A = gpuArray(X);
for i = 1:length(A)
B(i) = f(A(i));
end
However, if your function f contains only elementwise operations, then you could achieve more parallelism by using arrayfun like so:
B = arrayfun(@f, A);

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements 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