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 / om / codegen / moe_mutants.py
| 1 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | """Host verification oracle: mutate seeded .om input, never generated C or the C oracle.""" |
| 3 | import os |
| 4 | from pathlib import Path |
| 5 | import subprocess |
| 6 | import tempfile |
| 7 | |
| 8 | ROOT = Path(__file__).resolve().parents[2] |
| 9 | OMC = os.environ["OMEGA_OMC"] |
| 10 | BRIDGE = Path(os.environ["OMEGA_BRIDGE"]) |
| 11 | PARTS = ("cg_moe_emit.om", "cg_moe_core.om") |
| 12 | P1 = (1, 512, 8, 1, 3, 2, 0, 0, 1, 1) |
| 13 | P2 = (2, 512, 8, 1, 3, 0, 0, 0, 0, 0) |
| 14 | MUTANTS = ( |
| 15 | ("descriptor-immediate", "CG_MOE_SRC", PARTS + ("cg_moe.om",), |
| 16 | "put x ulong 6 ulong 856", "put x ulong 6 ulong 857", P1), |
| 17 | ("e4m3-bit-mask", "CG_MOE2_SRC", PARTS + ("cg_moe2.om",), |
| 18 | "put x ulong 6 ulong 133169152", "put x ulong 6 ulong 133169153", P2), |
| 19 | ("branch-relative-origin", "CG_MOE_SRC", PARTS + ("cg_moe.om",), |
| 20 | "imm = and sub tgt at ulong 4294967295", "imm = and sub tgt add at ulong 1 ulong 4294967295", P1), |
| 21 | ("allocator-bundle-kind", "CG_MOE2_SRC", PARTS + ("cg_moe2.om",), |
| 22 | "put m add ulong 64 n kind", "put m add ulong 64 n ulong 1", P2), |
| 23 | ("fixed-producer-latency", "CG_MOE_SCHED_SRC", ("cg_moe_sched.om",), |
| 24 | "put s 4 add get s 0 6", "put s 4 add get s 0 5", (1, 512, 8, 1, 3, 2, 0, 1, 1, 1)), |
| 25 | ("ignored-high-scalar-leak", "CG_MOE2_SRC", PARTS + ("cg_moe2.om",), |
| 26 | "put x ulong 6 ulong 856", "put x ulong 6 add ulong 856 get z ulong 4", (2, 512, 8, 1, 3, 2147483648, 0, 0, 0, 0)), |
| 27 | ("accepted-k-boundary", "CG_MOE_SRC", PARTS + ("cg_moe.om",), |
| 28 | "gt k ulong 32768", "gt k ulong 32767", (1, 32768, 8, 1, 1, 0, 0, 0, 0, 0)), |
| 29 | ) |
| 30 | |
| 31 | |
| 32 | def run(argv, **kwargs): |
| 33 | return subprocess.run(argv, cwd=ROOT, text=True, capture_output=True, **kwargs) |
| 34 | |
| 35 | |
| 36 | def main(): |
| 37 | baseline = ROOT / "build/codegen_moe_diff_test" |
| 38 | for _, _, _, _, _, point in MUTANTS: |
| 39 | result = run([str(baseline), *map(str, point)]) |
| 40 | if result.returncode: |
| 41 | raise RuntimeError(f"baseline {point}: rc={result.returncode}\n{result.stdout}{result.stderr}") |
| 42 | killed = 0 |
| 43 | for name, variable, parts, before, after, point in MUTANTS: |
| 44 | with tempfile.TemporaryDirectory(prefix="omega-moe-mutant-") as directory: |
| 45 | tmp = Path(directory) |
| 46 | source = "\n".join((ROOT / "om/codegen" / part).read_text() for part in parts) |
| 47 | if source.count(before) != 1: |
| 48 | raise RuntimeError(f"{name}: mutation site is not unique") |
| 49 | om = tmp / "mutant.om" |
| 50 | om.write_text(source.replace(before, after)) |
| 51 | env = dict(os.environ, OMEGA_SEEDED_OMC=OMC) |
| 52 | result = run(["sh", str(BRIDGE / "tools/bridge-seeded"), "c", str(om)], env=env) |
| 53 | if result.returncode: |
| 54 | raise RuntimeError(f"{name}: mutant must compile: rc={result.returncode}\n{result.stderr}") |
| 55 | c = tmp / "mutant.c" |
| 56 | c.write_text(result.stdout) |
| 57 | out = tmp / "build" |
| 58 | result = run(["make", "-j3", f"OUT_DIR={out}", f"{variable}={c}", |
| 59 | "CFLAGS=-std=gnu11 -Wall -Wextra -Werror -O0 -Isrc", |
| 60 | str(out / "codegen_moe_diff_test")]) |
| 61 | if result.returncode: |
| 62 | raise RuntimeError(f"{name}: mutant C must build: rc={result.returncode}\n{result.stdout}{result.stderr}") |
| 63 | result = run([str(out / "codegen_moe_diff_test"), *map(str, point)]) |
| 64 | if result.returncode != 1 or "DIFF" not in result.stderr: |
| 65 | raise RuntimeError(f"{name}: mutant survived or crashed: rc={result.returncode}\n{result.stdout}{result.stderr}") |
| 66 | print(f"KILLED Omega {name} config={point} rc=1", flush=True) |
| 67 | killed += 1 |
| 68 | print(f"CODEGEN MOE OMEGA MUTANTS PASS ({killed} source-mutant controls)") |
| 69 | |
| 70 | |
| 71 | if __name__ == "__main__": |
| 72 | main() |