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 / tests / om_fixture_verify_test.py

77 lines · 4874 bytes Raw Blame History
1#!/usr/bin/env python3
2# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3"""Host only. Invoke under the mandatory device-hidden bwrap; never opens a GPU."""
4from pathlib import Path
5import os
6import shutil
7import subprocess
8
9root = Path(__file__).resolve().parents[1]
10os.chdir(root)
11out = root / 'build/fixture-verify'
12out.mkdir(parents=True, exist_ok=True)
13bridge = Path(os.environ.get('OMEGA_BRIDGE', str(Path.home()/'work/cudastack/omega-bridge')))
14# OMEGA_SEED defaults to the bridge's own bootstrap compiler (tools/bootstrap.sh output), which is what the
15# hosted job builds next to OMEGA_BRIDGE; it no longer falls back to a lane checkout under the home directory.
16env = dict(os.environ, OMEGA_SEEDED_OMC=os.environ.get('OMEGA_OMC', str(Path.home()/'work/cudastack/omega-mv/seed/out/omc')), OMEGA_SEED=os.environ.get('OMEGA_SEED', str(bridge/'build/bootstrap/omc')))
17cc = ['gcc','-std=gnu11','-O2','-Wall','-Wextra','-Werror','-ffp-contract=off','-Isrc']
18unit = 'src/cudapp_freest_fixture_verify.c'
19source = 'tests/om_fixture_verify_test.c'
20rows = []
21def run(name, args, expect=0):
22 p = subprocess.run([str(x) for x in args], env=env, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
23 (out/(name+'.log')).write_bytes(p.stdout)
24 rows.append(f'{name}\t{p.returncode}\t'+ ' '.join(map(str,args)))
25 (out/'commands.tsv').write_text('\n'.join(rows)+'\n')
26 print(name, 'rc', p.returncode, flush=True)
27 if expect is not None and p.returncode != expect: raise SystemExit(p.stdout.decode(errors='replace'))
28 return p
29missing = run('missing-link', cc+[source,'-o',out/'missing'], None)
30assert missing.returncode and b'undefined reference' in missing.stdout
31print('PASS strong entry missing-link negative',flush=True)
32run('build-omega',cc+[source,unit,'-o',out/'omega'])
33run('build-oracle',cc+[source,'-DCUDAPP_MIGRATION_PENDING_C_ENGINE_FIXTURE_REST=1','-o',out/'oracle'])
34base = run('omega',[out/'omega']).stdout
35assert base == run('oracle',[out/'oracle']).stdout
36print('PASS scalar and wrapper source-partition differential',flush=True)
37text=(root/'om/codegen/fixture_verify.om').read_text()
38mutants = [
39 ('word_equal','if ne and a 4294967295 and c 4294967295','if eq and a 4294967295 and c 4294967295'),
40 ('error_index','add mul a 2 b','add mul a 3 b'),
41 ('status_equal','ret fv_bool eq a 0','ret fv_bool ne a 0'),
42 ('bf16_bit','4294967295 262144','4294967295 262145'),
43 ('bfly_bit','or c 288230376151711744','or c 288230376151711745'),
44 ('shift_count','x = shl x 16','x = shl x 15'),
45 ('optional_mask','mask = 15','mask = 7')]
46for name, old, new in mutants:
47 assert text.count(old)==1,(name,text.count(old))
48 path=out/(name+'.om'); path.write_text(text.replace(old,new))
49 p=run('generate-'+name,['sh',bridge/'tools/bridge-freest','c',path])
50 gen=out/(name+'.c'); gen.write_bytes(p.stdout)
51 run('build-'+name,cc+[source,gen,'-o',out/name])
52 observed=run('run-'+name,[out/name],None)
53 assert observed.returncode or observed.stdout != base, name+' SURVIVED'
54 print('KILLED',name,flush=True)
55# Every original fixture entrypoint, with only the predicate implementation switched.
56bindings=sorted(root.glob('src/cudapp_om_*.c'))+sorted(root.glob('src/cudapp_freest_*.c'))
57common=['tests/om_fixture_verify_calls.c','src/omega_blackwell_codegen.c','src/omega_blackwell_matmul.c','src/omega_gpu_om_ir.c','src/sha256.c']+bindings
58run('build-calls',cc+common+['-o',out/'calls'])
59run('build-calls-oracle',cc+['-DCUDAPP_MIGRATION_PENDING_C_ENGINE_FIXTURE_REST=1']+common+['-o',out/'calls-oracle'])
60assert run('calls',[out/'calls']).stdout == run('calls-oracle',[out/'calls-oracle']).stdout
61# Corrupt golden data in a private test copy: the actual exported verifier must reject it.
62cg=(root/'src/omega_blackwell_codegen.c').read_text()
63assert cg.count('0x00027308U')==1
64red=out/'red-codegen.c'; red.write_text(cg.replace('0x00027308U','0x00027309U'))
65red_common=[red if x=='src/omega_blackwell_codegen.c' else x for x in common]
66run('build-red-calls',cc+red_common+['-o',out/'red-calls'])
67p=run('red-calls',[out/'red-calls'],None)
68assert p.returncode==1 and b'FAIL codegen fixture invocation' in p.stdout
69# Oracle coverage records source-derived branch partition reachability, not hardware qualification.
70run('build-coverage',['gcc','-std=gnu11','-O0','--coverage','-Isrc','-DCUDAPP_MIGRATION_PENDING_C_ENGINE_FIXTURE_REST=1',source,'-o',out/'coverage'])
71run('coverage',[out/'coverage'])
72run('gcov',['gcov','-b','-c','-o',out,out/'coverage-om_fixture_verify_test.gcno'])
73# gcov finds the sources from the checkout and writes its .gcov files there: keep their text in the build
74# directory and the checkout clean (the pattern of tests/mathlibs_host_om.py)
75for path in root.glob('*.gcov'):
76 shutil.move(str(path), out/path.name)
77print('PASS seven exported fixtures; red golden-data control; mutants 7/7 KILLED; HW NOT_RUN',flush=True)