Repository navigation
shader: lower v_sin_f16 and v_cos_f16 in direct Compute DXIL - #3300
JohnConnorNPC merged 3 commits into
Conversation
|
I reviewed the diff (not run). Three notes:
AI-assisted. |
|
Thanks for the PR. I built it at 475a232 (clang-cl cross build, run under Wine, no GPU). The
This comment was AI-assisted. |
Leyukaka
left a comment
There was a problem hiding this comment.
Reviewed 475a2325 by its diff. The points from 06:48 and 06:56 are still open; one more on the tests:
negis only tested on cos (cos_0125_neg, diff:289). cos(-x) = cos(x), so dropping the neg modifier for these ops keeps the case green.- The SDWA
ABScase is cos of +0.5 (cos_sdwa_w0_pad, diff:299), whereabschanges nothing; no SDWA case setsNEG.
Fix: a VOP3 sin case with neg=1 (e.g. +0.125 → -0.7071), and SDWA sin cases on a negative selected half, one with ABS and one with NEG. (sin_0375_abs already covers VOP3 abs.)
|
Review of MUST
SHOULD
AI-assisted. |
Adds v_sin_f16 and v_cos_f16 to binary16_unary() and shares a DirectCompute::trig_turns() helper with v_sin_f32/v_cos_f32, rounding via packed_half_rne() while preserving D[31:16], -0.0 on v_sin_f16, exact quarter/half-turn zeros, and Inf/NaN -> 0x7e00. Fixes R0Y00#3298. Refs R0Y00#2935. AI-assisted.
- Model the reduction as DXIL Round_ne (op 26) in the reference, the IR interpreter and the docs, and drop the |part| == 0.75 cos clause, which can never hold with |part| <= 0.5. - Compare every bit in the ir mode on a model host that keeps NaN payloads, answers Inf - Inf with a negative default NaN and returns +0 from Sin of a zero angle, so the NaN select, its uge test and the sin -0 select are each pinned. - Add a VOP3 sin case with neg and SDWA sin cases with ABS and NEG on a negative half. - Replace the 0.001 hardware tolerance with 2^-20 absolute plus two binary16 ulp and document that no DXIL Sin/Cos bound was found. - Drop native_f16_alu's v_sin_f16 refusal control, which this lowering replaces (as R0Y00#3425 did for v_log_f16). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
475a232 to
6a48b7e
Compare
|
Thanks @Leyukaka and @JohnConnorNPC. I rebased onto Change request
Op 26
Unpinned selects
Tolerance and bound
Other
AI-assisted. |
|
I re-reviewed Rebase. The first commit keeps both sides of the #3425 change. The trig block has its own Change request (18:50). All three requested cases are now in the file. I computed their expected values with the RNE reference:
The unselected half is 0.5 turns, which gives sin = +0, so these cases also catch a wrong word select. Earlier points.
Still open (NIT). Not measured. CI does not run these tests: I found no blocking issues on this head. It still needs the change request re-reviewed on AI-assisted. |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks @JohnConnorNPC. The NIT is fixed in AI-assisted. |
Leyukaka
left a comment
There was a problem hiding this comment.
Reviewed 3a8aaf24 by its diff; this replaces the changes request on 475a2325.
- The three test points are covered:
sin_0125_neg(VOP3neg,tests/native_sin_cos_f16_check.py:151),sin_sdwa_w1_abs(:163) andsin_sdwa_w0_neg(:164), both on a negative selected half. - The 06:48 points are covered: the reference and the
irmodel host use round half to even for op 26, the0.75cos clause is gone, and the hardware tolerance is 2^-20 absolute plus two binary16 ulp instead of 0.001, stated in the doc as an assumption. trig_turns()is thev_sin_f32/v_cos_f32body moved unchanged.- Measured on
3a8aaf24, dev preset,-DX2W_WITH_OPUS=OFF:ctest --preset dev --no-tests=error -R '^native_sin_cos_f16_(ir|controls|hardware)$|^native_f16_alu'→ 5/5 passed.native_sin_cos_f16_hardwareran instead of exiting 77: "74 words matched with D[31:16] preserved and guards" on NVIDIA GeForce RTX 5080 (10de:2c02), driver 32.0.16.2101.native_f16_alu_hardwarepassed on the same adapter.
Lowers VOP1 (
0x60/0x61), VOP3 (0x1e0/0x1e1), and SDWAv_sin_f16andv_cos_f16in the direct Compute DXIL path viabinary16_unary()and a sharedDirectCompute::trig_turns()helper.Fixes #3298. Refs #2935.
Changes
src/gfx1013_compute_native.cpp(binary16_unary()): Addv_sin_f16andv_cos_f16, enabling direct binary16 unary decode/SDWA subword handling,MODEchecking, and DPP form refusal.src/gfx1013_direct_compute.inl(trig_turns(),float_alu()):trig_turns(bool cosine, const string &a)shared byv_sin_f32/v_cos_f32andv_sin_f16/v_cos_f16: reduces in turns with round-to-nearest-even (part = a - Round_ne(a), DXIL op 26,|part| <= 0.5, signed zero preserved) before converting to radians (* 2*pi), and forces exact+0.0at|part| == 0.5for sine and|part| == 0.25for cosine.v_sin_f16/v_cos_f16throughtrig_turns()+packed_half_rne(), mapping±InfandNaN(|source| >= 0x7c00) to0x7e00, preserving-0.0(0x8000) onv_sin_f16, and keeping destinationD[31:16]unchanged on VOP1/VOP3 (or applying SDWAPRESERVE/PAD).tests/native_sin_cos_f16_check.py,tests/cmake/native_sin_cos_f16.cmake,docs/experiments/native-sin-cos-f16.md: Addir,controls, andhardwarechecks covering 37 cases (VOP1, VOP3abs/negincluding sin withneg, SDWA sin withABS/NEGon a negative half, SDWAWORD_0/WORD_1PRESERVE/PAD, inline float/int, literal, SGPR, VGPR overlap,±0,±0.25,±0.5,±0.75,-1.75,2048.0,65504.0,±Inf,qNaN,sNaN, subnormals, general angles) and 8 negative refusal cases.Verification
On
6a48b7e2(rebased ontomainff9dcef0; the conflicts with #3425v_log_f16keep both sides):ctest --preset dev --no-tests=error -R '^native_sin_cos_f16_' -V:native_sin_cos_f16_ir: Passed, 37 cases matched bit for bit and 8 refusals verified.native_sin_cos_f16_controls: Passed, 37 cases compiled to DXIL and 8 refusals verified.native_sin_cos_f16_hardware: Skipped (77). The local adapter does not report SM 6.6 with wave32, so the readback is unmeasured here.ctest --preset dev --no-tests=error -R '^native_.*_(controls|ir)$|^native_sin_cos' -j 2: 138/138 passed.native_f16_alu_irusedv_sin_f16as its "direct DXIL lowering" refusal control. That control is removed because this PR lowers the op, as compute: lower binary16 VOP1 v_log_f16 in the direct compute path #3425 did forv_log_f16.python -B tests/docs_links_check.py: passed (179 Markdown files, 718 links).irmode runs on a model host. That host keeps NaN payloads (also throughlegacyF16ToF32), returns the negative default NaN0xffc00000forInf - Inf, and makes Sin of a zero angle return+0. Mutants ofnative_sin_cos_f16_ir, each rebuilt and then restored:ugetougt: fails.v_sin_f16-0.0select: fails.AI-assisted.
🤖 Generated with Claude Code