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
CUDApp / evidence / amd-speed-20261114 / raw / amd-launch-gap / card / run3 / final / logs / gap-microplan.py
| 1 | # Instrument (not Omega): OMPLAN01 launch micro-benchmark. Every step is N dispatches of the model's |
| 2 | # step_advance kernel (the same object real2 uses: driver-real2.py OBJ, sha256-checked), with |
| 3 | # kernargs (position pointer, u32 cap) exactly as real2 passes them; the pointer is relocated to a |
| 4 | # private VRAM buffer. No weights are read. |
| 5 | # Usage: gap-microplan.py DRIVER N N_GEN OUT.plan OUT_DIR (writes OUT_DIR/step_advance.hsaco) |
| 6 | import base64,hashlib,lzma,re,struct,sys |
| 7 | from pathlib import Path |
| 8 | drv,N,G,out,od=Path(sys.argv[1]),int(sys.argv[2]),int(sys.argv[3]),Path(sys.argv[4]),Path(sys.argv[5]) |
| 9 | m=re.search(r"'step_advance': \['([0-9a-f]{64})', '([^']+)'",drv.read_text()) |
| 10 | want,data=m.group(1),m.group(2) |
| 11 | obj=lzma.decompress(base64.b85decode(data));assert hashlib.sha256(obj).hexdigest()==want |
| 12 | od.mkdir(parents=True,exist_ok=True);(od/'step_advance.hsaco').write_bytes(obj) |
| 13 | # kernarg size from the kernel descriptor step_advance.kd (ELF64 symtab lookup; descriptor offset 8, u32) |
| 14 | shoff=struct.unpack_from('<Q',obj,40)[0];shnum,shstr=struct.unpack_from('<HH',obj,60) |
| 15 | sec=[struct.unpack_from('<IIQQQQIIQQ',obj,shoff+64*i) for i in range(shnum)] |
| 16 | def sect(i):return sec[i][4],sec[i][5] |
| 17 | kd=None |
| 18 | for s in sec: |
| 19 | if s[1]==2: # SHT_SYMTAB |
| 20 | stroff,_=sect(s[6]) |
| 21 | for k in range(s[5]//24): |
| 22 | nm,info,oth,shn,val,size=struct.unpack_from('<IBBHQQ',obj,s[4]+24*k) |
| 23 | name=obj[stroff+nm:obj.index(b'\0',stroff+nm)] |
| 24 | if name==b'step_advance.kd': |
| 25 | vaddr,off=None,None |
| 26 | for t in sec: |
| 27 | if t[3]<=val<t[3]+t[5] and t[1]!=8:off=t[4]+val-t[3] |
| 28 | kd=off |
| 29 | assert kd is not None |
| 30 | K=struct.unpack_from('<I',obj,kd+8)[0] |
| 31 | assert K>=12,K |
| 32 | raw=bytes(8)+struct.pack('<I',131072)+bytes(K-12) |
| 33 | name=b'step_advance' |
| 34 | hdr=b'OMPLAN01'+struct.pack('<7Q',1,0,2,N,1,G,1) |
| 35 | codes=struct.pack('<2Q',0,len(name)) |
| 36 | bufs=struct.pack('<6Q',4096,0,0,0,0,1)+struct.pack('<6Q',4096,0,0,0,0,2) |
| 37 | prompt=struct.pack('<i',0)+bytes(4) |
| 38 | one=struct.pack('<8I',0,1,1,1,64,K,1,0)+raw+struct.pack('<IIQ',0,0,0) |
| 39 | one+=bytes((-len(one))%8) |
| 40 | prefix=hdr+codes+bufs+prompt+one*N |
| 41 | plan=prefix+name+struct.pack('<4Q',len(prefix),len(name),len(prefix)+len(name),0) |
| 42 | out.write_bytes(plan) |
| 43 | print('MICROPLAN',out,'N',N,'gen',G,'kernarg',K,'bytes',len(plan),'object',want) |