Repository navigation
Conversation
The VEC_F table lowers v_add_f32, v_sub_f32, v_subrev_f32, v_mul_f32, v_mul_legacy_f32, v_min_f32, v_max_f32, v_fma_f32, v_mad_f32, v_mad_legacy_f32, v_med3_f32, v_min3_f32 and v_max3_f32, and no check ran any of them. tests/startup_gfx2hlsl_float_alu_check.py draws them with the shared per-lane runner (byte-identical copy of tests/startup_gfx2hlsl_lane_alu.py) on inputs with exact results, against references written from the RDNA 2 ISA (S1 - S0 for subrev, the legacy multiply's 0 against inf and NaN, the middle of three). Each operation has one mutated lowering whose first draw must read its own mutated words. All 52 draws match on WARP and an RX 6600 through FXC ps_5_1 and DXC ps_6_0, and the 26 mutated draws read their mutated words. Not covered and recorded in docs/experiments.md: the translation writes v_fma_f32 and v_mad_f32 as a * b + c, which WARP rounds twice and the RX 6600 fuses, so an inexact product reads 0 on one and 2^-24 on the other.
tedin7
left a comment
There was a problem hiding this comment.
Peer review at head_sha: 0389c74aa5df30e68390b29a96cdef1de97bb3d5
Verdict: 0 P1, 0 P2. The translator is not changed; this PR only adds checks.
Scope (full diff read)
- New:
tests/startup_gfx2hlsl_float_alu_check.pyand the shared runnertests/startup_gfx2hlsl_lane_alu.py. Changed:CMakeLists.txt(a controls test pluswarp/hardwaredraw tests withSKIP_RETURN_CODE 77),docs/experiments.md, and.github/workflows/windows.yml(two lines: thebinarycheck withllvm-mc-15in the Python check list, and the file in the Linux check list). Nothing undersrc/ortools/. - The runner is byte-identical to the copies in #1703, #1706 and #1708 (SHA-256 prefix
d8801e44cfe611cdfor all four heads), so the add/add on that path merges cleanly whichever lands first.git merge-treeagainst currentmain(eaa2024b): no conflicts; it also merges cleanly with #1716, and with both applied the controls,binarymode and my evaluation below still pass.
Semantics against the ISA
v_subrev_f32= S1 - S0;v_mul_legacy_f32andv_mad_legacy_f32use a multiply that reads 0 when either factor is 0, even against an infinity or NaN (the fixture sets include0 * inf,inf * 0,0 * NaN,NaN * 0);med3is the middle value;min3/max3are the nested min/max. These match theVEC_Fentries and themul_legacy/med3helpers ((a == 0.0 || b == 0.0) ? 0.0 : a * bandmax(min(a, b), min(max(a, b), c))).- The input sets are dyadic values whose sums and products fit in 24 bits, so the references are exact and do not depend on fusing. The PR says so itself, and it documents what it does not cover: inexact products (
v_fma_f32andv_mad_f32are both lowered asa * b + c, which gives adapter-dependent results on an inexact product), NaN and signed-zero ordering in min/max/med3, and denormals.
Independent check on Linux
The draw is Windows-only, so I evaluated the translated text myself: for each of the 13 operations I translated the fixture, evaluated the four per-lane expressions in Python (binary32 conversion for F/U, the two helpers as defined above), and compared with the reference words. I used the PR's draw sets plus 4,000 random exact sets per operation (multiples of 1/8, all with exact results), and did the same for each mutated lowering against its mutated reference: 11,026 four-lane chunks, 0 differences. llvm-mc-19 -mcpu=gfx1013 words for all 13 bodies match the recorded words (binary mode).
Findings
- nit: the check relies on the Windows draw (
startup_gfx2hlsl_float_alu_warp/_hardware) to prove the semantics. The Linux-run controls only check shape (four lanes translated, mutation pattern matches four times, mutation changes set 0). For example, flippingv_subrev_f32toa - bin the translator still passes the Linux controls andbinarymode (see below). That is by design, and the PR says the evaluator-style results come from the draw, but it means the numbers in the docs (52 draws on WARP and on an RX 6600, 26 mutated draws) are not something I could reproduce here.
Verified
Limits: Linux x86-64 only. No D3D12, no DXC/FXC, so draw (and the WARP and RX 6600 results in the docs) was not run. llvm-mc-15, which CI uses, is not installed here; I used llvm-mc-19.
python3 -B tests/startup_gfx2hlsl_float_alu_check.py-> exit 0 (41 checks ok).... binary /usr/bin/llvm-mc-19-> "fixture words match llvm-mc", exit 0.python3 -B tests/docs_links_check.py-> OK.- Mutation 1 (translator):
v_subrev_f32{1} - {0}->{0} - {1}: Linux controls exit 0 andbinaryexits 0 (escape; only the draw, or my evaluator, sees it:0xbf400000vs0x3f400000). - Mutation 2 (translator):
v_mad_legacy_f32mul_legacy({0}, {1}) + {2}->{0} * {1} + {2}: Linux controls exit 1 (AssertionError: ('v_mad_legacy_f32', 0), the mutation pattern no longer matches). - Mutation 3 (translator):
v_min3_f32reshaped tomin(min({0}, {1}), {2}): Linux controls exit 1 (same pattern assertion). - Mutation 4 (test): the recorded
v_med3_f32body word changed:binaryexits 1 (assembled ..., recorded ...). - All reverted with
git checkout -- .;git status --shortclean.
Also found (not for this PR)
v_fma_f32is lowered toa * b + c, which is not a single-rounding fused operation on every adapter (the docs show0x33800000on RX 6600 and0on WARP). That is a translator question for a later change, not a defect of this check.
AI-assisted; commands listed were executed locally.
Green on its base, red on mainI merged this branch into That is one local merge on my machine, not a CI run. The mutation for
I checked the other side on the same code, at the base this PR was written against ( For the Why the checks were greenThe PR's merge ref is What I would change
I have made no hardware claim here: the fixture never reached a draw, so this says nothing about RDNA 4 arithmetic. Once the controls pass I can run the 52 draws and the 26 mutants on the same machine that produced this report. AI-assisted. |
|
Hardware run of head 0389c74. Windows 11 Pro 26100.9168, DXC/FXC from Windows SDK 10.0.26100,
No changes made. |
|
@Asimmimx could you rebase this branch onto current GitHub reports head Files that conflict with current
Commands run locally: Once it is rebased and CI is green it will be re-checked right away. AI-assisted; commands listed were executed locally. |
Refs #1149.
Change
No check ran these thirteen binary32 operations of the
VEC_Ftable intools/startup/gfx2hlsl.py:v_add_f32,v_sub_f32,v_subrev_f32,v_mul_f32,v_mul_legacy_f32,v_min_f32,v_max_f32,v_fma_f32,v_mad_f32,v_mad_legacy_f32,v_med3_f32,v_min3_f32andv_max3_f32.This PR adds a check only. The translator does not change.
tests/startup_gfx2hlsl_float_alu_check.pydraws them with the per-lane runnertests/startup_gfx2hlsl_lane_alu.py. The runner is byte-identical to the copies in #1703, #1706 and #1708. In each draw:_e32and_e64for the VOP2 forms;binarymode;neg_loandneg_hi.References (AMD RDNA 2 ISA reference):
v_subrevis S1 - S0.0 * inf,inf * 0,0 * NaNandNaN * 0.v_med3_f32is the middle of three values.Every input set has an exact result: dyadic values whose sums and products fit in 24 bits. The check therefore does not depend on rounding or on whether a compiler fuses a multiply and an add.
Mutations, one per operation. The first draw with the mutated lowering must read the mutation's own reference words:
a * b - cfor the multiply-adds;max3formed3.Results
Commit
0389c74aonorigin/main. Windows 11 26300.9974, DXC 1.8.2502.11, FXC 10.0.26100, debug layer on.There were no skips.
binarywith llvm-mc 19.1.1 givesfixture words match llvm-mc.Observation:
v_fma_f32andv_mad_f32on an inexact product. The translation writes both asa * b + c.v_fma_f32rounds once.v_mad_f32rounds the product and then the sum.I drew them with
a = b = 1 + 2^-12andc = -(1 + 2^-11). A single rounding gives 2^-24 (0x33800000), and two roundings give 0.v_fma_f32, FXC and DXC0000000033800000v_mad_f32, FXC and DXC0000000033800000So the same translated text rounds twice on WARP and is fused on the RX 6600.
v_fma_f32differs from the ISA on WARP, andv_mad_f32differs on the RX 6600. As far as I know, binary32 HLSL has no form that guarantees either behaviour, which is also whycompute_store_aotrefuses fused multiply-add. I recorded this under "Not covered" indocs/experiments.mdand did not change the lowering.Also found.
v_add_f32 v1, v2(one source short) raisesIndexErrorinStage.oneinstead ofUnsupported. A VEC_F form with an extra source, such asv_med3_f32 v1, v2, v3, v4, v5, translates with the extra source silently dropped. The VEC_U table already checks the operand count. I'll send that fix as a separate PR.AI-assisted (Claude Code).