Skip to content

tests/semantic: run v_pk_add/mul/fma/min/max_f16 through the translator, not a self-built model - #3537

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
kapitche:sempkf16
Nov 23, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
kapitche:sempkf16

Conversation

@kapitche

Copy link
Copy Markdown
Contributor

AI-assisted.

Claim: batch A of the model-only semantic tests (coordination issue #3381, claiming: tests/semantic batch A (float)); follow-up of the finding under #3472.

What was wrong. test_valu_pk_{add,mul,fma,minmax}_f16.py (1.3k to 1.8k lines each) built their own SIMD model and never imported support or rdna2spirv. Repro of the gap: in the v_pk_*_f16 branch of tools/rdna2spirv.py make v_pk_add_f16 subtract, v_pk_fma_f16 read src1/src2 swapped, v_pk_min_f16 take the max, ignore neg_hi, or default op_sel_hi to 0; the old files stay green.

Fix. Same shape as #3448/#3457/#3472: every case goes through support.translate_lines and mrt0_words. Expected dwords are written by hand next to each case (per lane), rechecked lane by lane against a plain-Python binary16 reference (tests/semantic/f16_ref.py, byte-identical to the one in #3519, so whichever lands second merges cleanly; the min/max reference lives in the file). Covers per-lane edge values (signed zeros, ties, overflow, subnormals, inf/NaN by class; min/max NaN suppression and -0 < +0), every op_sel/op_sel_hi combination, hand-checked neg_lo/neg_hi/clamp cases, SGPR sources, and seeded random operands with random modifiers. v_pk_fma_f16 includes the fused (single-rounding) case. The translator agreed with the ISA on every case: no translator change. I left literal/inline-constant sources out on purpose: where the unused half comes from is not settled by the ISA text (see #3368).

Tested. Python 3.12.16, Linux (WSL): python -I -m unittest discover -s tests/semantic -p 'test_valu_pk_*_f16.py' runs 24 tests, all pass; tests/test_ci_registration.py passes.

Negative control. With a mutated copy of tools/ (LEONIDA_TOOLS_DIR): v_pk_add_f16 as OpFSub: new add file fails (169 failures), old file OK; v_pk_mul_f16 as an add: 183, old OK; v_pk_fma_f16 with src1/src2 swapped: 216, old OK; v_pk_min_f16/max swapped: 223, old OK; default op_sel_hi 0: 19 to 41 failures per file, old OK; neg_hi read from neg_lo: 88 (add) and 80 (fma), old OK.

…or instead of a self-built model

The four files modelled a register file and packed f16 SIMD themselves and never called tools/rdna2spirv.py. Each now
translates its cases and runs them on spirv_mini_interp with hand-written expected words, a binary16 reference
(tests/semantic/f16_ref.py, shared with the scalar f16 files), op_sel/op_sel_hi/neg_lo/neg_hi/clamp and SGPR sources,
and seeded random operands and modifiers.
@Vonsek

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Measured on gfx1036 (RDNA2, driver 26.10.1, raw hw_oracle kernels, one lane, game MODE: IEEE 0, DX10_CLAMP 1, f32 denormals flushed, f16/f64 denormals kept): v_pk_add_f16, v_pk_mul_f16, v_pk_min_f16, v_pk_max_f16 (S0, S1) and v_pk_fma_f16 (S0..S2), 120 random operand sets each (words built from the PR's special values - 0, -0, 1, 2, 0.5, max, inf, quiet and signalling NaN, subnormals - and random halves) under six modifier sets: none, clamp, neg_lo / neg_hi, op_sel / op_sel_hi as [1,0,..]/[0,1,..], all-ones, and op_sel:[0,1..] op_sel_hi:[0,0..]. The expectation per lane is the PR's f16_ref.py reference (ref_add, ref_mul, ref_fma, clamp01, and the ref_min / ref_max of test_valu_pk_minmax_f16.py) applied to the half each lane's op_sel / op_sel_hi selects, with neg_lo / neg_hi on lane 0 / lane 1; NaNs by class. 30 combinations x 120 = 3600 cases: all match, including min/max with a NaN operand (the other operand wins) and -0 < +0. This PR's translation, SGPR sources and literal operands were not part of this run. The scripts are local, not pushed. AI-assisted.

@iurysf

iurysf commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Code read of f8af82a5: looks good.

Ran on Windows 11, Python 3.14: the four files, 6 tests each, OK.

AI-assisted code read (Claude).

@zneel

zneel commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Reviewed and tested f8af82a5 on Windows 11 Pro 10.0.26300, AMD Ryzen 7 9800X3D CPU (64 GB RAM), AMD Radeon RX 9070 XT (AMD 26.11.2), Python 3.12.10: looks good.

run result
unittest discover -s tests/semantic -p test_valu_pk_add_f16.py 6 OK
unittest discover -s tests/semantic -p test_valu_pk_fma_f16.py 6 OK
unittest discover -s tests/semantic -p test_valu_pk_minmax_f16.py 6 OK
unittest discover -s tests/semantic -p test_valu_pk_mul_f16.py 6 OK

Review: I read the four rewritten files, f16_ref.py, and the v_pk_*_f16 branch of tools/rdna2spirv.py (6444-6500) at the head. Every case now goes through support.translate_lines, and I rechecked the hand rows by hand, including the fused fma row (2^-20 = 0x0010), 2050 + 1 rounding to 2052, and 100 * 100 = 0x70E2. On the overlap with #3519, iurysf already reported that the two f16_ref.py files are identical. I confirmed it from the git blob: both heads store blob fd108aae (#3519 at 4ecc0617) and main has no such file, so they do not conflict. One gap, not this PR's to fix: no case runs clamp with a NaN result. The branch uses FClamp (6493), which docs/design.md:315 already says leaves a NaN result to the driver. The mini-interpreter raises UnsupportedConstruct for it on all five ops (I ran it), while the hardware and clamp01 give +0. A smaller point: the "all sgpr" form in test_valu_pk_fma_f16.py:123 reads three SGPRs, one more than the GFX10 constant bus allows (tools/pk16_diff.py:27). It is harmless, because the translator accepts it.

AI-assisted (Claude Code); I checked the results.

@sds-228 sds-228 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review of f8af82a: no issues found. Packed-op coverage now runs through the translator with per-lane checks, and no contradictory expectations remain. Targeted suites: 24 tests OK; compileall and diff check clean.

AI-assisted (OpenCode).

@memorypressure

Copy link
Copy Markdown

Rewritten packed-f16 tests verified on Linux: merges cleanly into current main, compileall clean, and all four files pass under python -I (6 tests each) and pytest (24 tests / 896 subtests). Results demonstrably come from the translator — sabotaging the pk op selection or the single-rounding fma path in tools/rdna2spirv.py fails 169-223 subtests per file. One coordination note: tests/semantic/f16_ref.py here is byte-identical to the copy in #3519, so whichever of the two merges second adds nothing new (they merge together without conflict either way); the opcode coverage itself does not overlap. The DEBT entries for these four files could be dropped, as they now translate listings. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

@ItsNotRexed
ItsNotRexed merged commit e860a22 into ItsNotRexed:main Nov 23, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants