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_ex_policy_check.py
| 1 | #!/usr/bin/env python3 |
| 2 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | """Read-only oracle/mutation runner. Invoke inside the documented device-hidden wrapper.""" |
| 4 | import os |
| 5 | import pathlib |
| 6 | import shutil |
| 7 | import subprocess |
| 8 | import sys |
| 9 | |
| 10 | root = pathlib.Path(__file__).resolve().parents[1] |
| 11 | os.chdir(root) |
| 12 | d = root / 'build/gemm-ex-policy' |
| 13 | d.mkdir(parents=True, exist_ok=True) |
| 14 | log = (d / 'check.log').open('w') |
| 15 | def run(cmd, *, env=None, reject=False): |
| 16 | p = subprocess.run([str(x) for x in cmd], text=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env) |
| 17 | text = p.stdout |
| 18 | log.write('$ ' + ' '.join(map(str,cmd)) + '\nrc=' + str(p.returncode) + '\n' + text + '\n');log.flush() |
| 19 | if (p.returncode == 0) == reject: |
| 20 | print(text);raise SystemExit('FAIL command expectation: ' + ' '.join(map(str,cmd))) |
| 21 | return p |
| 22 | for key in ('OMEGA_OMC','OMEGA_BRIDGE','OMEGA_SEED'): |
| 23 | if not os.environ.get(key): raise SystemExit('NOT_RUN: missing ' + key) |
| 24 | run(['sh','om/units.sh','--check']) |
| 25 | run(['make','-j3','build/libomega_gpu.a']) |
| 26 | cc = [os.environ.get('CC','cc'),'-std=gnu11','-O0','-ffp-contract=off','-Isrc'] |
| 27 | lib = ['build/libomega_gpu.a','-lpthread','-lm'] |
| 28 | base = d / 'base' |
| 29 | for old in d.glob('base-*.gcda'): |
| 30 | old.unlink() |
| 31 | run(cc + ['--coverage','tests/gemm_ex_policy_test.c',*lib,'-o',base]) |
| 32 | p=run([base]); print(p.stdout.strip()) |
| 33 | run(cc + ['-DCUDAPP_MIGRATION_PENDING_C_GEMM_EX_HOST_POLICY=0','tests/gemm_ex_policy_test.c',*lib,'-o',d/'shell']) |
| 34 | p=run([d/'shell']);print('DEFAULT SHELL: '+p.stdout.strip()) |
| 35 | e=os.environ.copy();e['GEMM_POLICY_RED']='1' |
| 36 | p=run([base],env=e,reject=True) |
| 37 | if 'FAIL' not in p.stdout: raise SystemExit('FAIL red control did not reach comparator') |
| 38 | print('RED COMPARATOR: PASS (nonzero mismatch)') |
| 39 | # Real production archive, not the oracle harness, must refuse to link without this unit. |
| 40 | missing=d/'missing.a';shutil.copyfile('build/libomega_gpu.a',missing) |
| 41 | run(['ar','d',missing,'cudapp_om_gemm_ex_policy.o']) |
| 42 | p=run(cc+['-Itests','tests/gpu_gemm_ex_test.c',missing,'-lpthread','-lm','-o',d/'missing'],reject=True) |
| 43 | if 'omega_gemm_ex_policy' not in p.stdout: raise SystemExit('FAIL unrelated missing-unit failure') |
| 44 | print('STRONG LINK NEGATIVE: PASS (omega_gemm_ex_policy undefined)') |
| 45 | source=pathlib.Path('om/gemmex/policy.om').read_text() |
| 46 | mutants=[ |
| 47 | ('minimum','if lt a b','if gt a b'), |
| 48 | ('transpose-index','ret add mul d b c','ret add mul c b d'), |
| 49 | ('row-stride','if eq op 2\nif ne a 0\nret b','if eq op 2\nif ne a 0\nret 1'), |
| 50 | ('plane-pack','if and ne a 5 ne a 6','if and ne a 4 ne a 6'), |
| 51 | ('window-quota','ret div 65536 w','ret div 65535 w'), |
| 52 | ('contiguous','if or eq a 1 eq b mul c d','if or eq a 2 eq b mul c d'), |
| 53 | ('row-offset','ret mul mul a b c','ret add mul a b c'), |
| 54 | ('column-stride','if eq op 7\nif ne a 0','if eq op 7\nif eq a 0'), |
| 55 | ] |
| 56 | for name,old,new in mutants: |
| 57 | if source.count(old)!=1: raise SystemExit('FAIL nonunique mutant '+name) |
| 58 | om=d/(name+'.om');om.write_text(source.replace(old,new)) |
| 59 | env=os.environ.copy();env['OMEGA_SEEDED_OMC']=env['OMEGA_OMC'] |
| 60 | p=run(['sh',pathlib.Path(env['OMEGA_BRIDGE'])/'tools/bridge-seeded','c',om],env=env) |
| 61 | c=d/(name+'.c');c.write_text(p.stdout) |
| 62 | exe=d/name |
| 63 | run(cc+['tests/gemm_ex_policy_test.c',c,*lib,'-o',exe]) |
| 64 | p=run([exe],reject=True) |
| 65 | if 'FAIL' not in p.stdout: raise SystemExit('FAIL mutant not killed by comparison: '+name) |
| 66 | print('MUTANT '+name+': KILLED '+p.stdout.splitlines()[0]) |
| 67 | run(['gcov','-b','-c','-o',d,str(d/'base-gemm_ex_policy_test.gcno')]) |
| 68 | targets={'gx_min','gx_arow','gx_bcol','gx_brow','gx_pack','gx_conv'} |
| 69 | coverage=pathlib.Path('omega_gpu_gemm_ex.c.gcov').read_text() |
| 70 | summary=[line for line in coverage.splitlines() if line.startswith('function ') and line.split()[1] in targets] |
| 71 | (d/'coverage.txt').write_text('\n'.join(summary)+'\n') |
| 72 | for path in pathlib.Path('.').glob('*.gcov'): |
| 73 | shutil.move(str(path),d/path.name) |
| 74 | print('\n'.join(summary)) |
| 75 | for target in ('test-gpu-gemm-ex','test-gpu-gemm-ex-sim'): |
| 76 | p=run(['make','-j3',target]);print(target+': rc=0 '+'; '.join(line for line in p.stdout.splitlines() if 'PASS' in line)) |
| 77 | print('GEMM EX HOST POLICY ACCEPTANCE PASS (8 mutants, red comparator, missing-unit link)') |