Loop with GPU arrayfun
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Maxime Rivard
el 21 de Dic. de 2017
Comentada: Joss Knight
el 16 de En. de 2018
I'm looking at the Matlab example on rendering Fractals with GPUs ( https://www.mathworks.com/help/distcomp/examples/illustrating-three-approaches-to-gpu-computing-the-mandelbrot-set.html ) and it works fine. But I want to loop this, and I get this error:
Error using gpuArray.linspace
An unexpected error occurred trying to launch a kernel. The CUDA
error was:
invalid configuration argument
Error in matlabArrFunLoop (line 11)
x = gpuArray.linspace( xlim(1)/k, xlim(2)/k, gridSize );
What's wrong with looping this code? Thanks
Code:
clear
close all
gridSize = 3000;
xlim = [-0.748766713922161, -0.748766707771757];
ylim = [ 0.123640844894862, 0.123640851045266];
for k=1:1:3
% Setup
tic
k
x = gpuArray.linspace( xlim(1)/k, xlim(2)/k, gridSize );
y = gpuArray.linspace( ylim(1)/k, ylim(2)/k, gridSize );
[xGrid,yGrid] = meshgrid( x, y );
% Calculate
count = arrayfun( @iterFunc,xGrid, yGrid );
% Show
count = gather( count ); % Fetch the data back from the GPU
figure(3)
imagesc( x, y, count )
axis off
toc
end
function count = iterFunc(x0,y0)
maxIterations=5000;
z0 = complex(x0,y0);
z = z0;
count = 1;
while (count <= maxIterations) && (abs(z) <= 2)
count = count + 1;
z = z*z + z0;
end
count = log(count);
end
1 comentario
Walter Roberson
el 22 de Dic. de 2017
I get that message, but first I get
Error using gpuArray/arrayfun
The GPU has timed out. See www.mathworks.com/gputimeout for details about GPU timeouts and how to avoid them.
I have some other things going on with my computer at the moment which might be trying to use some of the GPU cycles. But just in general, gpu can time out if the work it is asked to do takes longer then the kernel hold time that is imposed for GPUs that are not in exclusive mode.
Respuesta aceptada
Matt J
el 22 de Dic. de 2017
The code runs fine for me. Try restarting MATLAB and/or the computer.
10 comentarios
Hoang Nguyen
el 8 de En. de 2018
Hello Joss, is there any problem if we disable timeouts by your suggestion. In fact, I could run any examples utilizing GPU but not so sure about consequences since that registry key is not built-in.
Joss Knight
el 16 de En. de 2018
There is potential for system lock-up if you are using perhaps less rigorous GPU code that may contain bugs. If the graphics card can't draw graphics because it's locked up running some CUDA kernel then to all intents and purposes your system has crashed.
But this is very rarely an issue for most people.
Más respuestas (0)
Ver también
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!