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 / runtime / api_plan_maxpos_mutants.py
| 1 | #!/usr/bin/env python3 |
| 2 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | """Keep the seven max-position controls after their C predicates move to Omega. |
| 4 | |
| 5 | This portable gate mutates checked generated bindings, not production sources. |
| 6 | The independent test-api-plan-mutants target mutates and recompiles canonical |
| 7 | .om source with the pinned compiler. Shared span admission now serves read, |
| 8 | write and step: one span mutant must trigger all three distinct expectations. |
| 9 | """ |
| 10 | import os |
| 11 | from pathlib import Path |
| 12 | import shlex |
| 13 | import subprocess |
| 14 | import sys |
| 15 | import tempfile |
| 16 | |
| 17 | root = Path(__file__).resolve().parents[2] |
| 18 | lib = str(Path(sys.argv[1]).resolve()) |
| 19 | flags = shlex.split(sys.argv[2]) |
| 20 | cc = shlex.split(os.environ.get('CC', 'cc')) |
| 21 | source = (root / 'src/cudapp_om_api_da_plan.c').read_text() |
| 22 | revert_first = len(sys.argv) == 4 and sys.argv[3] == '--revert-first' |
| 23 | assert len(sys.argv) == 3 or revert_first, 'usage: library cflags [--revert-first]' |
| 24 | cap = '_a=v3;uint64_t _b=131072ULL;o_op(10, 5, _a,_b);' |
| 25 | pos = '_a=o_get(v1, v1_n, 3ULL, 5);uint64_t _b=o_get(v1, v1_n, 5ULL, 5);o_op(10, 5, _a,_b);' |
| 26 | span = '_a=o_get(v1, v1_n, 5ULL, 5);uint64_t _b=o_get(v1, v1_n, 3ULL, 5);o_op(2, 5, _a,_b);' |
| 27 | rope = '_i=10ULL;uint64_t _v=({uint64_t _a=v3;uint64_t _b=512ULL;o_op(3, 5, _a,_b);});' |
| 28 | mutants = ( |
| 29 | ('cap-off-by-one', cap, cap.replace('o_op(10,', 'o_op(11,'), |
| 30 | (('cap-off-by-one', 'FAIL cache of 131072 positions'),)), |
| 31 | ('cap-one-chunk-over', cap, cap.replace('131072ULL', '131328ULL'), |
| 32 | (('cap-one-chunk-over', 'FAIL cache of 131072 positions'),)), |
| 33 | ('write-pos-bound', pos, '_a=0ULL;uint64_t _b=1ULL;o_op(6, 5, _a,_b);', |
| 34 | (('write-pos-bound', 'omega_gpu_decode_attn_cache_write(c, 0, 0, 131073, 1, k, v)'),)), |
| 35 | ('shared-span-bound', span, span.replace('o_op(2, 5, _a,_b);', 'o_op(1, 5, o_op(2, 5, _a,_b),1ULL);'), |
| 36 | (('write-count-bound', 'omega_gpu_decode_attn_cache_write(c, 0, 3, 131071, 2, k2, v2)'), |
| 37 | ('read-pos-bound', 'omega_gpu_decode_attn_cache_read(c, 0, 0, 131072, kr, vr)'), |
| 38 | ('step-pos-bound', 'omega_gpu_decode_attn(c, 0, 131072, g_qkv, 1e-6f, 1.0f, g_out, &info)'))), |
| 39 | ('rope-table-short', rope, rope.replace('_a=v3;', '_a=o_op(2,5,v3,8ULL);'), |
| 40 | (('rope-table-short', 'FAIL RoPE rows up to 131071'),)), |
| 41 | ) |
| 42 | controls = 0 |
| 43 | with tempfile.TemporaryDirectory(prefix='cudapp-maxpos-') as tmp: |
| 44 | tmp = Path(tmp) |
| 45 | for name, old, new, required in mutants: |
| 46 | assert source.count(old) == 1, (name, 'generated mutation site changed') |
| 47 | binding = tmp / (name + '.c') |
| 48 | exe = tmp / name |
| 49 | # The baseline target still exercises the requested migration switch. |
| 50 | if revert_first and name == 'cap-off-by-one': |
| 51 | print('NEGATIVE CONTROL: reverting cap-off-by-one mutation; gate must fail', flush=True) |
| 52 | new = old |
| 53 | binding.write_text(source.replace(old, new)) |
| 54 | # These binding-specific mutants must select the Omega adapter path. |
| 55 | subprocess.run(cc + flags + ['-O1', '-g', '-fsanitize=address,undefined', |
| 56 | '-fno-sanitize-recover=all', '-UCUDAPP_MIGRATION_PENDING_C_API_PLAN', |
| 57 | '-DCUDAPP_MIGRATION_PENDING_C_API_PLAN=0', '-o', str(exe), |
| 58 | str(root / 'tests/test_omega_gpu_decode_attn_maxpos.c'), |
| 59 | str(root / 'src/omega_gpu_decode_attn_api.c'), str(binding), lib, |
| 60 | '-lpthread', '-lm'], cwd=root, check=True) |
| 61 | result = subprocess.run([str(exe)], cwd=root, capture_output=True, text=True) |
| 62 | (tmp / (name + '.log')).write_text(result.stdout + result.stderr) |
| 63 | if revert_first: |
| 64 | assert result.returncode == 0, ('negative-control baseline failed', result) |
| 65 | print('NEGATIVE CONTROL: unchanged binding survives; gate rejects missing mutation', flush=True) |
| 66 | raise SystemExit(1) |
| 67 | assert result.returncode != 0 and '\nFAIL ' in '\n' + result.stdout, (name, result) |
| 68 | for control, expected in required: |
| 69 | assert expected in result.stdout, (control, result.stdout, result.stderr) |
| 70 | print('maxpos control killed:', control, flush=True) |
| 71 | controls += 1 |
| 72 | assert controls == 7 |
| 73 | print('test-gpu-decode-attn-maxpos: 7 of 7 controls killed (5 binding mutants)') |