interplane.Get Omega
Read in your language

CUDApp

CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit.

Brought by drakestapleton

branch main Branches Tags History

CUDApp / evidence / amd-speed-20261114 / recompute / common.py

103 lines · 3816 bytes Raw Blame History
1# Shared helpers for the report's recompute scripts (measuring tools, not Omega).
2# Python standard library only. Reads raw evidence files, never a lane's prose.
3# Evidence root: $AMD_REPORT_RAW, else ../raw beside this folder (the publication layout), else the handoff folder.
4import hashlib, json, os, re, statistics, sys
5from pathlib import Path
6
7HERE = Path(__file__).resolve().parent
8_raw = HERE.parent / 'raw'
9ROOT = Path(os.environ.get('AMD_REPORT_RAW') or (_raw if _raw.is_dir() else HERE.parent.parent)).resolve()
10OUT = HERE / 'out'
11OUT.mkdir(exist_ok=True)
12
13STEP = re.compile(r'^OMEGA_STEP (\d+) tok=(-?\d+) us=(\d+)$', re.M)
14IDS = re.compile(r'^OMEGA_PLAN ids=\[([0-9,\-]*)\]$', re.M)
15PROMPT = 30 # prompt steps of the lighthouse request
16
17
18def sha256(path):
19 h = hashlib.sha256()
20 with open(path, 'rb') as f:
21 for chunk in iter(lambda: f.read(1 << 20), b''):
22 h.update(chunk)
23 return h.hexdigest()
24
25
26def rel(path):
27 return str(Path(path).resolve().relative_to(ROOT))
28
29
30def omega_run(path, prompt=PROMPT):
31 """One launcher stdout capture: per-step microseconds and the emitted ids."""
32 text = Path(path).read_text(errors='replace')
33 us = [int(m.group(3)) for m in STEP.finditer(text)]
34 m = IDS.search(text)
35 ids = [int(x) for x in m.group(1).split(',')] if m and m.group(1) else None
36 dec = us[prompt:]
37 return dict(
38 steps=len(us),
39 decode_steps=len(dec),
40 decode_ms_median=statistics.median(dec) / 1000 if dec else None,
41 prefill_ms=sum(us[:prompt]) / 1000,
42 ids=ids,
43 )
44
45
46def first_difference(a, b):
47 if a is None or b is None:
48 return 0
49 for i, (x, y) in enumerate(zip(a, b)):
50 if x != y:
51 return i
52 return None if len(a) == len(b) else min(len(a), len(b))
53
54
55class Book:
56 """Collects the numbers of one topic and writes out/<topic>.json and .txt."""
57
58 def __init__(self, topic):
59 self.topic = topic
60 self.rows = []
61 self.fail = []
62
63 def add(self, id, value, unit, label, source, how, printed=None):
64 # label: MEASURED, MODELED, DERIVED (arithmetic on measured values), COUNT, RECORD
65 srcs = source if isinstance(source, list) else [source]
66 files = []
67 for s in srcs:
68 p = ROOT / s
69 if p.is_file():
70 files.append(dict(path=s, sha256=sha256(p)))
71 elif p.exists():
72 files.append(dict(path=s, sha256=None, note='directory'))
73 else:
74 files.append(dict(path=s, sha256=None, note='MISSING'))
75 self.fail.append(f'{id}: source missing {s}')
76 self.rows.append(dict(id=f'{self.topic}.{id}', value=value, unit=unit, label=label,
77 printed=printed, sources=files, how=how,
78 recompute=f'recompute/{self.topic}.py'))
79 return value
80
81 def check(self, name, ok, detail=''):
82 if not ok:
83 self.fail.append(f'CHECK {name}: {detail}')
84 return ok
85
86 def close(self):
87 (OUT / f'{self.topic}.json').write_text(json.dumps(self.rows, indent=1) + '\n')
88 lines = []
89 for r in self.rows:
90 lines.append(f"{r['id']}\t{r['printed'] if r['printed'] is not None else r['value']}"
91 f"\t{r['unit']}\t{r['label']}\t{r['value']}")
92 verdict = 'PASS' if not self.fail else 'FAIL'
93 lines.append(f'RECOMPUTE {self.topic} {verdict} numbers={len(self.rows)} failures={len(self.fail)}')
94 lines += self.fail
95 (OUT / f'{self.topic}.txt').write_text('\n'.join(lines) + '\n')
96 print(lines[len(self.rows)])
97 for f in self.fail:
98 print(' ' + f)
99 sys.exit(0 if not self.fail else 1)
100
101
102def fmt(x, nd):
103 return f'{x:.{nd}f}'