Derive FFT twiddle phase type from scalar lanes - #5
Closed
PhysicistJohn wants to merge 1 commit into
Closed
Conversation
Derive twiddle phase evaluation precision from the scalar lane and Metal's pi constant instead of naming float in generic FFT code.\n\nThis preserves current code generation while keeping phase precision under the template's usual arithmetic promotion.
PhysicistJohn
marked this pull request as ready for review
August 2, 2026 05:12
Owner
Author
|
Folded into ml-explore#3969 as part of its amended single commit (611e080). This fork PR remains the isolated review record. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
This fork draft targets
draft/generic-metal-fft, the source branch reviewed in ml-explore/mlx#3969. That work templates the Metal C2C FFT over its scalar lane type, butget_twiddle<T>still namesfloatdirectly for phase evaluation.This is the next narrow step toward generalizing FFT precision across all Metal planning paths.
Current MLX executes FFTs at one scalar precision: public transforms cast inputs to
float32orcomplex64, the Metal planner table instantiates onlyfloat/float2, and Bluestein's chirp and convolution constants arecomplex64. The restriction applies to Stockham, Rader, Bluestein, and four-step rather than Bluestein alone.float32/complex64complex64constantsChange
Derive the twiddle phase type from the templated scalar lane and Metal's pi constant:
The phase expression then remains in
phase_Tuntilfast::sinandfast::cos; the resulting twiddle is converted to the FFT lane type at the existing boundary.Deriving from the phase arithmetic is intentional.
decltype(fast::sin(T(0)))is include-context dependent because MLX's BF16 math wrapper declares a BF16 result while evaluating through FP32. In a JIT kernel that form prematurely quantized the phase, reduced accuracy, and slowed every measured planner. The arithmetic-promotion form is stable across static and JIT compilation.Scope
get_twiddle<T>.Validation
xcrun metalcompilation of the production FFT planner table.half2andbfloat2C2C instantiations across all four planners.clang-format --dry-run --Werrorandgit diff --checkpass.