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
CUDApp / evidence / amd-speed-20261114 / recompute / check_report.py
| 1 | #!/usr/bin/env python3 |
| 2 | # Check REPORT.md against numbers.json. What is checked, exactly: |
| 3 | # 1. Every decimal number outside code spans equals, to its printed precision, some value in numbers.json. |
| 4 | # 2. A decimal followed by a unit word (ms, us, percent, times, TB/s, GB, tokens per second, tokens per pass) must equal a |
| 5 | # value of that unit class, so a figure cannot be matched by an unrelated value in another unit. |
| 6 | # 3. Bound claims (claims.json): each regex must match the report, and every captured number (integers included) must |
| 7 | # equal the named numbers.json value. These cover the headline figures and ratios and the counts of runs, launches |
| 8 | # and gate cases. |
| 9 | # 4. No em or en dashes. |
| 10 | # Integers other than the bound claims, and decimals inside tables without a unit word, are checked only by rule 1 or not |
| 11 | # at all. --selftest applies known one-number mutations to a copy and requires each to fail. |
| 12 | # Usage: check_report.py REPORT.md numbers.json claims.json [--selftest] |
| 13 | import json, re, sys |
| 14 | from pathlib import Path |
| 15 | |
| 16 | UNITS = [(r'ms\b', {'ms/token', 'ms', 'ms/row'}), (r'(?:us|\u00b5s)\b', {'us', 'us/step'}), (r'percent\b', {'%'}), |
| 17 | (r'times\b', {'x'}), (r'TB/s', {'TB/s'}), (r'GB\b', {'GB', 'B'}), (r'tokens per second\b', {'tokens/s'}), |
| 18 | (r'tokens per pass\b', {'tokens/pass'})] |
| 19 | |
| 20 | |
| 21 | def load_values(nums): |
| 22 | vals = [] |
| 23 | for n in nums: |
| 24 | v = n['value'] |
| 25 | for x in (v if isinstance(v, list) else [v]): |
| 26 | if isinstance(x, (int, float)) and not isinstance(x, bool): |
| 27 | vals.append((float(x), n.get('unit', ''))) |
| 28 | if n.get('unit') == 'B': |
| 29 | vals.append((float(x) / 1e9, 'B')) |
| 30 | return vals |
| 31 | |
| 32 | |
| 33 | def check(report, nums, claims, quiet=False): |
| 34 | vals = load_values(nums) |
| 35 | byid = {n['id']: n['value'] for n in nums} |
| 36 | text = re.sub(r'```.*?```', lambda m: ' ' * len(m.group(0)), report, flags=re.S) |
| 37 | text = re.sub(r'`[^`\n]*`', lambda m: ' ' * len(m.group(0)), text) |
| 38 | bad, seen, bound = [], 0, 0 |
| 39 | for m in re.finditer(r'(?<![\w.-])(-?\d+\.\d+)(?![\w.]*\d)', text): |
| 40 | tok, b = m.group(1), m.end() |
| 41 | if text[b:b + 1] == '.' and text[b + 1:b + 2].isdigit(): |
| 42 | continue |
| 43 | seen += 1 |
| 44 | nd = len(tok.split('.')[1]) |
| 45 | x = float(tok) |
| 46 | ok = lambda v: abs(x - v) <= 0.5 * 10 ** -nd + 1e-12 |
| 47 | line = report.count('\n', 0, m.start()) + 1 |
| 48 | if not any(ok(v) for v, _ in vals): |
| 49 | bad.append(f'NO SOURCE {tok} (line {line})') |
| 50 | continue |
| 51 | after = text[b:b + 24].lstrip() |
| 52 | for pat, cls in UNITS: |
| 53 | if re.match(pat, after): |
| 54 | bound += 1 |
| 55 | if not any(ok(v) and u in cls for v, u in vals): |
| 56 | bad.append(f'WRONG UNIT {tok} {pat} (line {line})') |
| 57 | break |
| 58 | nclaims = 0 |
| 59 | for c in claims: |
| 60 | ms = list(re.finditer(c['pattern'], report)) |
| 61 | if not ms: |
| 62 | bad.append(f'CLAIM NOT FOUND {c["pattern"][:70]}') |
| 63 | continue |
| 64 | for m in ms: |
| 65 | for g, cid in zip(m.groups(), c['ids']): |
| 66 | nclaims += 1 |
| 67 | want = byid.get(cid) |
| 68 | if isinstance(want, list) and len(want) == 1: |
| 69 | want = want[0] |
| 70 | got = float(g.replace(',', '')) |
| 71 | nd = len(g.split('.')[1]) if '.' in g else 0 |
| 72 | if not isinstance(want, (int, float)) or abs(got - want) > 0.5 * 10 ** -nd + 1e-12: |
| 73 | bad.append(f'CLAIM MISMATCH {g} != {cid}={want} (line {report.count(chr(10), 0, m.start()) + 1})') |
| 74 | dash = [i + 1 for i, l in enumerate(report.splitlines()) if '\u2013' in l or '\u2014' in l] |
| 75 | if not quiet: |
| 76 | print(f'CHECK-REPORT decimals={seen} unit-bound={bound} claims={nclaims} MISMATCH {len(bad)} dashes={len(dash)}') |
| 77 | for x in bad: |
| 78 | print(' ' + x) |
| 79 | for d in dash: |
| 80 | print(' DASH line', d) |
| 81 | return not bad and not dash |
| 82 | |
| 83 | |
| 84 | MUTATIONS = [('16.226', '16.326'), ('1.674 times', '1.829 times'), ('173 completed', '171 completed'), |
| 85 | ('Spark gate: 318 checks', 'Spark gate: 316 checks'), ('5 of the 10 planned', '6 of the 10 planned')] |
| 86 | |
| 87 | if __name__ == '__main__': |
| 88 | report = Path(sys.argv[1]).read_text() |
| 89 | nums = json.loads(Path(sys.argv[2]).read_text())['numbers'] |
| 90 | claims = json.loads(Path(sys.argv[3]).read_text()) |
| 91 | if '--selftest' in sys.argv: |
| 92 | ok = check(report, nums, claims, quiet=True) |
| 93 | caught = 0 |
| 94 | for old, new in MUTATIONS: |
| 95 | if old not in report: |
| 96 | print(f' SELFTEST mutation target missing: {old}') |
| 97 | continue |
| 98 | caught += not check(report.replace(old, new, 1), nums, claims, quiet=True) |
| 99 | res = ok and caught == len(MUTATIONS) |
| 100 | print(f'CHECK-SELFTEST {"PASS" if res else "FAIL"} original={"pass" if ok else "fail"} mutations caught={caught}/{len(MUTATIONS)}') |
| 101 | sys.exit(0 if res else 1) |
| 102 | sys.exit(0 if check(report, nums, claims) else 1) |