Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/tools/sm121dis/zero_nvdisasm.sh # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers 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= 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. 17 set -u 18 OUT=${1:-build} 19 command -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. 23 WORK=$(mktemp -d "${TMPDIR:-/tmp}/zero_nvd.XXXXXX") || { echo "ZERO-NVDISASM: NOT_RUN (no work dir under ${TMPDIR:-/tmp})"; exit 2; } 24 case $WORK in *nvdisasm*) echo "ZERO-NVDISASM: NOT_RUN (the work dir $WORK names nvdisasm; set TMPDIR elsewhere)"; rmdir "$WORK"; exit 2;; esac 25 case $PWD in *nvdisasm*) echo "ZERO-NVDISASM: NOT_RUN (the checkout $PWD names nvdisasm; run it from another path)"; rmdir "$WORK"; exit 2;; esac 26 fail=0 27 28 # 1. static 29 hits=$(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:') 31 if [ -n "$hits" ]; then 32 echo "static: FAIL, these lines name the CUDA toolkit or look up nvdisasm:"; echo "$hits" | head -20; fail=1 33 else 34 echo "static: PASS, no file outside the oracle harness names the CUDA toolkit or looks up nvdisasm" 35 fi 36 37 # 2. dynamic 38 mkdir -p "$WORK/decoy" 39 cat > "$WORK/decoy/nvdisasm" <<'EOF' 40 #!/bin/sh 41 echo "DECOY nvdisasm called with: $*" >> "$ZERO_NVDISASM_MARK" 42 exit 1 43 EOF 44 chmod +x "$WORK/decoy/nvdisasm" 45 ZERO_NVDISASM_MARK=$WORK/decoy-calls; export ZERO_NVDISASM_MARK 46 cleanpath=$(printf '%s' "$PATH" | tr ':' '\n' | grep -vi 'cuda' | paste -sd: -) 47 n=0 48 run() { 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 } 57 run attention_hd64 "$OUT/gpu_attention_test" --host-only 58 run attention_hd128 "$OUT/gpu_attention_test" --hd 128 --host-only 59 run elementwise "$OUT/gpu_elementwise_test" --host-only 60 run fp8 "$OUT/gpu_fp8_api_test" --host-only 61 run reconv "$OUT/gpu_reconv_test" --host-only 62 run divsqrt sh tools/divsqrt_nvdisasm_check.sh 63 run ldst sh tools/ldst_nvdisasm_check.sh 64 run hazard "$OUT/bw_hazard_test" --disasm 65 run reduce make ${PHYSICS_DIR:+PHYSICS_DIR=$PHYSICS_DIR} test-numeric-reduce-nvdisasm 66 if [ "${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' 71 fi 72 73 calls=0 74 [ -f "$ZERO_NVDISASM_MARK" ] && calls=$(wc -l < "$ZERO_NVDISASM_MARK") 75 if [ "$calls" -ne 0 ]; then echo "decoy: FAIL, called $calls time(s):"; head -5 "$ZERO_NVDISASM_MARK"; fail=1 76 else echo "decoy: never called"; fi 77 78 if [ "$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 81 fi 82 echo "ZERO-NVDISASM: FAIL (details in $WORK)"; exit 1