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 / tests / om_fixture_rest_test.py
| 1 | #!/usr/bin/env python3 |
| 2 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | """Host-only acceptance. Invoke inside the mandatory no-device bwrap wrapper.""" |
| 4 | import os |
| 5 | from pathlib import Path |
| 6 | import shutil |
| 7 | import subprocess |
| 8 | |
| 9 | root = Path(__file__).resolve().parent.parent |
| 10 | os.chdir(root) |
| 11 | out = root / "build/fixture-rest" |
| 12 | out.mkdir(parents=True, exist_ok=True) |
| 13 | cc = ["gcc", "-std=gnu11", "-O2", "-Wall", "-Wextra", "-Werror", "-ffp-contract=off", "-Isrc"] |
| 14 | unit = "src/cudapp_om_eng.c" |
| 15 | text = "src/cudapp_om_fixture_text.c" |
| 16 | test = "tests/om_fixture_rest_test.c" |
| 17 | |
| 18 | def run(args, name, expected=0): |
| 19 | p = subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
| 20 | (out / (name + ".log")).write_bytes(p.stdout) |
| 21 | print(f"{name}: rc={p.returncode}", flush=True) |
| 22 | if p.returncode != expected: |
| 23 | print(p.stdout.decode(errors="replace")) |
| 24 | raise SystemExit(1) |
| 25 | return p.stdout |
| 26 | |
| 27 | # Strong references: omission must fail to link, not substitute a C answer. |
| 28 | p = subprocess.run(cc + [test, "-o", str(out / "missing")], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
| 29 | (out / "missing.log").write_bytes(p.stdout) |
| 30 | assert p.returncode != 0 and b"undefined reference" in p.stdout |
| 31 | print("PASS link-failure negative", flush=True) |
| 32 | run(cc + [test, unit, text, "-o", str(out / "omega")], "build-omega") |
| 33 | run(cc + ["-DCUDAPP_MIGRATION_PENDING_C_ENGINE_FIXTURE_REST=1", "-DCUDAPP_MIGRATION_PENDING_C_CLOCK_SCALARS=1", test, "-o", str(out / "oracle")], "build-oracle") |
| 34 | expected = run([str(out / "oracle")], "oracle") |
| 35 | actual = run([str(out / "omega")], "omega") |
| 36 | assert actual == expected, "host differential mismatch" |
| 37 | print("PASS host differential: scalars, overflow edges, flush words, f64 scaling, bounded text", flush=True) |
| 38 | for flag in ["CUDAPP_MIGRATION_PENDING_C_ENGINE_FIXTURE_REST", "CUDAPP_MIGRATION_PENDING_C_CLOCK_SCALARS"]: |
| 39 | run(cc + ["-D"+flag+"=1", test, unit, text, "-o", str(out/flag)], "build-"+flag) |
| 40 | assert run([str(out/flag)], flag) == expected, flag+" independent oracle mismatch" |
| 41 | run(["gcc", "-std=gnu11", "-O0", "--coverage", "-Isrc", |
| 42 | "-DCUDAPP_MIGRATION_PENDING_C_ENGINE_FIXTURE_REST=1", |
| 43 | "-DCUDAPP_MIGRATION_PENDING_C_CLOCK_SCALARS=1", test, "-o", str(out/"coverage")], "build-coverage") |
| 44 | run([str(out/"coverage")], "coverage") |
| 45 | run(["gcov", "-b", "-c", "-o", str(out), str(out/"coverage-om_fixture_rest_test.gcno")], "gcov") |
| 46 | # gcov finds the sources from the checkout and writes its .gcov files there: keep their text in the build |
| 47 | # directory and the checkout clean (the pattern of tests/mathlibs_host_om.py) |
| 48 | for path in root.glob("*.gcov"): |
| 49 | shutil.move(str(path), out / path.name) |
| 50 | |
| 51 | # Fresh mutant copies only; never modify production source or generated artifacts. |
| 52 | source = (root / "om/engine/fixture_rest.om").read_text() |
| 53 | eng = (root / "om/engine/eng.om").read_text() |
| 54 | mutants = [ |
| 55 | ("ns_scale", "mul a 1000000000", "mul a 1000000001"), |
| 56 | ("ms_divisor", "div b 1000000", "div b 1000001"), |
| 57 | ("size_cycle", "ix = rem a 8", "ix = rem a 7"), |
| 58 | ("count_wrap", "ret and add mul b 2 3 4294967295", "ret add mul b 2 3"), |
| 59 | ("flush_offset", "ret and add va 16 4294967295", "ret and add va 17 4294967295"), |
| 60 | ("float_scale", "1073741824.0", "1073741825.0"), |
| 61 | ("text_equal", "if same", "if not same"), |
| 62 | ] |
| 63 | bridge = Path(os.environ.get("OMEGA_BRIDGE", str(Path.home()/"work/cudastack/omega-bridge"))) |
| 64 | env = dict(os.environ, OMEGA_SEEDED_OMC=os.environ.get("OMEGA_OMC", str(Path.home()/"work/cudastack/omega-mv/seed/out/omc"))) |
| 65 | for name, old, new in mutants: |
| 66 | assert source.count(old) == 1, (name, "site count") |
| 67 | changed = source.replace(old,new,1) |
| 68 | mdir = out/name |
| 69 | mdir.mkdir(exist_ok=True) |
| 70 | inputs = [("eng", changed+"\n"+eng), ("text", changed)] |
| 71 | cs = [] |
| 72 | for kind, body in inputs: |
| 73 | om = mdir/(kind+".om") |
| 74 | om.write_text(body) |
| 75 | p = subprocess.run(["sh", str(bridge/"tools/bridge-seeded"), "c", str(om)], env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 76 | (mdir/(kind+"-gen.log")).write_bytes(p.stderr) |
| 77 | assert p.returncode == 0, (name,p.stderr.decode()) |
| 78 | c = mdir/(kind+".c") |
| 79 | c.write_bytes(p.stdout) |
| 80 | cs.append(str(c)) |
| 81 | run(cc + [test] + cs + ["-o", str(mdir/"test")], name+"-build") |
| 82 | p = subprocess.run([str(mdir/"test")], stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 83 | (mdir/"actual.txt").write_bytes(p.stdout) |
| 84 | assert p.returncode != 0 or p.stdout != expected, name+" SURVIVED" |
| 85 | print("KILLED " + name, flush=True) |
| 86 | print("PASS red control: ns_scale changed a real unit answer", flush=True) |
| 87 | |
| 88 | # Hardware fixtures are linked only; never executed, even in the device-free namespace. |
| 89 | tp = "third_party/nvidia-open-580.173.02" |
| 90 | inc = ["-Invrm", "-Im16", "-I"+tp+"/src/common/sdk/nvidia/inc", "-I"+tp+"/kernel-open/common/inc", "-I"+tp+"/kernel-open/nvidia-uvm", "-I"+tp+"/src/nvidia/arch/nvalloc/unix/include"] |
| 91 | common = ["nvrm/nvrm.c", "m16/m16_native.c", "src/omega_ampere_qmd.c", "src/cudapp_om_amp_runtime.c", "src/cudapp_om_amp_qmd.c", unit, text] |
| 92 | # Match the integrated native NVRM link: serializers, transport and chip admission. |
| 93 | common += [str(p.relative_to(root)) for p in sorted((root / "src").glob("cudapp_om_nvrm_*.c"))] |
| 94 | common += ["src/omega_gpu_chip.c", "src/cudapp_om_chip_admit.c", "src/cudapp_om_chip_enum.c"] |
| 95 | for path in ["m16/m16_requalify.c", "m16/m16_concurrent.c", "nvrm/lifecycle_gates.c", "nvrm/submission_visibility_gates.c"]: |
| 96 | extra = ["m16/m16_gpu_wait.c"] if path.endswith("m16_concurrent.c") else [] |
| 97 | name = Path(path).stem |
| 98 | run(cc + inc + common + extra + [path,"-o",str(out/name)], "build-only-"+name) |
| 99 | print("PASS fixtures BUILD_ONLY; HW NOT_RUN; mutants 7/7 KILLED", flush=True) |