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 / regalloc_om / packers_mutants.py
| 1 | #!/usr/bin/env python3 |
| 2 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | """Run this complete process under the device-free bwrap contract.""" |
| 4 | import os |
| 5 | from pathlib import Path |
| 6 | import subprocess |
| 7 | ROOT = Path(__file__).resolve().parents[2] |
| 8 | os.chdir(ROOT) |
| 9 | OUT = ROOT / 'build/packers-om/mutants' |
| 10 | OUT.mkdir(parents=True, exist_ok=True) |
| 11 | SOURCE = (ROOT / 'om/codegen/cg_pack_h.om').read_text() |
| 12 | CASES = [ |
| 13 | ('a-column-low-bit', 'mul shr cc 3 4 and cc 1\n', 'mul shr cc 3 4 xor and cc 1 1\n'), |
| 14 | ('a-row-lane-stride', 'mul and rr 7 32', 'mul and rr 7 16'), |
| 15 | ('b-group-stride', 'add get job 0 mul g 16', 'add get job 0 mul g 8'), |
| 16 | ('padding-value', 'put d x ushort 0\n', 'put d x ushort 1\n'), |
| 17 | ('bf16-tie-even', 'add add x 32767 and shr x 16 1', 'add add x 32767 ulong 0'), |
| 18 | ('row0-padding-zero', 'ph_z16 d blk c1\n', 'ph_z16 d blk 16\n'), |
| 19 | ] |
| 20 | bridge = Path(os.environ['OMEGA_BRIDGE']) / 'tools/bridge-seeded' |
| 21 | env = dict(os.environ, OMEGA_SEEDED_OMC=os.environ['OMEGA_OMC']) |
| 22 | expected = (ROOT / 'build/packers-om/oracle.out').read_bytes() |
| 23 | summary=[] |
| 24 | for name, old, new in CASES: |
| 25 | if SOURCE.count(old) != 1: raise RuntimeError(f'{name}: ambiguous anchor') |
| 26 | work = OUT / name |
| 27 | work.mkdir(exist_ok=True) |
| 28 | source=work/'mutant.om'; source.write_text(SOURCE.replace(old,new)) |
| 29 | generated=work/'mutant.c' |
| 30 | with generated.open('wb') as stdout, (work/'compile.log').open('wb') as stderr: |
| 31 | compiled=subprocess.run(['sh',str(bridge),'--runtime-views','c',str(source)],env=env,stdout=stdout,stderr=stderr) |
| 32 | if compiled.returncode: raise RuntimeError(f'{name}: NOT_KILLED compiler rc={compiled.returncode}') |
| 33 | binary=work/'packers' |
| 34 | with (work/'link.log').open('wb') as log: |
| 35 | subprocess.run([os.environ.get('CC','cc'),'-std=gnu11','-O2','-ffunction-sections','-fdata-sections','-Isrc', |
| 36 | 'tests/regalloc_om/packers.c','src/omega_blackwell_codegen.c','src/cudapp_om_cg_pack_len.c', |
| 37 | 'src/cudapp_om_cg_sentin.c',str(generated), |
| 38 | '-Wl,--gc-sections','-o',str(binary)],stdout=log,stderr=subprocess.STDOUT,check=True) |
| 39 | with (work/'output').open('wb') as output: |
| 40 | exercised=subprocess.run([str(binary),'--mutant'],stdout=output,stderr=subprocess.PIPE) |
| 41 | (work/'exercise.log').write_bytes(exercised.stderr) |
| 42 | if exercised.returncode: raise RuntimeError(f'{name}: NOT_KILLED exercise rc={exercised.returncode}') |
| 43 | if (work/'output').read_bytes()==expected: raise RuntimeError(f'{name}: SURVIVED') |
| 44 | summary.append(f'{name}\tcompile=0\texercise=0\tcomparison=different') |
| 45 | print(f'KILLED {summary[-1]}',flush=True) |
| 46 | (OUT/'mutants.tsv').write_text('\n'.join(summary)+'\n') |
| 47 | print(f'PASS fragment recompiled Omega semantic mutants={len(summary)}') |