Loop with GPU arrayfun

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

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.

Sign in to comment.

 Accepted Answer

Matt J
Matt J on 22 Dec 2017

0 votes

The code runs fine for me. Try restarting MATLAB and/or the computer.

10 Comments

MR
MR on 22 Dec 2017
Did you run it multiple times?
Matt J
Matt J on 22 Dec 2017
Edited: Matt J on 22 Dec 2017
About 5 or 6 times. How many times was I supposed to run it?
MR
MR on 22 Dec 2017
Edited: MR on 22 Dec 2017
I get it the first time. What gpu do you have? I have a 1080 ti.
Name: 'GeForce GTX 1080 Ti'
Index: 1
ComputeCapability: '6.1'
SupportsDouble: 1
DriverVersion: 8
ToolkitVersion: 8
MaxThreadsPerBlock: 1024
MaxShmemPerBlock: 49152
MaxThreadBlockSize: [1024 1024 64]
MaxGridSize: [2.1475e+09 65535 65535]
SIMDWidth: 32
TotalMemory: 1.1811e+10
AvailableMemory: 9.7107e+09
MultiprocessorCount: 28
ClockRateKHz: 1582000
ComputeMode: 'Default'
GPUOverlapsTransfers: 1
KernelExecutionTimeout: 1
CanMapHostMemory: 1
DeviceSupported: 1
DeviceSelected: 1
I do not get this the first time on my 650M: I get a response that the GPU has timed out. When you have a GPU device that is shared between graphics and compute usage, then kernels typically have a fairly limited timeout.
The information I find suggests that the GeForce GTX 1080 Ti does not support TCC.
As I have a very powerful card, I don't seem to get the timeout. However, when I loop large matrices, I get
Error using gpuArray.linspace
An unexpected error occurred trying to launch a kernel. The CUDA
error was:
invalid configuration argument
For example, I can run my algorithm (not the one posted) with 1080p frames to the end, but if I run the same algorithm with 4k frames, I invariably get this error at the 191th frame...
I have a Titan X, but I've disabled the timeout.
Timeouts can have some very odd side-effects. When I have timeouts enabled I get a launch failure issue with your code. But when I disable timeouts, I get no problems. So I recommend you try that first. The simplest way is to create a new DWORD registry key called TdrLevel in the appropriate place and set to 0, following the instructions on this page:
Then reboot and try again.
MR
MR on 22 Dec 2017
It solved the issue. Thanks!
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.
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.

Sign in to comment.

More Answers (0)

Categories

Find more on Get Started with GPU Coder in Help Center and File Exchange

Asked:

MR
on 21 Dec 2017

Commented:

on 16 Jan 2018

Community Treasure Hunt

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

Start Hunting!