Repository navigation
shader, xtask, docs: add a reduced GFX10 conformance corpus - #52
Conversation
|
This pull request changes 32371 lines (Cargo.lock aside). Pull requests of 1000 lines or more are reviewed only once split, or when a maintainer agreed to the size beforehand in an issue: see Size. If that agreement exists, link it in the description. |
|
Note on PR size ( |
simnJS
left a comment
There was a problem hiding this comment.
Thanks for picking up #14; the generator and the test are clean. I checked the corpus independently: all 31,719 entries appear verbatim in the 20 LLVM files at llvmorg-19.1.7, the shards hold nothing else, and CI is green. A few things before it goes in:
- Provenance and licence. The shards are third-party data (Apache-2.0 WITH LLVM-exception). Please restore the PR template and tick "Some of it comes from elsewhere", listing the source (llvm-project
llvmorg-19.1.7, the 20 files underllvm/test/MC/AMDGPU/), its licence and the files concerned. Please also add a short NOTICE.md section, and have the generator write into each shard headerSPDX-License-Identifier: Apache-2.0 WITH LLVM-exception, "Part of the LLVM Project, see https://llvm.org/LICENSE.txt" and "extracted and reformatted from …" (Apache-2.0 §4: attribution, licence, notice of changes). - Legacy MAD/MAC entry (
gfx10_conformance.rs:24): it says console silicon "keeps non-fused legacy MAD/MAC", which neither the corpus nor XTP establishes. These consoles are RDNA 2-class, and the GFX10.3 file in your corpus names these opcodesv_fma_legacy_f32/v_fmac_legacy_f32. Please state only what is known: our table follows Mesa's GFX10 column, GFX10.3 uses these opcodes for the fused forms, and which one the console runs is open. As written, the test reads as evidence for the unfused lowering inemit/lower/valu.rs. - Size: please link #14 in the description as the agreement for the corpus, as the bot asked.
- Nits:
require_gfx10_prefixisfalsefor everyLLVM_FILESentry, so drop it or use it; a SHA-256 per fetched file would makecurlregeneration verifiable.
The gaps you pinned (VOP3 VINTRP, image_gather4h, the _cd_g16 samples, v_dot8_i32_i4) are real decoder gaps; could you open a follow-up issue for them? Thanks!
fogydes
left a comment
There was a problem hiding this comment.
Review of PR #52: GFX10 decoder conformance corpus and test
Reviewed head 6a0f02b (one commit), by reading gh pr diff 52 and
origin/main. Nothing was built or run. All CI checks on
the PR are green, including policy, conventions, clippy,
clippy-diagnostics, test and gpu-debug-layer. Nobody has reviewed it yet
(no review, no maintainer comment); the only comments are the size bot and the
author's reply to it.
Verdict: needs changes
The Rust is good and the test is meaningful. Three things stop me recommending
approval as it stands:
- the licence handling is incomplete for Apache-2.0 data that the PR itself
labels as Apache-2.0 (finding 1); - at 32,378 changed lines, the PR is
size/XL, and issue #14 contains no prior
agreement to that size (finding 2); and - one of the eleven "explained differences" has an explanation that is
unsupported and probably wrong, so the test pins what may be a real decoder
error as correct (finding 3).
None of these is a rewrite. Items 1 and 3 are small edits; item 2 is a decision
for the maintainer, and I give a concrete way to cut the corpus to about 7 %
of its size without losing the properties the test checks.
Licensing and provenance (the main question)
Where the corpus comes from. From LLVM's public MC assembly tests,
llvm/test/MC/AMDGPU/*.s, tag llvmorg-19.1.7, 20 named files
(xtask/src/gfx10_corpus.rs:27-48). The generator reads the FileCheck lines
(// GFX10: <asm> ; encoding: [0x..,...]) and stores only mnemonic plus the
encoded dwords in hex. It is not from a disassembler, not from AMD documents,
and there is no console SDK, no driver dump and no game material anywhere. I
sampled the corpus (1,757 distinct mnemonics, 31,719 lines, one to five
dwords per line) and grepped it for title, SDK and console names: nothing.
docs/asset-policy.md is not touched by it, and the CI policy check passes
(.txt files under 512 KiB, no long hex runs, because words are spaced).
The list includes gfx1013.s and gfx1011_dlops.s; these are ordinary public
LLVM test files (anyone can read them upstream), and the issue asked for "LLVM
MC gfx10 tests" without naming files.
Licence. LLVM is "Apache License v2.0 with LLVM Exceptions". Apache-2.0 is
compatible with GPL-3.0-or-later (one way: Apache code can go into a GPLv3
work), and CONTRIBUTING.md lists Apache-2.0 as acceptable. The issue and
docs/analysis/shader.md S6 both name this source and licence as approved. So
the choice of source is correct.
What is missing.
- The corpus is a derivative of Apache-2.0 material, and the PR labels it as
such (# Source license: Apache-2.0 WITH LLVM-exception.in each shard,
xtask/src/gfx10_corpus.rs:120). Apache-2.0 section 4 asks anyone who
redistributes a Work or Derivative Work to give recipients a copy of the
licence, and to keep the copyright and attribution notices. The shard header
names the licence only; it carries no copyright holder ("The LLVM Project"),
no URL of the upstream repository, no pointer to a licence text, and the
repository has no copy of the licence (git ls-tree origin/mainhas only
LICENSE(GPL) andNOTICE.md).NOTICE.mdhas a section on references that
are not copied and says third-party material "keeps its own notices", but it
does not mention LLVM. - Honest caveat: the encodings and mnemonics are facts about hardware, and a
hex-only extract of them is thin, so a copyright claim over them would be
weak. That is not a reason to leave the PR's own Apache label without its
conditions; the cheap fix below removes the question. - The PR's Provenance section states the source tag and the licence in one
clause but does not follow the template's "Some of it comes from elsewhere"
form (each source, its licence, the files concerned, ticked box). The body
replaced the template. CIconventionspasses anyway. - The test's header and
KNOWN_NAME_DIFFERENCEScomments also cite "Mesa
22.3.0aco_opcodes.py" as the origin of the existingopcodes.rstable.
That is existing code and out of scope, but it is why the table (MIT) and
these comments agree, and the final licence note should say so too. - I could not check that the checked-in corpus equals what the generator would
produce from the tag (no network, no build). The PR records no hash of the
source files, so a reviewer cannot confirm either (finding 5). - The claim of independence from xcl is plausible: xcl's checked agreement
uses 23,812 encodings (docs/analysis/shader.mdsection 5.1) and this corpus
has 31,719 from a different, explicitly parsed file list, with its own parser.
I cannot prove it from the diff alone; the author's tick and the different
numbers are what I have.
Fix for finding 1: add crates/xtp-shader/tests/data/LICENSE-LLVM.txt
(the Apache-2.0 text with the LLVM exception, copied verbatim from upstream
llvm/LICENSE.TXT at the pinned tag, under the 512 KiB policy limit), give
each shard header a second line "Derived from the LLVM Project
(https://github.com/llvm/llvm-project, tag llvmorg-19.1.7), Copyright (c)
LLVM Project contributors; modified: reduced to mnemonic and encoding words,
deduplicated and sorted; see LICENSE-LLVM.txt", extend the generator's header
string to emit it, add one paragraph to NOTICE.md, and re-do the PR's
Provenance with the template's "comes from elsewhere" list (source, licence,
20 files). If the policy check rejects the licence file's type, it needs an
entry in xtask/src/policy.rs with a reason; that is a mechanical edit the
maintainer should expect.
Findings, by severity
High
-
Apache-2.0 conditions not met for the corpus (see above). Files:
crates/xtp-shader/tests/data/gfx10-llvm-mc-0{1,2,3}.txt:1-3,
xtask/src/gfx10_corpus.rs:117-124(the header),NOTICE.md.
Fix as described. -
PR size is
size/XLwithout prior agreement. 31,719 of the 32,378 lines
are generated data; the hand-written part is about 650 lines. The size bot
already said this, andCONTRIBUTING.md("Size") says XL is reviewed only
once split or when a maintainer agreed to it beforehand in an issue. Issue
#14 says "kept as test data we generate ourselves" but no size, and no
maintainer reply agrees to 32k lines. The author offered to trim.
Is it justified? Not at this size, for what the test checks. The test checks
only the decoded opcode name and dword length (gfx10_conformance.rs:~120-210).
Those depend on the opcode and a few mode bits, not on operand values, but
the corpus contains every operand variant LLVM tests (for example 14
buffer_atomic_addlines that differ only in offset and register fields):
there are only 2,227 distinct (mnemonic, dword count) pairs among 31,719
lines (7 %).
Fix options, in my order of preference:
(a) keep one representative per (mnemonic, dword count), and also keep any
line whose first word has a different value in the decoder-relevant bits
(the literal/DPP/SDWA/NSA selectors:src0in{0xff, 0xf9, 0xfa, 0xe9, 0xea}for VOP, the0xffsource for VOP3/SOP,w & 0x6for MIMG, bit 25
of MUBUF, bit 21 of MTBUF word 1, whichgfx10/mod.rsreads), giving
roughly 3-4k lines in one shard; (b) split the PR (generator and test with
the small corpus first); (c) ask the maintainer in issue #14 to agree to the
size. The generator keeps the full dump for anyone who wants it
(--llvm-dir), so nothing is lost. Whichever is chosen must be agreed in
the issue before merge.
Medium
-
The explanation of the legacy MAD/MAC difference is unsupported and
probably wrong.gfx10_conformance.rs:24-39: the test says XTP's name
v_mad_legacy_f32/v_mac_legacy_f32is right because "GFX10.1 / Xbox
Series silicon keeps non-fused legacy MAD/MAC" at VOP30x140and VOP2
0x006, while "GFX10.3 PC reused" them for FMA/FMAC. No source is given for
the console claim. Xbox Series is an RDNA 2 part, the familygfx1030_new.s
(in this very corpus) describes with FMA at those opcodes; the claim that
the console behaves like GFX10.1 contradicts that, and the test file's own
header says the table "targets Xbox Series / Scarlett silicon" while it is
generated from Mesa 22.3.0's GFX10 (gfx1010) table. If the console decodes
0x140as FMA, XTP names it wrongly, and this test now hides the error
(and 6 corpus lines). If the author learned the console behaviour from
non-public material, that conflicts with the asset policy and the
no-xcl-reading statement. Fix: either cite a public source (an LLVM or
Mesa commit, an AMD ISA document) in the comment, or rewrite the comment as
"unresolved: XTP follows Mesa's GFX10.1 table; GFX10.3 and later (LLVM
gfx1030_new.s) name these opcodesv_fma_legacy_f32/v_fmac_legacy_f32;
which one the console decodes is not established here" and open a follow-up
issue. Do not call it explained. -
Eleven pinned differences are not equally "explained", and one set is a
real decoder gap. The issue's acceptance is "100 % agreement or each
difference explained", and the listing is honest and self-checking (a stale
entry fails the test,gfx10_conformance.rs:265), which I like. But
v_interp_p1_f32_e64,v_interp_p2_f32_e64,v_interp_mov_f32_e64
(44 lines, the biggest group) are valid VOP3 instructions the decoder returns
no name for, becauseopcodes.rsdoes not alias VOP30x200..=0x202to
VINTRP (gfx10/mod.rs:name, Vop3 arm). The PR calls it "not aliased"; a
shader using attribute interpolation with modifiers would hit it. Likewise
image_gather4h, the fourimage_sample_*cd*_g16forms and
v_dot8_i32_i4are missing opcodes. The author avoidedopcodes.rsto
dodge the in-progress_g16/a16work (that was the maintainer's request
in the issue, so fine), but each gap needs a follow-up issue, and the
_g16entries will start failing the stale check as soon as the core team's
change lands (intended, but tell them). Fix: list the follow-ups in the PR
description.
Low
-
Generator reproducibility and provenance.
xtask/src/gfx10_corpus.rs:fetch_llvm_file(:104) shells out tocurlfor 20 URLs with no hash
check, so the output depends on whatever the tag serves; the header says
llvmorg-19.1.7(:120) even when--llvm-dirpoints at a different
checkout (:~65), which can mislabel a corpus. Fix: store a SHA-256 per
source file inLLVM_FILES, verify after reading either way, and emit the
hashes in the header (or refuse--llvm-dircontent that does not match).- The
LLVM_FILESflag is documented as "require_gfx10_prefix" but every
entry isfalse, so the parameter and theboolplumbing is dead
weight (:27-48,parse_llvm_mc,is_gfx10_prefix). Either use it for
the shared multi-architecture files (are there any in the list? the
comment says so; there is none) or remove it. is_gfx10_prefix(:206-242): the exclusion list uses substring checks
(contains("GFX9")and so on) and then accepts anything that
contains("GFX10"), so a prefix likeNOT-GFX10orGFX10-NOTwould be
taken as positive. None appear in the 20 files I can reason about, but
the function is fragile; match whole tokens split on-/,.- Only one parser unit test (
:~300, three positive and two negative
lines); no test for shard splitting, determinism orfirst_mnemonic
edge cases (a CHECK line without an inline mnemonic takes the last
source line's, which is right for LLVM's layout but can mislabel when an
alias was used in the source). - The generator writes into the repository by default; that is intended
here (checked-in test data) and is not a policy problem.
-
decode_oneleaves a public production API for a test.
gfx10/mod.rs(+8 lines): it ignores bytes after the first instruction
and duplicatesdecode's multiple-of-4 check. Fine and minimal, which
the issue asked for; add a doc line that trailing bytes are ignored and that
literals and extra dwords are part of the instruction, since the test relies
on both. -
Docs.
docs/analysis/shader.mdS6 still reads as open work and the new
cargo xtask gfx10-corpuscommand (flags--llvm-dir,--out-dir) is
documented only in--help. One line indocs/dev/START_HERE.mdand
updating S6's status would satisfy the conventions rule "docs updated where
commands change".
Is the test meaningful, or can it pass vacuously?
It is meaningful. In particular:
- Every corpus line must decode without error, to the same dword count as
LLVM (gfx10_conformance.rs:~190-205), which genuinely tests the decoder's
length logic (literals, DPP8/DPP16/SDWA, NSA address dwords for MIMG, the
s_setreg_imm32form) because the corpus passes the full encoded dwords. - Names are compared after removing
_e32/_e64/_dpp/_sdwa(:145-153), and a
Nonename from the decoder is a mismatch unless the difference table says
Nonefor that exact base mnemonic. - The difference table is checked for staleness (
:265) and the corpus must
exceed 30,000 entries (:158), which also catches a deleted shard (removing
any one shard leaves at most 24,504 entries, under the floor) and the 19 families are
asserted to be exercised (:268-292), so an empty or truncated corpus cannot
pass. - Reading is strict: a bad hex field, an empty line of words or an unreadable
shard panics.
Weaker points, none blocking: the test checks names and lengths only, not
operands or the encoding family (so v_add_f32_e64 decoding as VOP2 would
pass); 32-bit VINTRP (Encoding::Vintrp) is not exercised at all (no
LLVM line uses it; the test comment admits it); a known difference with None
passes for every encoding of that mnemonic, not only the ones documented; and
the "30,000" floor is a constant that must be hand-edited whenever the corpus
is regenerated smaller (it will break option 2(a) above, which is easy to fix
by reading the count from the shard header instead).
CI time
I could not run it. The author reports 0.09 s for the test; reading three
files of about 1 MB in total and 31.7k small decodes should stay far under a
second even in debug. The test job took 2 m 57 s on this PR, the same as on
other PRs. The generator is not part of CI.
What I did not do
No build, no test run, no GitHub comment, no check that the corpus equals
fresh generator output (no network). The numbers about the corpus come from
counting lines in the PR diff.
Review drafted with Claude Code; findings checked against the PR head by reading the code.
|
This pull request now conflicts with its base branch. Please rebase it on |
Check GFX10 instruction names and lengths against a pinned LLVM MC corpus. Keep representative decoder selectors, verify source hashes, and carry the LLVM attribution and licence. Track missing opcode names and the unresolved legacy MAD/MAC names as separate expectations.
6a0f02b to
2a130b3
Compare
simnJS
Follow-up issue #64 covers the nine missing names and the open legacy-opcode question. fogydes
|
|
Thanks for the thorough rework. Everything from my review is addressed, and #64 covers the gaps. I fetched the 20 files at llvmorg-19.1.7: every hash matches, and all 2,472 rows appear in them. Before approval:
The size is fine from our side, since most of it is the pinned conformance data under #14. During review, please push new commits rather than force-pushing. |
Keep both the replay and GFX10 corpus commands in xtask.
Reject the command before it can overwrite the reduced fixture.
|
Thanks for checking the 20 LLVM inputs and all 2,472 rows.
Both changes are new commits on top of the reviewed head. Local formatting, both Clippy configurations, asset policy, commit conventions, and both focused test suites passed. |
|
Other open pull requests change the same files. Check that they do not do the same work, and agree with their authors on which lands first: the other one will then need a rebase.
This comment is kept up to date automatically and removed when the overlap ends. |
simnJS
left a comment
There was a problem hiding this comment.
Thanks. Both points are done: Replay and Gfx10Corpus coexist, and --full now requires --out-dir, with a parser test. One optional nit: the full-shard header (gfx10_corpus.rs:291) still says gfx10-corpus --full, which no longer runs on its own.
Note on #68: whichever of the two lands second must remove the nine KNOWN_DECODER_GAPS pins, and the stale-pin check will flag them.
Approving; I'll merge once test is green.
What and why
Fixes: #14
Depends on: none
Add a GFX10 decoder conformance test against the public LLVM MC AMDGPU encodings. The test checks instruction lengths and names so that decoder changes get exercised across the instruction families represented in the corpus. Issue #14 records the agreement to keep a generated corpus as test data. Corpus agreement in #14
The checked-in corpus now has 2,472 encodings in one 82,997-byte shard, down from 31,719 encodings across three shards. It keeps one sorted representative per mnemonic, dword count, encoding family and decoder selector combination.
cargo xtask gfx10-corpus --llvm-dir <DIR>verifies the hashes of the pinned input files before extracting them. Use--full --out-dir <DIR>for all 31,716 unique encodings from the active LLVM checks. Full generation requires an explicit output directory so that it cannot accidentally overwrite the checked-in reduced shard. The maintainer verified all 20 source hashes and all 2,472 retained rows, and accepted the fixture size under #14.The conformance test checks every retained row, with zero decode errors or length mismatches across 19 encoding families. After accounting for encoding-form suffixes, the test pins nine missing opcode names and two unresolved legacy names. Follow-up issue #64 covers VOP3 VINTRP aliases,
image_gather4h, the fourimage_sample_*cd*_g16forms, andv_dot8_i32_i4. It also tracks which legacy MAD/MAC or FMA/FMAC forms the console decodes. XTP follows Mesa gfx1010 at the disputed opcodes, and the public LLVM GFX10.3 tests use FMA/FMAC.Area
Shader decoder and conformance fixtures, xtask corpus generation, and developer documentation and third-party notices.
Tests
cargo xtask pr-checkpasses on my machinecargo xtask pr-check --base upstream/main --title "shader, xtask, docs: add a reduced GFX10 conformance corpus" --skip testpassed formatting, both Clippy configurations, asset policy and conventions. The workspace test step was skipped.cargo test -p xtp-shader --test gfx10_conformancepassed (1 test).cargo test -p xtaskpassed (47 tests), including the new argument validation test and the replay test from main.cargo test -p xtp-shader --libpassed (448 tests, 40 ignored), and local corpus regeneration succeeded from the 20 pinned files.Provenance
I wrote all of this change myself for XTP, or it only moves code already in XTP.
Some of it comes from elsewhere. Each source, its licence and the files concerned are listed here, and every licence is compatible with GPL-3.0-or-later:
LLVM Project, tag
llvmorg-19.1.7, Apache-2.0 WITH LLVM-exception. XTP extracts and reformats only the mnemonic and encoding words intocrates/xtp-shader/tests/data/gfx10-llvm-mc-01.txt.crates/xtp-shader/tests/data/LICENSE-LLVM.txtcarries the licence and exception, and the shard records each source hash. Pinned LLVM MC AMDGPU sourcesThe inputs under
llvm/test/MC/AMDGPU/areexp-gfx10.s,gfx1011_dlops.s,gfx1013.s,gfx1030_new.s,gfx10_asm_dpp16.s,gfx10_asm_dpp8.s,gfx10_asm_ds.s,gfx10_asm_flat.s,gfx10_asm_mimg.s,gfx10_asm_mubuf.s,gfx10_asm_smem.s,gfx10_asm_sop.s,gfx10_asm_vop1.s,gfx10_asm_vop2.s,gfx10_asm_vop3.s,gfx10_asm_vopc.s,gfx10_asm_vopc_e64.s,gfx10_asm_vopc_sdwa.s,gfx10_asm_vopcx.s, andmtbuf-gfx10.s.The comparison uses the existing Mesa 22.3.0 GFX10 opcode table. Its MIT notice is in
crates/xtp-shader/src/gfx10/opcodes.rs.AI assistance: AI coding tools wrote parts of this change: Antigravity (Gemini) the original generator and test, OpenAI Codex the review changes. The corpus was regenerated from the pinned LLVM inputs and checked locally.
Checklist
<area>: <summary>; one topic; under 400 changed lines, or the reason is above