interplane.Get Omega
Read in your language

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

branch main Branches Tags History

CUDApp / tests / amd-kfd-launch / bundle.py

86 lines · 5420 bytes Raw Blame History
1#!/usr/bin/env python3
2# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3# External notebook-test artifact packaging; not a production dependency.
4import argparse,base64,hashlib,json,lzma,subprocess
5from pathlib import Path
6p=argparse.ArgumentParser()
7p.add_argument('--gate',type=Path,required=True)
8p.add_argument('--out',type=Path,required=True)
9a=p.parse_args()
10root=Path(__file__).resolve().parents[2]
11def sha(b): return hashlib.sha256(b).hexdigest()
12def git(tree,*args): return subprocess.check_output(['git','-C',str(tree),*args])
13summary=json.loads((a.gate/'summary.json').read_text())
14assert summary['failures']==0
15compiler=(root/'backend/amd/kfd/launch/COMPILER').read_text().splitlines()
16assert compiler[1].split()[0]==summary['compiler']
17bundle={'sources':{'launcher_head':git(root,'rev-parse','HEAD').decode().strip(),'compiler_head':compiler[0].split()[0],'compiler_sha256':summary['compiler'],'launcher_source_sha256':{str(f.relative_to(root)):sha(f.read_bytes()) for f in sorted((root/'backend/amd/kfd/launch').glob('*.om'))}},'assets':{}}
18bundle['sources']['notebook_template_sha256']=sha((root/'tests/amd-kfd-launch/notebook.py.in').read_bytes())
19REFERENCE_LABEL='REFERENCE (AMD runtime loading our object, not the Omega launcher)'
20def add(name,data,source):
21 bundle['assets'][name]={'sha256':sha(data),'xz_base85':base64.b85encode(lzma.compress(data,preset=9|lzma.PRESET_EXTREME)).decode(),'source':source}
22binary=(a.gate/'launch-x86').read_bytes()
23assert sha(binary)==summary['binaries']['x86']
24add('omega-launch',binary,{'gate':'tests/amd-kfd-launch/check.py'})
25vadd=(a.gate/'vadd.hsaco').read_bytes()
26assert sha(vadd)==summary['objects']['vadd']
27add('vadd.hsaco',vadd,{'repository_head':bundle['sources']['launcher_head'],'producer':'backend/amd/gfx942/hsaco.om'})
28a.out.mkdir(parents=True,exist_ok=False)
29for name,record in bundle['assets'].items():
30 path=a.out/name; path.write_bytes(lzma.decompress(base64.b85decode(record['xz_base85'])))
31 if name=='omega-launch': path.chmod(0o700)
32text=(root/'tests/amd-kfd-launch/notebook.py.in').read_text()
33assert text.count('@BUNDLE@')==1
34cell=text.replace('@BUNDLE@',json.dumps(bundle,separators=(',',':')))
35(a.out/'cell.py').write_text(cell)
36(a.out/'bundle.json').write_text(json.dumps(bundle,indent=2)+'\n')
37readme=f"""# launch4 notebook probe
38
39READY for the authorized MI300X notebook queue-pointer fix run. CPU launcher gates passed;
40actual KFD/GPU execution and the HIP comparison remain NOT_RUN.
41
42Paste all of `cell.py` into one notebook cell. It needs x86-64 Linux, Python 3
43standard library, executable temporary storage, permission to open `/dev/kfd`,
44the readable gfx942 topology node and its exact DRM render device. The comparison
45needs the installed ROCm torch package and the libamdhip64 that it loads; no torch
46kernels are run. No package/model downloads, credentials, strace or dmesg are needed.
47
48Download `amdserve-launch4.txt`, including on failure. CONTROLS is first, every
49launcher stdout line is saved as it arrives, and RESULT is last. The direct vadd
50uses its existing timeout, printed as `OMEGA diag wait_timeout_ns`, and existing
51packet bytes. The read-pointer page now initializes the AMD CP queue tail with
5264-bit pointer mode. The only device experiment is this corrected direct launch,
53compared with the separately retained launch3 baseline. It reads queue properties,
54queue pointers, signal, packet header/addresses, loaded
55descriptor fields and first eight output words on success or timeout. Values
56are decimal; create_queue_input_qword_N is the little-endian u64 at byte offset
578*N in the 88-byte ioctl input, including compiler-bound mapping addresses.
58Returned queue ID and full doorbell offset are separate rows.
59
60The notebook reads the child's KFD proc directory and queue/occupancy/VRAM files
61while signal_wait runs. Missing/inaccessible files are reported, not inferred.
62It then runs the identical vadd object and inputs once through HIP, even if Omega
63timed out. These rows are labelled `{REFERENCE_LABEL}`. No new doorbell value,
64extra Omega packet, alternative dispatch, other kernel, or Spark test is attempted.
65
66Interpret observations together, not as a diagnosis: unchanged read pointer
67with advanced write pointer may indicate CP did not consume the packet; expected
68output with a nonzero signal may indicate execution without signal completion;
69NaN fill means those output words were not observed written. Asynchronous reads
70are not a coherent device-wide snapshot. HIP success alone does not establish
71why direct dispatch failed. Host dispatch timing is not GPU event timing.
72
73Cell bytes: {len(cell.encode())}
74Cell sha256: {sha(cell.encode())}
75Binary sha256: {sha(binary)}
76Launcher source commit: {bundle['sources']['launcher_head']}
77Compiler source commit: {bundle['sources']['compiler_head']}
78Compiler sha256: {summary['compiler']}
79
80`bundle.json` records every object source commit and digest. `SHA256SUMS` covers
81every delivered file, including this README and cell.py, except itself.
82"""
83(a.out/'README.md').write_text(readme)
84files=sorted(f for f in a.out.iterdir() if f.is_file())
85(a.out/'SHA256SUMS').write_text(''.join(sha(f.read_bytes())+' '+f.name+'\n' for f in files))
86print(json.dumps({'cell_bytes':len(cell.encode()),'cell_sha256':sha(cell.encode()),'binary_sha256':sha(binary),'assets':{k:v['sha256'] for k,v in bundle['assets'].items()},'device':'NOT_RUN'},sort_keys=True))