#!/usr/bin/env python3 """Run Clang/GCC owner hashes at W1/W8/W12 and compare with b96dd73.""" from __future__ import annotations import json import re import subprocess import time from pathlib import Path ROOT = Path(__file__).resolve().parents[4] OUT = ROOT / "Saved/Linux/l130/hashes" BASELINE = json.loads((ROOT / "Saved/Linux/l125/hashes/summary.json").read_text()) DATASETS = { "owner4": ROOT / "Standalone/data/owner_world.json", "owner2": ROOT / "Standalone/data/regression/owner_world_2strate_l61.json", } RECIPES = {"owner4": ("surface-world",), "owner2": ("surface-world", "floating-islands")} BINARIES = { "clang": ROOT / "Saved/Linux/l130/bin/VoxelForgeCoreHeadless-l130-clang", "gcc": ROOT / "Saved/Linux/l130/bin/VoxelForgeCoreHeadless-l130-gcc", } HASH_RE = re.compile(r"^\[Pipeline(?:FullDetailHash|WholeViewHash|LODHash|ExactQueryHash)\].*$", re.M) STAMP_RE = re.compile(r"^\[VoxelForgeSourceStamp\] sha256=(\S+)$", re.M) def run(dataset: str, recipe: str, workers: int, compiler: str) -> dict: OUT.mkdir(parents=True, exist_ok=True) label = f"{dataset}-{recipe}-w{workers}-{compiler}" log = OUT / f"{label}.log" layout = OUT / f"{label}.layout.json" command = ["taskset", "-c", "0-11", "prlimit", "--as=6442450944", "--", "timeout", "1740s", str(BINARIES[compiler]), str(DATASETS[dataset]), f"--workers={workers}", "--world-assembler-prototype", "--stream-benchmark", "--stream-pipeline", "--force-generate", "--clip-radius=3", "--max-clip-level=8", "--max-level=8", f"--recipe={recipe}", "--stream-hash", f"--resolved-layout-output={layout}"] started = time.monotonic() with log.open("w", encoding="utf-8") as stream: result = subprocess.run(command, cwd=ROOT, stdout=stream, stderr=subprocess.STDOUT, check=False, timeout=1740) output = log.read_text(encoding="utf-8", errors="replace") hashes = HASH_RE.findall(output) if result.returncode or len(hashes) != 12: raise SystemExit(f"hash run failed: {label}; exit={result.returncode} " f"hashes={len(hashes)} log={log}") stamp = STAMP_RE.search(output) row = {"dataset": dataset, "recipe": recipe, "workers": workers, "compiler": compiler, "exit_code": result.returncode, "hashes": hashes, "source_stamp": stamp.group(1) if stamp else None, "elapsed_s": round(time.monotonic() - started, 3), "log": str(log.relative_to(ROOT))} print("[L130HashRun] " + json.dumps(row, sort_keys=True), flush=True) return row def main() -> int: if any(not path.is_file() for path in (*DATASETS.values(), *BINARIES.values())): raise SystemExit("missing L130 hash input") old = {(row["dataset"], row["recipe"], row["workers"], row["compiler"]): row for row in BASELINE["runs"]} rows = [] for dataset, recipes in RECIPES.items(): for recipe in recipes: for workers in (1, 8, 12): for compiler in ("clang", "gcc"): rows.append(run(dataset, recipe, workers, compiler)) (OUT / "runs-partial.json").write_text( json.dumps(rows, indent=2) + "\n", encoding="utf-8") groups = {} for dataset, recipes in RECIPES.items(): for recipe in recipes: group = [row for row in rows if row["dataset"] == dataset and row["recipe"] == recipe] key = f"{dataset}/{recipe}" stable = all(row["hashes"] == group[0]["hashes"] for row in group) baseline = old[(dataset, recipe, 12, "clang")]["hashes"] changed = [i for i, (before, after) in enumerate(zip(baseline, group[0]["hashes"])) if before != after] groups[key] = {"all_workers_and_compilers_match": stable, "matches_b96dd73_v225": not changed, "changed_hash_rows_from_v225": changed, "source_stamps": sorted({row["source_stamp"] for row in group})} if not stable: raise SystemExit(f"worker/compiler hash mismatch: {key}") (OUT / "summary.json").write_text( json.dumps({"baseline_source": "b96dd73", "runs": rows, "groups": groups}, indent=2) + "\n", encoding="utf-8") print("[L130HashSummary] " + json.dumps(groups, sort_keys=True), flush=True) return 0 if __name__ == "__main__": raise SystemExit(main())