Loop with GPU arrayfun
7 views (last 30 days)
Show older comments
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 Comment
Walter Roberson
on 22 Dec 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.
Accepted Answer
Matt J
on 22 Dec 2017
The code runs fine for me. Try restarting MATLAB and/or the computer.
10 Comments
Hoang Nguyen
on 8 Jan 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
on 16 Jan 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.
More Answers (0)
See Also
Categories
Find more on GPU Computing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!