CPU Fallback Implementation
How the library behaves when WebGPU is unavailable.
Overview
The library ships a complete CPU FFT path for environments where WebGPU cannot be initialized. This fallback covers:
- 1D and 2D complex FFT / IFFT
- 1D and 2D real-input RFFT / IRFFT
- CPU-only utilities such as spectrum analysis and image filtering
Detection
ts
import { createFFTEngine, cpuFFT, isWebGPUAvailable } from 'webgpu-fft';
if (await isWebGPUAvailable()) {
const engine = await createFFTEngine();
// Use GPU FFT
} else {
const spectrum = cpuFFT(signal);
// Use CPU FFT
}1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
CPU APIs
ts
import { cpuFFT, cpuIFFT, cpuRFFT, cpuIRFFT } from 'webgpu-fft';
const spectrum = cpuFFT(complexSignal);
const restoredComplex = cpuIFFT(spectrum);
const halfSpectrum = cpuRFFT(realSignal);
const restoredReal = cpuIRFFT(halfSpectrum);1
2
3
4
5
6
7
2
3
4
5
6
7
Implementation Notes
- The CPU path uses radix-2 Cooley-Tukey FFT logic.
- Real-input APIs are implemented as contract-first wrappers around the complex FFT path.
createSpectrumAnalyzer()andcreateImageFilter()are CPU-only utilities and remain outside the GPU FFT execution path.
Performance Notes
Run npm run benchmark to collect measured CPU results in the current environment. WebGPU results are reported only when WebGPU is actually available during that run.
Limitations
- CPU execution is slower for large transforms than the GPU path on supported hardware.
- Real-input CPU APIs are correctness-first wrappers, not dedicated optimized kernels.
Related
- FFTEngine — GPU FFT engine
- Architecture Overview — High-level architecture