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 / gemm_host_plan_check.py
| 1 | #!/usr/bin/env python3 |
| 2 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | """C-oracle proof runner; run inside the device-hidden wrapper documented in evidence.""" |
| 4 | import os |
| 5 | import pathlib |
| 6 | import shutil |
| 7 | import subprocess |
| 8 | root=pathlib.Path(__file__).resolve().parents[1];os.chdir(root) |
| 9 | d=root/'build/gemm-host-plan';d.mkdir(parents=True,exist_ok=True) |
| 10 | log=(d/'check.log').open('w') |
| 11 | def run(cmd,*,env=None,reject=False): |
| 12 | p=subprocess.run([str(x) for x in cmd],text=True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT,env=env) |
| 13 | log.write('$ '+' '.join(map(str,cmd))+'\nrc='+str(p.returncode)+'\n'+p.stdout+'\n');log.flush() |
| 14 | if (p.returncode==0)==reject: |
| 15 | print(p.stdout);raise SystemExit('FAIL command expectation: '+' '.join(map(str,cmd))) |
| 16 | return p |
| 17 | for key in ('OMEGA_OMC','OMEGA_BRIDGE'): |
| 18 | if not os.environ.get(key):raise SystemExit('NOT_RUN: missing '+key) |
| 19 | run(['sh','om/units.sh','--check']);run(['make','-j3','build/libomega_gpu.a']) |
| 20 | cc=[os.environ.get('CC','cc'),'-std=gnu11','-O0','-ffp-contract=off','-Isrc'] |
| 21 | lib=['build/libomega_gpu.a','-lpthread','-lm'];base=d/'base' |
| 22 | run(cc+['--coverage','tests/gemm_host_plan_test.c',*lib,'-o',base]) |
| 23 | for old in d.glob('base-*.gcda'): |
| 24 | old.unlink() |
| 25 | p=run([base]);print(p.stdout.strip()) |
| 26 | e=os.environ.copy();e['GEMM_POLICY_RED']='1' |
| 27 | p=run([base],env=e,reject=True) |
| 28 | if 'FAIL' not in p.stdout:raise SystemExit('FAIL red control missed comparator') |
| 29 | print('RED COMPARATOR: PASS (nonzero mismatch)') |
| 30 | missing=d/'missing.a';shutil.copyfile('build/libomega_gpu.a',missing) |
| 31 | run(['ar','d',missing,'cudapp_om_gemm_host.o','cudapp_om_gemm_value.o','cudapp_om_gemm_cfg.o','cudapp_om_gemm_plan.o','cudapp_om_gemm_span.o']) |
| 32 | p=run(cc+['-Itests','tests/gpu_gemm_test.c',missing,'-lpthread','-lm','-o',d/'missing'],reject=True) |
| 33 | if 'omega_gemm_' not in p.stdout:raise SystemExit('FAIL unrelated missing-unit error') |
| 34 | print('STRONG LINK NEGATIVE: PASS (Omega planner symbols undefined)') |
| 35 | source=pathlib.Path('om/gemm-any/host.om').read_text() |
| 36 | mutants=[ |
| 37 | ('tile-set','ret or eq v 1 or eq v 2 eq v 4','ret or eq v 1 or eq v 2 eq v 3'), |
| 38 | ('dimension-edge','if gt get x add i 8 16384','if ge get x add i 8 16384'), |
| 39 | ('rounding','ret mul div add v sub m 1 m m','ret mul div v m m'), |
| 40 | ('pack-padding','ret mul mul add mul groups ks2 2 frag 512','ret mul mul add mul groups ks2 1 frag 512'), |
| 41 | ('span-edge','if gt sp 4294967295','if gt sp 65535'), |
| 42 | ('band-grid','put p 12 mul band gy','put p 12 mul band gx'), |
| 43 | ('alignment','ret and add a 255 18446744073709551360','ret and a 18446744073709551360'), |
| 44 | ('main-registers','ret and mul 4 add add mul 4 a mul 2 b mul a b 4294967295','ret and mul 4 add add mul 3 a mul 2 b mul a b 4294967295'), |
| 45 | ] |
| 46 | wrappers=[('gemm_host',None),('gemm_value','value.om'),('gemm_cfg','config.om'),('gemm_plan','plan.om'),('gemm_span','span.om')] |
| 47 | for name,old,new in mutants: |
| 48 | if source.count(old)!=1:raise SystemExit('FAIL nonunique mutant '+name) |
| 49 | changed=source.replace(old,new);files=[] |
| 50 | env=os.environ.copy();env['OMEGA_SEEDED_OMC']=env['OMEGA_OMC'] |
| 51 | for unit,wrapper in wrappers: |
| 52 | om=d/(name+'-'+unit+'.om');om.write_text(changed+('\n'+pathlib.Path('om/gemm-any',wrapper).read_text() if wrapper else '')) |
| 53 | p=run(['sh',pathlib.Path(env['OMEGA_BRIDGE'])/'tools/bridge-seeded','c',om],env=env) |
| 54 | c=d/(name+'-'+unit+'.c');c.write_text(p.stdout);files.append(c) |
| 55 | exe=d/name;run(cc+['tests/gemm_host_plan_test.c',*files,*lib,'-o',exe]) |
| 56 | p=run([exe],reject=True) |
| 57 | if 'FAIL' not in p.stdout:raise SystemExit('FAIL mutant missed comparator '+name) |
| 58 | print('MUTANT '+name+': KILLED '+p.stdout.splitlines()[0]) |
| 59 | run(['gcov','-b','-c','-o',d,str(d/'base-gemm_host_plan_test.gcno')]) |
| 60 | targets={'esz','kstep','pow124','type_ok','band_ok','main_regs','omega_gpu_gemm_cfg_ok','roundup','omega_gpu_gemm_plan','ld_span','omega_gpu_gemm_span','omega_gpu_gemm_drive_ld','packed_locked','up16'} |
| 61 | coverage=pathlib.Path('omega_gpu_gemm.c.gcov').read_text() |
| 62 | summary=[line for line in coverage.splitlines() if line.startswith('function ') and line.split()[1] in targets] |
| 63 | (d/'coverage.txt').write_text('\n'.join(summary)+'\n') |
| 64 | for path in pathlib.Path('.').glob('*.gcov'): |
| 65 | shutil.move(str(path),d/path.name) |
| 66 | print('\n'.join(summary)) |
| 67 | run(['make','-j3','build/gpu_gemm_test']) |
| 68 | for tier in ('--host-only','--sim'): |
| 69 | p=run(['build/gpu_gemm_test',tier]);print('GEMM '+tier+': rc=0 '+p.stdout.splitlines()[-1]) |
| 70 | p=run(['make','-j3','test-gpu-gemm-any']) |
| 71 | print('GEMM ANY: rc=0 '+'; '.join(line for line in p.stdout.splitlines() if 'PASS' in line)) |
| 72 | print('GEMM HOST PLAN ACCEPTANCE PASS (8 mutants, red comparator, missing-unit link)') |