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 / tools / zero-cuda-gate.sh
| 1 | #!/usr/bin/env bash |
| 2 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | # Copied from aien-sovereign-core scripts/zero-cuda-gate.sh at 14126c62 (written by aien-dev, Drake's account). |
| 4 | # Zero-CUDA gate (FB-1 cut 6): fails when a binary needs an NVIDIA CUDA library or |
| 5 | # imports a CUDA runtime/driver/cuBLAS/NVRTC symbol. AIEN reaches the GB10 only through |
| 6 | # the Omega engine (libomega_gpu.a, linked statically, no CUDA). |
| 7 | # |
| 8 | # scripts/zero-cuda-gate.sh <binary>... check the given binaries |
| 9 | # scripts/zero-cuda-gate.sh --self-test negative control: builds a stub library |
| 10 | # and object that must FAIL the check |
| 11 | # Exit 0 = every binary clean, 1 = CUDA found, 2 = usage or tool error. |
| 12 | set -euo pipefail |
| 13 | |
| 14 | LIB_RE='lib(cuda|cudart|cublas|cublasLt|nvrtc|nvJitLink|cudnn|nvidia-ptxjitcompiler)\.so' |
| 15 | SYM_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_]*)(@.*)?$' |
| 16 | |
| 17 | check_one() { |
| 18 | local bin=$1 bad=0 |
| 19 | if [ ! -f "$bin" ]; then |
| 20 | echo "ZERO_CUDA ERROR $bin: no such file" >&2 |
| 21 | return 2 |
| 22 | fi |
| 23 | local needed undef |
| 24 | needed=$(readelf -d "$bin" 2>/dev/null | sed -n 's/.*(NEEDED).*\[\(.*\)\]/\1/p') || return 2 |
| 25 | undef=$(nm -D --undefined-only "$bin" 2>/dev/null | awk '{print $NF}') || return 2 |
| 26 | local hit |
| 27 | hit=$(printf '%s\n' "$needed" | grep -E "$LIB_RE" || true) |
| 28 | if [ -n "$hit" ]; then |
| 29 | echo "ZERO_CUDA FAIL $bin needs: $(echo $hit)" |
| 30 | bad=1 |
| 31 | fi |
| 32 | hit=$(printf '%s\n' "$undef" | grep -E "$SYM_RE" || true) |
| 33 | if [ -n "$hit" ]; then |
| 34 | echo "ZERO_CUDA FAIL $bin imports: $(echo $hit | cut -c1-400)" |
| 35 | bad=1 |
| 36 | fi |
| 37 | if [ $bad -eq 0 ]; then |
| 38 | echo "ZERO_CUDA PASS $bin needs=[$(echo $needed)]" |
| 39 | fi |
| 40 | return $bad |
| 41 | } |
| 42 | |
| 43 | self_test() { |
| 44 | local d |
| 45 | d=$(mktemp -d) |
| 46 | trap 'rm -rf "$d"' RETURN |
| 47 | # A stub named like the CUDA runtime, and an object that calls cudaMalloc through it. |
| 48 | printf 'int cudaMalloc(void **p, unsigned long n) { (void)p; (void)n; return 1; }\n' >"$d/stub.c" |
| 49 | printf 'int cudaMalloc(void **p, unsigned long n);\nint probe(void) { void *p; return cudaMalloc(&p, 1); }\n' >"$d/probe.c" |
| 50 | cc -shared -fPIC -o "$d/libcudart.so" -Wl,-soname,libcudart.so.13 "$d/stub.c" |
| 51 | cc -shared -fPIC -o "$d/probe.so" "$d/probe.c" -L"$d" -Wl,--no-as-needed -lcudart |
| 52 | printf 'int clean(void) { return 0; }\n' >"$d/clean.c" |
| 53 | cc -shared -fPIC -o "$d/clean.so" "$d/clean.c" |
| 54 | local out rc=0 |
| 55 | out=$(check_one "$d/probe.so") || rc=$? |
| 56 | echo "$out" |
| 57 | if [ $rc -ne 1 ] || ! grep -q 'needs: libcudart.so.13' <<<"$out" || ! grep -q 'imports: cudaMalloc' <<<"$out"; then |
| 58 | echo "ZERO_CUDA SELF-TEST BROKEN: the CUDA probe was not caught (rc=$rc)" >&2 |
| 59 | return 2 |
| 60 | fi |
| 61 | check_one "$d/clean.so" >/dev/null || { |
| 62 | echo "ZERO_CUDA SELF-TEST BROKEN: a CUDA-free library was rejected" >&2 |
| 63 | return 2 |
| 64 | } |
| 65 | echo "ZERO_CUDA SELF-TEST PASS (CUDA probe rejected, clean library accepted)" |
| 66 | } |
| 67 | |
| 68 | if [ $# -eq 0 ]; then |
| 69 | echo "usage: $0 <binary>... | --self-test" >&2 |
| 70 | exit 2 |
| 71 | fi |
| 72 | if [ "$1" = "--self-test" ]; then |
| 73 | self_test |
| 74 | exit $? |
| 75 | fi |
| 76 | status=0 |
| 77 | for b in "$@"; do |
| 78 | check_one "$b" || { rc=$?; [ $rc -gt $status ] && status=$rc; } |
| 79 | done |
| 80 | exit $status |