#!/usr/bin/env python3 """L80-protocol L104/L105 near and whole-view readiness pairs.""" from __future__ import annotations import json import re import statistics import subprocess import time from pathlib import Path ROOT = Path(__file__).resolve().parents[4] OUT = ROOT / "Saved/Linux/l105/readiness-paired" DATA = ROOT / "Standalone/data/owner_world.json" BINARIES = { "before": ROOT / "Saved/Linux/l104/bin/VoxelForgeCoreHeadless-l104-clang", "after": ROOT / "Saved/Linux/l105/bin/VoxelForgeCoreHeadless-l105-clang", } STRATA = { "sw": {"camera": (8.0, 16.0, -372.2626953125), "near": 1408, "whole": 2850}, "fi": {"camera": (25.8369140625, 3.19921875, -737.0), "near": 1216, "whole": 2249}, "tn": {"camera": (19.166015625, -14.2001953125, -753.3740234375), "near": 1344, "whole": 2233}, "vs": {"camera": (-20.0625, -5.068359375, -900.353515625), "near": 1344, "whole": 2329}, } NEAR = re.compile(r"^\[WorldAssemblerNearLODReady\] lods=0-2 tiles=(\d+)/(\d+) cold_ready_s=([0-9.]+)$", re.M) PIPELINE = re.compile(r"^\[StreamPipeline\] (.*)$", re.M) CONFIG = re.compile(r"^\[HeadlessConfig\] (.*)$", re.M) STAMP = re.compile(r"^\[VoxelForgeSourceStamp\] sha256=([0-9a-f]{64})$", re.M) FIELDS = re.compile(r"([a-zA-Z0-9_]+)=([^ ]+)") def run(stratum: str, workers: int, build: str, phase: str, replicate: int) -> dict: OUT.mkdir(parents=True, exist_ok=True) suffix = f"-r{replicate}" if phase == "measured" else "" log = OUT / f"{stratum}-w{workers}-{build}-{phase}{suffix}.log" camera = ",".join(f"{value:.12f}" for value in STRATA[stratum]["camera"]) + ",0,0" command = [ "taskset", "-c", "0-11", "prlimit", "--as=6442450944", "--", "timeout", "1740s", str(BINARIES[build]), str(DATA), "--world-assembler-prototype", "--stream-benchmark", "--stream-pipeline", f"--workers={workers}", "--clip-radius=3", "--max-clip-level=8", "--max-level=8", f"--camera={camera}", "--profile-lod-work", "--stream-scheduler-policy=3", ] started = time.monotonic() with log.open("w", encoding="utf-8") as stream: process = subprocess.run(command, cwd=ROOT, stdout=stream, stderr=subprocess.STDOUT, check=False, timeout=1740) content = log.read_text(encoding="utf-8", errors="replace") near, pipeline, config, stamp = (NEAR.search(content), PIPELINE.search(content), CONFIG.search(content), STAMP.search(content)) if process.returncode or not all((near, pipeline, config, stamp)): raise RuntimeError(f"readiness run failed or missing marker: {log}; exit={process.returncode}") expected = STRATA[stratum] config_fields = dict(FIELDS.findall(config.group(1))) pipeline_fields = dict(FIELDS.findall(pipeline.group(1))) if int(config_fields["workers"]) != workers: raise RuntimeError(f"worker mismatch: {log}") if (int(near.group(1)), int(near.group(2))) != (expected["near"], expected["near"]): raise RuntimeError(f"incomplete LOD0-2 set: {log}: {near.group(1)}/{near.group(2)}") whole_done, whole_total = map(int, pipeline_fields["whole_tiles"].split("/")) if (whole_done, whole_total) != (expected["whole"], expected["whole"]): raise RuntimeError(f"incomplete whole view: {log}: {whole_done}/{whole_total}") row = { "stratum": stratum, "workers": workers, "build": build, "phase": phase, "replicate": replicate, "source_stamp": stamp.group(1), "near_tiles": expected["near"], "whole_tiles": whole_done, "lod02_ready_s": float(near.group(3)), "whole_view_ready_s": float(pipeline_fields["whole_view_ready"].removesuffix("s")), "shape_s": float(pipeline_fields["shape"].removesuffix("s")), "far_shape_s": float(pipeline_fields["far_shape"].removesuffix("s")), "wall_s": round(time.monotonic() - started, 3), "log": str(log.relative_to(ROOT)), } print("[L105ReadinessRun] " + json.dumps(row, sort_keys=True), flush=True) return row def main() -> int: for path in (*BINARIES.values(), DATA): if not path.is_file(): raise SystemExit(f"missing input: {path}") cells = [(stratum, workers) for stratum in ("vs", "tn", "fi", "sw") for workers in (12, 8)] for stratum, workers in cells: for build in ("before", "after"): run(stratum, workers, build, "warmup", 0) orders = (("before", "after"), ("after", "before"), ("before", "after")) rows = [] for stratum, workers in cells: for replicate, order in enumerate(orders, 1): for build in order: rows.append(run(stratum, workers, build, "measured", replicate)) (OUT / "runs-partial.json").write_text( json.dumps(rows, indent=2) + "\n", encoding="utf-8") summary = [] for stratum in STRATA: for workers in (8, 12): group = [row for row in rows if row["stratum"] == stratum and row["workers"] == workers] item = {"stratum": stratum, "workers": workers, "measured_runs_per_build": 3} for build in ("before", "after"): subset = [row for row in group if row["build"] == build] for metric in ("lod02_ready_s", "whole_view_ready_s"): values = [row[metric] for row in subset] item[f"{build}_{metric}"] = values item[f"{build}_{metric}_median"] = statistics.median(values) for metric in ("lod02_ready_s", "whole_view_ready_s"): item[f"{metric}_delta_pct"] = 100.0 * ( item[f"after_{metric}_median"] / item[f"before_{metric}_median"] - 1.0) summary.append(item) (OUT / "summary.json").write_text( json.dumps({"runs": rows, "summary": summary}, indent=2) + "\n", encoding="utf-8") return 0 if __name__ == "__main__": raise SystemExit(main())