Bridge generic complex storage into Metal FFT - #6
Closed
PhysicistJohn wants to merge 1 commit into
Closed
Conversation
Teach FFTValueTraits to load and store complex_t<T> while preserving lane-typed vector arithmetic. Add a compile-only Metal regression for half and bfloat16 adapters without adding production kernel instantiations or changing the shipped metallib.
This was referenced Aug 2, 2026
Owner
Author
|
Superseded: the storage bridge is now folded into ml-explore#3981. |
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.
Note
Fork-only review PR. This is not an upstream submission.
Context
This is the narrow integration point for two foundations under upstream review:
611e080).complex_t<T>lane-generic while preservingcomplex64_tand existing entry points (7ea2b9a).The synthetic base,
integration/reduced-complex-foundations-v2, merges the exact current heads of those two PRs without other source changes. This PR adds one commit that connects them:FFTValueTraitscan load and storecomplex_t<T>while the FFT retains its lane-typed vector representation internally.Change
FFTValueTraits<complex_t<T>>with a floating-lane constraint, an exact two-lane layout check, and explicit load/store conversion.halfandbfloat16_t.mlx.metallib.Precedent
Reduced-precision complex FFT storage is established elsewhere:
torch.complex32/torch.chalfas two float16 components, andtorch.fft.fftsupportstorch.chalfon supported CUDA devices._Float16_2for half-precision complex-to-complex load and store.Those implementations have backend-specific constraints. This patch adds only MLX's internal storage bridge; it does not claim public API parity.
Scope
Validation
fft_complex_storage_halfandfft_complex_storage_bfloat16.{ half, half }and{ bfloat, bfloat }storage with zerofpextand zerofptruncinstructions.git diff --checkpass.The shipped
mlx.metallibis unchanged at 131,007,704 bytes, SHA-2568b7a8614751b1d41cb09e87cb6cf2ff7d35d2bf7b1c5881ecf842d253412dd19; neither test symbol is exported. A measured future static C2C matrix would add about 0.758% for half, 0.758% for BF16, or 1.516% for both, but this PR pays none of that cost.Runtime proof outside this diff
The preserved fork-only proof commit exercises Stockham, Rader, Bluestein, and four-step with half and BF16 storage. Packed storage is 4 bytes per complex value instead of 8, and the audited FFT lanes remain native reduced precision. Half measured 1.13-2.30x float throughput across the four representative planners; BF16 measured 0.86-2.12x. The BF16 Bluestein regression is deliberately not hidden and remains a separate planner-constant optimization rather than part of this storage adapter.
Public dtype semantics, CPU support, accuracy policy, production dispatch coverage, and planner-owned reduced-precision constants remain separate reviewable decisions after the foundations land.