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/moe/wide_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 / moe / wide_mutants.py` 101 lines · 5199 bytes Raw Blame History 1 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 2 """Host verification oracle: one-line mutants of the seeded _wide .om sources, never generated C. 3 4 Each mutant must still generate and compile, then fail a specific assertion of 5 tests/moe/run_wide.sh: a caller_wide.c CHECK (FAIL line N) or a nonzero admit-caller-wide.om code. 6 """ 7 import os 8 from pathlib import Path 9 import shutil 10 import subprocess 11 import tempfile 12 13 ROOT = Path(__file__).resolve().parents[2] 14 WIDE = ("moe_plan_wide.om", "moe_group_wide.om", "moe_ids32_wide.om", "moe_maps32_wide.om", 15 "moe_segs32_wide.om", "moe_windows_wide.om", "moe_admit_wide.om") 16 VERIFY = "moe_verify_wide.om" 17 MUTANTS = ( 18 ("plan-map-y-base", "moe_plan_wide.om", 19 "put mp add 1416 p get w add mul p 9 7", "put mp add 1415 p get w add mul p 9 7"), 20 ("plan-slots-cap-9", "moe_plan_wide.om", "gt get c 2 10", "gt get c 2 9"), 21 ("plan-experts-cap-511", "moe_plan_wide.om", "gt get c 3 512", "gt get c 3 511"), 22 ("plan-work-cap-1407", "moe_plan_wide.om", "gt get c 5 1408", "gt get c 5 1407"), 23 ("plan-shared-flag", "moe_plan_wide.om", "put sg add b 3 1", "put sg add b 3 0"), 24 ("plan-meta-version", "moe_plan_wide.om", "put m 4 2", "put m 4 1"), 25 ("plan-destination-stride", "moe_plan_wide.om", 26 "add mul t add get a 1539 1 s", "add mul t get a 1539 s"), 27 ("ids32-cap-1279", "moe_ids32_wide.om", "if gt n 1280", "if gt n 1279"), 28 ("maps32-y-base", "moe_maps32_wide.om", "p = add mul z 1416 i", "p = add mul z 1415 i"), 29 ("segs32-expert-511", "moe_segs32_wide.om", "if gt e 512", "if gt e 511"), 30 ("group-profile-511", "moe_group_wide.om", "if eq get r 15 512", "if eq get r 15 511"), 31 ("group-min-stride-legacy", "moe_group_wide.om", 32 "if lt get r 7 mul get r 11 16", "if lt get r 7 144"), 33 ("group-ids-extent-legacy", "moe_group_wide.om", "width = mul sub k 1 4", "width = ulong 32"), 34 ("windows-take-legacy", "moe_windows_wide.om", 35 "take = div ulong 128 get c 4", "take = ulong 14"), 36 ("windows-rows-legacy", "moe_windows_wide.om", 37 "put m 2 mul get c 1 get c 4", "put m 2 mul get c 1 9"), 38 ("windows-hidden-2561", "moe_windows_wide.om", "if eq get c 2 2560", "if eq get c 2 2561"), 39 ("admit-group-code-offset", "moe_admit_wide.om", "ret long add rc 80", "ret long add rc 79"), 40 ("verifier-map-y-base", VERIFY, 41 "if ne get mp add 1416 p get w add b 7", "if ne get mp add 1415 p get w add b 7"), 42 ) 43 GENERATED = "wrote checked portable Omega units" 44 CALLER_PASS = "MOE-WIDE HOST PASS" 45 ADMIT_PASS = "MOE-WIDE-ADMIT HOST PASS" 46 47 48 def tree(tmp): 49 om = tmp / "om" 50 om.mkdir() 51 for name in WIDE: 52 shutil.copyfile(ROOT / "om/moe" / name, om / name) 53 shutil.copyfile(ROOT / "tests/moe" / VERIFY, tmp / VERIFY) 54 return om, tmp / VERIFY 55 56 57 def run(om, verify): 58 env = dict(os.environ, MOE_WIDE_OM=str(om), MOE_WIDE_VERIFY=str(verify)) 59 return subprocess.run(["sh", str(ROOT / "tests/moe/run_wide.sh")], cwd=ROOT, env=env, 60 text=True, capture_output=True) 61 62 63 def main(): 64 caller = (ROOT / "tests/moe/caller_wide.c").read_text().splitlines() 65 with tempfile.TemporaryDirectory(prefix="omega-moe-wide-base-") as directory: 66 om, verify = tree(Path(directory)) 67 result = run(om, verify) 68 out = result.stdout + result.stderr 69 if result.returncode or CALLER_PASS not in out or ADMIT_PASS not in out: 70 raise RuntimeError(f"baseline: rc={result.returncode}\n{out}") 71 print("BASELINE PASS unmutated copies", flush=True) 72 killed = 0 73 for name, part, before, after in MUTANTS: 74 with tempfile.TemporaryDirectory(prefix="omega-moe-wide-mutant-") as directory: 75 om, verify = tree(Path(directory)) 76 path = verify if part == VERIFY else om / part 77 source = path.read_text() 78 if source.count(before) != 1: 79 raise RuntimeError(f"{name}: mutation site is not unique in {part}") 80 path.write_text(source.replace(before, after)) 81 result = run(om, verify) 82 out = result.stdout + result.stderr 83 if GENERATED not in out or "omc: line" in out or " error: " in out: 84 raise RuntimeError(f"{name}: mutant must generate and compile: rc={result.returncode}\n{out}") 85 if result.returncode == 0: 86 raise RuntimeError(f"{name}: mutant survived\n{out}") 87 fails = [line for line in out.splitlines() if line.startswith("FAIL line ")] 88 if fails: 89 number = int(fails[0].split()[2].rstrip(":")) 90 where = f"caller_wide.c:{number}: {caller[number - 1].strip()}" 91 elif CALLER_PASS in out and ADMIT_PASS not in out: 92 where = f"admit-caller-wide.om exit {result.returncode}" 93 else: 94 raise RuntimeError(f"{name}: mutant failed without a specific assertion: rc={result.returncode}\n{out}") 95 print(f"KILLED Omega {name} ({part}: '{before}' -> '{after}') by {where}", flush=True) 96 killed += 1 97 print(f"MOE-WIDE OMEGA MUTANTS PASS ({killed} of {len(MUTANTS)} source mutants killed by a specific assertion)") 98 99 100 if __name__ == "__main__": 101 main()