Merge pull request #1332 from fin-github/takeover/old-9928-wint-diff-gfx12

wint_diff: GFX12 has no always-true/false VALU compare; skip those programs by name (OLD-9928)
This commit is contained in:
MoonEyes
2026-11-28 15:30:40 +01:00
committed by GitHub
4 changed files with 92 additions and 6 deletions

View File

@ -385,6 +385,26 @@ class Filters(unittest.TestCase):
self.assertIn("s_ff0", asm.skip_reason(PROG + ["s_ff0_i32_b64 s[4:5], s[6:7]"], "gfx1201"))
self.assertEqual(len([op for op in asm.GFX12_REMOVED if op.startswith("s_cmpk_")]), 12)
def test_gfx12_has_no_always_true_or_false_valu_compare(self):
# gfx1036, gfx1100 and gfx1150 assemble these; gfx1201 rejects all sixteen (AMD LLVM 23).
self.assertEqual(len(asm.GFX12_VALU_REMOVED), 16)
for op in ("v_cmp_t_u32", "v_cmp_f_i32", "v_cmpx_t_u64", "v_cmpx_f_i64"):
for spelled in (op, op + "_e32", op + "_e64"):
self.assertIn("removed in GFX12", asm.valu_skip_reason(spelled, "gfx1201"), spelled)
self.assertIn("removed in GFX12", asm.valu_skip_reason(spelled, "gfx1200"), spelled)
for arch in ("gfx1013", "gfx1036", "gfx1100", "gfx1150"):
self.assertIsNone(asm.valu_skip_reason(spelled, arch), (spelled, arch))
for op in ("v_cmp_eq_u32", "v_cmp_lt_u32_e64", "v_cmpx_ne_u32_e32", "v_add_nc_u32"):
self.assertIsNone(asm.valu_skip_reason(op, "gfx1201"), op)
# the GFX10.1-only mads are unchanged
self.assertIn("GFX10.1", asm.valu_skip_reason("v_mad_f32", "gfx1201"))
self.assertIsNone(asm.valu_skip_reason("v_mad_f32", "gfx1013"))
prog = ["v_mov_b32_e32 v1, 5", "", "v_cmp_t_u32_e64 s[4:5], v1, v2", "v_cmp_f_i32_e32 vcc, v1, v2"]
self.assertEqual(asm.program_skip_reason(prog, "gfx1201"),
"v_cmp_t_u32: removed in GFX12 (no always-true/always-false VALU compare there)")
self.assertIsNone(asm.program_skip_reason(prog, "gfx1150"))
self.assertIsNone(asm.program_skip_reason(["v_mov_b32_e32 v1, 5"], "gfx1201"))
class VcvarsScript(unittest.TestCase):
"""The .cmd that calls vcvars64.bat and cl holds the checkout, %TEMP% and Visual Studio paths. A character

View File

@ -392,6 +392,28 @@ class Cli(unittest.TestCase):
self.assertEqual(d.hw_words(words, 64)[1], (4, 5, 6, 7))
self.assertEqual(d.hw_words("assembler rejected: x", 64), "assembler rejected: x")
def test_gfx12_skips_its_removed_compares_by_name_and_never_assembles_them(self):
class Fake:
def __init__(self, arch):
self.arch, self.sent = arch, []
def run(self, kernels):
self.sent += kernels
return [[7] * k.words for k in kernels]
removed = [program(["v_cmp_t_u32_e64 s[20:21], v1, v2"]), program(["v_cmpx_f_i32_e64 v1, v2"]),
program(["v_mov_b32_e32 v1, 5", "v_cmp_f_i32_e32 vcc, v1, v2"])]
kept = program(["v_cmp_eq_u32_e64 s[20:21], v1, v2"])
gfx12 = Fake("gfx1201")
got = d.hw_results(gfx12, removed + [kept])
for i, op in enumerate(("v_cmp_t_u32", "v_cmpx_f_i32", "v_cmp_f_i32")):
self.assertEqual(got[i], f"{op}: removed in GFX12 (no always-true/always-false VALU compare there)")
self.assertEqual(got[3][0], (7, 7, 7, 7))
self.assertEqual(len(gfx12.sent), 1) # only the program GFX12 can run is assembled
for arch in ("gfx1036", "gfx1150"): # GFX10/11 still have them: everything runs
other = Fake(arch)
self.assertTrue(all(not isinstance(r, str) for r in d.hw_results(other, removed + [kept])), arch)
self.assertEqual(len(other.sent), 4, arch)
class OracleGuards(unittest.TestCase):
def setUp(self):

View File

@ -318,6 +318,13 @@ VALU_REMOVED = {
"v_madmk_f32": _MAD_GONE.format("v_fmamk_f32"),
"v_mad_legacy_f32": _MAD_GONE.format("v_fma_dx9_zero_f32"),
}
# GFX12 dropped the always-true and always-false VALU compares. AMD LLVM 23 (rocm-sdk-core 10.0.0) assembles
# v_cmp_{t,f}_{i32,u32,i64,u64} and the v_cmpx_ forms for gfx1036, gfx1100 and gfx1150 and rejects every one for
# gfx1201 ("instruction not supported on this GPU"). There is no renamed form to substitute: a program that uses one
# cannot run there, so it is skipped with this reason rather than counted as an assembler rejection.
_CMP_TF_GONE = "removed in GFX12 (no always-true/always-false VALU compare there)"
GFX12_VALU_REMOVED = {f"v_{kind}_{tf}_{ty}": _CMP_TF_GONE
for kind in ("cmp", "cmpx") for tf in ("t", "f") for ty in ("i32", "u32", "i64", "u64")}
# Same instruction, new mnemonic: the assembler takes the GFX10 spelling for GFX11 and encodes the GFX11 name.
GFX11_VALU_RENAMED = {
"v_mul_legacy_f32": "v_mul_dx9_zero_f32", # DX9 rule: 0 * anything = 0 (the oracle itself checks it)
@ -396,9 +403,21 @@ def sync_lines(line, arch):
def valu_skip_reason(op, arch):
"""Why an f32 VALU opcode cannot be run on this architecture, or None."""
"""Why a VALU opcode cannot be run on this architecture, or None. An _e32/_e64 suffix is ignored."""
op = re.sub(r"_e(32|64)$", "", op)
if op in VALU_REMOVED and arch not in ("gfx1010", "gfx1011", "gfx1012", "gfx1013"):
return f"{op}: {VALU_REMOVED[op]}"
if op in GFX12_VALU_REMOVED and family(arch) == "gfx12":
return f"{op}: {GFX12_VALU_REMOVED[op]}"
return None
def program_skip_reason(lines, arch):
"""The first valu_skip_reason of a program's instruction lines (their first word), or None."""
for line in lines:
why = valu_skip_reason(line.split(None, 1)[0], arch) if line.strip() else None
if why:
return why
return None

View File

@ -779,6 +779,32 @@ def hw_words(words, wave):
return [tuple(words[4 * lane:4 * lane + 4]) for lane in range(wave)]
def hw_skip(oracle, prog):
"""Why the oracle's GPU cannot run this program (asm.program_skip_reason: v_cmp_t_u32 / v_cmp_f_i32 and their
v_cmpx_ forms on GFX12), or None. An oracle without a GPU architecture name skips nothing."""
arch = getattr(oracle, "arch", None)
if not isinstance(arch, str):
return None
from hw_oracle import asm
return asm.program_skip_reason(prog.lines(), arch)
def hw_results(oracle, progs):
"""Per program the hardware's per-lane words, or a str reason. A program hw_skip names is never assembled; it
gets that reason, so it is a named skip and not one of the assembler's rejections. The others go to the oracle,
which must return one result per program."""
out = [hw_skip(oracle, p) for p in progs]
todo = [i for i, why in enumerate(out) if not why]
if todo:
raw = oracle.run([hw_kernel(progs[i]) for i in todo])
if raw is None or len(raw) != len(todo):
count = 0 if raw is None else len(raw)
raise RuntimeError(f"the hardware runner returned {count} results for {len(todo)} programs")
for i, words in zip(todo, raw):
out[i] = hw_words(words, progs[i].wave)
return out
# ---- comparison, shrinking, the run --------------------------------------------------------------------------
def _diff(prog, want, got, label):
@ -904,11 +930,7 @@ def run_suite(programs, seed, max_ops, ops, waves=(32,), backends=("translator",
rng = random.Random(seed)
progs = [generate(rng, rng.randrange(1, max_ops + 1), ops, waves[i % len(waves)]) for i in range(programs)]
if "hw" in backends:
raw = oracle.run([hw_kernel(p) for p in progs])
if raw is None or len(raw) != len(progs):
count = 0 if raw is None else len(raw)
raise RuntimeError(f"the hardware runner returned {count} results for {len(progs)} programs")
hw = [hw_words(w, p.wave) for w, p in zip(raw, progs)]
hw = hw_results(oracle, progs)
else:
hw = [None] * programs
if "vk" in backends:
@ -1035,6 +1057,9 @@ def main(argv=None):
def check_fn(prog):
def run_hw_one(p):
why = hw_skip(oracle, p)
if why:
return why
res = oracle.run([hw_kernel(p)])
if not res:
raise RuntimeError("the hardware runner returned no result for shrunk program")