Clear Filters
Clear Filters

GPU FFT: unable to allocate sufficient resources

4 views (last 30 days)
Hello, Some similar questions have been asked already, but I seem to have an extreme case: Matlab claims I don't have enough resources on my GPU to do FFT, while 'gpuDevice' says I have 6GB of AvailbleMemory. I have the nvidia quadro K5200 that boasts 8GB of RAM. My questions are (1.) Does Matlab somewhere cap the amount of RAM a GPU can use, or is it based on the particular GPU installed? (i.e. is it a settings problem)? (2.) I am using this GPU for display as well. I know this is sub-optimal, but could it cause such a massive discrepancy? (3.) Why is GPU running out of memory to allocate when Matlab seems to think it has 6GB left? fft doesn't use THAT much RAM does it?
The Problem: Note: I used 'whos' in CPU memory to estimate the number of bytes for each of the arrays (I note memory requirements in code/comments below). I am working on a GPU-based STFT function. So, I wanna test out the GPU with a "small" a test vector:
x = randn(7e6,1) + 1i*randn(7e6,1); % 0.1 GB
R = 128;
Nfft = 2048;
X = gpuSTFT(x,128,2048); % I know these are silly parameters
The error I receive is "Error using gpuArray/fft Out of memory on device. MATLAB was unable to allocate sufficient resources on the GPU to complete this operation. If the problem persists, reset the GPU by calling 'gpuDevice(1)'."
Here is the code for my gpuSTFT function (I realize it may be incorrect for STFT; at this point I'm just trying to figure out this memory problem):
function X = gpuSTFT(x,R,Nfft)
% cosine window
n = (1:R)' - 0.5;
window = cos(pi*n/R-pi/2);
% normalization constant
M = 2;
normConst = sqrt(sum(window.^2) * M * Nfft/R);
% to deal with first and last block:
x = [zeros(1,R) x zeros(1,R)];
% some 'measurements'
Nx = length(x);
Nc = ceil(2*Nx/R)-1; % Number of blocks (cols of X)
L = R/2 * (Nc + 1);
if Nx < L
x = [x zeros(1,L-Nx)]; % zero pad x as necessary
end
startpoint = [0:Nc-1].*R/2;
r = 1:R;
NC = 2^ceil(log2(Nc));
% I'm creating a big mtx of x values to allow big multiplication below
allXes = zeros(R,NC);
for k = 1:Nc
allXes(:,k) = x(startpoint(k)+r);
end
allXes(:,Nc+1:end) = 0; % zero-padding dimensions to a power of 2 for efficient fft
% about 0.268GB
% gX = gpuArray(allXes); % Is is faster to pre-allocate this to GPU?...(note: commented out)
gW = gpuArray(window);
% multiply signal by window and tell matlab will be complex
X = complex(arrayfun(@times,gW, allXes));
clear gW % to "free up" memory....
% At this point, 'gpuDevice' suggests I still have ~6GB of AvailableMemory
X = fft(X,Nfft)./normConst ; % Here, I incur the error
X = gather(X);
end
It works for other magnitudes: I started with a smaller array and worked my way up when I got to the millions-length arrays:
>> x = randn(6e4,1) + 1i*randn(6e4,1);
>> tic,X = gpuSTFT(x,128,2048);,toc
Elapsed time is 0.035569 seconds.
>> x = randn(6e5,1) + 1i*randn(6e5,1);
>> tic,X = gpuSTFT(x,128,2048);,toc
Elapsed time is 0.473606 seconds.
>> x = randn(6e6,1) + 1i*randn(6e6,1);
>> tic,X = gpuSTFT(x,128,2048);,toc
Error using gpuArray/fft
Out of memory on device. MATLAB was unable to allocate sufficient
resources on the GPU to complete this operation. If the problem
persists, reset the GPU by calling 'gpuDevice(1)'.
Error in gpuSTFT (line 71)
X = fft(X,Nfft);%./Nc;
  3 Comments
BenImage
BenImage on 22 Aug 2016
Thanks so much Joss, I am really just testing out the limits of the GPU, so the signal length can be anything (say, 2^22). From my calculation, 8x might push the limits, especially if the GPU is using a ton of resources for disply.
BenImage
BenImage on 22 Aug 2016
Another comment: Using length 2^23 for x, I see that the approximate change in gpuDevice.FreeMemory is 0.805 GB after creating X in the above code, at which point gpuDevice.FreeMemory ~ 6GB. So, 8x is a little bit too much.

Sign in to comment.

Answers (0)

Categories

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

Community Treasure Hunt

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

Start Hunting!