Repository navigation
shader: lower v_ldexp_f16 in the direct compute path - #3123
Conversation
tedin7
left a comment
There was a problem hiding this comment.
Review of 0594e43 (the change from 520ac7d, updated with main). Comment only.
The scaling, the denormal normalization, the round-to-nearest-even subnormal path and the overflow to Inf read correctly to me, and the CPU reference is independent of the lowering.
One thing should change before merge: inline float constants. operand32(i, i.src[0]) returns the f32 bit pattern for sources 240-248, and the lowering then keeps only the low 16 bits. For 0.5, 1.0, 2.0, 4.0 and their negatives the low half of the f32 pattern is 0, so v_ldexp_f16 v4, 1.0, v3 scales +0 instead of 1.0h; 1/(2*pi) gives an unrelated value. The v_add_f16 block in the same file maps these sources through halves[] (binary16 roundings). Could you do the same here, or refuse 240-248, and add one inline-constant source to the fixture? The same pattern was raised on #3135, and #3120 (already merged) has it too, so one follow-up could cover all of them.
Windows Server 2025 (Build 26100, MSVC 14.44.35207, D3D12 WARP) at 0594e433, for information:
- dev:
ctest --preset dev -R <native sweep>after buildingcompile_dxil native_store_replay: 100% tests passed out of 134 - release: same with
--preset release: 100% tests passed out of 134 <native sweep>is everynative_*test exceptnative_startup_request_cache_hardware(fails on WARP-only hosts with or without this PR). The_hardwarelegs skip on WARP.
AI-assisted; commands listed were executed locally.
KelboLive
left a comment
There was a problem hiding this comment.
Correct lowering of v_ldexp_f16 using exact integer-based IEEE-754 binary16 scaling. The denormal normalization, exponent clamping to [-64, 64], round-to-nearest-even subnormal underflow, and overflow handling are all precise. VOP3A abs/neg/clamp support is correct and unsupported modifiers (omod, neg/abs on src1, op_sel) are properly refused. Test suite covers denormal promotion, negative exponents, tie cases, and negative controls. Approved.
|
This PR shares the same inline float constant bug that tedin7 already flagged on this PR: Missing graphics guard. The v_add_f16 block has CMake guard. Same issue as #3125/#3135: uses NaN/Inf test coverage. The reference correctly handles NaN and Inf ( VOP2 abs/neg not tested. The lowering supports |
|
Thanks for the ldexp lowering. I reviewed
Minor, and consistent with some existing blocks: there's no On the conflict: This was a static review: code reading plus This comment was AI-assisted. |
|
Merged current
Verified on NVIDIA GeForce RTX 5080 (
Ready for re-review! Commit: 7a971b3 |
pigalot
left a comment
There was a problem hiding this comment.
Retested 7a971b36 integrated over main 32dc3d7c (tree 7b0ce75a). The merge is clean and git diff --check is clean.
Earlier points. tedin7's inline-constant finding is addressed: src0 240..248 now goes through packed_f16_inline_constant, and batch 1 covers it. The graphics_input guard, the MODE gate, the half_binary scan entry and the CMake guard are in. The delta cases cover ±0, ±Inf, qNaN, ±100 and INT16_MIN.
What I traced. I read the new v_ldexp_f16 block against the RDNA ISA description:
- delta is the sign-extended low 16 bits of src1, clamped to ±64;
- denormal inputs are normalised before scaling;
- subnormal results round to nearest even;
e > 30overflows to Inf;- Inf, NaN and ±0 pass through;
- clamp sends NaN and negative results to 0 and caps at 1.0;
- the high half of D is kept.
The wide form refuses op_sel, src1/src2 modifiers and src2, and the block refuses subword, DPP, permuted and scaled forms.
What I ran. I built in dev and release with the pinned SPIR-V tools set, then ran:
ctest --test-dir out/build/<preset> --no-tests=error -R '^(native_ldexp_f16_controls|native_f16_alu_.*|native_.*_(controls|ir))$' -E '_hardware$'
ctest --test-dir out/build/<preset> --no-tests=error -j 1 -V -R '^(native_ldexp_f16_hardware|native_f16_alu_hardware)$'The _hardware run went through the GPU lock. Results in Debug and Release /O2, with no skips:
- 97 non-hardware tests pass.
- Both hardware tests pass on the RTX 5090.
native_ldexp_f16_hardwareprintsbatch=0/1: 2048 result words (high halves kept) and 16 guards matched.
Control and mutants. Each mutant changes src/gfx1013_direct_compute.inl, then runs native_ldexp_f16_controls and native_ldexp_f16_hardware:
| Change | Result |
|---|---|
source back to main (control) |
killed: controls test, "direct DXIL lowering for v_ldexp_f16" missing |
| inline src0 read as the low half of the f32 word | killed: batch 1 word 9, beef0000 vs beef5000 |
| drop the Inf/NaN/zero pass-through | killed: batch 1 word 8 |
| subnormal ties round up | killed: batch 0 word 28 |
| denormal exponent off by one | killed: batch 0 word 16 |
| delta clamp ±20 instead of ±64 | killed: batch 1 word 32 |
| high half of D zeroed | killed: batch 0 word 8 |
| clamp lets NaN through | killed: batch 1 word 27 |
| drop the MODE gate inside the ldexp block | survived |
Restored afterwards; the worktree matches the trial merge.
Non-blocking.
- Dropping the MODE gate inside the new block doesn't fail anything. The
bad_moderefusal (s_round_mode 0xC) in the controls test still passes, so something earlier refuses that program first. I didn't trace which. Either the in-block gate is redundant, or the control needs a case that only that gate catches. - There is no
_irmode. The value semantics are pinned only by the hardware test, so they run only on wave32 GPUs. CI's controls test checks the DXIL forshl,lshrand15360only. - The "negative controls" in
tests/native_ldexp_f16_check.pycompare the Python reference with itself. They don't exercise the lowering. - No signalling-NaN input. A qNaN case is present.
Verdict: approve on 7a971b36.
Environment: NVIDIA GeForce RTX 5090 driver 32.0.16.1088, Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; SDK 10.0.28000.0 DXC; wave32; Python 3.12.10.
CI: Build and test on Windows passes on 7a971b36.
This reply was AI-assisted.
Fixes #3122. Refs #2935.
What this changes
v_ldexp_f16(VOP20x3b/ VOP3A0x13b) insrc/gfx1013_direct_compute.inlusing exact 32-bit integer IEEE-754 binary16 scaling while preservingD[31:16].S1[15:0]and clamps the exponent delta to[-64, 64], normalizes denormal inputs without flushing, rounds subnormal underflows to nearest-even, preserves±0.0h,±Inf, andNaN, supports VOP3Aabs/negonsrc0andclamp, and refuses unsupported modifiers (omod,neg/absonsrc1,op_sel, unusedsrc2).Tests & docs added
tests/native_ldexp_f16_check.py&tests/cmake/native_ldexp_f16.cmake:native_ldexp_f16_controls: validates emitted integer DXIL (shl i32/lshr i32), refuses invalid modifiers, and verifies that theflush_denormals,truncate_subnormal,no_clamp, andzero_highnegative controls each differ.native_ldexp_f16_hardware: dispatches 8 binary16 scaling cases (normals, negativei16exponent, denormal promotion, subnormal round-up and even/odd ties, overflow to+Inf/clamp) across VOP2 and VOP3A with pre-seededD[31:16], matching 2048 result words and 16 sentinel guards.docs/experiments/native-ldexp-f16.md: experiment note and reproduction commands.Verification
520ac7d110.0.26300.9974), MSVC19.44.35230, Windows SDK / DXC10.0.26100.0, NVIDIA GeForce RTX 5080 (10de:2c02, driver32.0.16.2124).ctest --preset dev --no-tests=error -R '^native_ldexp_' -V: 4/4 passed (0 skipped).ctest --preset release --no-tests=error -R '^native_ldexp_': 4/4 passed (0 skipped).tests/docs_links_check.py&tests/bidi_controls_check.py: passed.Scope: covers synthetic direct-DXIL compute fixtures for
v_ldexp_f16only; does not establish full-game execution.