Repository navigation
shader: lower v_min3_f16, v_max3_f16, and v_med3_f16 in direct Compute and Pixel DXIL - #3266
legacy-code-archaeologist wants to merge 2 commits into
Conversation
|
I reviewed the diff (not run). I found nothing wrong in the lowering. There are three gaps in the fixture cases, though:
AI-assisted. |
pigalot
left a comment
There was a problem hiding this comment.
I reviewed 8223b4b7 merged over main 240e0fb9. The merge is clean (tree ab12c114) and git diff --cached --check is clean. I first ran everything over dbb933d1, then reran the builds and tests over 240e0fb9, which adds v_pk_fmac_f16 and the f16 rounding ops to the same file.
I found nothing wrong with the lowering itself. Three of its terms have no case that tells them apart, though: two of Leyukaka's gaps (I reran both as mutants) and one more. I'm requesting the cases, not code changes.
What I traced. VOP3 0x351/0x354/0x357 are v_min3_f16/v_max3_f16/v_med3_f16, and decode already names them. The lowering is integer selects on the 16-bit patterns, using the same order key and NaN rule as main's v_pk_min_f16/v_pk_max_f16:
x ^ (x >= 0x8000 ? 0xffff : 0x8000)puts -0 below +0;- one NaN returns the other operand, and two NaNs return
0x7e00.
v_med3_f16 is max(min(a, b), min(max(a, b), c)). If any input is NaN, it is min3 instead, as the RDNA 2 ISA pseudo-code for V_MED3 defines.
The rest:
- clamp sends NaN and every sign-set result to
+0, and anything above0x3bffto1.0; op_sel[3]places the result in the high half and keeps the other half ofvdst;- high-half
op_selon a non-VGPR source, omod, DPP/SDWA and special scalar sources are refused; - all three ops join
half_binary.
What I ran. I built compile_dxil native_store_replay offscreen_check native_compute_ir_dump native_global_srv_heap_replay native_compute_manifest_reasons in dev and release, then ran:
ctest --test-dir out/build/<preset> --no-tests=error -j 4 -R '^native_' -E '_hardware'
python .agentic\scripts\with_gpu_lock.py ctest --test-dir out/build/<preset> --no-tests=error -j 1 -R '^native_(minmax|min|max|med|f16|sdwa_f16|packed|pk|fma_f16)[a-z0-9_]*_hardware$'- Non-hardware: 145 tests per preset. 128 pass and 17
_warptests skip with 77, the same WARP capability skips as onmain, in both Debug and Release/O2.native_minmax_med3_f16_ir,_controlsand_pixel_warppass. - Hardware: 25/25 pass in both presets.
native_minmax_med3_f16_compute_hardwareruns here (it skipped on your Intel adapter), and so do_pixel_hardwareand the packed/f16 neighbours. - Negative control:
tests/cmake/native_minmax_med3_f16.cmakeis new, somainregisters none of these tests. - What the GPU runs show: because the lowering is integer selects, the GPU runs confirm that the DXIL matches the Python model. The model's NaN and signed-zero conventions are
main'sv_pk_min/max_f16conventions; gfx1013 itself is not measured here.
Mutants. Each was rebuilt in dev, then I ran native_minmax_med3_f16_(ir|controls|pixel_warp|pixel_hardware|compute_hardware). The first twelve ran over dbb933d1; N1 and N2 ran over 240e0fb9.
| Mutant | Result |
|---|---|
order key ignores the sign (x ^ 0x8000) |
killed |
| two NaNs return the first operand | killed |
| NaN not skipped (plain ordered select) | killed |
median computed as max(min(a, b), c) |
killed |
| clamp upper bound 2.0 | killed |
clamp condition nan or sign changed to nan and sign |
killed (by the -0 case) |
abs ignored |
killed |
| low-half write doesn't keep the high half | killed |
op_sel source reads the low half |
killed |
| omod accepted | killed |
N1: clamp NaN term dropped (or i1 false, sign) |
survives |
N2: any_nan ignores src2 (is_nan(a) or is_nan(b)) |
survives |
negative inline integers (193..208) sign-flipped |
survives |
in-op denormal gate (mode_bits & 0xc0) != 0xc0 removed |
survives (expected, see below) |
Restored and rebuilt afterwards; git diff --quiet is clean.
Cases that would kill the survivors (expected values from the lowering as written):
- Clamp of a NaN result. No case sends a NaN into the clamp:
med3_clamp_nan_to_zerohands it0x8000. For example,med3_three_nanswithclamp=1is0x7e00before the clamp and0x0000after it. Without the NaN term it is0x3c00. med3with a NaN only in src2.med3(0x4200, 0x3800, 0x7E01)gives0x3800. With N2 it gives0x4200.- Negative inline integer.
half_bitsmaps193..208to(192 - r) & 0xffff, and no case reads that branch: the only193in the test is the EXECs_mov.min3with src0 = inline-1(193), as the PR reads it0xffff, a NaN pattern, and0x3C00,0x4000gives0x3c00. With the sign flipped, src0 becomes0x0001, and the result is0x0001.
Leyukaka's other point holds too, though no mutant isolates it. The only sign-set input that reaches the clamp is -0. A clamp case with a negative nonzero result, such as 0xBC00, would pin the sign term for real negatives.
Non-blocking: the in-op denormal gate can't be reached. mode_bits starts at 0xf0, and changes only through consume_half_mode. That function already refuses any MODE write that changes the binary16 bits while half_binary is set, so both refusal controls stop there. The same holds for the existing v_pk_min/max_f16 gate. I'd keep the line as defence in depth; this survivor needs no case.
Verdict: changes requested on 8223b4b7, for cases 1–3. I'll re-run the mutants on the new head.
Environment: NVIDIA GeForce RTX 5090 driver 32.0.16.1088 and WARP, Windows 11 25H2 build 26200.9974, MSVC 19.52.37029, Windows SDK 10.0.28000.0 DXC, Python 3.12.10, wave32; I did not check the debug-layer status.
CI: Build and test on Windows passes on 8223b4b7.
This reply was AI-assisted.
|
Thanks @pigalot and @Leyukaka — added the 5 requested fixture cases to
Verification (
Sensitivity mutant checks on
AI-assisted. |
…0Y00#3264) Lower VOP3 v_min3_f16 (0x351), v_max3_f16 (0x354), and v_med3_f16 (0x357) in DirectCompute::float_alu() with abs/neg/clamp/op_sel[3:0], exact binary16 NaN and signed-zero ordering, other-half preservation, binary16 denormal mode tracking, and IR/DXIL/Pixel/Compute tests. Fixes R0Y00#3264, Refs R0Y00#2935. AI-assisted.
Add med3_nan_src2, med3_two_nans, min3_clamp_negative, med3_three_nans_clamp, and min3_inline_neg_int (src0=193) to tests/native_minmax_med3_f16_check.py (29 cases total). Refs R0Y00#3264, R0Y00#2935. AI-assisted.
|
Rebased onto
AI-assisted. |
bbab9bd to
df6c054
Compare
|
Thank you for the added cases. I reviewed Requested changes. All three cases from the review on
On the unmodified merge,
From our side this looks ready, pending the re-review on the new head. This comment was AI-assisted. |
|
Thanks for the work here. This branch no longer merges with current Could you merge or rebase current This comment was AI-assisted. |
pigalot
left a comment
There was a problem hiding this comment.
I retested df6c0545 merged over main c6f23813. This supersedes my changes-requested review on 8223b4b7.
What changed. git range-diff shows that the lowering commit (b82ba196) is the same as 8223b4b7, apart from the rebase context in the half_binary list. df6c0545 adds five cases to tests/native_minmax_med3_f16_check.py, and the model supplies their expected values. Each of my earlier findings:
- Case 1, clamp of a NaN result: addressed.
med3_three_nans_clampsends0x7e00into the clamp. - Case 2,
med3with a NaN only in src2: addressed bymed3_nan_src2.med3_two_nansadds the two-NaNs-one-number case. - Case 3, negative inline integer: addressed.
min3_inline_neg_intreads inline-1(193). - Leyukaka's negative clamp: addressed.
min3_clamp_negativeclamps0xBC00to+0.
Merge with main. The branch conflicts with c6f23813 in src/gfx1013_direct_compute.inl. #3292 added v_cvt_norm_i16_f16/v_cvt_norm_u16_f16 to the same half_binary list. Keeping both sides resolves it:
op.name == "v_cvt_norm_i16_f16" ||
op.name == "v_cvt_norm_u16_f16" ||
op.name == "v_min3_f16" ||
op.name == "v_max3_f16" ||
op.name == "v_med3_f16")With that resolution, the tree is 2eab42a7 and git diff --cached --check is clean. I didn't push it.
What I ran on that tree. I built compile_dxil native_store_replay offscreen_check native_compute_ir_dump native_global_srv_heap_replay native_compute_manifest_reasons in dev and release, then ran:
ctest --test-dir out/build/<preset> --no-tests=error -j 4 -R '^native_' -E '_hardware'
python .agentic\scripts\with_gpu_lock.py ctest --test-dir out/build/<preset> --no-tests=error -j 1 -R '^native_(minmax|min|max|med|f16|sdwa_f16|packed|pk|fma_f16)[a-z0-9_]*_hardware$'- Non-hardware: 163 tests per preset. 145 pass and 18 skip with 77 (WARP capability skips), in both Debug and Release
/O2. - Hardware: 27/27 pass in both presets, including
native_minmax_med3_f16_compute_hardwareand_pixel_hardware.
Mutants. Each was rebuilt in dev, then I ran native_minmax_med3_f16_*, hardware included. All 13 are killed now; the three marked "now killed" survived on 8223b4b7:
| Mutant | Result |
|---|---|
| order key ignores the sign | killed |
| two NaNs return the first operand | killed |
| NaN not skipped | killed |
median computed as max(min(a, b), c) |
killed |
| clamp upper bound 2.0 | killed |
clamp nan or sign changed to nan and sign |
killed |
abs ignored |
killed |
| low-half write doesn't keep the high half | killed |
op_sel source reads the low half |
killed |
| omod accepted | killed |
| N1: clamp NaN term dropped | now killed |
N2: any_nan ignores src2 |
now killed |
| negative inline integers sign-flipped | now killed |
Restored and rebuilt afterwards; git diff --quiet is clean. I didn't rerun the in-op denormal-gate mutant. It can't be reached, as I noted on 8223b4b7, and this push doesn't change that.
Verdict: approve on df6c0545. It can't merge until main is merged in; the resolution above is the whole conflict.
Environment: NVIDIA GeForce RTX 5090 driver 32.0.16.1088 and WARP, Windows 11 25H2 build 26200.9974, MSVC 19.52.37029, Windows SDK 10.0.28000.0 DXC, Python 3.12.10, wave32; I did not check the debug-layer status.
CI: Build and test on Windows passes on df6c0545.
This reply was AI-assisted.
|
@legacy-code-archaeologist |
|
Taking this over since there has been no activity for 2 h; will hand back if you resume. Plan: merge current |
Lowers VOP3
v_min3_f16(0x351),v_max3_f16(0x354), andv_med3_f16(0x357) in direct Compute and Pixel DXIL.Fixes #3264. Refs #2935.
Summary
src/gfx1013_direct_compute.inl:v_min3_f16,v_max3_f16, andv_med3_f16inDirectCompute::float_alu()withabs[2:0],neg[2:0],clamp(NaN/negative ->+0.0, positive subnormals preserved,> 0x3bff->1.0),op_sel[3:0](high-half source reads on VGPRs and destination high/low half placement preserving the other 16 bits ofvdst), VGPR/SGPR/literal/inline sources, exact 16-bit signed-zero (-0.0 < +0.0) and NaN ordering (includingv_med3_f16returningminof numeric inputs when any input is NaN), and the binary16 denormal mode gate ((mode_bits & 0xc0u) == 0xc0u).omod, high-halfop_selon non-VGPR sources, special scalar sources (106..127/253), and non-default or unknown binary16 denormal modes (half_binary = trueinDirectCompute::lower()).tests/native_minmax_med3_f16_check.py,tests/cmake/native_minmax_med3_f16.cmake:24cases across all 3 opcodes: all 6 distinct permutations ofmed3_f16, signed zeros (-0.0/+0.0), binary16 subnormals and±Inf, 1/2/3-NaN inputs,abs/neg,clamp,op_sel[3:0]with0xDEADCAFEdestination half preservation, SGPR/literal/inline sources, and partialEXEC_LO(0xAAAAAAAA) lane preservation.7refusals:omod != 0, high-halfop_selon SGPR and inline float constants,vcc_losource,s_denorm_mode 0x3, and conditionalMODEwrite.Verification (
devandrelease/O2, Windows10.0.26100)ctest --preset dev --no-tests=error -V -R '^native_minmax_med3_f16_'&ctest --preset release --no-tests=error -V -R '^native_minmax_med3_f16_':native_minmax_med3_f16_ir: Passed (24cases matched exact model;7refusals matched).native_minmax_med3_f16_controls: Passed (24cases compiled to DXIL;7refusals verified).native_minmax_med3_f16_pixel_warp: Passed (Microsoft Basic Render Driver10.0.26100.9711,12pixel draws /24cases matched;debug_layer=unavailable).native_minmax_med3_f16_pixel_hardware: Passed (12pixel draws /24cases matched;NVIDIA Quadro M1000M,32.0.15.7371,debug_layer=unavailable).native_minmax_med3_f16_compute_hardware: Skipped (77) (Intel(R) HD Graphics 530, vendor8086, device191b, driver31.0.101.2111lacks SM 6.6 wave32 — needs testing on a wave32-capable GPU).ctest --preset dev --no-tests=error -R '^native_.*_(controls|ir)$' --output-on-failure: 71/71 passed (0skips).rc=8): droppingany_naninv_med3_f16(med3_one_nan_uses_min), dropping high-halfop_sel & 8udestination placement (max3_opsel_dst_hi), and removingv_med3_f16fromhalf_binary = true(cond_modeunhandleds_denorm_mode) all failednative_minmax_med3_f16_ir.AI-assisted.