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 / latmeas / run_spark.sh
| 1 | #!/bin/sh |
| 2 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | # One-shot GB10 latency run. Builds and encodes before taking the shared lock. |
| 4 | # Usage: sh tools/latmeas/run_spark.sh OUTPUT_DIR |
| 5 | set -eu |
| 6 | if [ $# -ne 1 ] || [ -z "$1" ]; then |
| 7 | echo "usage: sh tools/latmeas/run_spark.sh OUTPUT_DIR" >&2 |
| 8 | exit 2 |
| 9 | fi |
| 10 | root=$(CDPATH= cd -- "$(dirname -- "$0")/../.." && pwd) |
| 11 | out=$1 |
| 12 | case "$out" in |
| 13 | /*) ;; |
| 14 | *) out=$root/$out ;; |
| 15 | esac |
| 16 | cd "$root" |
| 17 | |
| 18 | write_receipt() { |
| 19 | rec=$1/RECEIPT.txt |
| 20 | gitdir=${CUDAPP_RECEIPT_GIT:-.} |
| 21 | launch_cmd=${2:-} |
| 22 | launch_rc=${3:-} |
| 23 | { |
| 24 | echo "utc: $(date -u +%Y-%m-%dT%H:%M:%SZ)" |
| 25 | echo "head: $(git -C "$gitdir" rev-parse HEAD)" |
| 26 | echo "head_parents: $(git -C "$gitdir" rev-parse HEAD^@ 2>/dev/null | tr '\n' ' ')" |
| 27 | if [ -n "$(git -C "$gitdir" status --porcelain)" ]; then |
| 28 | echo "worktree: dirty" |
| 29 | else |
| 30 | echo "worktree: clean" |
| 31 | fi |
| 32 | if [ -n "$launch_cmd" ]; then |
| 33 | echo "launch_command: $launch_cmd" |
| 34 | echo "launch_rc: $launch_rc" |
| 35 | fi |
| 36 | echo "kernel: $(uname -srvm)" |
| 37 | echo "gcc: $(gcc --version | head -n 1)" |
| 38 | if [ -r /proc/driver/nvidia/version ]; then |
| 39 | echo "driver: $(head -n 1 /proc/driver/nvidia/version)" |
| 40 | else |
| 41 | echo "driver: unread" |
| 42 | fi |
| 43 | found=0 |
| 44 | sysroot=${CUDAPP_RECEIPT_SYSROOT:-} |
| 45 | for info in ${CUDAPP_RECEIPT_GPU_INFO:-/proc/driver/nvidia/gpus/*/information}; do |
| 46 | [ -f "$info" ] || continue |
| 47 | found=1 |
| 48 | bdf=$(basename "$(dirname "$info")") |
| 49 | echo "device: $bdf" |
| 50 | model=$(sed -n 's/^Model:[[:space:]]*//p' "$info" | head -n 1) |
| 51 | bus=$(sed -n 's/^Bus Location:[[:space:]]*//p' "$info" | head -n 1) |
| 52 | # The open module prints "Model: Unknown" for the GB10. The doctor names |
| 53 | # that chip from PCI id 0x2e12 (src/omega_gpu_chip.c). |
| 54 | if [ -z "$model" ] || [ "$model" = "Unknown" ]; then |
| 55 | ven=$(cat "$sysroot/sys/bus/pci/devices/$bdf/vendor" 2>/dev/null || true) |
| 56 | dev=$(cat "$sysroot/sys/bus/pci/devices/$bdf/device" 2>/dev/null || true) |
| 57 | ven=$(printf '%s' "$ven" | tr -d '[:space:]') |
| 58 | dev=$(printf '%s' "$dev" | tr -d '[:space:]') |
| 59 | if [ "$ven" = "0x10de" ] && [ "$dev" = "0x2e12" ]; then |
| 60 | echo "model: NVIDIA GB10 (sm_121)" |
| 61 | echo "model_source: pci 0x2e12; proc Model was ${model:-empty}" |
| 62 | else |
| 63 | echo "model: Unknown" |
| 64 | echo "model_source: proc Model was ${model:-empty}; pci ${ven:-unread}:${dev:-unread}" |
| 65 | fi |
| 66 | else |
| 67 | echo "model: $model" |
| 68 | fi |
| 69 | if [ -n "$bus" ]; then |
| 70 | echo "bus: $bus" |
| 71 | fi |
| 72 | done |
| 73 | if [ "$found" -eq 0 ]; then |
| 74 | echo "device: none" |
| 75 | fi |
| 76 | if [ -f "$1/raw.json" ]; then |
| 77 | echo "raw_json_sha256: $(sha256sum "$1/raw.json" | awk '{print $1}')" |
| 78 | else |
| 79 | echo "raw_json_sha256: absent" |
| 80 | fi |
| 81 | } > "$rec" |
| 82 | echo "latmeas: wrote $rec" |
| 83 | } |
| 84 | |
| 85 | if [ "$1" = "--receipt-self-test" ]; then |
| 86 | tmp=$(mktemp -d) |
| 87 | printf '{}\n' > "$tmp/raw.json" |
| 88 | write_receipt "$tmp" "flock /tmp/aien-gb10.lock timeout 600 ./build/gpu_latmeas_test --launch $tmp/kernels --out $tmp/raw.json" 0 |
| 89 | got=$(awk '/^raw_json_sha256: / {print $2}' "$tmp/RECEIPT.txt") |
| 90 | want=$(sha256sum "$tmp/raw.json" | awk '{print $1}') |
| 91 | grep -q '^utc: ' "$tmp/RECEIPT.txt" |
| 92 | grep -q '^head: ' "$tmp/RECEIPT.txt" |
| 93 | grep -q '^head_parents: ' "$tmp/RECEIPT.txt" |
| 94 | grep -q '^kernel: ' "$tmp/RECEIPT.txt" |
| 95 | grep -q '^gcc: ' "$tmp/RECEIPT.txt" |
| 96 | grep -q '^device: ' "$tmp/RECEIPT.txt" |
| 97 | test "$got" = "$want" |
| 98 | grep -q '^launch_command: ' "$tmp/RECEIPT.txt" |
| 99 | grep -q '^launch_rc: 0$' "$tmp/RECEIPT.txt" |
| 100 | rm -rf "$tmp" |
| 101 | # proc Model "Unknown" plus PCI 10de:2e12 is the GB10 the doctor names. |
| 102 | fake=$(mktemp -d) |
| 103 | mkdir -p "$fake/gpus/000f:01:00.0" "$fake/sys/bus/pci/devices/000f:01:00.0" |
| 104 | printf 'Model: Unknown\nBus Location: 000f:01:00.0\n' > "$fake/gpus/000f:01:00.0/information" |
| 105 | printf '0x10de\n' > "$fake/sys/bus/pci/devices/000f:01:00.0/vendor" |
| 106 | printf '0x2e12\n' > "$fake/sys/bus/pci/devices/000f:01:00.0/device" |
| 107 | printf '{}\n' > "$fake/raw.json" |
| 108 | CUDAPP_RECEIPT_SYSROOT=$fake CUDAPP_RECEIPT_GPU_INFO=$fake/gpus/000f:01:00.0/information \ |
| 109 | write_receipt "$fake" |
| 110 | grep -q '^model: NVIDIA GB10 (sm_121)$' "$fake/RECEIPT.txt" |
| 111 | grep -q '^model_source: pci 0x2e12' "$fake/RECEIPT.txt" |
| 112 | rm -rf "$fake" |
| 113 | # An untracked file must mark the tree dirty. git diff --quiet would miss it. |
| 114 | repo=$(mktemp -d) |
| 115 | rout=$(mktemp -d) |
| 116 | git -C "$repo" init -q |
| 117 | git -C "$repo" config user.email receipt@example.com |
| 118 | git -C "$repo" config user.name receipt |
| 119 | echo tracked > "$repo/a" |
| 120 | git -C "$repo" add a |
| 121 | git -C "$repo" commit -q -m init |
| 122 | printf '{}\n' > "$rout/raw.json" |
| 123 | echo untracked > "$repo/untracked" |
| 124 | CUDAPP_RECEIPT_GIT=$repo write_receipt "$rout" "launch-cmd" 7 |
| 125 | grep -q '^worktree: dirty$' "$rout/RECEIPT.txt" |
| 126 | grep -q '^launch_rc: 7$' "$rout/RECEIPT.txt" |
| 127 | rm "$repo/untracked" |
| 128 | CUDAPP_RECEIPT_GIT=$repo write_receipt "$rout" "launch-cmd" 0 |
| 129 | grep -q '^worktree: clean$' "$rout/RECEIPT.txt" |
| 130 | rm -rf "$repo" "$rout" |
| 131 | echo "receipt self-test PASS" |
| 132 | exit 0 |
| 133 | fi |
| 134 | |
| 135 | mkdir -p "$out" |
| 136 | echo "latmeas: building (outside the chip lock)" |
| 137 | make -j"$(nproc)" build/gpu_latmeas_test build/cudapp-doctor |
| 138 | echo "latmeas: doctor (outside the chip lock; NOT READY aborts before flock)" |
| 139 | ./build/cudapp-doctor |
| 140 | git rev-parse HEAD > "$out/head.txt" |
| 141 | ./build/gpu_latmeas_test --print-plan |
| 142 | ./build/gpu_latmeas_test --emit "$out/kernels" |
| 143 | python3 tools/latmeas/diff_nak.py --check --md "$out/diff.md" |
| 144 | echo "latmeas: taking flock /tmp/aien-gb10.lock for the launch only; timeout 600" |
| 145 | echo "latmeas: the launch bound is the estimated chip window printed above" |
| 146 | # flock waits here without holding the lock. timeout covers only the launch. |
| 147 | set +e |
| 148 | launch_cmd="flock /tmp/aien-gb10.lock timeout 600 ./build/gpu_latmeas_test --launch $out/kernels --out $out/raw.json" |
| 149 | flock /tmp/aien-gb10.lock timeout 600 ./build/gpu_latmeas_test --launch "$out/kernels" --out "$out/raw.json" |
| 150 | rc=$? |
| 151 | set -e |
| 152 | if [ -f "$out/raw.json" ]; then |
| 153 | python3 tools/latmeas/fill_template.py --results "$out/raw.json" --md "$out/sm121_vs_NAK.md" |
| 154 | fi |
| 155 | write_receipt "$out" "$launch_cmd" "$rc" |
| 156 | exit "$rc" |