#!/usr/bin/env python3 """Compare L118 owner4 hashes to L115 at W1/W8/W12 under Clang and GCC.""" 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/l118/hashes" DATA = ROOT / "Standalone/data/owner_world.json" BASELINE = ROOT / "Saved/Linux/l115/hashes/summary.json" BINARIES = { "clang": ROOT / "Saved/Linux/l118/bin/VoxelForgeCoreHeadless-l118-clang", "gcc": ROOT / "Saved/Linux/l118/bin/VoxelForgeCoreHeadless-l118-gcc", } HASH = re.compile(r"^\[Pipeline(?:FullDetailHash|WholeViewHash|LODHash|ExactQueryHash)\].*$", re.M) STAMP = re.compile(r"^\[VoxelForgeSourceStamp\] sha256=(\S+)$", re.M) def run(workers: int, compiler: str) -> dict: OUT.mkdir(parents=True, exist_ok=True) label = f"owner4-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(DATA), "--workers=" + str(workers), "--world-assembler-prototype", "--stream-benchmark", "--stream-pipeline", "--force-generate", "--clip-radius=3", "--max-clip-level=8", "--max-level=8", "--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) content = log.read_text(encoding="utf-8", errors="replace") hashes = HASH.findall(content) if result.returncode or len(hashes) != 12: raise SystemExit(f"hash run failed or incomplete: {label}; exit={result.returncode} " f"hashes={len(hashes)} log={log}") row = {"workers": workers, "compiler": compiler, "exit_code": result.returncode, "hashes": hashes, "source_stamp": (STAMP.search(content).group(1) if STAMP.search(content) else None), "elapsed_s": round(time.monotonic() - started, 3), "log": str(log.relative_to(ROOT))} print("[L118HashRun] " + json.dumps(row, sort_keys=True), flush=True) return row def main() -> int: if not DATA.is_file() or not BASELINE.is_file() or any(not path.is_file() for path in BINARIES.values()): raise SystemExit("missing L118 hash input or L115 reference") reference = json.loads(BASELINE.read_text(encoding="utf-8"))["runs"] reference = [row for row in reference if row["dataset"] == "owner4" and row["recipe"] == "surface-world"] rows = [run(workers, compiler) for workers in (1, 8, 12) for compiler in ("clang", "gcc")] comparisons = [] for row in rows: matches = [old for old in reference if old["workers"] == row["workers"] and old["compiler"] == row["compiler"]] if len(matches) != 1: raise SystemExit(f"expected one L115 reference for W{row['workers']}/{row['compiler']}") match = row["hashes"] == matches[0]["hashes"] comparisons.append({"workers": row["workers"], "compiler": row["compiler"], "matches_l115": match, "l115_log": matches[0]["log"], "l118_log": row["log"]}) if not match: raise SystemExit(f"L118 hash mismatch versus L115 at W{row['workers']}/{row['compiler']}") summary = {"runs": rows, "comparisons": comparisons, "l115_hashes_identical": len({tuple(r["hashes"]) for r in reference}) == 1, "candidate_matches_l115_all_workers_and_compilers": True} (OUT / "summary.json").write_text(json.dumps(summary, indent=2) + "\n", encoding="utf-8") return 0 if __name__ == "__main__": raise SystemExit(main())