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 / tests / dec_mutants.py

71 lines · 4037 bytes Raw Blame History
1#!/usr/bin/env python3
2# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3"""Recompiled Omega mutants for the cg_dec and gdn_admit units.
4
5Each mutant is a literal text swap on a site that occurs exactly once in its .om source. The mutated source is
6compiled with the pinned seeded compiler through bridge-seeded, and the resulting unit object is linked ahead of
7libomega_gpu.a into the unit's differential, so the mutant replaces the checked-in unit. A mutant is killed when
8the differential exits nonzero. Usage: OMEGA_OMC=... OMEGA_BRIDGE=... python3 tests/dec_mutants.py [build-dir]
9"""
10import os, subprocess, sys, tempfile
11
12ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
13OUT = sys.argv[1] if len(sys.argv) > 1 else os.path.join(ROOT, "build")
14DEC = ["om/codegen/cg_dec_emit.om", "om/codegen/cg_dec.om"]
15ADMIT = ["om/gdn/admit.om"]
16MUTANTS = [
17 ("dec-inv-h", DEC, "ret 973078528", "ret 973078529"),
18 ("dec-width-bound", DEC, "if or ne rem h 1024 0 gt n 32", "if or ne rem h 1024 0 gt n 36"), # 33..35 are equivalent: no multiple of 1024 lies in 8193..9215
19 ("dec-dispatch-argmax", DEC, "if eq kind 4", "if eq kind 9"),
20 ("dec-group-slots", DEC, "if or lt sl 1 gt sl 16", "if or lt sl 1 gt sl 17"),
21 ("dec-axpy-stride", DEC, "if or eq st 0 ne rem st 256 0", "if or eq st 0 ne rem st 128 0"),
22 ("dec-warp-reduce", DEC, "while gt o 0 bound 5", "while gt o 1 bound 5"),
23 ("admit-max-layers", ADMIT, "if or eq a 0 gt a 64", "if or eq a 0 gt a 65"),
24 ("admit-move-grid", ADMIT, "if gt div by 4096 2147483647", "if gt div by 4096 2147483648"),
25 ("admit-align16", ADMIT, "if ne and m16 15 0", "if ne and m16 7 0"),
26 ("admit-tail-bytes", ADMIT, "put o 7 mul vh 6144", "put o 7 mul vh 6145"),
27 ("admit-finite", ADMIT, "if eq and shr x 23 255 255", "if eq and shr x 24 255 255"),
28]
29
30def run(cmd, **kw):
31 return subprocess.run(cmd, cwd=ROOT, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, **kw)
32
33def main():
34 env = os.environ
35 omc, bridge = env["OMEGA_OMC"], env.get("OMEGA_BRIDGE") or env["OMEGA_BRIDGE_DIR"]
36 cc = env.get("CC", "cc")
37 flags = ["-std=gnu11", "-O2", "-D_GNU_SOURCE", "-Isrc", "-Itests"]
38 killed = 0
39 with tempfile.TemporaryDirectory() as tmp:
40 for name, files, old, new in MUTANTS:
41 text = "\n".join(open(os.path.join(ROOT, f)).read() for f in files)
42 if text.count(old) != 1:
43 print(f"FAIL mutant {name}: site found {text.count(old)} times"); return 1
44 src = os.path.join(tmp, name + ".om")
45 open(src, "w").write(text.replace(old, new))
46 gen = run(["sh", os.path.join(bridge, "tools/bridge-seeded"), "c", src],
47 env=dict(env, OMEGA_SEEDED_OMC=omc))
48 if gen.returncode:
49 print(f"FAIL mutant {name}: did not compile rc={gen.returncode} {gen.stdout[-200:]}"); return 1
50 unit_c = os.path.join(tmp, name + ".c")
51 open(unit_c, "w").write(gen.stdout)
52 if files is DEC:
53 test, extra = "tests/codegen_dec_diff.c", os.path.join(OUT, "codegen_dec_oracle.o")
54 else:
55 test, extra = "tests/gdn_admit_diff.c", os.path.join(OUT, "gdn_admit_oracle.o")
56 exe = os.path.join(tmp, name)
57 link = run([cc, *flags, "-o", exe, test, unit_c, extra, os.path.join(OUT, "libomega_gpu.a"), "-lpthread", "-lm"])
58 if link.returncode:
59 print(f"FAIL mutant {name}: link {link.stdout[-400:]}"); return 1
60 res = run([exe])
61 last = (res.stdout.strip().splitlines() or [""])[-1]
62 if res.returncode == 0:
63 print(f"FAIL mutant {name} survived: {last}"); return 1
64 killed += 1
65 print(f"killed {name} rc={res.returncode}: {last[:160]}")
66 dec = sum(1 for m in MUTANTS if m[1] is DEC)
67 print(f"PASS dec mutants killed={killed}/{len(MUTANTS)} (cg_dec {dec}, gdn_admit {len(MUTANTS) - dec})")
68 return 0
69
70if __name__ == "__main__":
71 sys.exit(main())