upleb.uk

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

summaryrefslogtreecommitdiff
path: root/tools/shader_diff.py
diff options
context:
space:
mode:
authorSolthodox <100046219+Solthodox@users.noreply.github.com>2026-11-23 16:50:23 +0100
committerGitHub <noreply@github.com>2026-11-23 09:50:23 -0600
commit924b14656ca0e2c6b0c77353ae68aa75e2a8d19e (patch)
tree23d8d15b794015cff282f1f0e46993dcc78b8963 /tools/shader_diff.py
parent5d96ea83937866d9ad75691339ddfbf99c262722 (diff)
shader_diff: replay a single seeded program by index (#6855)
Squash-merged after diff review of PR #6855 - shader_diff: replay a single seeded program by index
Diffstat (limited to 'tools/shader_diff.py')
-rw-r--r--tools/shader_diff.py30
1 files changed, 23 insertions, 7 deletions
diff --git a/tools/shader_diff.py b/tools/shader_diff.py
index 6de49e365..fc3e2ec3a 100644
--- a/tools/shader_diff.py
+++ b/tools/shader_diff.py
@@ -11,6 +11,7 @@ interpreter and is never modified here.
11 11
12Usage: 12Usage:
13 python -I tools/shader_diff.py [--programs N] [--seed S] [--max-ops N] 13 python -I tools/shader_diff.py [--programs N] [--seed S] [--max-ops N]
14 python -I tools/shader_diff.py --program-index I --seed S --max-ops N
14 python -I tools/shader_diff.py --self-test # harness canaries (must fail loudly if broken) 15 python -I tools/shader_diff.py --self-test # harness canaries (must fail loudly if broken)
15 python -I tools/shader_diff.py --list-ops 16 python -I tools/shader_diff.py --list-ops
16 17
@@ -255,28 +256,32 @@ def run_one(name, lines, writers):
255 return ("mismatch", mismatch) 256 return ("mismatch", mismatch)
256 257
257 258
258def run_suite(programs, seed, max_ops, limit=None): 259def run_suite(programs, seed, max_ops, limit=None, *, start=0):
259 """Run N seeded programs. Returns (counts, first_failure).""" 260 """Generate the seeded sequence, executing cases from index start. Return (counts, first_failure)."""
260 counts = {"pass": 0, "mismatch": 0, "skip": {}, "harness-error": 0} 261 counts = {"pass": 0, "mismatch": 0, "skip": {}, "harness-error": 0}
261 first_failure = None 262 first_failure = None
262 rng = random.Random(seed) 263 rng = random.Random(seed)
263 total = programs if limit is None else min(programs, limit) 264 total = programs if limit is None else min(programs, limit)
264 for i in range(total): 265 for i in range(total):
265 name = f"ps_diff_{i:04d}"
266 lines, writers = generate_program(rng, rng.randrange(1, max_ops + 1)) 266 lines, writers = generate_program(rng, rng.randrange(1, max_ops + 1))
267 if i < start: # advance the original RNG stream, but skip both oracles
268 continue
269 name = f"ps_diff_{i:04d}"
267 try: 270 try:
268 status, detail = run_one(name, lines, writers) 271 status, detail = run_one(name, lines, writers)
269 except Exception as e: # noqa: BLE001 - harness bugs must be loud 272 except Exception as e: # noqa: BLE001 - harness bugs must be loud
270 counts["harness-error"] += 1 273 counts["harness-error"] += 1
271 if first_failure is None: 274 if first_failure is None:
272 first_failure = f"{name}: harness error {type(e).__name__}: {e}" 275 first_failure = (f"{name}: harness error {type(e).__name__}: {e}\n"
276 f"Replay: --seed {seed} --max-ops {max_ops} --program-index {i}")
273 continue 277 continue
274 if status == "match": 278 if status == "match":
275 counts["pass"] += 1 279 counts["pass"] += 1
276 elif status == "mismatch": 280 elif status == "mismatch":
277 counts["mismatch"] += 1 281 counts["mismatch"] += 1
278 if first_failure is None: 282 if first_failure is None:
279 first_failure = (f"{name} (seed {seed} program {i}): {detail}\n" + 283 first_failure = (f"{name} (seed {seed} program {i}): {detail}\n"
284 f"Replay: --seed {seed} --max-ops {max_ops} --program-index {i}\n" +
280 "\n".join("\t" + line for line in lines)) 285 "\n".join("\t" + line for line in lines))
281 else: 286 else:
282 counts["skip"][detail] = counts["skip"].get(detail, 0) + 1 287 counts["skip"][detail] = counts["skip"].get(detail, 0) + 1
@@ -325,7 +330,10 @@ def _at_least_one(value):
325 330
326def main(argv=None): 331def main(argv=None):
327 ap = argparse.ArgumentParser(description="Differential oracle: cpu_ref vs translated SPIR-V.") 332 ap = argparse.ArgumentParser(description="Differential oracle: cpu_ref vs translated SPIR-V.")
328 ap.add_argument("--programs", type=_at_least_one, default=200, help="number of programs to run (default: 200)") 333 selection = ap.add_mutually_exclusive_group()
334 selection.add_argument("--programs", type=_at_least_one, help="number of programs to run (default: 200)")
335 selection.add_argument("--program-index", type=int, metavar="I",
336 help="replay only zero-based program I using the original --seed and --max-ops")
329 ap.add_argument("--seed", type=int, default=1) 337 ap.add_argument("--seed", type=int, default=1)
330 ap.add_argument("--max-ops", type=_at_least_one, default=8, 338 ap.add_argument("--max-ops", type=_at_least_one, default=8,
331 help="maximum ops per generated program (default: 8)") 339 help="maximum ops per generated program (default: 8)")
@@ -340,7 +348,15 @@ def main(argv=None):
340 return 0 348 return 0
341 if a.self_test: 349 if a.self_test:
342 return 0 if self_test() else 1 350 return 0 if self_test() else 1
343 counts, first_failure = run_suite(a.programs, a.seed, a.max_ops, a.limit) 351 if a.program_index is None:
352 counts, first_failure = run_suite(a.programs or 200, a.seed, a.max_ops, a.limit)
353 else:
354 if a.program_index < 0:
355 ap.error("--program-index must be nonnegative")
356 if a.limit is not None:
357 ap.error("--program-index cannot be combined with --limit")
358 print(f"replaying program {a.program_index} (seed {a.seed}, max ops {a.max_ops})")
359 counts, first_failure = run_suite(a.program_index + 1, a.seed, a.max_ops, start=a.program_index)
344 total_skips = sum(counts["skip"].values()) 360 total_skips = sum(counts["skip"].values())
345 total_run = counts["pass"] + counts["mismatch"] + total_skips + counts["harness-error"] 361 total_run = counts["pass"] + counts["mismatch"] + total_skips + counts["harness-error"]
346 print(f"{total_run} programs (seed {a.seed}): " 362 print(f"{total_run} programs (seed {a.seed}): "