FFT is suddenly slow down for repeated operations.

3 次查看(过去 30 天)
Hello. I am conducting a simulation with a 3-dimensional matrix using Matlab. While performing FFT about one dimension of the 3-dimensional matrix using GPU for repeated operations, I noticed that the computation speed suddenly slows down. Below is a brief summary of the problematic code.
matlab
clear all; close all; clc;
k = 501;
A = zeros(k,k,k,'gpuArray');
B = zeros(k,k,k,'gpuArray');
for n = 1:k
tic
B(:,:,:) = fftshift(fft(ifftshift(A,1),[],1),1);
disp(num2str([n, toc]))
end
The result of running the code is as follows:
Result
....
236 7.52e-05
237 7.03e-05
238 7.11e-05
239 7.34e-05
240 7.29e-05
241 7.02e-05
242 0.0235287
243 0.0472623
244 0.0312132
245 0.0444045
246 0.0305904
247 0.0463637
248 0.0309244
....
As the result, from the 242nd iteration, the FFT operation significantly slows down.
I am curious about the cause of this issue.
The GPU used is 4090.
I would appreciate it if you could let me know what the problem might be.

采纳的回答

Edric Ellis
Edric Ellis 2024-5-16
This is due to the asynchronous nature of gpuArray operations. Where possible, operations on the GPU are queued up and run in the background. At some point, we run out of queue, and the operations have to actually run - that's the point at which you see the change in time.
The best way to time operations on the GPU is to use gputimeit which takes into account this asynchronous behaviour. The other option is to call wait on the gpuDevice before calling toc, like this:
d = gpuDevice();
t = tic();
% do stuff on the GPU
wait(d);
time = toc(t)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 GPU Computing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by