interplane.Get Omega
Read in your language

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

branch main Branches Tags History

CUDApp / tools / sm121dis / check.sh

79 lines · 4407 bytes Raw Blame History
1#!/bin/sh
2# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3# check.sh <sm121dis> <kernel-dir> <work-dir>: Omega's disassembler against nvdisasm (the oracle) on every <kernel-dir>/*.bin.
4# Per kernel: PASS when every word's text is the same (spacing collapsed), else FAIL with the first differences.
5# Exit 0 only when every kernel passes; 2 when nvdisasm or a kernel is missing. nvdisasm is a decoder used offline as
6# the reference (docs/OMEGA.md C6); nothing it prints is used anywhere else.
7# Kernels are checked SM121DIS_JOBS at a time (default: every CPU this process may use); each writes
8# <work-dir>/<name>.res and the report below reads them back in kernel order, so it is the same at any job count.
9# A kernel without a result fails.
10set -u
11HERE=$(cd "$(dirname "$0")" && pwd)
12NVDISASM=${NVDISASM:-/usr/local/cuda/bin/nvdisasm}
13
14if [ "${1:-}" = --one ]; then
15 # check.sh --one <sm121dis> <work-dir> <kernel.bin>: one kernel. First line of .res: PASS|FAIL <words>; the rest
16 # is what the report prints for it. Written under a temporary name and renamed, so a cut-short check leaves none.
17 DIS=$2; WORK=$3; f=$4
18 b=$(basename "$f" .bin)
19 if ! "$NVDISASM" -b SM121 -hex "$f" > "$WORK/$b.nv" 2>&1; then
20 { echo "FAIL 0"; echo "[FAIL] $b: nvdisasm refused it"; head -3 "$WORK/$b.nv"; } > "$WORK/$b.res.tmp"
21 else
22 sh "$HERE/oracle_pairs.sh" "$WORK/$b.nv" > "$WORK/$b.want"
23 n=$(wc -l < "$WORK/$b.want")
24 # Capture the decoder directly: a pipeline would hide its exit status behind sed.
25 rc=0
26 "$DIS" --pairs "$f" > "$WORK/$b.raw" 2> "$WORK/$b.err" || rc=$?
27 if [ "$rc" -ne 0 ]; then
28 { echo "FAIL $n"; echo "[FAIL] $b: decoder exited $rc"; head -3 "$WORK/$b.err"; } > "$WORK/$b.res.tmp"
29 elif ! sed 's/[[:space:]]\{1,\}/ /g' "$WORK/$b.raw" > "$WORK/$b.got"; then
30 { echo "FAIL $n"; echo "[FAIL] $b: decoder output normalization failed"; } > "$WORK/$b.res.tmp"
31 elif [ "$n" -gt 0 ] && cmp -s "$WORK/$b.want" "$WORK/$b.got"; then
32 { echo "PASS $n"; echo "[PASS] $b: $n words"; } > "$WORK/$b.res.tmp"
33 else
34 { echo "FAIL $n"; echo "[FAIL] $b: $(diff "$WORK/$b.want" "$WORK/$b.got" | grep -c '^<') of $n words differ"
35 diff "$WORK/$b.want" "$WORK/$b.got" | head -6; } > "$WORK/$b.res.tmp"
36 # the instruction class (mnemonic, guard skipped) of every differing word, oracle side, for the report
37 awk 'NR == FNR { w[FNR] = $0; nw = FNR; next }
38 { g[FNR] = $0; ng = FNR }
39 END { m = nw > ng ? nw : ng
40 for (i = 1; i <= m; i++) if (w[i] != g[i]) {
41 split(w[i], t, " "); c = t[4]; if (c ~ /^@/) c = t[5]; if (w[i] == "") c = "(extra word)"
42 print c } }' "$WORK/$b.want" "$WORK/$b.got" > "$WORK/$b.cls"
43 fi
44 fi
45 mv "$WORK/$b.res.tmp" "$WORK/$b.res"
46 exit 0
47fi
48
49DIS=$1; DIR=$2; WORK=$3
50[ -x "$NVDISASM" ] || { echo "VERDICT NOT_RUN: $NVDISASM missing"; exit 2; }
51ls "$DIR"/*.bin >/dev/null 2>&1 || { echo "VERDICT NOT_RUN: no kernels in $DIR"; exit 2; }
52mkdir -p "$WORK"
53# "$WORK/." so a work dir that is a symlink (to /dev/shm, say) is swept too; a stale PASS must never be read back.
54find "$WORK/." -maxdepth 1 \( -name '*.res' -o -name '*.res.tmp' -o -name '*.cls' \) -exec rm -f {} +
55echo "oracle: $("$NVDISASM" --version | grep -o "release [0-9.]*, V[0-9.]*")"
56JOBS=${SM121DIS_JOBS:-$(nproc 2>/dev/null || echo 1)}
57for f in "$DIR"/*.bin; do printf '%s\0' "$f"; done | xargs -0 -n 1 -P "$JOBS" sh "$HERE/check.sh" --one "$DIS" "$WORK"
58k=0; bad=0; words=0
59for f in "$DIR"/*.bin; do
60 b=$(basename "$f" .bin)
61 k=$((k + 1))
62 if [ -f "$WORK/$b.res" ] && read -r st n < "$WORK/$b.res"; then
63 sed 1d "$WORK/$b.res"
64 words=$((words + n))
65 [ "$st" = PASS ] || bad=$((bad + 1))
66 else
67 echo "[FAIL] $b: no result"; bad=$((bad + 1))
68 fi
69done
70echo "kernels: $k, words: $words, failed kernels: $bad"
71echo "identical kernels: $((k - bad)), differing kernels: $bad"
72if ls "$WORK"/*.cls > /dev/null 2>&1; then
73 echo "differing words by instruction class (oracle mnemonic):"
74 cat "$WORK"/*.cls | LC_ALL=C sort | uniq -c | LC_ALL=C sort -k1,1nr -k2
75else
76 echo "differing instruction classes: none"
77fi
78[ $bad = 0 ] && { echo "VERDICT PASS"; exit 0; }
79echo "VERDICT FAIL"; exit 1