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/omega-mv/blob/main/tests/amd-kfd-launch/check.py # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / tests / amd-kfd-launch / check.py` 216 lines ยท 7429 bytes Raw Blame History 1 #!/usr/bin/env python3 2 """Level 2 driver for the UXL brief, on the omega-mv tree. 3 4 Rebuilds the direct-KFD launcher and the gfx942 kernels with seed/out/omc 5 and compares them to gpu/amd/card.tsv (the receipt hashes). launch-x86 and 6 vadd are the hashes printed in Zenodo 10.5281/zenodo.`24237047`. 7 8 Arm64-only instruments (tests/amd-kfd-launch/trace.c in the CUDApp layout, 9 and tests/kfd/trace.c here) are SKIPPED on any host that is not aarch64. 10 A skip is counted and is not a pass. A hash mismatch exits 1. If omc cannot 11 be executed, the rebuild is SKIPPED and the exit is 77. 12 """ 13 from __future__ import annotations 14 15 import hashlib 16 import platform 17 import subprocess 18 import sys 19 import tempfile 20 from pathlib import Path 21 22 BRIEF_LAUNCH = "`08a504911ec6e87a9746632a14d22245155597e3a8ed384c93c0e5260bb691e1`" 23 BRIEF_VADD = "`10eb12e019ff2117ddc0190650899d4254589375c62e5ebb970b1bbb7e67e55f`" 24 ROOT = Path(__file__).resolve().parents[2] 25 26 27 def sha256_file(path): 28 digest = hashlib.sha256() 29 with path.open("rb") as handle: 30 while True: 31 block = handle.read(1024 * 1024) 32 if not block: 33 break 34 digest.update(block) 35 return digest.hexdigest() 36 37 38 def card_rows(path): 39 rows = [] 40 for line in path.read_text(encoding="utf-8").splitlines(): 41 if not line or line.startswith("#"): 42 continue 43 kind, name, digest = line.split() 44 rows.append((kind, name, digest)) 45 return rows 46 47 48 def omc_runs(omc): 49 try: 50 proc = subprocess.run( 51 [str(omc)], 52 input=b"fn main to int\nret 7\nend\n", 53 stdout=subprocess.PIPE, 54 stderr=subprocess.PIPE, 55 timeout=90, 56 ) 57 except OSError as exc: 58 return False, "cannot execute seed/out/omc (%s)" % exc 59 except subprocess.TimeoutExpired: 60 return False, "seed/out/omc timed out" 61 err = proc.stderr.decode("utf-8", "replace").strip() 62 if proc.returncode != 0 or not proc.stdout.startswith(b"\x7fELF"): 63 return False, "seed/out/omc exit %s (%s)" % (proc.returncode, err or "no ELF output") 64 return True, "seed/out/omc executed (%d byte program)" % len(proc.stdout) 65 66 67 def enable_hint(system, arch): 68 return ( 69 "omc is an aarch64 Linux binary and cannot run on %s/%s. " 70 "On x86 Linux: sudo apt-get install qemu-user-static binfmt-support, " 71 "mount binfmt_misc, and register /usr/lib/binfmt.d/qemu-aarch64.conf " 72 "so the kernel runs qemu-aarch64. On Windows, use WSL with that binfmt setup." 73 % (system, arch) 74 ) 75 76 77 def stream(cmd, cwd): 78 proc = subprocess.Popen( 79 cmd, 80 cwd=str(cwd), 81 stdout=subprocess.PIPE, 82 stderr=subprocess.STDOUT, 83 ) 84 assert proc.stdout is not None 85 lines = [] 86 for raw in proc.stdout: 87 line = raw.decode("utf-8", "replace").rstrip("\n") 88 print(line, flush=True) 89 lines.append(line) 90 code = proc.wait() 91 return code, lines 92 93 94 def compare(kind, name, expected, artifact): 95 if artifact is None or not artifact.is_file(): 96 computed = "MISSING" 97 verdict = "MISMATCH" 98 else: 99 computed = sha256_file(artifact) 100 verdict = "MATCH" if computed == expected else "MISMATCH" 101 print( 102 "HASH %s %s expected %s computed %s %s" % (kind, name, expected, computed, verdict), 103 flush=True, 104 ) 105 return verdict == "MATCH" 106 107 108 def main(): 109 system = platform.system() 110 arch = platform.machine() 111 print("HOST os=%s arch=%s python=%s" % (system, arch, platform.python_version()), flush=True) 112 scan = subprocess.run([sys.executable, str(ROOT / "tools/uxl/windows_paths.py")]) 113 if scan.returncode: 114 print("LEVEL2_COUNTS pass=0 fail=1 skip=0", flush=True) 115 return 1 116 117 arm = arch in ("aarch64", "arm64") 118 skipped = 0 119 if arm: 120 trace = ROOT / "tests/amd-kfd-launch/trace.c" 121 if not trace.is_file(): 122 print( 123 "SKIP tests/amd-kfd-launch/trace.c: arm64-only instrument is not in this tree " 124 "(it stays in CUDApp); host is %s/%s" % (system, arch), 125 flush=True, 126 ) 127 skipped += 1 128 else: 129 print( 130 "SKIP tests/amd-kfd-launch/trace.c: arm64-only (AArch64 ptrace); " 131 "detected host %s/%s; not compiled, not passed" % (system, arch), 132 flush=True, 133 ) 134 print( 135 "SKIP tests/kfd/trace.c: arm64-only (AArch64 ptrace); " 136 "detected host %s/%s; not compiled, not passed" % (system, arch), 137 flush=True, 138 ) 139 skipped += 2 140 141 omc = ROOT / "seed/out/omc" 142 ok, detail = omc_runs(omc) 143 print("OMC %s sha256=%s" % (detail, sha256_file(omc) if omc.is_file() else "MISSING"), flush=True) 144 if not ok: 145 print("SKIP Level 2 rebuild: %s" % enable_hint(system, arch), flush=True) 146 print("LEVEL2_COUNTS pass=0 fail=0 skip=%d" % (skipped + 1), flush=True) 147 return 77 148 149 pinned = card_rows(ROOT / "gpu/amd/card.tsv") 150 by_name = {(kind, name): digest for kind, name, digest in pinned} 151 if by_name.get(("bin", "launch-x86")) != BRIEF_LAUNCH or by_name.get(("obj", "vadd")) != BRIEF_VADD: 152 print( 153 "FAIL card.tsv launch-x86 or vadd does not match the hash printed in " 154 "Zenodo 10.5281/zenodo.`24237047`", 155 flush=True, 156 ) 157 print("LEVEL2_COUNTS pass=0 fail=1 skip=%d" % skipped, flush=True) 158 return 1 159 print( 160 "PINNED gpu/amd/card.tsv (MI300X receipt). launch-x86 and vadd match " 161 "Zenodo 10.5281/zenodo.`24237047`.", 162 flush=True, 163 ) 164 165 parent = Path(tempfile.mkdtemp(prefix="uxl-level2-")) 166 gate = parent / "gate" 167 blob = b"om2\n" + (ROOT / "seed/ng/sha256.om").read_bytes() + (ROOT / "gpu/amd/gate.om").read_bytes() 168 proc = subprocess.run( 169 [str(omc)], 170 input=blob, 171 stdout=subprocess.PIPE, 172 stderr=subprocess.PIPE, 173 timeout=180, 174 ) 175 if proc.returncode != 0 or not proc.stdout: 176 sys.stderr.write(proc.stderr.decode("utf-8", "replace")) 177 print("FAIL building gpu/amd/gate.om exit %s" % proc.returncode, flush=True) 178 print("LEVEL2_COUNTS pass=0 fail=1 skip=%d" % skipped, flush=True) 179 return 1 180 gate.write_bytes(proc.stdout) 181 gate.chmod(0o700) 182 scratch = parent / "work" 183 print("LEVEL2 rebuild start", flush=True) 184 code, _lines = stream([str(gate), str(omc), str(scratch)], ROOT) 185 if code != 0: 186 print("FAIL gpu/amd gate exit %s" % code, flush=True) 187 print("LEVEL2_COUNTS pass=0 fail=1 skip=%d" % skipped, flush=True) 188 return 1 189 190 passed = 0 191 failed = 0 192 launch = scratch / "launch-x86.1" 193 if compare("launcher", "launch-x86", BRIEF_LAUNCH, launch): 194 passed += 1 195 else: 196 failed += 1 197 kernels = [name for kind, name, _digest in pinned if kind == "obj" and name != "vadd"] 198 for name in kernels: 199 if compare("kernel", name, by_name[("obj", name)], scratch / (name + ".hsaco")): 200 passed += 1 201 else: 202 failed += 1 203 if compare("object", "vadd", BRIEF_VADD, scratch / "vadd.hsaco"): 204 passed += 1 205 else: 206 failed += 1 207 print( 208 "LEVEL2_COUNTS pass=%d fail=%d skip=%d kernels=%d" 209 % (passed, failed, skipped, len(kernels)), 210 flush=True, 211 ) 212 return 1 if failed else 0 213 214 215 if __name__ == "__main__": 216 sys.exit(main())