ai.onnx.DFT
ai.onnx · standard ONNX operator · ONNX opset ≥ 20
Description
Computes the discrete Fourier Transform (DFT) of the input along a specified axis. For a signal of length N, output bin k is sum_{n=0}^{N-1} exp(-2*pi*j*k*n/N) * x[n]; the inverse divides by N and negates the exponent sign. Supports forward/inverse, real-to-complex (RFFT), and complex-to-real (IRFFT) modes via the onesided and inverse attributes. A nonempty result requires a positive transform length: an empty signal can be zero-padded with an explicit positive dft_length, but cannot produce a one-sided bin at implicit length zero. Empty results require no transform evaluation.
See the ONNX DFT spec for the reference semantics.
Inputs
| Name | Logical dtype | WebGPU storage | Rank | Shape | Description | Presence |
|---|---|---|---|---|---|---|
input |
T |
same as logical dtype | — | — | Input signal tensor; the last dimension is 1 for real values or 2 for complex (real, imaginary) pairs. |
required |
dft_length |
L |
same as logical dtype | 0 |
— | Optional positive int32 scalar controlling the transform length; input is zero-padded or truncated to this length. Defaults to the signal-axis size, or twice (the bin count minus one) for IRFFT. Positive lengths can zero-pad an empty signal or spectrum. Scalar values stay on the GPU and must satisfy this contract at each call. | optional |
axis |
I |
int32 |
0 |
— | Optional logical int64 scalar specifying the dimension over which to compute the DFT (the last axis is reserved for the real/imaginary component and is excluded); signed axes use int32 WebGPU storage and default to -2 when omitted. |
optional |
Outputs
| Name | Logical dtype | Rank | Shape | Description | Presence |
|---|---|---|---|---|---|
output |
T |
same as input |
derived | DFT result tensor; last dimension is 2 (complex) for full DFT, full inverse DFT and RFFT, or 1 (real) for IRFFT. | required |
Attributes
Default values (overridable per request):
| Attribute | Default | Description |
|---|---|---|
inverse |
0 |
When set to 1, computes the inverse DFT (IDFT/IRFFT) instead of the forward transform; default is 0 (forward). |
onesided |
0 |
When set to 1, exploits conjugate symmetry to return only the non-redundant half of the spectrum (RFFT for forward, IRFFT for inverse); default is 0 (full spectrum). |
Type constraints
| Variable | Allowed dtypes |
|---|---|
T |
float32, float16 |
L |
int32 |
I |
int64 |
Implementation variants
One implementation is selected per call from the device capabilities, the request shapes and the dtypes; these notes say what each one covers.
batch_axis1_general_residue_dft— Factors real forward transforms into bounded residue classes, computes each local spectrum with compensated direct summation, and combines paired spectra. A work bound requires at least half as many root terms as a direct transform.batch_axis1_mixed_fft_factor19— Compensated staged mixed-factor FFT for real forward transforms whose bounded shared workspace and fully factored odd tail allow radix-19 butterflies.batch_axis1_direct_root_table— Real forward odd-length transform with one shared signal row and a compensated paired root table reused across batches and frequency tiles.batch_axis1_fft_residual_tiles— FFT over device-sized residue-class tiles, followed by a paired-root gather: a real spectrum when its tiles fit half the reported shared memory (full capacity when needed to keep gather work logarithmic), else the full complex spectrum; odd real lengths use smooth odd residue tiles with a local mixed-radix transform and a compensated root table.axis_fft_shared_roots— Shared-memory FFT with protected residual arithmetic and a precomputed paired root table reused across transforms: radix-2, compensated mixed-factor, a real signal packed into a half-length complex transform, or residual components kept in separate per-transform rows of a temporary buffer beyond the shared-memory limit.batch_axis1_fft_storage_inplace— Inverse transforms beyond shared-memory capacity use an in-place full-spectrum output buffer. Forward transforms retain residual components in their precision-preserving paths.contiguous_naive— Direct DFT over the default axis of a contiguous rank-2 signal or a batch of rank-3 signals, for lengths that no FFT variant supports.batch_axis1_real_packed_mixed_shared_roots— Computes a compensated half-length mixed-factor real FFT in one pass when the transform and quarter roots fit shared storage.
Device requirements
Some implementation variants require subgroups. Other variants run without it; which variant runs also depends on the request's shapes and dtypes.
Files
metadata.json— kernel metadata (id, file digests, manifest spec, provenance)manifest.json— the op contract (source of truth)test.json— correctness casesbench.json— benchmark casesdft-contiguous-naive.wgsl.jinjadft-general.wgsl.jinjadft-paired-roots.wgsl.jinjadft-rank4.wgsl.jinjadft-residual-gather.wgsl.jinjadft-residue-direct.wgsl.jinjadft-runtime-axis-fft-shared.wgsl.jinjadft-tiled-real.wgsl.jinjafft-radix2-dit-storage.wgsl.jinjafft-residual-shared.wgsl.jinjafft-stockham-shared.wgsl.jinja
Use with @huggingface/kernels
npm install --save-exact @huggingface/kernels@0.0.1-preview.4
Paste the example into a browser app that resolves npm imports. Serve the app over HTTPS or localhost with WebGPU available.
Required output shapes and logical data types are inferred from the supplied inputs and attributes; result tensors are allocated automatically.
The version: 1 option selects the published kernel contract; it is independent of any operator opset, contrib since_version, or model version.
It follows the v1 branch as fixes land. To pin exact artifact bytes, pass a 40-character commit revision instead of version.
import { getKernel } from "@huggingface/kernels";
const kernel = await getKernel("webgpu-kernels/ai.onnx.DFT", { version: 1 });
const inputData = Float32Array.of(1, 2);
const { output } = await kernel({ input: { data: inputData, shape: [1, 1, 1, 1, 1, 1, 2, 1] } });
console.log({ output });
- Downloads last month
- -
Requires WebGPU support. See the compatibility table.