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/amd-exec/token_bundle.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 / amd-exec / token_bundle.py` 82 lines · 6024 bytes Raw Blame History 1 #!/usr/bin/env python3 2 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 3 """Package the completed CPU acceptance evidence for the notebook relay. 4 This is an outside verification/transport instrument, not a model runtime. 5 """ 6 import hashlib 7 import json 8 import pathlib 9 import re 10 import shutil 11 import subprocess 12 import sys 13 from decimal import Decimal 14 15 def sha(path): return hashlib.sha256(path.read_bytes()).hexdigest() 16 def bundle(evidence,dest): 17 root=pathlib.Path(__file__).resolve().parents[2]; src=root/'backend/amd/gfx942'; out=evidence/'exec' 18 host=(evidence/'host.log').read_text(); log=(evidence/'exec.log').read_text(); torch=(evidence/'torch.log').read_text() 19 assert 'AMD-GFX942-HOST PASS' in host and 'AMD-GFX942-EXEC PASS' in log 20 assert 'PASS torch-recurrent-rounding-boundaries kind=dense' in torch 21 access=json.loads((out/'token-access.json').read_text()) 22 head=subprocess.check_output(['git','rev-parse','HEAD'],cwd=root,text=True).strip() 23 assert not dest.exists(),'refusing to overwrite an evidence bundle' 24 dest.mkdir(parents=True) 25 manifest=dict(source_head=head,hardware='NOT_RUN',performance='NOT_RUN',compiler_sha256=re.search(r'PIN omc=([0-9a-f]{64})',log)[1], 26 evidence={n:dict(path=str(evidence/n),sha256=sha(evidence/n)) for n in ('host.log','exec.log','torch.log')}, 27 access_evidence=dict(path=str(out/'token-access.json'),sha256=sha(out/'token-access.json')),kernels=[]) 28 lines=['# Token decode notebook objects','',f'Source head: `{head}`','', 29 'Host/functional executor only. MI300X execution, timing, and full-model serving are NOT_RUN.', 30 'Grid entries are workgroups; block is (64,1,1). All pointers are device uint64 addresses.', 31 'FP32-word BF16 boundaries, state layout, row selection, and operation ordering are defined in PROVENANCE.md sections 21–22.', 32 'The attention-prep concrete fixture has position=1 and capacity=4; cache lengths are capacity*4*256*2 bytes.', 33 'Maximum offsets below are measured by the per-buffer-checking executor for the full fixture, including safe overdispatch.', 34 'The reported numerical error is distance to the midpoint of the independently derived ISA interval, not hardware error.', 35 'Sections use the existing v8 run_section(ctx) interface and generate their fixtures/oracles in-cell.', 36 'Load a section in a fresh namespace, then supply its matching objects plus the established allocation/launch/copy context.', 37 '', '| Object | SHA256 | Kernarg bytes | Grid |', '|---|---|---:|---|'] 38 for report in access: 39 name=report['kernel']; table=(src/(name+'.isa')).read_text(); args=[]; i=0; payload=None 40 for line in table.splitlines(): 41 fields=line.split() 42 if fields and fields[0]=='A': 43 _,label,offset,size,kind=fields 44 a=dict(name=label,offset=int(offset),bytes=int(size),kind='pointer' if kind=='0' else 'u32') 45 if kind=='0': 46 b=report['buffers'][i]; measured=report['objects'][0]['access'][i+1] 47 a.update(buffer_bytes=b['bytes'],max_read_byte=measured['max_read_byte'],max_write_byte=measured['max_write_byte']); i+=1 48 else: 49 if payload is None: payload=json.loads((out/(name+'-intervals.json')).read_text()) 50 a['fixture_value']=payload['cases'][-1]['args'][len(args)][1] 51 args.append(a) 52 assert i==len(report['buffers']) 53 matches=re.findall(r'^PASS '+name+r' (.+) interval_escapes=0 worst_midpoint_error=([^ ]+).*$',log,re.M) 54 assert matches,name 55 worst=max((error for label,error in matches),key=Decimal) 56 controls=[o['object'] for o in report['objects'][1:]] 57 for control in controls: assert 'CONTROL '+control+' CAUGHT' in log,control 58 assert 'CONTROL ACCESS '+name+' short-input CAUGHT exit=68' in log 59 objects=[] 60 for obj in report['objects']: 61 variant=obj['object']; origin=out/(variant+('.1.hsaco' if variant==name else '.hsaco')) 62 filename=variant+'.hsaco'; shutil.copyfile(origin,dest/filename) 63 item=dict(file=filename,sha256=sha(origin),entry=name,bytes=origin.stat().st_size,access=obj['access']) 64 objects.append(item) 65 lines.append(f'| {filename} | `{item["sha256"]}` | {report["kernarg_bytes"]} | {report["grid"]} |') 66 section=out/(name+'.py'); shutil.copyfile(section,dest/section.name) 67 manifest['kernels'].append(dict(kernel=name,table_sha256=sha(src/(name+'.isa')),section=dict(file=section.name,sha256=sha(section)), 68 kernarg_bytes=report['kernarg_bytes'],args=args,grid=report['grid']+[1],block=report['block'],case=report['case'], 69 interval_escapes=0,worst_midpoint_error=worst,cases=[dict(label=l,worst_midpoint_error=e) for l,e in matches],controls_caught=controls, 70 access_control='short-input: exit 68',objects=objects)) 71 lines+=['','## Kernarg layouts and measured byte bounds',''] 72 for k in manifest['kernels']: 73 lines+=['### '+k['kernel'],f'Worst interval-midpoint error: {k["worst_midpoint_error"]}; interval escapes: 0.', 74 '| Arg | Offset | Kind | Buffer bytes | Max read byte | Max write byte |','|---|---:|---|---:|---:|---:|'] 75 for a in k['args']: 76 lines.append('| '+ ' | '.join(str(a.get(key,'—')) for key in ('name','offset','kind','buffer_bytes','max_read_byte','max_write_byte'))+' |') 77 lines.append('') 78 (dest/'list.json').write_text(json.dumps(manifest,indent=2)+'\n') 79 (dest/'list.md').write_text('\n'.join(lines)+'\n') 80 (dest/'SHA256SUMS').write_text(''.join(sha(p)+' '+p.name+'\n' for p in sorted(dest.iterdir()) if p.is_file())) 81 print('BUNDLE',dest,'source_head='+head,'kernels='+str(len(access))) 82 if __name__=='__main__': bundle(pathlib.Path(sys.argv[1]).resolve(),pathlib.Path(sys.argv[2]).resolve())