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