interplane.Get Omega
Read in your language

aien-sovereign-core-mv

AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.

Brought by drakestapleton

branch main Branches Tags History

aien-sovereign-core-mv / scripts / zero-cuda-gate.sh

93 lines · 3564 bytes Raw Blame History
1#!/usr/bin/env bash
2# SPDX-License-Identifier: Apache-2.0
3# Copyright 2026 Drake Stapleton (AIEN / aien-dev)
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17# Zero-CUDA gate (FB-1 cut 6): fails when a binary needs an NVIDIA CUDA library or
18# imports a CUDA runtime/driver/cuBLAS/NVRTC symbol. AIEN reaches the GB10 only through
19# the Omega engine (libomega_gpu.a, linked statically, no CUDA).
20#
21# scripts/zero-cuda-gate.sh <binary>... check the given binaries
22# scripts/zero-cuda-gate.sh --self-test negative control: builds a stub library
23# and object that must FAIL the check
24# Exit 0 = every binary clean, 1 = CUDA found, 2 = usage or tool error.
25set -euo pipefail
26
27LIB_RE='lib(cuda|cudart|cublas|cublasLt|nvrtc|nvJitLink|cudnn|nvidia-ptxjitcompiler)\.so'
28SYM_RE='^(cu[A-Z][A-Za-z0-9_]*|cuda[A-Z][A-Za-z0-9_]*|cublas[A-Za-z0-9_]*|nvrtc[A-Z][A-Za-z0-9_]*|__cuda[A-Za-z0-9_]*)(@.*)?$'
29
30check_one() {
31 local bin=$1 bad=0
32 if [ ! -f "$bin" ]; then
33 echo "ZERO_CUDA ERROR $bin: no such file" >&2
34 return 2
35 fi
36 local needed undef
37 needed=$(readelf -d "$bin" 2>/dev/null | sed -n 's/.*(NEEDED).*\[\(.*\)\]/\1/p') || return 2
38 undef=$(nm -D --undefined-only "$bin" 2>/dev/null | awk '{print $NF}') || return 2
39 local hit
40 hit=$(printf '%s\n' "$needed" | grep -E "$LIB_RE" || true)
41 if [ -n "$hit" ]; then
42 echo "ZERO_CUDA FAIL $bin needs: $(echo $hit)"
43 bad=1
44 fi
45 hit=$(printf '%s\n' "$undef" | grep -E "$SYM_RE" || true)
46 if [ -n "$hit" ]; then
47 echo "ZERO_CUDA FAIL $bin imports: $(echo $hit | cut -c1-400)"
48 bad=1
49 fi
50 if [ $bad -eq 0 ]; then
51 echo "ZERO_CUDA PASS $bin needs=[$(echo $needed)]"
52 fi
53 return $bad
54}
55
56self_test() {
57 local d
58 d=$(mktemp -d)
59 trap 'rm -rf "$d"' RETURN
60 # A stub named like the CUDA runtime, and an object that calls cudaMalloc through it.
61 printf 'int cudaMalloc(void **p, unsigned long n) { (void)p; (void)n; return 1; }\n' >"$d/stub.c"
62 printf 'int cudaMalloc(void **p, unsigned long n);\nint probe(void) { void *p; return cudaMalloc(&p, 1); }\n' >"$d/probe.c"
63 cc -shared -fPIC -o "$d/libcudart.so" -Wl,-soname,libcudart.so.13 "$d/stub.c"
64 cc -shared -fPIC -o "$d/probe.so" "$d/probe.c" -L"$d" -Wl,--no-as-needed -lcudart
65 printf 'int clean(void) { return 0; }\n' >"$d/clean.c"
66 cc -shared -fPIC -o "$d/clean.so" "$d/clean.c"
67 local out rc=0
68 out=$(check_one "$d/probe.so") || rc=$?
69 echo "$out"
70 if [ $rc -ne 1 ] || ! grep -q 'needs: libcudart.so.13' <<<"$out" || ! grep -q 'imports: cudaMalloc' <<<"$out"; then
71 echo "ZERO_CUDA SELF-TEST BROKEN: the CUDA probe was not caught (rc=$rc)" >&2
72 return 2
73 fi
74 check_one "$d/clean.so" >/dev/null || {
75 echo "ZERO_CUDA SELF-TEST BROKEN: a CUDA-free library was rejected" >&2
76 return 2
77 }
78 echo "ZERO_CUDA SELF-TEST PASS (CUDA probe rejected, clean library accepted)"
79}
80
81if [ $# -eq 0 ]; then
82 echo "usage: $0 <binary>... | --self-test" >&2
83 exit 2
84fi
85if [ "$1" = "--self-test" ]; then
86 self_test
87 exit $?
88fi
89status=0
90for b in "$@"; do
91 check_one "$b" || { rc=$?; [ $rc -gt $status ] && status=$rc; }
92done
93exit $status