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 / om / codegen / tern_mutants.py

69 lines · 3316 bytes Raw Blame History
1# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2"""Host verification oracle: mutate seeded Omega sources, never the checked C output."""
3import os
4from pathlib import Path
5import subprocess
6import tempfile
7
8ROOT = Path(__file__).resolve().parents[2]
9OMC = os.environ["OMEGA_OMC"]
10BRIDGE = Path(os.environ["OMEGA_BRIDGE"])
11# Every supported (layout, rows) shape crosses both output paths and epilogues.
12# Depth two also exercises the multi-step unrolled activation path; the explicit
13# deep/chunk points exercise its streaming alternative and the chunk loop.
14SHAPES = ((0, 1), (0, 2), (0, 4), (1, 2), (1, 4))
15POINTS = tuple(
16 (256, layout, rows, warps, 1, epi, 0)
17 for layout, rows in SHAPES for warps in (1, 32) for epi in (0, 1)
18) + tuple(
19 (512, layout, rows, 1, 2, epi, 0)
20 for layout, rows in SHAPES for epi in (0, 1)
21) + (
22 (4096, 0, 1, 1, 16, 0, 0), (4096, 1, 2, 1, 8, 1, 0),
23 (16384, 0, 1, 1, 16, 0, 0), (16384, 1, 2, 1, 8, 0, 0),
24)
25
26
27def run(argv, **kwargs):
28 return subprocess.run(argv, cwd=ROOT, text=True, capture_output=True, **kwargs)
29
30
31def main():
32 baseline = ROOT / "build/codegen_tern_diff_test"
33 for point in POINTS:
34 r = run([str(baseline), *map(str, point)])
35 if r.returncode:
36 raise RuntimeError(f"baseline {point}: rc={r.returncode}\n{r.stdout}{r.stderr}")
37 killed = 0
38 for name, source, before, after, variable, parts in (
39 ("builder-bias", "cg_tern.om", "put x 6 2147516416", "put x 6 2147516417", "CG_TERN_SRC", ("cg_tern_common.om", "cg_tern.om")),
40 ("fixed-latency", "cg_tern_sched.om", "put s 4 add get s 0 6", "put s 4 add get s 0 5", "CG_TERN_SCHED_SRC", ("cg_tern_sched.om",)),
41 ):
42 with tempfile.TemporaryDirectory(prefix="omega-tern-mutant-") as tmp:
43 tmp = Path(tmp)
44 data = "\n".join((ROOT / "om/codegen" / part).read_text() for part in parts)
45 if data.count(before) != 1:
46 raise RuntimeError(f"{name}: mutation site is not unique")
47 om = tmp / "mutant.om"
48 om.write_text(data.replace(before, after))
49 env = dict(os.environ, OMEGA_SEEDED_OMC=OMC)
50 r = run(["sh", str(BRIDGE / "tools/bridge-seeded"), "c", str(om)], env=env)
51 if r.returncode:
52 raise RuntimeError(f"{name}: mutant must compile: rc={r.returncode}\n{r.stderr}")
53 c = tmp / "mutant.c"
54 c.write_text(r.stdout)
55 out = tmp / "build"
56 r = run(["make", "-j3", f"OUT_DIR={out}", f"{variable}={c}", "CFLAGS=-std=gnu11 -Wall -Wextra -Werror -O0 -Isrc", str(out / "codegen_tern_diff_test")])
57 if r.returncode:
58 raise RuntimeError(f"{name}: mutant C must build: rc={r.returncode}\n{r.stdout}{r.stderr}")
59 for point in POINTS:
60 r = run([str(out / "codegen_tern_diff_test"), *map(str, point)])
61 if r.returncode != 1 or "TERN DIFF" not in r.stderr:
62 raise RuntimeError(f"{name}: mutant survived or crashed at {point}: rc={r.returncode}\n{r.stdout}{r.stderr}")
63 print(f"KILLED Omega {name} config={point} rc=1", flush=True)
64 killed += 1
65 print(f"CODEGEN TERN OMEGA MUTANTS PASS ({killed} source-mutant/config controls)")
66
67
68if __name__ == "__main__":
69 main()