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 / gemm_selectors.py
| 1 | #!/usr/bin/env python3 |
| 2 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | """Host-only CLI refusal tests. Invalid selectors must never reach device work.""" |
| 4 | import pathlib |
| 5 | import subprocess |
| 6 | import sys |
| 7 | import tempfile |
| 8 | |
| 9 | |
| 10 | def refused(run, receipt): |
| 11 | text = run.stdout + run.stderr |
| 12 | return (run.returncode == 2 and "INVALID" in text |
| 13 | and "PASS" not in text and receipt == "unchanged\n") |
| 14 | |
| 15 | |
| 16 | def main(): |
| 17 | build = pathlib.Path(sys.argv[1] if len(sys.argv) > 1 else "build").resolve() |
| 18 | failures = 0 |
| 19 | # Negative control: a zero-case PASS and a refusal that overwrites a |
| 20 | # receipt must both be rejected by the same check used below. |
| 21 | fake_pass = subprocess.CompletedProcess([], 0, "GPU_GEMM: PASS\n", "") |
| 22 | fake_refusal = subprocess.CompletedProcess([], 2, "", "INVALID shape\n") |
| 23 | if refused(fake_pass, "unchanged\n") or refused(fake_refusal, "overwritten\n"): |
| 24 | print("FAIL selector checker negative control") |
| 25 | return 1 |
| 26 | print("PASS selector checker rejects zero-case PASS and overwritten receipt") |
| 27 | with tempfile.TemporaryDirectory(prefix="gemm-selectors-") as tmp: |
| 28 | for name in ("pfgemm", "qgemm", "fp8gemm"): |
| 29 | binary = build / ("gpu_" + name + "_test") |
| 30 | modes = [[], ["--host-only"], ["--sim"]] |
| 31 | if name != "fp8gemm": |
| 32 | modes[0] = ["--chip"] |
| 33 | for mode in modes: |
| 34 | for selector in ("typo", "", "GATEUP"): |
| 35 | out = pathlib.Path(tmp) / "receipt.json" |
| 36 | out.write_text("unchanged\n") |
| 37 | args = [str(binary), *mode, "--shape", selector] |
| 38 | if name == "fp8gemm": |
| 39 | args += ["--out", str(out)] |
| 40 | run = subprocess.run(args, capture_output=True, text=True) |
| 41 | text = run.stdout + run.stderr |
| 42 | ok = refused(run, out.read_text()) |
| 43 | if not ok: |
| 44 | failures += 1 |
| 45 | print(f"FAIL {name} {mode} shape={selector!r}: rc={run.returncode} {text.strip()}") |
| 46 | # A known selector must remain accepted by the real host path, not |
| 47 | # by a new validation-only surrogate or any GPU-capable mode. |
| 48 | selectors = ["gateup", "down", "qkv", "o"] |
| 49 | if name == "fp8gemm": |
| 50 | selectors += ["all", "d768"] |
| 51 | for selector in selectors: |
| 52 | run = subprocess.run([str(binary), "--host-only", "--shape", selector], |
| 53 | capture_output=True, text=True) |
| 54 | if run.returncode or "PASS" not in run.stdout: |
| 55 | failures += 1 |
| 56 | print(f"FAIL {name} valid host control {selector}: rc={run.returncode}\n{run.stdout}{run.stderr}") |
| 57 | if name != "fp8gemm": |
| 58 | run = subprocess.run([str(binary), "--host-only", "--sim"], |
| 59 | capture_output=True, text=True) |
| 60 | if run.returncode != 2 or "NOT_RUN" not in run.stderr or "PASS" in run.stdout: |
| 61 | failures += 1 |
| 62 | print(f"FAIL {name} empty mode selection: rc={run.returncode}") |
| 63 | print(f"GEMM_SELECTOR_TEST: {'FAIL' if failures else 'PASS'} ({failures} failures; host only)") |
| 64 | return bool(failures) |
| 65 | |
| 66 | |
| 67 | if __name__ == "__main__": |
| 68 | sys.exit(main()) |