Loop with GPU arrayfun

7 次查看(过去 30 天)
Maxime Rivard
Maxime Rivard 2017-12-21
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 个评论
Walter Roberson
Walter Roberson 2017-12-22
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.

请先登录,再进行评论。

采纳的回答

Matt J
Matt J 2017-12-22
The code runs fine for me. Try restarting MATLAB and/or the computer.
  10 个评论
Hoang Nguyen
Hoang Nguyen 2018-1-8
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
Joss Knight 2018-1-16
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 GPU Computing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by