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

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
Michael Lee 2015년 11월 5일
편집: Michael Lee 2015년 11월 5일
This is a simplified version of my larger code. As for the unused arguments, I largely did it to show I/O from a gpuarray. I made some minor edits to the variables used for clarity.

댓글을 달려면 로그인하십시오.

답변 (1개)

Edric Ellis
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
Michael Lee 2015년 11월 5일
편집: Michael Lee 2015년 11월 5일
Well so I guess this hits at the heart of my question. If fft2 is placed in the first loop, and passed a [m x n] gpuArray it is able to run the FFT without any problem. the problem is coming when trying to access FFT2 from the nested function. by definition FFT2 has to be performed on a matrix so its inclusion in the list of overloaded gpu functions implies that matlab can handle some matrix operations on the gpu...
my hope is that I will be able to move the large X, Y matrices to the gpu and then perform element-wise calculations on a vector of frequencies applied to the X&Y matrices of the larger scope. (this would help save on I/O by not having to move the X&Y vectors for each frequency).
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.
There's a different list of functions supported inside arrayfun on the GPU here.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 GPU Computing에 대해 자세히 알아보기

질문:

2015년 11월 5일

댓글:

2015년 11월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by