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 / om / attention-mirror / dispatch-mutants.py
| 1 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | # External transport mutants: the actual-dispatch checker must reject each fault. |
| 3 | from pathlib import Path |
| 4 | import os,subprocess,sys,tempfile |
| 5 | root=Path(__file__).resolve().parents[2] |
| 6 | source=(root/'src/omega_gpu_prefill_attn256_api.c').read_text() |
| 7 | test=(root/'om/attention-mirror/dispatch-check.c').read_text() |
| 8 | wrap=['omega_gpu_session_lock','omega_gpu_session_unlock','omega_gpu_session_open','omega_gpu_session_on_close','omega_gpu_decode_attn256_cache_view','omega_gpu_session_sync_to_gpu','omega_gpu_session_sync_to_cpu','omega_gpu_session_free','omega_gpu_pf_alloc_dev_locked','omega_gpu_pf_copy_va_locked','omega_gpu_session_launch'] |
| 9 | mutants={ |
| 10 | 'copy_failure_ignored':('if (omega_gpu_pf_copy_va_locked(g.mirror.va, v.k_va, (size_t)mirror_bytes, copy_ns) != OMEGA_GPU_PF_OK)','if (omega_gpu_pf_copy_va_locked(g.mirror.va, v.k_va, (size_t)mirror_bytes, copy_ns) != OMEGA_GPU_PF_OK && 0)'), |
| 11 | 'wrong_k_pointer':('attend[1] = g.mirror.va;', 'attend[1] = v.k_va;'), |
| 12 | 'scoped_option_ignored':('uint64_t mirror_bytes = 0;', 'mirror_mode = 0; uint64_t mirror_bytes = 0;'), |
| 13 | 'failed_hook_ignored':('if (omega_gpu_session_on_close(on_session_close) != 0)', 'if (omega_gpu_session_on_close(on_session_close) != 0 && 0)'), |
| 14 | } |
| 15 | with tempfile.TemporaryDirectory(prefix='attention-dispatch-mutants-') as td: |
| 16 | t=Path(td) |
| 17 | for name,(old,new) in mutants.items(): |
| 18 | assert source.count(old)==1,(name,source.count(old)) |
| 19 | c=t/(name+'.c');c.write_text(source.replace(old,new));check=t/(name+'-check.c');check.write_text(test.replace('#include "../../src/omega_gpu_prefill_attn256_api.c"','#include "'+str(c)+'"')) |
| 20 | exe=t/name |
| 21 | subprocess.run([os.environ.get('CC','cc'),'-std=gnu11','-O2','-I'+str(root/'src'),'-I'+str(root/'om/attention-mirror'),str(check),sys.argv[1],*['-Wl,--wrap='+x for x in wrap],'-lpthread','-lm','-o',str(exe)],check=True) |
| 22 | p=subprocess.run([str(exe)],capture_output=True,text=True) |
| 23 | assert p.returncode!=0 and 'Assertion' in p.stderr,(name,p.returncode,p.stderr) |
| 24 | print(name+': caught',flush=True) |