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 个评论
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.
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Get Started with GPU Coder 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!