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/aien-train/blob/main/tests/omegallm/gpu-disasm.sh # aien-train AIEN training programme: language-model history, GB10 constraints and the route to training on the project engine. Plans and runnable checks are distinguished. 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 `aien-train / tests / omegallm / gpu-disasm.sh` 89 lines ยท 5577 bytes Raw Blame History 1 #!/bin/sh 2 # Disassemble the GB10 kernels that native/omegallm/gpu/ emits (rung 4), with nvdisasm as a read-only 3 # oracle. Builds the gb10 sources (gg.om's main renamed ggmain) plus tests/omegallm/gpu-dump.om, runs 4 # the dump on the CPU (no GPU), cuts slot N (16 KiB at N * 16384; two slots for the 64x64 GEMM ids 40-58, whose kernels 5 # span two), trims trailing zero bytes to a 16-byte multiple (an untrimmed slot disassembles its zero tail 6 # as illegal instructions) and prints the listing. Then it checks the slot's declared GPR count gkgpr 7 # (the dump's stderr, one byte per id) against the highest GPR in the listing: the hardware burns 2 GPRs 8 # of the QMD count for the program counter (Mesa NAK sm70.rs hw_reserved_gprs), so gkgpr must be at 9 # least max + 3, else the kernel hangs on the chip (evidence/OMEGALLM/gpu-k8 attempt 1). The max is an 10 # upper bound: a .128/.64/.WIDE opcode widens every register operand outside brackets, a bracketed 11 # R.64 counts as a pair. Prints "GPR s max R m need k declared d OK|LOW"; any LOW exits 4. Then 12 # "SMEM s target t" with the slot's QMD TARGET_SM_CONFIG hw value (gk.om gksmw; KiB = (t - 1) * 4). 13 # Usage: sh tests/omegallm/gpu-disasm.sh SLOT... (0-7 GEMM 32x32, 9-24 gr.om, 25-26 fused-epilogue 14 # GEMM 32x32, 27-36 BF16 GEMM 64x64 (27-34 plain, 35/36 fused epilogue), 40-54 even GEMM 64x64, 15 # 56/58 fused-epilogue GEMM 64x64) 16 # Env: OMC (default ../omega-mv/seed/out/omc), OUT (default ../build), NVDISASM 17 # (default /usr/local/cuda/bin/nvdisasm), CORE (default 6), SHAPE (grset V T D H F B, default the 18 # parity shape "256 32 64 2 128 2"; "4096 256 256 8 1024 8" is the max shape, whose T 256 gives 19 # the softmax kernels 8 column chunks where the parity shape gives 1). 20 set -eu 21 here=$(cd "$(dirname "$0")/../.." && pwd) 22 PIN=`2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f` 23 OMC=${OMC:-$here/../omega-mv/seed/out/omc} 24 OUT=${OUT:-$here/../build} 25 NVDISASM=${NVDISASM:-/usr/local/cuda/bin/nvdisasm} 26 CORE=${CORE:-6} 27 SHAPE=${SHAPE:-256 32 64 2 128 2} 28 [ $# -ge 1 ] || { echo "usage: gpu-disasm.sh SLOT..." >&2; exit 2; } 29 got=$(sha256sum "$OMC" | cut -d' ' -f1) 30 [ "$got" = "$PIN" ] || { echo "OMC_PIN_MISMATCH $got" >&2; exit 3; } 31 mkdir -p "$OUT" 32 src=$here/native/omegallm 33 g=$src/gpu 34 # gk.om calls gb.om's BF16 check hooks and gb.om calls gg.om, so the dump takes the whole gb10 source; 35 # gg.om's main becomes ggmain (gpu-dump.om's main runs) and gg.om supplies model.om's ogmask hook. 36 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/cli.om" "$src/lio.om" | 37 sed 's/^fn main to int$/fn ocpumain to int/' > "$OUT/gpu-dump.om" 38 sed "s/^grset 256 32 64 2 128 2\$/grset $SHAPE/" "$here/tests/omegallm/gpu-dump.om" > "$OUT/gpu-dump-main.om" 39 grep -qx "grset $SHAPE" "$OUT/gpu-dump-main.om" || { echo "SHAPE_NOT_SET $SHAPE" >&2; exit 2; } 40 cat "$g/context.om" "$g/vector.om" "$g/launch.om" "$g/gk.om" "$g/gr.om" "$g/gb.om" >> "$OUT/gpu-dump.om" 41 n=$(grep -c '^fn main to int$' "$g/gg.om" || true) 42 [ "$n" = 1 ] || { echo "GG_MAIN_COUNT $n, want 1" >&2; exit 4; } 43 sed 's/^fn main to int$/fn ggmain to int/' "$g/gg.om" >> "$OUT/gpu-dump.om" 44 cat "$OUT/gpu-dump-main.om" >> "$OUT/gpu-dump.om" 45 taskset -c "$CORE" nice -n 19 "$OMC" < "$OUT/gpu-dump.om" > "$OUT/gpu-dump" 46 chmod +x "$OUT/gpu-dump" 47 "$OUT/gpu-dump" > "$OUT/gpu-code.bin" 2> "$OUT/gpu-gpr.bin" 48 [ "$(wc -c < "$OUT/gpu-gpr.bin")" -eq 128 ] || { echo "GPR_TABLE_SIZE $(wc -c < "$OUT/gpu-gpr.bin")" >&2; exit 2; } 49 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)" 50 for s in "$@"; do 51 ns=1 52 [ "$s" -ge 40 ] && [ "$s" -le 58 ] && ns=2 53 dd if="$OUT/gpu-code.bin" of="$OUT/gpu-slot$s.bin" bs=16384 skip="$s" count="$ns" status=none 54 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 }') 55 n=$(( (last + 15) / 16 * 16 )) 56 head -c "$n" "$OUT/gpu-slot$s.bin" > "$OUT/gpu-slot$s.t.bin" 57 echo "SLOT $s bytes $n sha256 $(sha256sum "$OUT/gpu-slot$s.t.bin" | cut -d' ' -f1)" 58 [ "$n" -eq 0 ] && { echo "SLOT $s empty"; continue; } 59 "$NVDISASM" -b SM121 "$OUT/gpu-slot$s.t.bin" > "$OUT/gpu-slot$s.sass" 60 cat "$OUT/gpu-slot$s.sass" 61 d=$(od -An -tu1 -j "$s" -N1 "$OUT/gpu-gpr.bin" | tr -d ' ') 62 awk -v s="$s" -v d="$d" ' 63 function scan(x, ext, t, e, v) { 64 x = " " x 65 while (match(x, /[^A-Za-z0-9_.]R[0-9]+(\.64)?/)) { 66 t = substr(x, RSTART + 2, RLENGTH - 2); e = ext 67 if (t ~ /\.64$/) { e = 1; sub(/\.64$/, "", t) } 68 v = t + e; if (v > mx) mx = v 69 x = substr(x, RSTART + RLENGTH) 70 } 71 } 72 BEGIN { mx = -1 } 73 match($0, /\/\*[0-9a-f]+\*\//) { 74 r = substr($0, RSTART + RLENGTH); sub(/;.*/, "", r); sub(/^[ \t]+/, "", r) 75 if (r ~ /^@/) sub(/^[^ \t]+[ \t]+/, "", r) 76 op = r; sub(/[ \t].*/, "", op); sub(/^[^ \t]+/, "", r) 77 w = 1; if (op ~ /\.128/) w = 4; else if (op ~ /\.64|\.WIDE/) w = 2 78 while (match(r, /\[[^]]*\]/)) { 79 p = RSTART; l = RLENGTH 80 scan(substr(r, p, l), 0) 81 r = substr(r, 1, p - 1) " " substr(r, p + l) 82 } 83 scan(r, w - 1) 84 } 85 END { k = mx + 3; printf "GPR %s max R%d need %d declared %d %s\n", s, mx, k, d, (d >= k ? "OK" : "LOW"); exit (d >= k ? 0 : 4) } 86 ' "$OUT/gpu-slot$s.sass" || bad=1 87 echo "SMEM $s target $(od -An -tu1 -j $((64 + s)) -N1 "$OUT/gpu-gpr.bin" | tr -d ' ')" 88 done 89 [ "${bad:-0}" -eq 0 ] || { echo "GPR_LOW" >&2; exit 4; }