upleb.uk

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

summaryrefslogtreecommitdiff
path: root/tools/mem_diff.py
diff options
context:
space:
mode:
authorLuanFreitas <luanftrs@gmail.com>2026-11-21 22:16:25 -0300
committerLuanFreitas <luanftrs@gmail.com>2026-11-21 22:23:22 -0300
commit14d81dd093e91c2f9b4a21f74fe0db2d26db1199 (patch)
tree3488d42c8f8c5a7e99de4b466bf30b90ccd7cbce /tools/mem_diff.py
parentbaa6beed3a16ac006350060c3ffdc001710cbf79 (diff)
SHADER-86: align mem_diff reference with RX 6700 typed-buffer decode
Repeat missing channels, drop the old norm-ulp1/missing-w32 splits, and allow DST_SEL 1 in the fuzzer.
Diffstat (limited to 'tools/mem_diff.py')
-rw-r--r--tools/mem_diff.py45
1 files changed, 9 insertions, 36 deletions
diff --git a/tools/mem_diff.py b/tools/mem_diff.py
index b6bae05fa..0469d763e 100644
--- a/tools/mem_diff.py
+++ b/tools/mem_diff.py
@@ -20,9 +20,8 @@ s_buffer_load alignment truncation and swizzling depend on descriptor fields doc
20so they are left to a GPU-confirmed follow-up instead of being guessed here. 20so they are left to a GPU-confirmed follow-up instead of being guessed here.
21 21
22Typed buffer loads (buffer_load_format_*, tbuffer_load_format_*) are decoded from the GFX10 format names in 22Typed buffer loads (buffer_load_format_*, tbuffer_load_format_*) are decoded from the GFX10 format names in
23tools/gfx10_formats.json, not from the translator's table. Two outcomes awaiting a hardware measurement are 23tools/gfx10_formats.json, not from the translator's table. Missing channels repeat (*c* mod *n*), UNORM/SNORM
24counted apart instead of as mismatches: 'norm-ulp1' (a UNORM/SNORM result one ULP from the correctly rounded 24use correctly rounded division, and DST_SEL 1 is integer 1 for UINT/SINT (SHADER-86, RX 6700).
25value) and 'missing-w32' (the missing W of a 32-bit format: the translator returns 0, every other format 1).
26 25
27Usage: 26Usage:
28 python -I tools/mem_diff.py [--programs N] [--seed S] [--max-ops N] 27 python -I tools/mem_diff.py [--programs N] [--seed S] [--max-ops N]
@@ -72,8 +71,6 @@ class Program:
72 def __init__(self): 71 def __init__(self):
73 self.lines = [] 72 self.lines = []
74 self.memory = {} 73 self.memory = {}
75 self.norm_regs = set() # VGPRs that hold a UNORM/SNORM result (rounding differences are counted apart)
76 self.missing_w32_regs = set() # VGPRs that select the missing W of a 32-bit format (counted apart)
77 74
78 75
79# ---------------------------------------------------------------- typed-buffer formats (reference decode) 76# ---------------------------------------------------------------- typed-buffer formats (reference decode)
@@ -126,7 +123,7 @@ def f32_round(q):
126 123
127 124
128def decode_element(raw, widths, kind): 125def decode_element(raw, widths, kind):
129 """Decode one element (an int of sum(widths) bits) -> 4 result words, missing channels 0, 0, 0, 1.""" 126 """Decode one element (an int of sum(widths) bits) -> 4 result words; missing channels repeat (*c* mod *n*)."""
130 from fractions import Fraction 127 from fractions import Fraction
131 out, bit = [], 0 128 out, bit = [], 0
132 for w in widths: 129 for w in widths:
@@ -147,9 +144,9 @@ def decode_element(raw, widths, kind):
147 out.append(v) 144 out.append(v)
148 else: # FLOAT 16 -> f32 bits (exact) 145 else: # FLOAT 16 -> f32 bits (exact)
149 out.append(struct.unpack("<I", struct.pack("<f", struct.unpack("<e", struct.pack("<H", v))[0]))[0]) 146 out.append(struct.unpack("<I", struct.pack("<f", struct.unpack("<e", struct.pack("<H", v))[0]))[0])
150 one = 1 if kind in ("UINT", "SINT") else ONE_F32 147 n = len(out)
151 while len(out) < 4: 148 while len(out) < 4:
152 out.append(0 if len(out) < 3 else one) 149 out.append(out[len(out) % n])
153 return out 150 return out
154 151
155 152
@@ -551,7 +548,7 @@ def gen_buffer_format(rng, prog):
551 else: 548 else:
552 code = rng.choice(_typed_codes()) 549 code = rng.choice(_typed_codes())
553 widths, kind = parse_format(FORMAT_NAMES[code]) 550 widths, kind = parse_format(FORMAT_NAMES[code])
554 sels = [rng.choice((0, 4, 5, 6, 7)) for _ in range(4)] # no SEL_1: its integer value is unconfirmed 551 sels = [rng.choice((0, 1, 4, 5, 6, 7)) for _ in range(4)]
555 word3 = code << 12 | sels[0] | sels[1] << 3 | sels[2] << 6 | sels[3] << 9 552 word3 = code << 12 | sels[0] | sels[1] << 3 | sels[2] << 6 | sels[3] << 9
556 size = sum(widths) // 8 553 size = sum(widths) // 8
557 base = _buffer_base(rng) 554 base = _buffer_base(rng)
@@ -580,12 +577,6 @@ def gen_buffer_format(rng, prog):
580 else: 577 else:
581 prog.lines.append(f"buffer_load_format_{suffix} {vdata}, {operands} {addr_mods}") 578 prog.lines.append(f"buffer_load_format_{suffix} {vdata}, {operands} {addr_mods}")
582 prog.lines.append("s_waitcnt vmcnt(0)") 579 prog.lines.append("s_waitcnt vmcnt(0)")
583 if kind in ("UNORM", "SNORM"):
584 prog.norm_regs.update(VDATA + c for c in range(ncomp))
585 if set(widths) == {32} and len(widths) < 4:
586 for c in range(ncomp):
587 if (word3 >> (3 * c)) & 7 == 7:
588 prog.missing_w32_regs.add(VDATA + c)
589 return [("v", VDATA + c) for c in range(ncomp)] 580 return [("v", VDATA + c) for c in range(ncomp)]
590 581
591 582
@@ -608,13 +599,9 @@ def generate_program(rng, n_ops, families=None):
608 for _ in range(n_ops): 599 for _ in range(n_ops):
609 family = rng.choice(names) 600 family = rng.choice(names)
610 prog.lines.append(f"; {family}") 601 prog.lines.append(f"; {family}")
611 prog.norm_regs = set() # only the last operation's results are exported
612 prog.missing_w32_regs = set()
613 results = GENERATORS[family](rng, prog) or results 602 results = GENERATORS[family](rng, prog) or results
614 picks = [results[min(i, len(results) - 1)] for i in range(4)] if results else [] 603 picks = [results[min(i, len(results) - 1)] for i in range(4)] if results else []
615 prog.export_sources = {} 604 for dst, (kind, reg) in zip(EXPORT, picks):
616 for k, (dst, (kind, reg)) in enumerate(zip(EXPORT, picks)):
617 prog.export_sources[k] = reg if kind == "v" else None
618 if not (kind == "v" and reg == dst): 605 if not (kind == "v" and reg == dst):
619 prog.lines.append(f"v_mov_b32 v{dst}, {kind}{reg}") 606 prog.lines.append(f"v_mov_b32 v{dst}, {kind}{reg}")
620 return prog 607 return prog
@@ -659,16 +646,6 @@ def run_one(name, prog):
659 i = bad[0] 646 i = bad[0]
660 g = f"{got[i]:#010x}" if i < len(got) else "missing" 647 g = f"{got[i]:#010x}" if i < len(got) else "missing"
661 detail = f"export word {i}: expected {want[i]:#010x}, translated {g}" 648 detail = f"export word {i}: expected {want[i]:#010x}, translated {g}"
662 # A UNORM/SNORM result one ULP from the correctly rounded value is a rounding-convention question (the
663 # translator multiplies by a rounded reciprocal), kept apart so it can't hide a real decode error.
664 sources = prog.export_sources if hasattr(prog, "export_sources") else {}
665 if all(k < len(got) and sources.get(k) in prog.norm_regs and abs(got[k] - want[k]) == 1 for k in bad):
666 return "norm-ulp1", detail
667 # The missing W of a 32-bit format: the translator gives 0, every other format (and this model) 1 / 1.0.
668 # Posted as a finding awaiting a hardware measurement; counted apart until then.
669 if all(k < len(got) and sources.get(k) in prog.missing_w32_regs and got[k] == 0 and want[k] in (1, ONE_F32)
670 for k in bad):
671 return "missing-w32", detail
672 return "mismatch", detail 649 return "mismatch", detail
673 if memory != ref.mem: 650 if memory != ref.mem:
674 bad = sorted(a for a in set(memory) | set(ref.mem) if memory.get(a, 0) != ref.mem.get(a, 0)) 651 bad = sorted(a for a in set(memory) | set(ref.mem) if memory.get(a, 0) != ref.mem.get(a, 0))
@@ -679,7 +656,7 @@ def run_one(name, prog):
679 656
680 657
681def run_suite(programs, seed, max_ops, families=None): 658def run_suite(programs, seed, max_ops, families=None):
682 counts = {"pass": 0, "mismatch": 0, "norm-ulp1": 0, "missing-w32": 0, "skip": {}, "harness-error": 0} 659 counts = {"pass": 0, "mismatch": 0, "skip": {}, "harness-error": 0}
683 first = None 660 first = None
684 rng = random.Random(seed) 661 rng = random.Random(seed)
685 for i in range(programs): 662 for i in range(programs):
@@ -693,8 +670,6 @@ def run_suite(programs, seed, max_ops, families=None):
693 continue 670 continue
694 if status == "match": 671 if status == "match":
695 counts["pass"] += 1 672 counts["pass"] += 1
696 elif status in ("norm-ulp1", "missing-w32"):
697 counts[status] += 1
698 elif status == "mismatch": 673 elif status == "mismatch":
699 counts["mismatch"] += 1 674 counts["mismatch"] += 1
700 if first is None: 675 if first is None:
@@ -748,9 +723,7 @@ def main(argv=None):
748 counts, first = run_suite(a.programs, a.seed, a.max_ops, a.family) 723 counts, first = run_suite(a.programs, a.seed, a.max_ops, a.family)
749 skips = sum(counts["skip"].values()) 724 skips = sum(counts["skip"].values())
750 print(f"{a.programs} programs (seed {a.seed}): {counts['pass']} pass, {counts['mismatch']} mismatch, " 725 print(f"{a.programs} programs (seed {a.seed}): {counts['pass']} pass, {counts['mismatch']} mismatch, "
751 f"{counts['norm-ulp1']} UNORM/SNORM 1-ULP rounding differences, " 726 f"{skips} skipped, {counts['harness-error']} harness errors")
752 f"{counts['missing-w32']} missing-W-of-a-32-bit-format differences, {skips} skipped, "
753 f"{counts['harness-error']} harness errors")
754 for reason, n in sorted(counts["skip"].items()): 727 for reason, n in sorted(counts["skip"].items()):
755 print(f" skip x{n}: {reason}") 728 print(f" skip x{n}: {reason}")
756 if first: 729 if first: