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-kfd-launch/notebook.py.in # 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-kfd-launch / notebook.py.in` 210 lines · 12339 bytes Raw Blame History 1 # launch4: external Python measuring harness; the production launcher is seeded Omega. 2 import base64, ctypes, hashlib, json, lzma, os, platform, selectors, struct, subprocess, tempfile, time 3 from pathlib import Path 4 BUNDLE = json.loads(r'''@BUNDLE@''') 5 REPORT = Path('amdserve-launch4.txt') 6 ROWS = [] 7 WORK = None 8 ASSETS = {} 9 BIN = None 10 KFD_PROC_ROOT = Path('/sys/class/kfd/kfd/proc') 11 SAMPLE_DELAYS = (0.0, 1.0, 3.0) 12 REFERENCE = 'REFERENCE (AMD runtime loading our object, not the Omega launcher)' 13 def say(line): 14 ROWS.append(str(line).replace('\n',' ')) 15 temp=REPORT.with_suffix('.tmp'); temp.write_text('\n'.join(ROWS)+'\n'); temp.replace(REPORT) 16 print(ROWS[-1],flush=True) 17 def asset(name): 18 a=BUNDLE['assets'][name]; data=lzma.decompress(base64.b85decode(a['xz_base85'])) 19 if hashlib.sha256(data).hexdigest()!=a['sha256']: raise RuntimeError('asset digest '+name) 20 p=WORK/name; p.write_bytes(data) 21 if name=='omega-launch': p.chmod(0o700) 22 return p 23 def topology_table(): 24 root=Path('/sys/class/kfd/kfd/topology/nodes') 25 try: nodes=sorted(root.iterdir(),key=lambda p: int(p.name) if p.name.isdecimal() else -1) 26 except OSError as exc: 27 say('OMEGA topology table fail errno='+str(exc.errno)+' path='+str(root)); return 28 for node in nodes: 29 if not node.name.isdecimal(): continue 30 values={'node':node.name} 31 for name in ('gpu_id','properties'): 32 try: 33 data=(node/name).read_text() 34 if name=='gpu_id': values[name]=data.strip() 35 else: 36 props=dict(line.split(None,1) for line in data.splitlines() if len(line.split(None,1))==2) 37 values.update({k:props.get(k,'missing') for k in ('gfx_target_version','drm_render_minor','simd_count','device_id')}) 38 except OSError as exc: values[name+'_errno']=exc.errno 39 say('OMEGA topology table '+json.dumps(values,sort_keys=True)) 40 def sample_kfd(pid,index): 41 root=KFD_PROC_ROOT/str(pid) 42 prefix='OMEGA proc sample='+str(index)+' pid='+str(pid)+' ' 43 def contents(path): 44 try: 45 names=sorted(p.name for p in path.iterdir()) 46 say(prefix+str(path)+' entries='+json.dumps(names)); return names 47 except OSError as exc: 48 say(prefix+str(path)+' missing/unreadable errno='+str(exc.errno)); return [] 49 def value(path): 50 try: 51 data=path.read_text().strip(); say(prefix+str(path)+' value='+json.dumps(data)); return data 52 except OSError as exc: 53 say(prefix+str(path)+' missing/unreadable errno='+str(exc.errno)); return None 54 names=contents(root) 55 gpuids=set() 56 for queue in contents(root/'queues'): 57 for field in ('size','type','gpuid'): 58 data=value(root/'queues'/queue/field) 59 if field=='gpuid' and data and data.isdecimal(): gpuids.add(data) 60 for name in names: 61 for stem in ('stats_','vram_'): 62 if name.startswith(stem) and name[len(stem):].isdecimal(): gpuids.add(name[len(stem):]) 63 if not gpuids: say(prefix+'stats_/cu_occupancy and vram_ missing: no observed gpuid') 64 for gpu in sorted(gpuids): 65 value(root/('stats_'+gpu)/'cu_occupancy') 66 value(root/('vram_'+gpu)) 67 68 def invoke(arguments,label,expected=0,sample=False): 69 start=time.perf_counter_ns() 70 command=[str(BIN),*map(str,arguments)] 71 say('OMEGA invocation '+json.dumps({'label':label,'argv':command},sort_keys=True)) 72 streams={'stdout':bytearray(),'stderr':bytearray()} 73 pending={'stdout':b'','stderr':b''} 74 waiting=None; sampled=0 75 with subprocess.Popen(command,stdout=subprocess.PIPE,stderr=subprocess.PIPE) as child: 76 with selectors.DefaultSelector() as selector, (WORK/(label+'.stdout')).open('wb') as out, (WORK/(label+'.stderr')).open('wb') as err: 77 logs={'stdout':out,'stderr':err} 78 selector.register(child.stdout,selectors.EVENT_READ,'stdout') 79 selector.register(child.stderr,selectors.EVENT_READ,'stderr') 80 deadline=time.monotonic()+330 81 try: 82 while selector.get_map(): 83 now=time.monotonic(); left=deadline-now 84 if left<=0: raise subprocess.TimeoutExpired(command,330) 85 if waiting is not None and sampled