Repository navigation
feat: add packed f16x2 fma ftz and saturating forms - #659
Merged
Merged
Conversation
Completes the `packed_alu` fma modifier coverage for `f16x2`. The family already had `fma.rn.f16x2` and `fma.rn.relu.f16x2`; LLVM also declares the `ftz` and `sat` combinations, each with a single tablegen selection record, and all four lower on the pinned backend. Adds 4 intrinsics: - `fma_ftz_f16x2` - `fma.rn.ftz.f16x2` - `fma_sat_f16x2` - `fma.rn.sat.f16x2` - `fma_ftz_sat_f16x2` - `fma.rn.ftz.sat.f16x2` - `fma_ftz_relu_f16x2` - `fma.rn.ftz.relu.f16x2` The four `bf16x2` counterparts are excluded. LLVM declares them but the NVPTX backend has no selection pattern, so instruction selection fails with "Cannot select: intrinsic %llvm.nvvm.fma.rn.ftz.bf16x2"; they also carry no tablegen selection record in the imported ledger. `packed_alu_recipe` now returns `Option` and rejects those pairs by name, so the family fails closed with "is outside the closed packed-ALU recipe" instead of admitting a variant that cannot lower. That is also why the dispatcher had to become fallible rather than panicking on an unknown pair. Architecture floors differ inside the group and are not collapsed: `ftz`, `sat`, and `ftz.sat` are native at PTX 4.2 / sm_53, while `ftz.relu` needs PTX 7.0 / sm_80. The first three therefore mirror the existing `fma_f16x2` per-backend floors exactly - PTX 6.0 / sm_70 for the pinned LLVM route, PTX 4.2 / sm_75 for libNVVM, the latter because CUDA 13.3 ptxas no longer accepts sm_70. Evidence is measured, not asserted, for both backend profiles. On the pinned LLVM the inline-PTX bundles lower with every exact instruction head present and assemble under CUDA 13.3 ptxas; independent typed calls to the `llvm.nvvm` symbols emit the same heads. On CUDA 13.3 libNVVM the same forms compile to PTX 9.3, assemble, and survive `-gen-lto` plus nvJitLink. Hardware verification extends the launched `f16x2_arith` example from 9 to 14 checked operations, run on an sm_86 RTX A2000. The new cases are chosen to discriminate rather than merely execute: a subnormal input pair (`0x0002_0001`) is preserved by `fma_f16x2` and flushed to zero by `fma_ftz_f16x2` and `fma_ftz_relu_f16x2`, and `2*3+7 = 13` / `4*5+11 = 31` clamp to 1.0 under the saturating forms. All 14 pass bit-exactly. Verified: `check`, `probe --all --skip-terminal` (833/833 routes, all four new ones lowering to the expected instruction), `check-abi-history` (829 base entries preserved), `cargo fmt --all --check` in all three workspaces, `cargo clippy --workspace --all-targets -D warnings`, `RUSTDOCFLAGS='-D warnings' cargo doc`, cuda-intrinsics-gen (288 tests), and `scripts/smoketest.sh -o '^f16x2_arith$'` launched on hardware. Claude-Session: https://claude.ai/code/session_01LXYptgNnAcDSbkgyWGYQzk Signed-off-by: abder <[email protected]>
…oor lookup Two review findings on the preceding commit, neither observable in the generated output - regeneration is byte-identical. `packed_alu_backend_floor` re-derived the recipe it was handed a moment earlier and used `expect` to discharge the `Option` the previous commit introduced. Every one of its three callers already holds the resolved recipe, so it now takes that by reference. The panic path is gone rather than argued unreachable, and a redundant lookup goes with it. The four new f16x2 match arms were also inserted wherever they happened to fit, which split the relu pair and left the arm order out of step with the enum. `FmaFtzRelu` now follows `FmaRelu`, so the arms read in enum order. Verified: `check`, `probe --all --skip-terminal` (833/833), 288 generator tests, `cargo fmt --all --check`, `cargo clippy --workspace --all-targets -D warnings`, `RUSTDOCFLAGS='-D warnings' cargo doc`, and the launched `f16x2_arith` example on sm_86. Claude-Session: https://claude.ai/code/session_01LXYptgNnAcDSbkgyWGYQzk Signed-off-by: abder <[email protected]>
… backend Carried over from the NVIDIA#649 review, where the maintainer independently checked a near-identical exclusion against the PTX ISA grammar rather than taking the backend failure at face value. Doing that here changes the answer's basis. The `ftz` and `sat` fma forms do not exist for `bf16x2` in the ISA at all. ptxas rejects hand-written `fma.rn.ftz.bf16x2` with "Illegal modifier `.ftz` for instruction `fma`", and accepts `fma.rn.relu.bf16x2` beside it, so the assembler - not LLVM - is the authority. LLVM declaring the intrinsics anyway is why instruction selection is merely what fails first. The recipe comment and the `bf16x2` module docs now say that, so the asymmetry between six `f16x2` fma forms and two `bf16x2` ones reads as an ISA fact rather than an omission. Also documents the `f16x2` fma modifier set with its split floors: the four non-ReLU forms are native at PTX ISA 4.2, while both ReLU forms require sm_80 and PTX ISA 7.0. Verified: `check`, `probe --all --skip-terminal` (857/857), `check-abi-history` (853 base entries preserved), 288 generator tests, `cargo fmt --all --check`, `cargo clippy --workspace --all-targets -D warnings`, `RUSTDOCFLAGS='-D warnings' cargo doc`, and `f16x2_arith` launched on sm_86. Claude-Session: https://claude.ai/code/session_01LXYptgNnAcDSbkgyWGYQzk Signed-off-by: abder <[email protected]>
Collaborator
|
Ran the full battery locally (sm_120):
Merging. |
nihalpasham
approved these changes
Aug 5, 2026
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.
Completes the
packed_alufma modifier coverage forf16x2. The family already hadfma.rn.f16x2andfma.rn.relu.f16x2; LLVM also declares theftzandsatcombinations, each with a single tablegen selection record, and all four lower on the pinned backend.What this adds
fma_ftz_f16x2fma.rn.ftz.f16x2fma_sat_f16x2fma.rn.sat.f16x2fma_ftz_sat_f16x2fma.rn.ftz.sat.f16x2fma_ftz_relu_f16x2fma.rn.ftz.relu.f16x2Floors are not collapsed across the group. The first three mirror the existing
fma_f16x2per-backend floors exactly - PTX 6.0 / sm_70 for the pinned LLVM route, PTX 4.2 / sm_75 for libNVVM.None of the four is reachable any other way: generic
llvm.fma.v2f16lowers only to the plainfma.rn.f16x2, which already existed, andftz/sat/reluhave no Rust or generic-LLVM spelling. Verified on the pinnedllc.Why the bf16x2 counterparts are excluded
They do not exist in the PTX ISA. ptxas rejects hand-written
fma.rn.ftz.bf16x2:while accepting
fma.rn.relu.bf16x2beside it, so the assembler is the authority. LLVM declares the intrinsics anyway, which is why instruction selection is merely what fails first (Cannot select: intrinsic %llvm.nvvm.fma.rn.ftz.bf16x2); they also carry no tablegen selection record inintrinsics/imported.json. The recipe comment and thebf16x2module docs state this, so the six-vs-two asymmetry reads as an ISA fact rather than an omission.Fail-closed recipe lookup
packed_alu_recipereturnedPackedAluRecipeunconditionally, so an operation one format supports and another does not had nowhere to go but a panic. It now returnsOptionandpacked_bf16x2_alu_reciperejects the four pairs by name, so the family errors withis outside the closed packed-ALU recipeinstead of admitting a variant that cannot lower.packed_alu_backend_flooralso takes the caller's already-resolved recipe rather than re-deriving it, so the newOptionis discharged where it is created rather than behind anexpectjustified by a caller invariant.Evidence
Measured for both backend profiles:
llvm.nvvmsymbols emit the same heads.-gen-ltoplus nvJitLink.Hardware verification
The launched
f16x2_arithexample goes from 9 to 14 checked operations on an sm_86 RTX A2000, with cases chosen to discriminate rather than merely execute:0x0002_0001) is preserved byfma_f16x2and flushed to zero byfma_ftz_f16x2andfma_ftz_relu_f16x2- direct proof theftzmodifier acts, not just that the stub compiles.2*3+7 = 13and4*5+11 = 31both clamp to1.0under the saturating forms.All 14 pass bit-exactly.
What I could not verify
Two gaps, stated rather than left to be found:
fma_f16x2record already does for the same reason.Verification
Rebased on
e28248c1; 3 commits, all DCO signed off.cargo run -p cuda-intrinsics-gen -- check- cleanprobe --all --skip-terminal- 857/857 routes; all four new ones lower to their expected instructioncheck-abi-history --base-ref upstream/main- 853 base entries preserved, 857 total (this PR uses i0854-i0857)cargo fmt --all -- --check- clean in all three workspacescargo clippy --workspace --all-targets -- -D warnings- cleanRUSTDOCFLAGS='-D warnings' cargo doc- cleanscripts/smoketest.sh -o '^f16x2_arith$'- launched on hardwareFull CI is green on the fork PR (50/50 including
compile all examples): honeyspoon#116Follows #649. Independent of it - different family and contract, no shared code, non-overlapping ABI ids.
https://claude.ai/code/session_01LXYptgNnAcDSbkgyWGYQzk