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 / tests / chip_enum_check.py
| 1 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | import os |
| 3 | from pathlib import Path |
| 4 | import subprocess |
| 5 | |
| 6 | root=Path.cwd() |
| 7 | out=root/'build/chip-enum' |
| 8 | out.mkdir(parents=True,exist_ok=True) |
| 9 | cc=os.environ.get('CC','cc') |
| 10 | base=[cc,'-std=gnu11','-O0','--coverage','-Wall','-Wextra','-Werror','-Isrc',str(root/'tests/chip_enum_diff.c'),str(root/'tests/chip_enum_oracle.c'),str(root/'src/omega_gpu_chip.c'),str(root/'src/cudapp_om_chip_admit.c')] |
| 11 | def build(dest,binding,defs=()): |
| 12 | subprocess.run([*base,*defs,*binding,'-o',str(dest)],check=True) |
| 13 | def run(cmd,name,good=True): |
| 14 | p=subprocess.run([str(x) for x in cmd],capture_output=True) |
| 15 | (out/(name+'.log')).write_bytes(p.stdout+p.stderr) |
| 16 | assert (p.returncode==0)==good,(name,p.returncode,p.stderr) |
| 17 | return p.stdout |
| 18 | binding=str(root/'src/cudapp_om_chip_enum.c') |
| 19 | build(out/'om',[binding]);build(out/'c',[binding],['-DCUDAPP_MIGRATION_PENDING_C_CHIP_ENUM_POLICY=1']) |
| 20 | print(run([out/'om'],'diff').decode().strip()) |
| 21 | run([out/'om','--plant'],'red',False) |
| 22 | missing=subprocess.run([*base,'-o',str(out/'missing')],capture_output=True) |
| 23 | (out/'link-negative.log').write_bytes(missing.stdout+missing.stderr) |
| 24 | assert missing.returncode and b'omega_chip_enum' in missing.stderr |
| 25 | print('RED and strong-link missing-unit controls PASS') |
| 26 | fixture=out/'root' |
| 27 | devices=fixture/'sys/bus/pci/devices' |
| 28 | devices.mkdir(parents=True,exist_ok=True) |
| 29 | vendors=[0,1,0x10dd,0x10de,0x10df,0xffff,0x10000,0xffffffff,0xffffffffffffffff] |
| 30 | classes=[0,1,0x2ffff,0x30000,0x30001,0x3ffff,0x40000,0xffffffff,0x100030000,0xffffffffffffffff] |
| 31 | ids=[0,0x2e11,0x2e12,0x2e13,0xffff,0x10000,0xffffffff] |
| 32 | i=0 |
| 33 | for v in vendors: |
| 34 | for c in classes: |
| 35 | for d in ids: |
| 36 | p=devices/f'fixture-{i:04d}' |
| 37 | p.mkdir(exist_ok=True) |
| 38 | for name,value in [('vendor',v),('class',c),('device',d)]: (p/name).write_text(f'{value:x}\n') |
| 39 | i+=1 |
| 40 | for name,files in [('missing',{}),('bad-vendor',{'vendor':'not-hex'}),('bad-class',{'vendor':'10de','class':'junk'}),('bad-device',{'vendor':'10de','class':'30000','device':'bad!'})]: |
| 41 | p=devices/name;p.mkdir(exist_ok=True) |
| 42 | for key,value in files.items():(p/key).write_text(value+'\n') |
| 43 | # A leading dot is excluded before any sysfs reads. |
| 44 | p=devices/'.hidden';p.mkdir(exist_ok=True) |
| 45 | for key,value in [('vendor','10de'),('class','30000'),('device','2e12')]:(p/key).write_text(value+'\n') |
| 46 | assert run([out/'om','--scan',fixture],'scan-om')==run([out/'c','--scan',fixture],'scan-c') |
| 47 | assert run([out/'om','--scan',out/'absent'],'missing-sysfs-om')==run([out/'c','--scan',out/'absent'],'missing-sysfs-c') |
| 48 | print('FIXTURE scan differential PASS vendor/class/device edges, capacities -1/0/1/2/3, null output, missing sysfs') |
| 49 | text=(root/'om/admission/chip_enum.om').read_text() |
| 50 | mutants=[('row-vendor','ce_eq a c','ce_eq a d'),('row-device','ce_eq b d','ce_eq b c'),('vendor','ce_eq a 4318','ce_eq a 4319'),('class','shr a 16 3','shr a 15 3'),('mask','ret and a b','ret or a b'),('capacity','lt a b','le a b'),('dot','ce_eq a 46','ce_eq a 47')] |
| 51 | # make sets CHIP_ENUM_MUTANTS=1 only where the pinned omc executes (CUDAPP_OMC_HOST). |
| 52 | run_mutants=os.environ['CHIP_ENUM_MUTANTS']=='1' |
| 53 | for name,old,new in mutants: |
| 54 | assert text.count(old)==1 |
| 55 | if not run_mutants: |
| 56 | print('NOT_RUN',name,'(om/units.sh requires the pinned AArch64 omc)') |
| 57 | continue |
| 58 | here=out/name;here.mkdir(exist_ok=True) |
| 59 | unit=here/'chip_enum.om';unit.write_text(text.replace(old,new)) |
| 60 | env=dict(os.environ,OMEGA_UNITS=str(unit),OMEGA_UNITS_DEST=str(here)) |
| 61 | p=subprocess.run(['sh','om/units.sh'],env=env,capture_output=True) |
| 62 | (here/'compile.log').write_bytes(p.stdout+p.stderr) |
| 63 | # On failure name the mutant, the exit status and the end of both streams (also kept in compile.log). |
| 64 | assert p.returncode==0,f'om/units.sh {name} rc={p.returncode} (log {here/"compile.log"}): '+(p.stdout+p.stderr).decode(errors='replace')[-2000:] |
| 65 | build(here/'check',[str(here/'cudapp_om_chip_enum.c')]) |
| 66 | run([here/'check'],name,False) |
| 67 | print('KILLED',name) |
| 68 | cov=subprocess.run(['gcov','-b','-c','-t',str(out/'om-chip_enum_oracle.gcno')],capture_output=True) |
| 69 | (out/'oracle.gcov').write_bytes(cov.stdout);(out/'coverage.log').write_bytes(cov.stderr) |
| 70 | assert cov.returncode==0,cov.stderr |
| 71 | if run_mutants:print('CHIP ENUM DIFFERENTIAL RED LINK SEVEN MUTANTS PASS') |
| 72 | else:print('CHIP ENUM DIFFERENTIAL RED LINK PASS; SEVEN .om MUTANTS NOT_RUN (no pinned omc on this host)') |