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/tests/device-trace/run-emitter-checks.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 / tests / device-trace / run-emitter-checks.sh` 138 lines · 5545 bytes Raw Blame History 1 #!/bin/sh 2 # Offline checks for the device-side trace emitter (CUDApp #82 first slice). 3 # 4 # Two layers, deliberately separate: 5 # 1. emitter/address/guard/body-test.om -- host checks compiled by the pinned seed compiler. 6 # 2. Omega's own sm_121 disassembler (build/sm121dis, om/disasm/sm121_dis.om; CUDA++ C6, 7 # DRA-475) on the emitted words: it confirms that the emitted words decode to the intended 8 # instructions. NVIDIA nvdisasm 13.0 stays an outside ORACLE only: when NVDISASM names it, 9 # its text of the same words must equal ours. Neither listing is committed (AGENTS.md 10 # forbids committing NVIDIA-tool output), so the expectations below are written by hand 11 # (opcode counts, the two S2R SR_GLOBALTIMERLO timer reads, and the address-formation lines 12 # of the #85 repair: MOV of the record offset, then IMAD.WIDE.U32 base + offset). 13 # 14 # Usage: OMEGA_COMPILER=/path/to/seed/out/omc [SM121DIS=build/sm121dis] [NVDISASM=/path/to/nvdisasm] \ 15 # sh tests/device-trace/run-emitter-checks.sh 16 set -eu 17 root=$(CDPATH= cd -- "$(dirname "$0")/../.." && pwd) 18 compiler=${OMEGA_COMPILER:-} 19 [ -n "$compiler" ] && [ -x "$compiler" ] || { 20 echo 'OMEGA_COMPILER must name the pinned seed compiler (seed/out/omc)' >&2 21 exit 69 22 } 23 work=${TMPDIR:-/tmp}/cudapp-emitter-check.$$ 24 mkdir -p "$work" 25 trap 'rm -rf -- "$work"' EXIT HUP INT TERM 26 27 echo "compiler $(sha256sum "$compiler" | cut -d' ' -f1)" 28 29 compile_unit() { 30 src=$1 31 out=$2 32 if "$compiler" < "$src" > "$out.elf" 2> "$out.compile.stderr"; then 33 : 34 else 35 rc=$? 36 cat "$out.compile.stderr" >&2 37 return "$rc" 38 fi 39 [ ! -s "$out.compile.stderr" ] || { cat "$out.compile.stderr" >&2; return 1; } 40 chmod +x "$out.elf" 41 } 42 43 # 1. All semantic units must pass before any external decode is attempted. 44 for name in emitter address guard body; do 45 : > "$work/$name.om" 46 if [ "$name" = body ]; then 47 cat "$root/native/blackwell/vector.om" >> "$work/$name.om" 48 fi 49 cat "$root/native/blackwell/trace-emit.om" "$root/tests/device-trace/$name-test.om" >> "$work/$name.om" 50 compile_unit "$work/$name.om" "$work/$name" 51 if "$work/$name.elf" > "$work/$name.out"; then 52 : 53 else 54 rc=$? 55 cat "$work/$name.out" >&2 56 echo "host unit $name failed: exit $rc" >&2 57 exit "$rc" 58 fi 59 if [ "$name" = emitter ]; then 60 fails=$(awk '$2 == 1 { n++ } END { print n + 0 }' "$work/$name.out") 61 checks=$(wc -l < "$work/$name.out") 62 echo "host checks: $checks, failures: $fails" 63 [ "$fails" = 0 ] || { cat "$work/$name.out" >&2; exit 1; } 64 fi 65 echo "host unit $name: PASS" 66 done 67 68 # 2. instruction decode of the two marker blocks (no kernel words between them) 69 cat > "$work/dump.om" <<'EOF' 70 global Ob uchar 1024 71 global Obn ulong 1 72 fn main to int 73 put gbinlen 0 0 74 put gtchecks 0 1 75 ok = gtewrap 1 4 76 if not ok 77 ret 3 78 end 79 for i ulong get gboutlen 0 80 c = get gbout i 81 put Ob get Obn 0 c 82 put Obn 0 add get Obn 0 1 83 end 84 r = write 1 Ob 0 get Obn 0 85 ret 0 86 end 87 EOF 88 cat "$root/native/blackwell/trace-emit.om" "$work/dump.om" > "$work/dump_full.om" 89 compile_unit "$work/dump_full.om" "$work/dump" 90 "$work/dump.elf" > "$work/words.bin" 91 echo "words: $(wc -c < "$work/words.bin") bytes, $(( $(wc -c < "$work/words.bin") / 16 )) instructions" 92 [ "$(wc -c < "$work/words.bin")" = 640 ] || { echo 'expected 40 instructions (640 bytes)' >&2; exit 1; } 93 94 dis=${SM121DIS:-$root/build/sm121dis} 95 [ -x "$dis" ] || { echo "NOT_RUN: $dis missing (make build/sm121dis)" >&2; exit 69; } 96 "$dis" -b SM121 "$work/words.bin" > "$work/got.sass" || { 97 echo 'Omega disassembler: some emitted words are not a known form (printed ??)' >&2; exit 1; } 98 if [ -n "${NVDISASM:-}" ]; then 99 # ORACLE, offline only: nvdisasm's text of the same words, spacing collapsed, must equal ours. 100 "$NVDISASM" --binary SM121 "$work/words.bin" > "$work/oracle.sass" 101 norm() { awk '$1 ~ /^\/\*[0-9a-f]+\*\/$/ { $1 = $1; print }' "$1"; } 102 norm "$work/oracle.sass" > "$work/oracle.txt"; norm "$work/got.sass" > "$work/ours.txt" 103 cmp -s "$work/oracle.txt" "$work/ours.txt" || { echo 'Omega disassembler text differs from the nvdisasm oracle' >&2 104 diff "$work/oracle.txt" "$work/ours.txt" | head -6 >&2; exit 1; } 105 echo "oracle: nvdisasm text equals ours on all $(wc -l < "$work/ours.txt") words" 106 fi 107 # Opcode histogram of the two marker blocks (20 instructions each). 108 awk '$1 ~ /^\/\*[0-9a-f]+\*\/$/ { op = $2; if (op ~ /^@/) op = $3; n[op]++ } 109 END { for (o in n) print o, n[o] }' "$work/got.sass" | LC_ALL=C sort > "$work/ops.txt" 110 LC_ALL=C sort > "$work/ops.want" <<'EOF' 111 BRA 2 112 IMAD.WIDE.U32 2 113 ISETP.GE.AND 2 114 LDC.64 6 115 LDCU.64 2 116 MOV 8 117 S2R 2 118 STG.E 16 119 EOF 120 bad=0 121 if ! diff -u "$work/ops.want" "$work/ops.txt"; then 122 echo 'opcode counts differ from the hand-written expectation' >&2 123 bad=1 124 fi 125 # Record address = capture base (R4:R5) + record offset, full 64-bit width. The two timer reads must name 126 # SR_GLOBALTIMERLO: without NVDISASM this is the only check of S2R text (the `f1b50cbf` decoder printed SR82). 127 for want in '0010 @P0 BRA 0x140' '0030 S2R R2, SR_GLOBALTIMERLO' '0170 S2R R2, SR_GLOBALTIMERLO' \ 128 '0070 MOV R6, 0x40' '0080 IMAD.WIDE.U32 R8, R6, 0x1, R4' \ 129 '01b0 MOV R6, 0x80' '01c0 IMAD.WIDE.U32 R8, R6, 0x1, R4'; do 130 off=${want%% *}; ins=${want#* } 131 got=$(awk -v o="/*$off*/" '$1 == o { $1 = ""; sub(/^ +/, ""); sub(/ *;$/, ""); print }' "$work/got.sass") 132 if [ "$got" != "$ins" ]; then 133 echo "offset 0x$off: want '$ins', got '$got'" >&2 134 bad=1 135 fi 136 done 137 [ "$bad" = 0 ] || exit 1 138 echo 'Omega disassembler decode matches the hand-written expectations (40 instructions)'