upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com>2026-11-22 23:15:30 -0500
committerItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com>2026-11-22 23:15:30 -0500
commita90289cbb4dd9761edbf0c44553aa5a4eead2c8d (patch)
tree619ff2119689dfeab6a440a9240fd3a29f0c8a0b /tools
parent4c4cb16bbf2dc642e74e4496bfb8f227adae7465 (diff)
parentdbe5070d185d1c216e21e1f23b80156e7f2b3ad8 (diff)
Merge pull request #4519 from Størm
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/hw_oracle/asm.py34
-rw-r--r--tools/lds_fuzz.py23
2 files changed, 40 insertions, 17 deletions
diff --git a/tools/hw_oracle/asm.py b/tools/hw_oracle/asm.py
index f39cf47a5..c6a9dd872 100644
--- a/tools/hw_oracle/asm.py
+++ b/tools/hw_oracle/asm.py
@@ -314,7 +314,7 @@ GFX11_VALU_RENAMED = {
314# the GFX10 spelling of all of them on gfx1150 except ds_cmpst_rtn_b32 ("instruction not supported on this GPU"), and 314# the GFX10 spelling of all of them on gfx1150 except ds_cmpst_rtn_b32 ("instruction not supported on this GPU"), and
315# takes the GFX11 spelling on gfx1030 for none. The new spelling is used on GFX11/GFX12 so the program text is what 315# takes the GFX11 spelling on gfx1030 for none. The new spelling is used on GFX11/GFX12 so the program text is what
316# the target names, not what an alias happens to accept. ds_cmpstore_rtn_b32 also takes its two data operands in the 316# the target names, not what an alias happens to accept. ds_cmpstore_rtn_b32 also takes its two data operands in the
317# other order (ds_line). 317# other order (ds_line), and GFX12 spells the barrier and the LDS wait differently (sync_lines).
318DS_RENAMED_GFX11 = { 318DS_RENAMED_GFX11 = {
319 "ds_wrxchg_rtn_b32": "ds_storexchg_rtn_b32", 319 "ds_wrxchg_rtn_b32": "ds_storexchg_rtn_b32",
320 "ds_cmpst_rtn_b32": "ds_cmpstore_rtn_b32", 320 "ds_cmpst_rtn_b32": "ds_cmpstore_rtn_b32",
@@ -337,24 +337,26 @@ def ds_mnemonic(op, arch):
337 337
338 338
339def ds_line(line, arch): 339def ds_line(line, arch):
340 """A whole instruction line (GFX10 spelling and operand order in) respelled for the architecture. On GFX11 340 """A whole instruction line (GFX10 spelling and operand order in) respelled for the architecture. On GFX11 and
341 (measured on gfx1150; GFX12 is not measured, lds_fuzz skips it) ds_cmpstore_rtn_b32 takes the value to store first and the compare value second, the reverse of GFX10's 341 GFX12 ds_cmpstore_rtn_b32 takes the value to store first and the compare value second, the reverse of GFX10's
342 ds_cmpst_rtn_b32 vdst, vaddr, cmp, store (measured on gfx1150: tools/lds_fuzz.py --oracle hw, and it is what LLVM's 342 ds_cmpst_rtn_b32 vdst, vaddr, cmp, store (measured on gfx1150: tools/lds_fuzz.py --oracle hw, and it is what LLVM's
343 cmpxchg selection does for GFX11); llvm-mc encodes both spellings of the same text identically, so only the 343 cmpxchg selection does for GFX11; measured on gfx1201, an RX 9070 XT: with M = 7 at the address, data v1 = 9 and
344 v2 = 7 the dword becomes 9 and with v1 = 7, v2 = 9 it stays 7, for the rtn and the non-returning form, while
345 gfx1036's ds_cmpst does the opposite); llvm-mc encodes both spellings of the same text identically, so only the
344 operand order tells them apart.""" 346 operand order tells them apart."""
345 op, sep, rest = line.partition(" ") 347 op, sep, rest = line.partition(" ")
346 if op == "ds_cmpst_rtn_b32" and family(arch) == "gfx11": 348 if op == "ds_cmpst_rtn_b32" and family(arch) in ("gfx11", "gfx12"):
347 m = re.fullmatch(r"(v\d+),\s*(v\d+),\s*(v\d+),\s*(v\d+)(.*)", rest) 349 m = re.fullmatch(r"(v\d+),\s*(v\d+),\s*(v\d+),\s*(v\d+)(.*)", rest)
348 if not m: 350 if not m:
349 raise ValueError(f"cannot swap the operands of {line!r}") 351 raise ValueError(f"cannot swap the operands of {line!r}")
350 dst, addr, cmp_, store, tail = m.groups() 352 dst, addr, cmp_, store, tail = m.groups()
351 rest = f"{dst}, {addr}, {store}, {cmp_}{tail}" 353 rest = f"{dst}, {addr}, {store}, {cmp_}{tail}"
352 elif op == "ds_cmpst_b32" and family(arch) == "gfx11": 354 elif op == "ds_cmpst_b32" and family(arch) in ("gfx11", "gfx12"):
353 # The non-returning form is renamed as well, and its two data operands swap the same way: GFX10's 355 # The non-returning form is renamed as well, and its two data operands swap the same way: GFX10's
354 # ds_cmpst_b32 vaddr, cmp, store is GFX11's ds_cmpstore_b32 vaddr, store, cmp (measured on gfx1100: with 356 # ds_cmpst_b32 vaddr, cmp, store is GFX11's ds_cmpstore_b32 vaddr, store, cmp (measured on gfx1100: with
355 # M = 7, vaddr = 0 and data v1 = 9, v2 = 7 the dword becomes 9, so the store operand is v1). The rename is 357 # M = 7, vaddr = 0 and data v1 = 9, v2 = 7 the dword becomes 9, so the store operand is v1; the same on
356 # done here rather than in DS_RENAMED_GFX11 because the swap is only measured on GFX11, and renaming 358 # gfx1201). The rename is done here rather than in DS_RENAMED_GFX11 so that it never happens without the
357 # without swapping on GFX12 would silently compare and store the wrong way round. 359 # swap, which would silently compare and store the wrong way round.
358 m = re.fullmatch(r"(v\d+),\s*(v\d+),\s*(v\d+)(.*)", rest) 360 m = re.fullmatch(r"(v\d+),\s*(v\d+),\s*(v\d+)(.*)", rest)
359 if not m: 361 if not m:
360 raise ValueError(f"cannot swap the operands of {line!r}") 362 raise ValueError(f"cannot swap the operands of {line!r}")
@@ -363,6 +365,20 @@ def ds_line(line, arch):
363 return ds_mnemonic(op, arch) + sep + rest 365 return ds_mnemonic(op, arch) + sep + rest
364 366
365 367
368def sync_lines(line, arch):
369 """A wait or barrier line (GFX10/GFX11 spelling in) as the instructions that do it on this architecture. GFX12 has
370 no s_barrier (AMD LLVM 23: "instruction not supported on this GPU (gfx1201)"); a workgroup barrier there is
371 s_barrier_signal -1 then s_barrier_wait -1. It also split lgkmcnt into dscnt (LDS) and kmcnt (scalar memory), so
372 a wait for the LDS is s_wait_dscnt 0 rather than the legacy s_waitcnt encoding the assembler still takes."""
373 if family(arch) == "gfx12":
374 text = line.strip()
375 if text == "s_barrier":
376 return ["s_barrier_signal -1", "s_barrier_wait -1"]
377 if text == "s_waitcnt lgkmcnt(0)":
378 return ["s_wait_dscnt 0"]
379 return [line]
380
381
366def valu_skip_reason(op, arch): 382def valu_skip_reason(op, arch):
367 """Why an f32 VALU opcode cannot be run on this architecture, or None.""" 383 """Why an f32 VALU opcode cannot be run on this architecture, or None."""
368 if op in VALU_REMOVED and arch not in ("gfx1010", "gfx1011", "gfx1012", "gfx1013"): 384 if op in VALU_REMOVED and arch not in ("gfx1010", "gfx1011", "gfx1012", "gfx1013"):
diff --git a/tools/lds_fuzz.py b/tools/lds_fuzz.py
index 44a7df23a..ed9bccc6b 100644
--- a/tools/lds_fuzz.py
+++ b/tools/lds_fuzz.py
@@ -424,11 +424,11 @@ class Program:
424 def hw_lines(self, arch, ops=None): 424 def hw_lines(self, arch, ops=None):
425 """The program as a native kernel body for tools/hw_oracle: the entry EXEC is saved and restored (a partial 425 """The program as a native kernel body for tools/hw_oracle: the entry EXEC is saved and restored (a partial
426 wave has fewer lanes than -1), the stores go through the output pointer in s[2:3], and the ds_* mnemonics are 426 wave has fewer lanes than -1), the stores go through the output pointer in s[2:3], and the ds_* mnemonics are
427 the ones the architecture names them.""" 427 the ones the architecture names them, and so are the barrier and the LDS waits (GFX12, asm.sync_lines)."""
428 from hw_oracle import asm 428 from hw_oracle import asm
429 ops = self.ops if ops is None else ops 429 ops = self.ops if ops is None else ops
430 lines = self.body(ops, hw=True, arch=arch) 430 lines = self.body(ops, hw=True, arch=arch)
431 return [asm.ds_line(ln, arch) for ln in lines] 431 return [out for ln in lines for out in asm.sync_lines(asm.ds_line(ln, arch), arch)]
432 432
433 def body(self, ops, hw=False, arch="gfx1150"): 433 def body(self, ops, hw=False, arch="gfx1150"):
434 w64 = self.wave == 64 434 w64 = self.wave == 64
@@ -922,13 +922,20 @@ def run_translator(progs, a, work, tally):
922 922
923def hw_skip_reason(p, arch): 923def hw_skip_reason(p, arch):
924 """Why a program cannot run natively on this GPU, or None. GFX11 renamed the ds_* loads and stores, which 924 """Why a program cannot run natively on this GPU, or None. GFX11 renamed the ds_* loads and stores, which
925 asm.ds_line respells, and swaps ds_cmpstore's data operands (measured on gfx1150). The swap is not measured on 925 asm.ds_line respells, and swaps ds_cmpstore's data operands (measured on gfx1150 and on gfx1201); GFX12 also
926 GFX12, so a program with a ds_cmpst is skipped there; everything else the generator emits is spelled the same 926 spells the barrier and the LDS wait differently, which asm.sync_lines respells. Everything else the generator
927 on GFX10, GFX11 and GFX12 (assembled for gfx1030, gfx1100, gfx1150 and gfx1201), so the other skips are the 927 emits is spelled the same on GFX10, GFX11 and GFX12 (assembled for gfx1030, gfx1100, gfx1150 and gfx1201), so
928 assembler's own rejections, which the runner reports.""" 928 the other skips are the assembler's own rejections, which the runner reports.
929
930 One behaviour differs on GFX12: a wave64 ds_bpermute_b32 reaches all 64 lanes there, while RDNA2 (the console's
931 generation, and what this model describes) keeps each 32-lane half separate. Measured with every lane asking for
932 lane (l + 32) mod 64: an RX 9070 XT (gfx1201) returns lane l ^ 32, a gfx1036 iGPU returns lane l, and on gfx1201
933 300 of 300 wave64 programs match --perturb bpermute_wave64_cross. So those programs can't check the RDNA2 model on
934 GFX12 and are skipped there; wave32 and every other wave64 program still run."""
929 from hw_oracle import asm 935 from hw_oracle import asm
930 if asm.family(arch) == "gfx12" and any(op["kind"] == "cmpst" for op in p.ops): 936 if asm.family(arch) == "gfx12" and p.wave == 64 and "bpermute_wave64_cross" not in PERTURB \
931 return "ds_cmpstore_rtn_b32 operand order is only measured on GFX11 (gfx1150)" 937 and any(op["kind"] == "bpermute" for op in p.ops):
938 return "a wave64 ds_bpermute_b32 reaches all 64 lanes on GFX12 (measured on gfx1201), not each 32-lane half"
932 return None 939 return None
933 940
934 941