interplane.Get Omega
Read in your language

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

branch main Branches Tags History

CUDApp / om / q38-head / envelope-mutants.py

30 lines · 1443 bytes Raw Blame History
1# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2# External verification of the Omega source, never a runtime dependency.
3import pathlib
4import subprocess
5import sys
6import tempfile
7
8here = pathlib.Path(__file__).resolve().parent
9source = (here / 'envelope.om').read_text()
10driver = (here / 'envelope-driver.om').read_text()
11mutants = {
12 'omit_tail': ('for i ulong 5120', 'for i ulong 5119'),
13 'round_down': ('div add sig 1 2', 'div sig 2'),
14 'accept_nonfinite': ('if ge v 2139095040\nret 0', 'if ge v 2139095040\nret 1065353216'),
15 'omit_margin': ('mul sig 73800', 'mul sig 73728'),
16 'keep_sign_bit': ('and ulong get bits i 2147483647', 'ulong get bits i'),
17}
18with tempfile.TemporaryDirectory(prefix='q38-envelope-') as tmp:
19 for name, (old, new) in mutants.items():
20 assert source.count(old) == 1
21 binary = pathlib.Path(tmp) / name
22 result = subprocess.run([sys.argv[1]], input=(source.replace(old, new) + driver).encode(),
23 capture_output=True, check=True)
24 binary.write_bytes(result.stdout)
25 binary.chmod(0o700)
26 result = subprocess.run([sys.executable, str(here / 'envelope-check.py'), str(binary)],
27 capture_output=True)
28 assert result.returncode != 0, f'{name}: survived'
29 assert b'AssertionError' in result.stderr, (name, result.stderr)
30 print(f'{name}: caught by numerical oracle')