Repository navigation
shader: lower v_fma_f16, v_fmac_f16, v_fmamk_f16 and v_fmaak_f16 in the direct C++ path - #3187
Conversation
8ca9629 to
6d5f8ee
Compare
|
The title says "lower v_fma_f16...", but this PR removes the implementation ( |
|
@KelboLive You may have caught GitHub's diff view right during the force-push/rebase onto
AI-assisted. |
pigalot
left a comment
There was a problem hiding this comment.
I tried to review 6d5f8ee2 over current main 8a8da963. The trial merge (git merge --no-ff --no-commit) conflicts in src/gfx1013_direct_compute.inl, in two places:
- Next to the binary16 helpers: #3151 (
25a4fb23, merged today) addedpacked_f16_arithmeticandfused_half_rne, where this PR addsfma_half_rne. - The
half_binarymode scan: #3144 (e219d724) reformatted that condition and addedv_pk_min_f16/v_pk_max_f16, where this PR adds the four FMA names.
The PR's merge base is 3d7b3a26, so both landed after it.
Not just a textual conflict. main now has fused_half_rne(a, b, c), which #3151 uses for v_pk_fma_f16. Its contract is the same as this PR's fma_half_rne: three binary16 encodings in the low 16 bits, one exact single-rounded RNE result, and 0x7e00 for every NaN. Keeping both would put two independent 120-line implementations of the same arithmetic in one file, and they could disagree on edge cases without any test noticing.
Suggested direction (unconfirmed): rebase onto current main, and have the scalar v_fma_f16 / v_fmac_f16 / v_fmamk_f16 / v_fmaak_f16 path call fused_half_rne on the decoded and modified halves (including abs and neg) instead of adding fma_half_rne. Your native_fma_f16_ir / _controls / _hardware cases, the four #2073 tie witnesses and the subnormal, overflow and cancellation edges, would then also pin the shared helper. If fused_half_rne gets one of those cases wrong, that is worth a finding of its own, so please report it on the PR if it does.
I stopped at the conflict, so I have not built or run this head. I'll retest once it merges cleanly.
Environment: Windows 11 25H2 build 26200.9974; Git trial merge only.
CI: Build and test on Windows passes on 6d5f8ee2 against its own base.
This reply was AI-assisted.
…irect compute Lower v_fma_f16 (VOP3), v_fmac_f16 (VOP2/VOP3A), v_fmamk_f16 (VOP2) and v_fmaak_f16 (VOP2) in DirectCompute::float_alu() using the shared single-rounded binary16 FMA helper fused_half_rne() (R0Y00#3151) while preserving D[31:16]. Supports VOP3 abs/neg/clamp, enforces the default binary16 MODE contract via half_binary, refuses DPP/SDWA/omod/high-half op_sel/third-source modifiers on v_fmac_f16, updates the unlowered placeholder in tests/native_f16_alu_check.py from v_fmac_f16 to v_pk_fmac_f16, and adds @dx.op.unaryBits.i32(i32 33, ...) evaluation to native_f16_alu_check.py's IR interpreter. Fixes R0Y00#3186 Refs R0Y00#2935 AI-assisted.
6d5f8ee to
eb3524f
Compare
|
@pigalot Thank you for the review! Rebased onto Also added Result on Local verification (
AI-assisted. |
R0Y00
left a comment
There was a problem hiding this comment.
I independently applied exact head eb3524f6 over main e582a9a4, including #3188's DPP16 support (clean trial tree dd9b7dc2). The scalar forms now use #3151's shared fused_half_rne; the packed path remains and the resolved change retains #3188's handling. I built compile_dxil native_store_replay native_compute_ir_dump and ran ctest --test-dir <build> --no-tests=error -j1 -V -R '^(native_fma_f16_.*|native_f16_alu_(ir|hardware)|native_packed_f16_controls)$'. Debug and Release /O2 each passed 6/6, with no skips. The IR and RTX 4060 Laptop readback matched all 41 scalar witnesses and the controls matched 12 named refusals. Windows 11 26200.9974, driver 32.0.16.1656, debug layer off for the standalone replay. Required hosted Windows passed. @pigalot, the two conflicts from the previous head no longer reproduce; could you update your review on this head?
pigalot
left a comment
There was a problem hiding this comment.
Retested eb3524f6 merged over current main f6206217, which includes #3188's DPP16 change. The merge is clean (tree 6d04976f) and git diff --cached --check is clean.
Earlier finding: addressed. fma_half_rne is gone. The scalar v_fma_f16, v_fmac_f16, v_fmamk_f16 and v_fmaak_f16 forms call #3151's fused_half_rne on the decoded halves, after abs and neg are applied. The IR interpreter in tests/native_f16_alu_check.py now evaluates FirstbitHi (op 33), which the shared helper uses. This supersedes my changes-requested review on 6d5f8ee2.
What I traced.
- Operands: inline constants 240 to 248 map to binary16 encodings. Inline integers become 16-bit integers.
fmamktakes the literal asb, andfmaaktakes it asc.fmacreads its addend from the low half ofD, and the e64 form refuses asrc2field or a third-source modifier. - Result: clamp sends NaN and negatives to 0 and anything above 1.0 to
0x3c00.D[31:16]is kept. - Refusals: DPP, SDWA, omod, high-half
op_seland non-default MODE are refused. The scan entry makes MODE known for these ops. - #3188: it does not reach these ops, because they are not in
binary16_alu. Their DPP forms are still refused, as before.
What I ran.
-
devandrelease/O2: builtcompile_dxil,native_store_replay,native_compute_ir_dumpandoffscreen_check, then ranctest --test-dir out/build/<preset> --no-tests=error -j 4 -R '^(native_f16_alu_ir|native_fma_f16_ir|native_fma_f16_controls|native_cvt_f16_i16_ir|native_packed_f16_controls|native_cvt_f16_i16_controls|native_packed_f16_pixel_warp|native_direct_container)$' ctest --test-dir out/build/<preset> --no-tests=error -j 1 -R '^(native_f16_alu_hardware|native_fma_f16_hardware)$'
10/10 pass in each preset, with no skips.
-
Fuzz: a local fuzz compares the dumped IR, run through the test's interpreter, against an exact
FractionFMA reference rounded once to binary16. It uses random and near-cancellationv_fma_f16VOP3 cases. 250,000 cases over five seeds give 0 mismatches. The last 50,000 ran on this merge, and the rest ran on the earlier886a5a28merge.
Mutants, each rebuilt in dev (on the 886a5a28 merge, where the new block is byte-identical) and run against native_fma_f16_ir, _controls and _hardware. The unmutated baseline passes first.
| Mutant | Result |
|---|---|
| new block off (negative control) | killed |
fmamk / fmaak literal positions swapped |
killed |
fmac addend from src2 instead of D |
killed |
| clamp keeps NaN | killed |
| clamp upper bound dropped | killed |
D[31:16] zeroed |
killed |
| neg applied before abs | killed |
| negative inline integer wrong | killed |
op_sel refusal dropped |
killed |
fmac third-source modifier refusal dropped |
killed |
| MODE scan entry dropped | killed |
| inline 248 (1/(2π)) off by one ulp | survives |
| MODE refusal dropped | survives |
Two mutants of the shared helper, sticky bit dropped and round-to-odd dropped, both fail native_fma_f16_ir. Your tie witnesses catch the round-to-odd one, which my random fuzz misses. Restored and rebuilt afterwards; git diff --quiet is clean.
Non-blocking.
- Inline 248 is not exercised. No case reads it, so a wrong constant would pass.
- The MODE refusal is not pinned. No control sets a non-default rounding or denormal mode before one of these ops. One control with
s_round_modebefore av_fma_f16would pin it.
Verdict: approve on eb3524f6.
Environment: NVIDIA GeForce RTX 5090 driver 32.0.16.1088; Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; DXC 1.9.2602.17; Python 3.12.10; wave32; debug layer off.
CI: Build and test on Windows, Assemble and translate gfx1013 fixtures and Run platform-independent Python checks on Linux pass on eb3524f6.
This reply was AI-assisted.
Lowers scalar binary16 FMA instructions (
v_fma_f16,v_fmac_f16,v_fmamk_f16,v_fmaak_f16) in the direct C++ compute path (DirectCompute::float_alu()insrc/gfx1013_direct_compute.inl).Summary of changes
fused_half_rne()): Reuses the shared 32-bit integerfused_half_rne(a, b, c)helper introduced in#3151(25a4fb23) rather than adding a duplicate FMA helper, preservingD[31:16].v_fma_f16(VOP3),v_fmac_f16(VOP2/VOP3A),v_fmamk_f16(VOP2),v_fmaak_f16(VOP2), including SGPR/literal/inline-float/inline-int sources anddst = src0overlap.abs,neg, andclamp([0.0, 1.0]saturation).half_binaryinDirectCompute::lower().omod, high-halfop_sel, and third-source modifiers/src2onv_fmac_f16_e64.tests/cmake/native_fma_f16.cmake,tests/native_fma_f16_check.py(41 cases incl. all 4#2073tie witnesses,diff_e >= 30sticky-bit midpoint128.0625 + 2^-24->0x5801, underflow/overflow/cancellation/Inf/NaN + 12 refusals), anddocs/experiments/native-direct-fma-f16.md.tests/native_f16_alu_check.pyfromv_fmac_f16tov_pk_fmac_f16, and added@dx.op.unaryBits.i32(i32 33, ...)evaluation to its IR interpreter sonative_fma_f16_irevaluatesfused_half_rne()directly.Fixes #3186
Refs #2935
AI-assisted.