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-hip.py
| 1 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | """Instrument (not Omega): the published HIP graph arm, lighthouse-oracle.py mode `graph`, keeping the |
| 3 | per-step decode times and all 256 ids instead of only the median. Same driver, Card, kernels and timer: |
| 4 | real2 Card.forward begins perf_counter before hipGraphLaunch and stops after hipStreamSynchronize; host |
| 5 | readback of logits and the token id happen after the timer stops. |
| 6 | Usage: gap-hip.py DRIVER WEIGHTS FIXTURE OUT.json CAPACITY""" |
| 7 | import hashlib,importlib.util,json,os,statistics,sys |
| 8 | from pathlib import Path |
| 9 | |
| 10 | driver,weights,fixture_path,out,cap=Path(sys.argv[1]),Path(sys.argv[2]),Path(sys.argv[3]),Path(sys.argv[4]),int(sys.argv[5]) |
| 11 | fixture=json.loads(fixture_path.read_bytes()) |
| 12 | P,G=fixture['prompt_ids'],fixture['generated_ids'] |
| 13 | os.environ['AMDSERVE_WEIGHTS']=str(weights);os.environ['AMDSERVE_OUTPUT']=str(out)+'.log' |
| 14 | spec=importlib.util.spec_from_file_location('real2driver',driver);drv=importlib.util.module_from_spec(spec);spec.loader.exec_module(drv) |
| 15 | drv.GOLD=dict(drv.GOLD,prompt_ids=list(P),generated_ids=list(G),top5=[[(0,0.0)]]*len(G)) |
| 16 | drv.top5_difference=lambda logits,expected:None |
| 17 | if cap<len(P)+len(G):raise SystemExit('capacity below prompt+generated') |
| 18 | drv.Card.cap=property(lambda self:cap,lambda self,value:None) |
| 19 | import torch,time |
| 20 | drv.prepare() |
| 21 | # Same-clock record: real2's forward returns (logits.cpu(), tok.item(), elapsed) where elapsed stops after |
| 22 | # hipStreamSynchronize; the wall time of the whole call also covers the logits copy and token read. |
| 23 | walls=[];orig=drv.Card.forward |
| 24 | def timed(self,*a,**k): |
| 25 | t0=time.perf_counter();r=orig(self,*a,**k);walls.append(((time.perf_counter()-t0)*1000,r[2]));return r |
| 26 | drv.Card.forward=timed |
| 27 | with torch.inference_mode():r=drv.measure(torch,'omega-graph') |
| 28 | dec=walls[len(walls)-len(r['decode_ms']):] |
| 29 | res=dict(forward_wall_ms=[w for w,_ in dec],forward_wall_ms_median=statistics.median(w for w,_ in dec),mode='graph',capacity=cap,ids=r['ids'],decode_ms=r['decode_ms'],decode_ms_median=r['decode_ms_median'], |
| 30 | capture_ms=r['capture_ms'],timing_mode=r['timing_mode'],fixture_sha256=hashlib.sha256(fixture_path.read_bytes()).hexdigest(), |
| 31 | driver=str(driver),driver_sha256=hashlib.sha256(driver.read_bytes()).hexdigest()) |
| 32 | out.write_text(json.dumps(res)+'\n') |
| 33 | print('GAPHIP',json.dumps({k:v for k,v in res.items() if k not in ('ids','decode_ms')})) |