Nested functions with GPU does not support FFT2
显示 更早的评论
I am trying to run a series of spatial ffts for a series of frequencies on the GPU. In order to minimize I/O between C/GPU I am trying to use a nested functions that I can call via arrayfun. However, MATLAB is spitting out an error that fft2 is an "unsupported or unknown function". This only happens when the fft2 is in the nested function, not in the main.
Any ides?
function ps = gpuDemo()
NFFT = 2048;
freq = 100:100:1000;
x = 0:.1:1;
y = 0:.1:1;
[X, Y] = ndgrid(x,y);
% gpu var
freq = gpuArray(freq);
p0 = ones(1,length(freq), 'single','gpuArray');
F = ones(NFFT, 'single','gpuArray');
RL = ones(1,length(freq), 'single','gpuArray');
function ps = nestedGPU(freq, R, p0)
Fspectral = fft2(X);
a = .0254*15;
ps = a * Fspectral*freq;
end
ps = arrayfun(@nestedGPU, freq, RL, p0);
end
MATLAB 2015a
2 个评论
Walter Roberson
2015-11-5
I am not sure why you are passing parameters in to nestedGPU when you never use those parameters? But you do use FFTConst which is not defined, and you set a to no purpose.
Michael Lee
2015-11-5
编辑:Michael Lee
2015-11-5
回答(1 个)
Edric Ellis
2015-11-5
0 个投票
arrayfun with gpuArray arguments is primarily designed for element-wise computation. Therefore, the functions that you can call within the arrayfun function are limited to element-wise operations. So, in this case, you should probably simply write a for loop.
2 个评论
Michael Lee
2015-11-5
编辑:Michael Lee
2015-11-5
Edric Ellis
2015-11-6
I suggest getting your code working using loops instead of arrayfun in the first instance, and then identify blocks of purely element-wise operations later.
类别
在 帮助中心 和 File Exchange 中查找有关 GPU Computing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!