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
CUDApp / tools / artifact_smoke.sh
| 1 | #!/bin/sh |
| 2 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | # Offline smoke for exported native artifacts. Uses nvdisasm/cuobjdump only if |
| 4 | # present; they are independent readers, never build inputs. Opens no device. |
| 5 | set -eu |
| 6 | dir=${1:-build/artifact-test} |
| 7 | fail=0 |
| 8 | for c in "$dir"/*.cubin; do |
| 9 | [ -f "$c" ] || continue |
| 10 | echo "== $c" |
| 11 | m=${c%.cubin}.manifest |
| 12 | # Omega's own sm_121 disassembler reads the kernel text (the manifest's text role, the words inside the cubin); |
| 13 | # every word must be a known form (CUDA++ C6, DRA-475). nvdisasm below is an independent ORACLE reader only. |
| 14 | t=${c%.cubin}.text.bin |
| 15 | dis=${SM121DIS:-build/sm121dis} |
| 16 | if [ -x "$dis" ] && [ -f "$t" ]; then |
| 17 | "$dis" -b SM121 "$t" >/dev/null && echo "sm121dis: PASS ($(( $(wc -c < "$t") / 16 )) words)" || { echo "sm121dis: FAIL"; fail=1; } |
| 18 | else |
| 19 | echo "sm121dis: NOT_RUN ($dis or $t missing)" |
| 20 | fi |
| 21 | if command -v nvdisasm >/dev/null 2>&1; then |
| 22 | nvdisasm -c "$c" >/dev/null && echo "nvdisasm: PASS" || { echo "nvdisasm: FAIL"; fail=1; } |
| 23 | else |
| 24 | echo "nvdisasm: NOT_RUN (not installed)" |
| 25 | fi |
| 26 | if command -v cuobjdump >/dev/null 2>&1; then |
| 27 | cuobjdump -res-usage "$c" >/dev/null && echo "cuobjdump: PASS" || { echo "cuobjdump: FAIL"; fail=1; } |
| 28 | meta=$(cuobjdump -elf "$c" 2>/dev/null || true) |
| 29 | regs=$(sed -n 's/^gpr_count=//p' "$m" 2>/dev/null || true) |
| 30 | if [ -n "$regs" ] && ! printf '%s\n' "$meta" | grep -q "register count: $regs"; then |
| 31 | echo "REGCOUNT does not match manifest"; fail=1 |
| 32 | fi |
| 33 | if printf '%s\n' "$meta" | grep -q "EIATTR_EXIT_INSTR_OFFSETS"; then |
| 34 | echo "fabricated EXIT_INSTR_OFFSETS present"; fail=1 |
| 35 | fi |
| 36 | if ! printf '%s\n' "$meta" | grep -q "Ordinal : 0x0"; then |
| 37 | echo "KPARAM ordinal 0 missing"; fail=1 |
| 38 | fi |
| 39 | psize=$(printf '%s\n' "$meta" | awk '/EIATTR_CBANK_PARAM_SIZE/{f=1;next} f&&/Value:/{print $2;exit}') |
| 40 | pcb=$(printf '%s\n' "$meta" | awk '/EIATTR_PARAM_CBANK/{f=1;next} f&&/Value:/{print $3;exit}') |
| 41 | if [ -n "$psize" ] && [ -n "$pcb" ]; then |
| 42 | hi=$(( (pcb >> 16) & 0xffff )) |
| 43 | ps=$(( psize )) |
| 44 | [ "$hi" -eq "$ps" ] || { echo "PARAM_CBANK size $hi != CBANK_PARAM_SIZE $ps"; fail=1; } |
| 45 | else |
| 46 | echo "parameter cbank metadata missing"; fail=1 |
| 47 | fi |
| 48 | shnum=$(readelf -h "$c" 2>/dev/null | sed -n 's/.*Number of section headers:[[:space:]]*//p') |
| 49 | [ "$shnum" = "12" ] || { echo "unexpected section count: $shnum"; fail=1; } |
| 50 | # The driver refuses an sm_121 image without the toolkit note (200 INVALID_IMAGE on GB10, evidence/MAX-INTEROP/G2). |
| 51 | readelf -S "$c" 2>/dev/null | grep -q '\.note\.nv\.tkinfo' || { echo ".note.nv.tkinfo missing"; fail=1; } |
| 52 | else |
| 53 | echo "cuobjdump: NOT_RUN (not installed)" |
| 54 | fi |
| 55 | [ -f "$m" ] || { echo "manifest missing: $m"; fail=1; continue; } |
| 56 | id=$(sed -n 's/^artifact_id=//p' "$m") |
| 57 | echo "artifact_id=$id" |
| 58 | # Every listed role digest must equal the file next to the manifest. |
| 59 | for role in cubin text qmd0 qmd1 cbank_args; do |
| 60 | want=$(sed -n "s/^${role}_sha256=//p" "$m") |
| 61 | case $role in |
| 62 | cubin) f=${c%.cubin}.cubin ;; |
| 63 | text) f=${c%.cubin}.text.bin ;; |
| 64 | qmd0) f=${c%.cubin}.qmd0.bin ;; |
| 65 | qmd1) f=${c%.cubin}.qmd1.bin ;; |
| 66 | cbank_args) f=${c%.cubin}.cbank_args.bin ;; |
| 67 | esac |
| 68 | got=$(sha256sum "$f" | cut -d' ' -f1) |
| 69 | [ "$want" = "$got" ] || { echo "digest mismatch $role"; fail=1; } |
| 70 | done |
| 71 | done |
| 72 | # The frozen v1 bounds and ids are enforced by the exporter itself. |
| 73 | if [ -x ./build/artifact-export ]; then |
| 74 | cm=647116fc1ba1e1394982fc8ba181ce565293f160a6b56afc0f02b2128a675704 |
| 75 | ca=003696e422bba7274877ba9e01a61076ea0f862f32760cbaa06c60f85a115359 |
| 76 | if ./build/artifact-export matmul --m 16 --k 16 --n 9000 --contract-id $cm --out /tmp/oob --commit 0000000000000000000000000000000000000000 2>/dev/null; then |
| 77 | echo "out-of-contract n accepted"; fail=1 |
| 78 | fi |
| 79 | if ./build/artifact-export matmul --m 16 --k 16 --n 8 --contract-id $ca --out /tmp/oob --commit 0000000000000000000000000000000000000000 2>/dev/null; then |
| 80 | echo "wrong contract id accepted"; fail=1 |
| 81 | fi |
| 82 | if ./build/artifact-export attention --q-heads 96 --kv-heads 3 --contract-id $ca --out /tmp/oob --commit 0000000000000000000000000000000000000000 2>/dev/null; then |
| 83 | echo "out-of-contract heads accepted"; fail=1 |
| 84 | fi |
| 85 | fi |
| 86 | [ $fail -eq 0 ] && echo "ARTIFACT SMOKE PASS" |
| 87 | exit $fail |