interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / tools / sm121dis / zero_nvdisasm.sh

82 lines · 4843 bytes Raw Blame History
1#!/bin/sh
2# zero_nvdisasm.sh: the second half of bar C6 in docs/OMEGA.md, "nothing calls nvdisasm" (L386).
3#
4# Two checks, both must pass:
5# 1. Static. No file under src/ tests/ tools/ mk/ or the Makefile names the CUDA toolkit directory or looks
6# up an nvdisasm binary. The one declared exception is the oracle harness of the nvdisasm comparison,
7# tools/sm121dis/check.sh and oracle_pairs.sh, which exists to compare Omega's decoder WITH nvdisasm.
8# 2. Dynamic. Every listing check and provenance check runs (a) with a DECOY nvdisasm first on PATH that records
9# each call and fails, (b) with every CUDA directory removed from PATH, and (c) under strace -f tracing execve.
10# PASS only when every command exits 0, the decoy was never called, and no execve names a path containing
11# "nvdisasm". A test that quietly fell back to the toolkit would fail one of the three.
12#
13# Usage: PHYSICS_DIR=<pinned physics checkout> sh tools/sm121dis/zero_nvdisasm.sh [build-dir]
14# after: make PHYSICS_DIR=... build/sm121dis build/gpu_attention_test build/gpu_elementwise_test \
15# build/gpu_fp8_api_test build/gpu_reconv_test build/bw_hazard_test build/test_omega_reduce_cpu
16# Last line: "ZERO-NVDISASM: PASS (...)" or "ZERO-NVDISASM: FAIL (...)". Exit 0 only on PASS.
17set -u
18OUT=${1:-build}
19command -v strace > /dev/null 2>&1 || { echo "ZERO-NVDISASM: NOT_RUN (strace missing)"; exit 2; }
20# The work dir holds the decoy, which is first on PATH, so every PATH lookup (make, gcc's as and ld, ...) tries it and
21# appears in the trace; its path therefore must not contain "nvdisasm", or those lookups would match the execve check.
22# The same holds for the checkout: any execve of a repo binary by absolute path would name it.
23WORK=$(mktemp -d "${TMPDIR:-/tmp}/zero_nvd.XXXXXX") || { echo "ZERO-NVDISASM: NOT_RUN (no work dir under ${TMPDIR:-/tmp})"; exit 2; }
24case $WORK in *nvdisasm*) echo "ZERO-NVDISASM: NOT_RUN (the work dir $WORK names nvdisasm; set TMPDIR elsewhere)"; rmdir "$WORK"; exit 2;; esac
25case $PWD in *nvdisasm*) echo "ZERO-NVDISASM: NOT_RUN (the checkout $PWD names nvdisasm; run it from another path)"; rmdir "$WORK"; exit 2;; esac
26fail=0
27
28# 1. static
29hits=$(grep -rnE '/usr/local/cuda|command -v nvdisasm|which nvdisasm|cuda/bin/nvdisasm' src tests tools mk Makefile 2>/dev/null \
30 | grep -vE '^tools/sm121dis/(check|oracle_pairs|zero_nvdisasm)\.sh:')
31if [ -n "$hits" ]; then
32 echo "static: FAIL, these lines name the CUDA toolkit or look up nvdisasm:"; echo "$hits" | head -20; fail=1
33else
34 echo "static: PASS, no file outside the oracle harness names the CUDA toolkit or looks up nvdisasm"
35fi
36
37# 2. dynamic
38mkdir -p "$WORK/decoy"
39cat > "$WORK/decoy/nvdisasm" <<'EOF'
40#!/bin/sh
41echo "DECOY nvdisasm called with: $*" >> "$ZERO_NVDISASM_MARK"
42exit 1
43EOF
44chmod +x "$WORK/decoy/nvdisasm"
45ZERO_NVDISASM_MARK=$WORK/decoy-calls; export ZERO_NVDISASM_MARK
46cleanpath=$(printf '%s' "$PATH" | tr ':' '\n' | grep -vi 'cuda' | paste -sd: -)
47n=0
48run() {
49 name=$1; shift
50 n=$((n + 1))
51 env PATH="$WORK/decoy:$cleanpath" strace -f -qq -e trace=execve -o "$WORK/$name.strace" "$@" > "$WORK/$name.out" 2>&1
52 rc=$?
53 ex=$(grep -cE 'execve\("[^"]*nvdisasm[^"]*"' "$WORK/$name.strace" 2>/dev/null)
54 printf '%s: exit %s, execve naming nvdisasm: %s' "$name" "$rc" "$ex"
55 if [ "$rc" -eq 0 ] && [ "$ex" -eq 0 ]; then echo " ok"; else echo " FAIL"; fail=1; fi
56}
57run attention_hd64 "$OUT/gpu_attention_test" --host-only
58run attention_hd128 "$OUT/gpu_attention_test" --hd 128 --host-only
59run elementwise "$OUT/gpu_elementwise_test" --host-only
60run fp8 "$OUT/gpu_fp8_api_test" --host-only
61run reconv "$OUT/gpu_reconv_test" --host-only
62run divsqrt sh tools/divsqrt_nvdisasm_check.sh
63run ldst sh tools/ldst_nvdisasm_check.sh
64run hazard "$OUT/bw_hazard_test" --disasm
65run reduce make ${PHYSICS_DIR:+PHYSICS_DIR=$PHYSICS_DIR} test-numeric-reduce-nvdisasm
66if [ "${2:-}" = "--red" ]; then
67 # Red check of the gate itself: two planted shell-outs, one by name (the decoy must catch it) and one by the
68 # toolkit's absolute path (strace must catch it). The gate must then say FAIL; a gate that stays green here is broken.
69 run planted_by_name sh -c 'nvdisasm --version'
70 run planted_by_path sh -c '/usr/local/cuda/bin/nvdisasm --version > /dev/null 2>&1; exit 0'
71fi
72
73calls=0
74[ -f "$ZERO_NVDISASM_MARK" ] && calls=$(wc -l < "$ZERO_NVDISASM_MARK")
75if [ "$calls" -ne 0 ]; then echo "decoy: FAIL, called $calls time(s):"; head -5 "$ZERO_NVDISASM_MARK"; fail=1
76else echo "decoy: never called"; fi
77
78if [ "$fail" -eq 0 ]; then
79 echo "ZERO-NVDISASM: PASS ($n commands under strace, decoy calls 0, no execve of nvdisasm, static clean)"
80 rm -rf "$WORK"; exit 0
81fi
82echo "ZERO-NVDISASM: FAIL (details in $WORK)"; exit 1