#!/usr/bin/env python3 """Measure exact far-hit triangle probes with the L104 memo disabled/enabled.""" from __future__ import annotations import json import os import re import subprocess import time from pathlib import Path ROOT = Path(__file__).resolve().parents[4] OUT = ROOT / "Saved/Linux/l104/probes" DATA = ROOT / "Standalone/data/owner_world.json" BINARY = ROOT / "Saved/Linux/l104/bin/VoxelForgeCoreHeadless-l104-clang" CAMERAS = { "SW": (8.0, 16.0, -372.2626953125), "FI": (25.8369140625, 3.19921875, -737.0), "TN": (19.166015625, -14.2001953125, -753.3740234375), "VS": (-20.0625, -5.068359375, -900.353515625), } def run(stratum: str, cache: str) -> dict: OUT.mkdir(parents=True, exist_ok=True) log = OUT / f"{stratum.lower()}-{cache}.log" camera = ",".join(f"{value:.12f}" for value in CAMERAS[stratum]) + ",0,0" command = [ "taskset", "-c", "0-11", "prlimit", "--as=6442450944", "--", "env", f"VOXELFORGE_L104_FAR_HIT_CACHE={0 if cache == 'off' else 1}", "VOXELFORGE_L104_FAR_HIT_STATS=1", "timeout", "1740s", str(BINARY), str(DATA), "--world-assembler-prototype", "--stream-benchmark", "--stream-pipeline", "--workers=12", "--clip-radius=3", "--max-clip-level=8", "--max-level=8", f"--camera={camera}", "--stream-scheduler-policy=3", ] 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") rows = [] pattern = re.compile( r"^\[FarHitQueryStats\] lod=(\d+) origin=\(([^)]*)\) " r"down_queries=(\d+) down_candidate_tests=(\d+) down_hit_queries=(\d+) " r"up_queries=(\d+) up_candidate_tests=(\d+) up_hit_queries=(\d+)$", re.M) for match in pattern.finditer(content): rows.append({ "lod": int(match.group(1)), "origin": match.group(2), "down_queries": int(match.group(3)), "down_candidate_tests": int(match.group(4)), "down_hit_queries": int(match.group(5)), "up_queries": int(match.group(6)), "up_candidate_tests": int(match.group(7)), "up_hit_queries": int(match.group(8)), }) if result.returncode or not rows: raise RuntimeError(f"probe stats failed or missing: {log}; exit={result.returncode}") row = {"stratum": stratum, "cache": cache, "exit_code": result.returncode, "source_stamp": re.search(r"^\[VoxelForgeSourceStamp\] sha256=(\S+)$", content, re.M).group(1), "wall_s": round(time.monotonic() - started, 3), "indices": len(rows), "stats": rows, "log": str(log.relative_to(ROOT))} (OUT / f"{stratum.lower()}-{cache}.json").write_text( json.dumps(row, indent=2) + "\n", encoding="utf-8") print("[L104ProbeStatsRun] " + json.dumps( {key: value for key, value in row.items() if key != "stats"}, sort_keys=True), flush=True) return row def main() -> int: if not BINARY.is_file() or not DATA.is_file(): raise SystemExit(f"missing input: {BINARY} or {DATA}") rows = [] for stratum in CAMERAS: for cache in ("off", "on"): rows.append(run(stratum, cache)) (OUT / "runs-partial.json").write_text( json.dumps(rows, indent=2) + "\n", encoding="utf-8") (OUT / "runs.json").write_text(json.dumps(rows, indent=2) + "\n", encoding="utf-8") return 0 if __name__ == "__main__": raise SystemExit(main())