Template Metal C2C FFT scalar lanes - #3969
Conversation
4b0e3b7 to
90b7f12
Compare
90b7f12 to
3bac56f
Compare
3bac56f to
611e080
Compare
Template C2C FFT arithmetic and I/O over their scalar lane while retaining the existing static entry points and packed real paths. Make the C2C four-step second pass use the same generic storage path so future scalar lanes preserve the existing indexing and scaling behavior. Derive twiddle phase evaluation precision from the scalar lane and Metal's pi constant instead of naming float in generic FFT code, while preserving current code generation.
611e080 to
acca981
Compare
|
Thanks for the review! Applied all four: dropped Also rebased onto main to pick up #3970, which resolves the conflict, and folded in the explicit |
Motivation
MLX's Metal C2C FFT core hard-codes
float2. This PR is the narrow Metal-kernel foundation for #2112: it removes that source-level coupling so a later, end-to-end reduced-precision complex proposal can be evaluated without rewriting the FFT implementation first.The target use case is complex I/Q and signal-processing workloads, where storing real and imaginary lanes in FP16 or BF16 halves storage and bytes transferred relative to two FP32 lanes. This PR does not claim that lower precision is appropriate for every workload; public dtype semantics, host dispatch, operation coverage, accuracy policy, and new static instantiations remain separate work.
Existing accelerator-library precedent
This is not a novel representation:
CUDA_C_16Fand bfloat16-complexCUDA_C_16BFtransforms through its type-generic planning API.rocfft_precision_halftogether with complex interleaved and planar array layouts.Those are direct GPU-vendor FFT libraries. This patch only prepares MLX's C2C Metal implementation for equivalent storage lanes; it does not add a public reduced-precision complex type.
Scope
floatinside generic FFT code.Binary-size impact
No new static kernels or public exports are instantiated.
mlx.metallib: 130,977,720 B → 130,994,264 Bmetal-nm -gexported-symbol output: exact match to the base buildValidation
xcrun metalcompile andmetalliblink of the changedfft.metalusing MLX's build flags.ctest261/261 passed, including all FFT cases.python -m unittest test_fft -v— 16 passed, 2 expected skips.half2andbfloat2across Stockham, Rader, Bluestein, and four-step planners.pre-commit(clang-format) andgit diff --checkpassed.Focused float32 regression checks
The second measurement is a focused dispatch-scale check, not a claim of a material performance change. There is no end-to-end reduced-precision performance claim until a future public dtype and dispatch path exists.
Downstream half-complex FFT result
PhysicistJohn/mlx#7 adds one
dependent commit on top of #3969, #3970, and the storage adapter in
PhysicistJohn/mlx#6. It
instantiates packed
complex_t<half>C2C Stockham, Rader, Bluestein, andfour-step kernels.
A matched M5 Max benchmark compared the half kernels directly with untouched
mainFP32 (fb5133e1) using identical plans, geometry, inputs, batches,warmups, samples, and order-balanced runs:
The candidate FP32 control was bit-identical to original FP32 on all four paths
and measured 0.992x-1.065x its throughput across forward and inverse. Packed
half-complex storage and external I/O are 50% smaller. A 39-length correctness
sweep through 1,048,576 points remained finite, with worst normalized RMSE of
0.2585% forward and 0.4101% round trip.