フィルターのクリア

FFT is suddenly slow down for repeated operations.

3 ビュー (過去 30 日間)
Hosung Jeon
Hosung Jeon 2024 年 5 月 13 日
コメント済み: Hosung Jeon 2024 年 5 月 16 日
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)
  1 件のコメント
Hosung Jeon
Hosung Jeon 2024 年 5 月 16 日
Thank you for your response. I understand now!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGPU Computing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by