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-exec / fp8block_fast_notebook / build.py

68 lines · 3783 bytes Raw Blame History
1#!/usr/bin/env python3
2# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3"""Outside notebook packaging instrument; no kernel production dependency."""
4import base64
5import hashlib
6import json
7from pathlib import Path
8import zlib
9
10HERE=Path(__file__).resolve().parent
11
12def sha(data): return hashlib.sha256(data).hexdigest()
13def encoded(data): return base64.b85encode(zlib.compress(data,9)).decode()
14
15def main():
16 manifest=json.loads((HERE/'list.json').read_text())
17 report=json.loads((HERE/'report.json').read_text())
18 objects={}
19 for kernel in manifest['kernels']:
20 for item in kernel['objects']:
21 raw=(HERE/item['file']).read_bytes()
22 assert sha(raw)==item['sha256']
23 name=Path(item['file']).stem
24 assert name not in objects
25 objects[name]=dict(sha256=item['sha256'],base64=base64.b64encode(raw).decode(),entry=item['entry'])
26 timed_kernels=[kernel['name'] for kernel in manifest['kernels']]
27 shapes=[[c['M'],c['K']] for c in report['cases'] if c.get('checkpoint')]
28 assert len(shapes)==len({tuple(s) for s in shapes})
29 controls=[c['mutant'] for c in report['controls'] if 'mutant' in c]
30 groups=[dict(id='ctl-'+c,kind='control') for c in controls]
31 groups += [dict(id='correct-%dx%d'%tuple(s),kind='correctness',shape=s) for s in shapes]
32 groups += [dict(id='tails',kind='tails')]
33 groups += [dict(id='time-'+name+'-%dx%d'%tuple(s),kind='timing',shape=s,kernel=name)
34 for s in shapes for name in timed_kernels]
35 groups += [dict(id='ref-%dx%d'%tuple(s),kind='reference',shape=s) for s in shapes]
36 data=dict(source_head=manifest['source_head'],baseline_source_head=manifest['baseline_source_head'],
37 timed_kernels=timed_kernels,groups=groups,objects=objects,
38 tails=[[c['M'],c['K']] for c in report['cases'] if c['case'].startswith('tail-')])
39 template=(HERE/'driver.template.py').read_text()
40 assert template.count('@DATA@')==1
41 driver=template.replace('@DATA@',encoded(json.dumps(data,separators=(',',':')).encode()))
42 compile(driver,'driver-v13.py','exec')
43 digest=sha(driver.encode())
44 cell=("# Paste the complete cell into the MI300X notebook. No model weights or downloads needed.\n"
45 "import base64, hashlib, pathlib, subprocess, sys, zlib\n"
46 "try:\n"
47 " _raw=zlib.decompress(base64.b85decode(%r))\n" % encoded(driver.encode())+
48 " assert hashlib.sha256(_raw).hexdigest()==%r, 'driver digest mismatch'\n" % digest+
49 " _driver=pathlib.Path('driver-v13.py'); _driver.write_bytes(_raw)\n"
50 " _run=subprocess.run([sys.executable,str(_driver.resolve())])\n"
51 " if _run.returncode: raise RuntimeError('probe parent exit='+str(_run.returncode))\n"
52 "except BaseException:\n"
53 " print('CONTROLS ESCAPED or NOT_RUN; cell wrapper failed',flush=True)\n"
54 " print('RESULT overall FAIL_OR_INCOMPLETE; cell wrapper failed',flush=True)\n"
55 " raise\n")
56 compile(cell,'cell-v13.py','exec')
57 size=len(cell.encode())
58 assert size<60000,('notebook cell size alarm',size)
59 (HERE/'driver-v13.py').write_text(driver)
60 (HERE/'cell-v13.py').write_text(cell)
61 result=dict(file='cell-v13.py',bytes=size,sha256=sha(cell.encode()),driver_sha256=digest,
62 source_head=manifest['source_head'],template_sha256=sha(template.encode()),
63 source_manifest_sha256=sha((HERE/'list.json').read_bytes()),groups=groups,
64 hardware='NOT_RUN',performance='NOT_RUN')
65 (HERE/'build.json').write_text(json.dumps(result,indent=2)+'\n')
66 print('CELL cell-v13.py bytes=%d sha256=%s groups=%d' % (size,result['sha256'],len(groups)))
67
68if __name__=='__main__': main()