78. 2D FFT medium
Compute the 2D Discrete Fourier Transform (2D DFT) of a complex-valued signal stored on the GPU.
Given a 2D complex input signal of shape M × N, compute its 2D DFT spectrum
using the row-column decomposition: apply a 1D DFT along each row, then a 1D DFT along each
column of the result. All values are 32-bit floating point.
Implementation Requirements
- Use only native features (external libraries are not permitted)
- The
solvefunction signature must remain unchanged - The final result must be stored in
spectrum -
The input and output are stored as 1D arrays of interleaved real and imaginary parts in
row-major order: element
x[m, n]has its real part at index2*(m*N + n)and imaginary part at index2*(m*N + n) + 1
Example
Input: M = 2, N = 2
Signal (real part):
Signal (imaginary part):
Output:
Spectrum (real part):
Spectrum (imaginary part):
Constraints
- 1 ≤
M,N≤ 4096 - Signal values are 32-bit floating point (real and imaginary parts)
- Performance is measured with
M= 2,048,N= 2,048
Starter code (CUDA)
#include <cuda_runtime.h>
// signal, spectrum are device pointers
extern "C" void solve(const float* signal, float* spectrum, int M, int N) {}
From LeetGPU, CC BY-NC-ND 4.0.