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 / model_graphs_nested.py
| 1 | #!/usr/bin/env python3 |
| 2 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | """Compare real production nested recorders; fake resources, not fake recorders.""" |
| 4 | import os |
| 5 | from pathlib import Path |
| 6 | import shlex |
| 7 | import subprocess |
| 8 | |
| 9 | ROOT = Path(__file__).resolve().parents[1] |
| 10 | BUILD = Path(os.environ.get('OUT_DIR', ROOT / 'build')) |
| 11 | OUT = BUILD / 'model-graphs-nested' |
| 12 | CC = shlex.split(os.environ.get('CC', 'cc')) |
| 13 | FLAGS = ['-std=gnu11','-D_GNU_SOURCE','-O2','-Wall','-Wextra','-Werror','-Wno-unused-function','-ffunction-sections','-fdata-sections','-Isrc','-Itests','-Im16','-Invrm'] |
| 14 | |
| 15 | def run(cmd): |
| 16 | subprocess.run([str(x) for x in cmd], cwd=ROOT, check=True) |
| 17 | |
| 18 | binaries = {} |
| 19 | for variant in ('old','new','flip'): |
| 20 | # These OUT_DIRs never share graph objects, including legacy-selector builds. |
| 21 | out = OUT / variant |
| 22 | out.mkdir(parents=True, exist_ok=True) |
| 23 | objects=[] |
| 24 | for family in ('FP8','BF16','GDN','ATTN','ATTN256','ROUTER'): |
| 25 | obj=out / (family.lower()+'.o') |
| 26 | run(CC+FLAGS+['-DMG_NEST_'+family,'-c','tests/model_graphs_nested_objects.c','-o',obj]);objects.append(obj) |
| 27 | for family in ('q36','q38','decode'): |
| 28 | obj=out / (family+'.o') |
| 29 | defs=['-DMODEL_GRAPHS_NESTED'] |
| 30 | if variant=='old':defs+=['-DCUDAPP_MIGRATION_PENDING_C_GRAPHS=1'] |
| 31 | run(CC+FLAGS+defs+['-c',f'tests/model_graphs_{family}_fixture.c','-o',obj]);objects.append(obj) |
| 32 | binary=out/'nested' |
| 33 | neg=['-DMG_NEGATIVE','-Wl,--wrap=omega_mg_node'] if variant=='flip' else [] |
| 34 | run(CC+FLAGS+neg+['tests/test_model_graphs_nested.c','tests/model_graphs_nested_native.c',*objects,BUILD/'libomega_gpu.a','-Wl,--gc-sections','-lpthread','-lm','-o',binary]) |
| 35 | binaries[variant]=binary |
| 36 | |
| 37 | # family, graph mode, attention, conversation heads, feature flags, position, layers. |
| 38 | # Process isolation also prevents one shape's pinned production kernel from |
| 39 | # invalidating another shape's residency contract. |
| 40 | cases=[] |
| 41 | for pos in (0,1,255,256,131064,131071): |
| 42 | for attention in (0,1): |
| 43 | cases += [(36,8,attention,1,0,pos,2),(38,2,attention,1,0,pos,2),(38,2,attention,1,1280,pos,2),(30,2,0,1,0,pos,2)] |
| 44 | # Batched independent conversations, contiguous prefill, expert/router GEMM, |
| 45 | # optional FP8 output head, BF16 9B split down, exact BF16 masked head. |
| 46 | for attention in (0,1): |
| 47 | cases += [(36,2,attention,2,0,255,2),(36,3,attention,2,48,255,2),(36,4,attention,2,0,255,2),(36,6,attention,2,0,255,2),(36,7,attention,2,0,255,2),(36,8,attention,1,4,255,2),(38,2,attention,1,1290,255,2)] |
| 48 | cases += [(36,5,0,2,0,0,2),(38,1,0,1,512,0,2)] |
| 49 | for index,case in enumerate(cases): |
| 50 | blobs=[] |
| 51 | for variant in ('old','new'): |
| 52 | capture=OUT/variant/'capture.bin' |
| 53 | run([binaries[variant],*case,capture]) |
| 54 | blobs.append(capture.read_bytes()) |
| 55 | if blobs[0]!=blobs[1]: |
| 56 | raise SystemExit(f'FAIL nested byte comparison case={index} spec={case}') |
| 57 | # A real plan descriptor is corrupted, not the comparison buffer or a recorder. |
| 58 | case=cases[0] |
| 59 | run([binaries['new'],*case,OUT/'new/negative-reference.bin']) |
| 60 | run([binaries['flip'],*case,OUT/'flip/negative.bin']) |
| 61 | if (OUT/'new/negative-reference.bin').read_bytes()==(OUT/'flip/negative.bin').read_bytes(): |
| 62 | raise SystemExit('FAIL nested plan-word flip survived') |
| 63 | print(f'MODEL-GRAPHS-NESTED PASS cases={len(cases)} real-recorders=GDN,attention,FP8,BF16,GEMM,router old-submissions=1 new-submissions=1 plan-word-flip=KILLED') |