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/ampere/native_omega_x86.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 / ampere / native_omega_x86.py` 112 lines · 4284 bytes Raw Blame History 1 #!/usr/bin/env python3 2 """Explicit experimental #923 oracle. Host EMULATED only; never GPU evidence. 3 4 The large cubin private-ABI unit is compiled, not called: local Omega arrays 5 cannot supply its full 16 MiB/128 MiB view arguments. No signatures are shrunk. 6 """ 7 import argparse 8 import hashlib 9 from pathlib import Path 10 import subprocess 11 12 PIN = "`becf5c817bcb7e0846d12ebfc2be91042d8ad89a`" 13 COMPILER_SHA = "`5f0faab7cd4fc12158cf8e099418098d278df644efc10e4e7e2e5ca6141fca86`" 14 ROOT = Path(__file__).resolve().parents[2] 15 ENCODER_MAIN = """ 16 fn main to int 17 ins = new ulong 8192 0 18 phys = new ulong 288 0 19 code = new uchar 16384 0 20 n = ENTRY view ins view phys 1 0 edit code 21 if ne n 16 22 ret 1 23 end 24 w = write 1 code 0 n 25 if ne w 16 26 ret 2 27 end 28 ret 0 29 end 30 """ 31 RUNTIME_MAIN = """ 32 fn main to int 33 m = new ulong 16 0 34 q = new ulong 64 0 35 put m 0 2 36 put m 1 4096 37 put m 2 1 38 put m 3 4096 39 r = amp_runtime view m edit q 40 if ne r 0 41 ret 1 42 end 43 put m 3 0 44 r = amp_runtime view m edit q 45 if ne r 1 46 ret 2 47 end 48 ret 0 49 end 50 """ 51 52 53 def run(command, **kw): 54 return subprocess.run(command, capture_output=True, timeout=180, **kw) 55 56 57 def compile_program(compiler, source, path): 58 result = run([str(compiler)], input=source) 59 if result.returncode: 60 raise RuntimeError(f"compile refused {path.name}: {result.returncode}: {result.stderr!r}") 61 path.write_bytes(result.stdout) 62 path.chmod(0o755) 63 64 65 def main(): 66 parser = argparse.ArgumentParser(description=__doc__) 67 parser.add_argument("--compiler-tree", type=Path, required=True) 68 parser.add_argument("--output", type=Path, required=True) 69 args = parser.parse_args() 70 tree = args.compiler_tree.resolve() 71 observed = subprocess.check_output(["git", "-C", str(tree), "rev-parse", "HEAD"], text=True).strip() 72 compiler = tree / "seed/out/omc" 73 if observed != PIN or hashlib.sha256(compiler.read_bytes()).hexdigest() != COMPILER_SHA: 74 raise SystemExit("experimental compiler source/binary pin mismatch") 75 args.output.mkdir(parents=True, exist_ok=True) 76 units = (("om/encoder/bw_enc_sm121.om", "bw_enc_sm121"), 77 ("om/encoder/ampere_enc_sm86.om", "ampere_enc_sm86"), 78 ("om/encoder/amp_runtime.om", "amp_runtime"), 79 ("om/cubin/cubin_elf.om", "cubin_elf")) 80 for relative, entry in units: 81 source = (ROOT / relative).read_bytes() 82 bare = args.output / (entry + ".x86.unit") 83 compile_program(compiler, b"target x86linux\n" + source, bare) 84 print("EMULATED-ORACLE INPUT COMPILE", relative, hashlib.sha256(source).hexdigest(), 85 "x86-unit-sha256", hashlib.sha256(bare.read_bytes()).hexdigest()) 86 if entry == "cubin_elf": 87 print("NOT_RUN native-cubin private-ABI execution: full-size external buffer caller required") 88 continue 89 suffix = RUNTIME_MAIN if entry == "amp_runtime" else ENCODER_MAIN.replace("ENTRY", entry) 90 program = source + suffix.encode() 91 arm = args.output / (entry + ".arm") 92 x86 = args.output / (entry + ".x86") 93 compile_program(compiler, program, arm) 94 compile_program(compiler, b"target x86linux\n" + program, x86) 95 native = run([str(arm)]) 96 emulated = run(["qemu-x86_64", str(x86)]) 97 if native.returncode or emulated.returncode or native.stdout != emulated.stdout: 98 raise RuntimeError(f"{entry} runtime parity failed: native={native.returncode}, x86={emulated.returncode}") 99 mutant_suffix = suffix.replace("if ne r 1", "if ne r 0") if entry == "amp_runtime" else suffix.replace("view phys 1 0", "view phys 0 0") 100 mutant = args.output / (entry + ".mutant.x86") 101 compile_program(compiler, b"target x86linux\n" + source + mutant_suffix.encode(), mutant) 102 negative = run(["qemu-x86_64", str(mutant)]) 103 expected = 2 if entry == "amp_runtime" else 1 104 if negative.returncode != expected: 105 raise RuntimeError(f"{entry} negative control was not caught: {negative.returncode}") 106 print("EMULATED PASS", entry, "native-AArch64/x86-QEMU stdout-sha256", 107 hashlib.sha256(emulated.stdout).hexdigest(), "negative-exit", negative.returncode) 108 print("EXPERIMENTAL NATIVE X86 SMALL-UNIT PROBES PASS; native-cubin runtime NOT_RUN; device NOT_RUN") 109 110 111 if __name__ == "__main__": 112 main()