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-hipmicro.py
| 1 | # Instrument (not Omega): HIP graph replay of N step_advance launches per step, the same kernel |
| 2 | # object as the Omega micro plan (driver-real2.py's embedded objects), timed the way real2 times |
| 3 | # a step: perf_counter before hipGraphLaunch, after hipStreamSynchronize. Also times the parts: |
| 4 | # launch call return, synchronize return, and a 4-byte token readback (tok.item()). |
| 5 | # Usage: gap-hipmicro.py DRIVER N STEPS OUT.json |
| 6 | import importlib.util,json,statistics,sys,time |
| 7 | from pathlib import Path |
| 8 | driver,N,S,out=Path(sys.argv[1]),int(sys.argv[2]),int(sys.argv[3]),Path(sys.argv[4]) |
| 9 | spec=importlib.util.spec_from_file_location('real2driver',driver);drv=importlib.util.module_from_spec(spec);spec.loader.exec_module(drv) |
| 10 | import torch |
| 11 | hip=drv.Hip(torch) |
| 12 | pos=torch.zeros(1,dtype=torch.int32,device='cuda');tok=torch.zeros(1,dtype=torch.int32,device='cuda') |
| 13 | cap=131072 |
| 14 | def emit(): |
| 15 | for _ in range(N):hip.launch('step_advance',1,1,pos,cap) |
| 16 | torch.cuda.synchronize() |
| 17 | g=hip.capture(emit) |
| 18 | rows=[] |
| 19 | try: |
| 20 | for s in range(S+1): |
| 21 | t0=time.perf_counter();hip.replay(g);t1=time.perf_counter();hip.sync();t2=time.perf_counter();v=int(tok.item());t3=time.perf_counter() |
| 22 | if s:rows.append(((t2-t0)*1e6,(t1-t0)*1e6,(t2-t1)*1e6,(t3-t2)*1e6)) |
| 23 | finally:hip.release_graph(g) |
| 24 | cols=list(zip(*rows)) |
| 25 | res=dict(N=N,steps=S,step_us=list(cols[0]),median_step_us=statistics.median(cols[0]),median_launch_call_us=statistics.median(cols[1]), |
| 26 | median_sync_us=statistics.median(cols[2]),median_token_readback_us=statistics.median(cols[3]),position=int(pos.item())) |
| 27 | out.write_text(json.dumps(res)+'\n') |
| 28 | print('HIPMICRO',json.dumps({k:v for k,v in res.items() if k!='step_us'})) |