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 / 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
16set -eu
17root=$(CDPATH= cd -- "$(dirname "$0")/../.." && pwd)
18compiler=${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}
23work=${TMPDIR:-/tmp}/cudapp-emitter-check.$$
24mkdir -p "$work"
25trap 'rm -rf -- "$work"' EXIT HUP INT TERM
26
27echo "compiler $(sha256sum "$compiler" | cut -d' ' -f1)"
28
29compile_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.
44for 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"
66done
67
68# 2. instruction decode of the two marker blocks (no kernel words between them)
69cat > "$work/dump.om" <<'EOF'
70global Ob uchar 1024
71global Obn ulong 1
72fn main to int
73put gbinlen 0 0
74put gtchecks 0 1
75ok = gtewrap 1 4
76if not ok
77ret 3
78end
79for i ulong get gboutlen 0
80c = get gbout i
81put Ob get Obn 0 c
82put Obn 0 add get Obn 0 1
83end
84r = write 1 Ob 0 get Obn 0
85ret 0
86end
87EOF
88cat "$root/native/blackwell/trace-emit.om" "$work/dump.om" > "$work/dump_full.om"
89compile_unit "$work/dump_full.om" "$work/dump"
90"$work/dump.elf" > "$work/words.bin"
91echo "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
94dis=${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; }
98if [ -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"
106fi
107# Opcode histogram of the two marker blocks (20 instructions each).
108awk '$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"
110LC_ALL=C sort > "$work/ops.want" <<'EOF'
111BRA 2
112IMAD.WIDE.U32 2
113ISETP.GE.AND 2
114LDC.64 6
115LDCU.64 2
116MOV 8
117S2R 2
118STG.E 16
119EOF
120bad=0
121if ! diff -u "$work/ops.want" "$work/ops.txt"; then
122 echo 'opcode counts differ from the hand-written expectation' >&2
123 bad=1
124fi
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).
127for 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
136done
137[ "$bad" = 0 ] || exit 1
138echo 'Omega disassembler decode matches the hand-written expectations (40 instructions)'