Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/CUDApp/blob/main/tests/codegen_tc_mutants.py # 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 Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `CUDApp / tests / codegen_tc_mutants.py` 70 lines · 3259 bytes Raw Blame History 1 #!/usr/bin/env python3 2 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 3 """Compile changed Omega, then require the C differential to reject each variant. 4 5 Compiler/converter failures are errors, never killed mutants. The real checked 6 portable artifact is linked normally for the unmodified negative control. 7 """ 8 import os 9 from pathlib import Path 10 import re 11 import subprocess 12 import tempfile 13 14 ROOT = Path(__file__).resolve().parents[1] 15 OUT = Path(os.environ.get("OUT_DIR", "build")) 16 OMC = os.environ["OMEGA_OMC"] 17 BRIDGE = Path(os.environ["OMEGA_BRIDGE"]) 18 ENV = dict(os.environ, OMEGA_SEEDED_OMC=OMC) 19 EMIT = (ROOT / "om/codegen/cg_tc_emit.om").read_text() 20 SOURCE = (ROOT / "om/codegen/cg_tc.om").read_text() 21 22 23 def run(args, **kw): 24 return subprocess.run(args, cwd=ROOT, env=ENV, text=True, **kw) 25 26 27 def replace_phase(source, kind, before, after): 28 # Match the owning builder's phase, not helper text in a different builder. 29 pattern = re.compile(r"fn tc_" + str(kind) + r"_part\d+ .*?\nend\n(?=fn|\n|$)", re.S) 30 for match in pattern.finditer(source): 31 text = match.group() 32 if before in text: 33 return source[:match.start()] + text.replace(before, after, 1) + source[match.end():] 34 raise RuntimeError(f"missing Omega mutation site: {kind}: {before}") 35 36 37 mutants = [ 38 ("probe-hmma-spacing", 0, 0, "put x 7 ulong 15", "put x 7 ulong 14"), 39 ("peak-hmma-spacing", 1, 1, "put x 7 get r 18", "put x 7 add get r 18 ulong 1"), 40 ("bandwidth-fold", 2, 2, "tc_i x ulong 29", "tc_i x ulong 18"), 41 ("tcgemm-fp8-decode", 3, 3, "put x 6 ulong `8323199`", "put x 6 ulong `8323198`"), 42 ("tc2-f32-rescale", 4, 4, "tc_i x 32", "tc_i x 30"), 43 ("tc2-swiglu-rescale", 5, 4, "tc_i x 32", "tc_i x 30"), 44 ] 45 46 with tempfile.TemporaryDirectory(prefix="codegen-tc-mutants-") as td: 47 tmp = Path(td) 48 for name, variant, kind, before, after in mutants: 49 control = run([str(OUT / "codegen_tc_diff"), "--variant", str(variant)]) 50 if control.returncode: 51 raise SystemExit(f"unmodified {name} differential failed") 52 om = tmp / (name + ".om") 53 c = tmp / (name + ".c") 54 exe = tmp / name 55 om.write_text(EMIT + "\n" + replace_phase(SOURCE, kind, before, after)) 56 with c.open("w") as f: 57 compiled = run(["sh", str(BRIDGE / "tools/bridge-seeded"), "c", str(om)], stdout=f) 58 if compiled.returncode: 59 raise SystemExit(f"{name}: converter failed (not a kill)") 60 linked = run([os.environ.get("CC", "cc"), "-std=gnu11", "-O2", "-Isrc", "-o", str(exe), 61 "tests/codegen_tc_diff.c", str(c), str(OUT / "codegen_tc_oracle.o"), 62 str(OUT / "codegen_tc2_oracle.o"), str(OUT / "libomega_gpu.a"), "-lpthread", "-lm"]) 63 if linked.returncode: 64 raise SystemExit(f"{name}: link failed (not a kill)") 65 result = run([str(exe), "--variant", str(variant)], capture_output=True) 66 print(result.stderr, end="") 67 if result.returncode != 1 or "IR differs" not in result.stderr: 68 raise SystemExit(f"{name}: differential did not kill emitted semantic mutant") 69 print(f"CODEGEN TC OMEGA MUTANT {name}: KILLED", flush=True) 70 print("CODEGEN TC OMEGA MUTANTS PASS (6 mutants)")