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 / om_bw_mutants.py
| 1 | #!/usr/bin/env python3 |
| 2 | """Recompile semantic Omega mutants; refusal never counts as a kill.""" |
| 3 | import os |
| 4 | from pathlib import Path |
| 5 | import subprocess |
| 6 | import tempfile |
| 7 | |
| 8 | ROOT = Path(__file__).resolve().parents[1] |
| 9 | BRIDGE = Path(os.environ['OMEGA_BRIDGE']) |
| 10 | OMC = os.environ['OMEGA_OMC'] |
| 11 | ENV = dict(os.environ, OMEGA_SEEDED_OMC=OMC) |
| 12 | SCALAR = ROOT / 'om/blackwell/scalar.om' |
| 13 | IDENT = ROOT / 'om/blackwell/identity.om' |
| 14 | CPUI = ROOT / 'om/blackwell/cpui.om' |
| 15 | CPUH = ROOT / 'om/blackwell/cpuf16.om' |
| 16 | CPUB = ROOT / 'om/blackwell/cpubf16.om' |
| 17 | SHAPE = ROOT / 'om/blackwell/shape.om' |
| 18 | NAME = ROOT / 'om/blackwell/name.om' |
| 19 | CASES = [ |
| 20 | ('half-exponent', SCALAR, 'shl add exp 112 23', 'shl add exp 111 23'), |
| 21 | ('half-subnormal', SCALAR, 'shl sub BEXP 10 23', 'shl sub BEXP 9 23'), |
| 22 | ('bf16-expand', SCALAR, 'ret shl and x 65535 16', 'ret shl and x 65535 15'), |
| 23 | ('bf16-round', SCALAR, 'add add x 32767', 'add add x 32766'), |
| 24 | ('alloc-round', SCALAR, 'b = and add add x y 4095', 'b = and add add x y 4094'), |
| 25 | ('admit-cbank', SCALAR, 'gt v 128', 'gt v 127'), |
| 26 | ('identity-byte', IDENT, 'put msg i get data i', 'put msg i xor get data i uchar 1'), |
| 27 | ('integer-product', CPUI, 'mul ulong a ulong b', 'add ulong a ulong b'), |
| 28 | ('half-dot-zero', CPUH, 'sum = bitcast f32 uint 0', 'sum = bitcast f32 uint 1065353216'), |
| 29 | ('bf16-dot-stride', CPUB, 'bi = and add bi nn 4294967295', 'bi = and add bi 1 4294967295'), |
| 30 | ('shape-root-equality', SHAPE, 'if le mid div x mid', 'if lt mid div x mid'), |
| 31 | ('name-terminator', NAME, 'if eq get data i 0', 'if ne get data i 0'), |
| 32 | ] |
| 33 | |
| 34 | |
| 35 | def run(args, **kw): |
| 36 | p = subprocess.run([str(a) for a in args], cwd=ROOT, env=ENV, capture_output=True, **kw) |
| 37 | if p.returncode: |
| 38 | raise RuntimeError(f'{args}: rc={p.returncode}\n{p.stdout!r}\n{p.stderr!r}') |
| 39 | return p.stdout |
| 40 | |
| 41 | |
| 42 | with tempfile.TemporaryDirectory(prefix='bw-mutants-') as td: |
| 43 | t = Path(td) |
| 44 | for name, source, old, new in CASES: |
| 45 | text = source.read_text() |
| 46 | assert text.count(old) == 1, (name, text.count(old)) |
| 47 | text = text.replace(old, new) |
| 48 | if source == IDENT: |
| 49 | text = (ROOT / 'om/cache/digest.om').read_text() + '\n' + text |
| 50 | elif source in (CPUI, CPUH, CPUB, SHAPE): |
| 51 | parts = [ROOT / 'om/blackwell/views.om'] |
| 52 | if source == CPUH: |
| 53 | parts.append(SCALAR) |
| 54 | if source == SHAPE: |
| 55 | text += '\n' + (ROOT / 'om/blackwell/shape_probe.om').read_text() |
| 56 | else: |
| 57 | parts.append(SHAPE) |
| 58 | text = '\n'.join(p.read_text() for p in parts) + '\n' + text |
| 59 | unit = t / f'{name}.om' |
| 60 | unit.write_text(text) |
| 61 | generated = t / f'{name}.c' |
| 62 | frontend = 'bridge-freest' if source == SCALAR else 'bridge-seeded' |
| 63 | profile = ['--runtime-views'] if source in (CPUI, CPUH, CPUB, SHAPE, NAME) else [] |
| 64 | generated.write_bytes(run([BRIDGE / 'tools' / frontend, *profile, 'c', unit])) |
| 65 | exe = t / name |
| 66 | run(['cc', '-std=gnu11', '-O0', '-g', '-Wall', '-Wextra', '-Werror', |
| 67 | '-ffp-contract=off', '-Isrc', '-DCUDAPP_MIGRATION_PENDING_BW_MATMUL=1', |
| 68 | 'tests/om_bw_diff_test.c', 'tests/om_bw_matmul_oracle.c', |
| 69 | 'tests/om_bw_realize_oracle.c', generated, 'build/libomega_gpu.a', |
| 70 | '-lpthread', '-lm', '-o', exe]) |
| 71 | p = subprocess.run([exe], cwd=ROOT, env=ENV, capture_output=True) |
| 72 | assert p.returncode == 1 and b'FAIL line' in p.stderr, (name, p.returncode, p.stdout, p.stderr) |
| 73 | print(f'KILLED {name}: compiled=0 differential=1', flush=True) |
| 74 | print(f'PASS bw semantic mutants killed={len(CASES)}') |