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-helix/blob/main/tests/gpu-disasm.sh # omega-helix This project has not described itself yet. 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 `omega-helix / tests / gpu-disasm.sh` 135 lines ยท 6007 bytes Raw Blame History 1 #!/bin/sh 2 # Disassemble the GB10 kernels that native/gpu/ emits, with nvdisasm as a read-only 3 # oracle. Builds the gb10 sources plus tests/gpu-dump.om, runs the dump on the CPU (no GPU), 4 # cuts slot N (16 KiB at N * 16384; two slots for 64x64 GEMM ids 40-58), trims trailing zero 5 # bytes to a 16-byte multiple, disassembles with `nvdisasm -b SM121`, checks for illegal 6 # instructions, and verifies declared GPR count gkgpr >= max_gpr + 3 (2 hardware-reserved 7 # PC GPRs). Any LOW or illegal instruction exits 4. 8 # 9 # Usage: 10 # sh tests/gpu-disasm.sh --all # check all 78 non-empty SM121 kernel slots 11 # sh tests/gpu-disasm.sh SLOT... # check specific slot ids (e.g. 0 27 40) 12 # 13 # Env: 14 # OMC Path to seeded omc (auto-detected if unset) 15 # OMC_PIN Optional expected sha256 of OMC (enforced only when set) 16 # OUT Scratch/output dir (default: ./build/gpu-disasm) 17 # NVDISASM Path to nvdisasm (default: /usr/local/cuda/bin/nvdisasm or PATH) 18 # SHAPE grset V T D H F B (default: "256 32 64 2 128 2") 19 # VERBOSE Set to 1 to print full SASS listings (default: 0 for --all, 1 for explicit slots) 20 set -eu 21 22 here=$(cd "$(dirname "$0")/.." && pwd) 23 OUT=${OUT:-$here/build/gpu-disasm} 24 SHAPE=${SHAPE:-256 32 64 2 128 2} 25 NVDISASM=${NVDISASM:-$(command -v nvdisasm 2>/dev/null || printf '/usr/local/cuda/bin/nvdisasm')} 26 27 find_omc() { 28 if [ -n "${OMC:-}" ] && [ -x "$OMC" ]; then 29 printf '%s\n' "$OMC" 30 return 0 31 fi 32 for cand in \ 33 "$(command -v omc 2>/dev/null || true)" \ 34 "$HOME/.local/bin/omc" \ 35 "$HOME/canon/omega-mv/seed/out/omc" \ 36 "$here/../omega-mv/seed/out/omc" 37 do 38 if [ -n "$cand" ] && [ -x "$cand" ]; then 39 printf '%s\n' "$cand" 40 return 0 41 fi 42 done 43 echo "error: seeded 'omc' compiler not found (set OMC=/path/to/omc)" >&2 44 exit 1 45 } 46 47 [ $# -ge 1 ] || { echo "usage: gpu-disasm.sh --all | SLOT..." >&2; exit 2; } 48 [ -x "$NVDISASM" ] || { echo "error: nvdisasm not found at '$NVDISASM'" >&2; exit 3; } 49 50 OMC=$(find_omc) 51 if [ -n "${OMC_PIN:-}" ]; then 52 got=$(sha256sum "$OMC" | cut -d' ' -f1) 53 [ "$got" = "$OMC_PIN" ] || { echo "OMC_PIN_MISMATCH $got" >&2; exit 3; } 54 fi 55 56 if [ "$1" = "--all" ]; then 57 VERBOSE=${VERBOSE:-0} 58 set -- 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 42 44 46 48 50 52 54 56 58 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 59 else 60 VERBOSE=${VERBOSE:-1} 61 fi 62 63 mkdir -p "$OUT" 64 src=$here/native 65 g=$src/gpu 66 67 { 68 printf 'om2\n' 69 cat "$src/math.om" "$src/data.om" "$src/lpool.om" "$src/model.om" "$src/adam.om" "$src/ckpt.om" "$src/bpe.om" "$src/spec.om" "$src/rev.om" "$src/arboris.om" "$src/sp_solve.om" "$src/spiral.om" "$src/apu_weave.om" "$src/omg.om" "$src/pillars_cli.om" "$src/cli.om" "$src/lio.om" "$src/noserve.om" | 70 sed 's/^fn main to int$/fn ocpumain to int/' 71 cat "$g/context.om" "$g/vector.om" "$g/launch.om" "$g/batch.om" "$g/gk.om" "$g/gr.om" "$g/gb.om" "$g/gg.om" "$g/gt.om" "$g/gm.om" "$g/ring.om" "$g/ejit.om" "$src/apu_fabric_linux.om" "$src/apu_fabric_gb10.om" 72 sed "s/^grset 256 32 64 2 128 2\$/grset $SHAPE/" "$here/tests/gpu-dump.om" 73 } > "$OUT/gpu-dump.om" 74 grep -qx "grset $SHAPE" "$OUT/gpu-dump.om" || { echo "SHAPE_NOT_SET $SHAPE" >&2; exit 2; } 75 76 "$OMC" < "$OUT/gpu-dump.om" > "$OUT/gpu-dump.tmp" 77 chmod +x "$OUT/gpu-dump.tmp" 78 mv -f "$OUT/gpu-dump.tmp" "$OUT/gpu-dump" 79 80 "$OUT/gpu-dump" > "$OUT/gpu-code.bin" 2> "$OUT/gpu-gpr.bin" 81 [ "$(wc -c < "$OUT/gpu-gpr.bin")" -eq 196 ] || { echo "GPR_TABLE_SIZE $(wc -c < "$OUT/gpu-gpr.bin")" >&2; exit 2; } 82 echo "DUMP $(sha256sum "$OUT/gpu-dump" | cut -d' ' -f1) source_sha256 $(sha256sum "$OUT/gpu-dump.om" | cut -d' ' -f1) code_sha256 $(sha256sum "$OUT/gpu-code.bin" | cut -d' ' -f1)" 83 84 bad=0 85 ok_slots=0 86 for s in "$@"; do 87 ns=1 88 [ "$s" -ge 40 ] && [ "$s" -le 58 ] && ns=2 89 dd if="$OUT/gpu-code.bin" of="$OUT/gpu-slot$s.bin" bs=16384 skip="$s" count="$ns" status=none 90 last=$(od -An -v -tu1 "$OUT/gpu-slot$s.bin" | tr -s ' ' '\n' | awk 'NF { n++; if ($1 != 0) l = n } END { print l + 0 }') 91 n=$(( (last + 15) / 16 * 16 )) 92 head -c "$n" "$OUT/gpu-slot$s.bin" > "$OUT/gpu-slot$s.t.bin" 93 [ "$VERBOSE" = 1 ] && echo "SLOT $s bytes $n sha256 $(sha256sum "$OUT/gpu-slot$s.t.bin" | cut -d' ' -f1)" 94 [ "$n" -eq 0 ] && { echo "SLOT $s empty"; continue; } 95 "$NVDISASM" -b SM121 "$OUT/gpu-slot$s.t.bin" > "$OUT/gpu-slot$s.sass" 96 [ "$VERBOSE" = 1 ] && cat "$OUT/gpu-slot$s.sass" 97 if grep -qi 'illegal\|unknown' "$OUT/gpu-slot$s.sass"; then 98 echo "SLOT $s ILLEGAL_INSN" >&2 99 bad=1 100 continue 101 fi 102 d=$(od -An -tu1 -j "$s" -N1 "$OUT/gpu-gpr.bin" | tr -d ' ') 103 awk -v s="$s" -v d="$d" -v v="$VERBOSE" ' 104 function scan(x, ext, t, e, v2) { 105 x = " " x 106 while (match(x, /[^A-Za-z0-9_.]R[0-9]+(\.64)?/)) { 107 t = substr(x, RSTART + 2, RLENGTH - 2); e = ext 108 if (t ~ /\.64$/) { e = 1; sub(/\.64$/, "", t) } 109 v2 = t + e; if (v2 > mx) mx = v2 110 x = substr(x, RSTART + RLENGTH) 111 } 112 } 113 BEGIN { mx = -1 } 114 match($0, /\/\*[0-9a-f]+\*\//) { 115 r = substr($0, RSTART + RLENGTH); sub(/;.*/, "", r); sub(/^[ \t]+/, "", r) 116 if (r ~ /^@/) sub(/^[^ \t]+[ \t]+/, "", r) 117 op = r; sub(/[ \t].*/, "", op); sub(/^[^ \t]+/, "", r) 118 w = 1; if (op ~ /\.128/) w = 4; else if (op ~ /\.64|\.WIDE/) w = 2 119 while (match(r, /\[[^]]*\]/)) { 120 p = RSTART; l = RLENGTH 121 scan(substr(r, p, l), 0) 122 r = substr(r, 1, p - 1) " " substr(r, p + l) 123 } 124 scan(r, w - 1) 125 } 126 END { 127 k = mx + 3 128 if (v == 1 || d < k) printf "GPR %s max R%d need %d declared %d %s\n", s, mx, k, d, (d >= k ? "OK" : "LOW") 129 exit (d >= k ? 0 : 4) 130 } 131 ' "$OUT/gpu-slot$s.sass" && ok_slots=$((ok_slots + 1)) || bad=1 132 [ "$VERBOSE" = 1 ] && echo "SMEM $s target $(od -An -tu1 -j $((96 + s)) -N1 "$OUT/gpu-gpr.bin" | tr -d ' ')" 133 done 134 echo "GPU_DISASM_OK slots=$ok_slots bad=$bad" 135 [ "$bad" -eq 0 ] || { echo "GPU_DISASM_FAIL" >&2; exit 4; }