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 / tests / dagsim / corpus_diff.py
| 1 | #!/usr/bin/env python3 |
| 2 | """Byte-compare the C oracle CLI and the Omega CLI on a generated OEV corpus. |
| 3 | |
| 4 | Usage: corpus_diff.py C_BIN OM_BIN [N] |
| 5 | Prints PASS n=... or the first mismatch and exits 1. |
| 6 | Deterministic: seed 20261106. |
| 7 | """ |
| 8 | import os |
| 9 | import random |
| 10 | import subprocess |
| 11 | import sys |
| 12 | import tempfile |
| 13 | |
| 14 | C_BIN, OM_BIN = sys.argv[1], sys.argv[2] |
| 15 | N = int(sys.argv[3]) if len(sys.argv) > 3 else 1200 |
| 16 | ASOF = "2026-10-20" |
| 17 | |
| 18 | |
| 19 | def header(slots=2, cap=1000000, bw=1e9): |
| 20 | return [ |
| 21 | "oev version=1", |
| 22 | "machine id=t soc=t cores=4 mem_bytes=1000 prov=specified src=test", |
| 23 | "build repo=omega-mv sha=0000000000000000000000000000000000000000", |
| 24 | "calibration id=c taken=2026-10-19 valid_days=3650 load1=0 src=synthetic", |
| 25 | f"resource id=cpu kind=compute slots={slots} prov=specified src=test", |
| 26 | f"resource id=mem kind=capacity cap={cap} prov=specified src=test", |
| 27 | f"resource id=bus kind=bandwidth cap={bw} lo={bw} hi={bw} prov=specified src=test", |
| 28 | "resource id=lch kind=launch prov=specified src=test", |
| 29 | "energy instrument=none", |
| 30 | ] |
| 31 | |
| 32 | |
| 33 | def emit(lines, path): |
| 34 | with open(path, "w") as f: |
| 35 | f.write("\n".join(lines) + "\n") |
| 36 | |
| 37 | |
| 38 | def case_chain(rng, nops): |
| 39 | lines = header(slots=rng.choice([1, 2, 4])) |
| 40 | for i in range(nops): |
| 41 | t = rng.randint(1, 5000) |
| 42 | lines.append(f"op id=a{i} kind=compute engine=cpu t_ns={t} prov=synthetic src=t") |
| 43 | for i in range(nops - 1): |
| 44 | if rng.random() < 0.7: |
| 45 | lines.append(f"dep a{i} a{i+1}") |
| 46 | return lines |
| 47 | |
| 48 | |
| 49 | def case_bw(rng, nops): |
| 50 | lines = header(slots=4, bw=rng.choice([1e6, 1e8, 1e9])) |
| 51 | for i in range(nops): |
| 52 | t = rng.randint(10, 2000) |
| 53 | b = rng.choice([0, 1000, 100000, 1000000]) |
| 54 | extra = f" bytes={b} bw=bus" if b else "" |
| 55 | lines.append(f"op id=a{i} kind=copy engine=cpu t_ns={t}{extra} prov=synthetic src=t") |
| 56 | return lines |
| 57 | |
| 58 | |
| 59 | def case_buf(rng, nops, invert=False, over=False): |
| 60 | cap = 1000 if over else 1000000 |
| 61 | lines = header(slots=2, cap=cap) |
| 62 | for i in range(nops): |
| 63 | lines.append(f"op id=a{i} kind=compute engine=cpu t_ns={rng.randint(1, 100)} prov=synthetic src=t") |
| 64 | for i in range(nops - 1): |
| 65 | lines.append(f"dep a{i} a{i+1}") |
| 66 | nb = rng.randint(1, min(4, nops)) |
| 67 | for b in range(nb): |
| 68 | first = rng.randint(0, nops - 1) |
| 69 | last = rng.randint(0, nops - 1) |
| 70 | if invert: |
| 71 | first, last = nops - 1, 0 |
| 72 | nbytes = 2000 if over else rng.choice([0, 10, 80, 500]) |
| 73 | lines.append(f"buffer id=b{b} bytes={nbytes} cap=mem first=a{first} last=a{last}") |
| 74 | return lines |
| 75 | |
| 76 | |
| 77 | def case_cycle(rng, nops): |
| 78 | lines = case_chain(rng, max(nops, 3)) |
| 79 | lines.append(f"dep a{nops-1} a0") |
| 80 | return lines |
| 81 | |
| 82 | |
| 83 | def case_launch(rng, nops): |
| 84 | lines = header(slots=1) |
| 85 | for i in range(nops): |
| 86 | lines.append( |
| 87 | f"op id=a{i} kind=compute engine=cpu t_ns={rng.randint(1, 100)} " |
| 88 | f"launch_ns={rng.randint(0, 50)} launcher=lch prov=synthetic src=t" |
| 89 | ) |
| 90 | return lines |
| 91 | |
| 92 | |
| 93 | def case_barrier(rng, nops): |
| 94 | lines = header(slots=rng.choice([1, 3])) |
| 95 | for i in range(nops): |
| 96 | lines.append(f"op id=a{i} kind=compute engine=cpu t_ns={rng.randint(1, 200)} prov=synthetic src=t") |
| 97 | if nops >= 2: |
| 98 | ids = ",".join(f"a{i}" for i in range(nops)) |
| 99 | lines.append(f"sync id=bar ops={ids}") |
| 100 | lines.append("op id=tail kind=compute engine=cpu t_ns=5 prov=synthetic src=t") |
| 101 | lines.append("dep bar tail") |
| 102 | return lines |
| 103 | |
| 104 | |
| 105 | BUILDERS = [case_chain, case_bw, case_buf, case_cycle, case_launch, case_barrier] |
| 106 | |
| 107 | |
| 108 | def run(bin, path): |
| 109 | p = subprocess.run([bin, "eval", path, "--asof", ASOF], capture_output=True) |
| 110 | return p.returncode, p.stdout, p.stderr |
| 111 | |
| 112 | |
| 113 | def main(): |
| 114 | rng = random.Random(20261106) |
| 115 | tmp = tempfile.mkdtemp(prefix="dagsim-corpus-") |
| 116 | bad = 0 |
| 117 | kinds = {b.__name__: 0 for b in BUILDERS} |
| 118 | for i in range(N): |
| 119 | b = BUILDERS[i % len(BUILDERS)] |
| 120 | nops = 1 + (i % 12) |
| 121 | if b is case_buf and i % 18 == 2: |
| 122 | lines = case_buf(rng, nops, invert=True) |
| 123 | elif b is case_buf and i % 18 == 8: |
| 124 | lines = case_buf(rng, nops, over=True) |
| 125 | else: |
| 126 | lines = b(rng, nops) |
| 127 | path = os.path.join(tmp, f"c{i}.oev") |
| 128 | emit(lines, path) |
| 129 | rc1, o1, e1 = run(C_BIN, path) |
| 130 | rc2, o2, e2 = run(OM_BIN, path) |
| 131 | kinds[b.__name__] += 1 |
| 132 | if rc1 != rc2 or o1 != o2 or e1 != e2: |
| 133 | bad += 1 |
| 134 | if bad == 1: |
| 135 | sys.stderr.write(f"DIFF case {i} {b.__name__} rc {rc1} vs {rc2}\n") |
| 136 | sys.stderr.write(o1.decode()[:400] + "\n---\n" + o2.decode()[:400] + "\n") |
| 137 | if bad >= 5: |
| 138 | break |
| 139 | print(f"{'FAIL' if bad else 'PASS'} n={N} bad={bad} dir={tmp} kinds={kinds}") |
| 140 | return 1 if bad else 0 |
| 141 | |
| 142 | |
| 143 | if __name__ == "__main__": |
| 144 | sys.exit(main()) |