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 / coder / bench.sh

93 lines · 4904 bytes Raw Blame History
1#!/bin/bash
2# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3# ERC1 host decode rate: bytes of decoded matrix per second, one thread on one core.
4# bash tests/coder/bench.sh OMC OUTDIR CORE [CHECKPOINT_DIR]
5# Takes the pool locks of CORE (the queen's pool-CORE.lock and /tmp/omega-pool-CORE.lock, waits when held),
6# pins the process with taskset, and records the conditions it ran under (load, other busy cores, CPU model).
7# It measures the host decoder only. It is not a GPU number and not a tokens-per-second number.
8export LC_ALL=C
9HERE=$(cd "$(dirname "$0")" && pwd)
10ROOT=$(cd "$HERE/../.." && pwd)
11. "$HERE/lib.sh"
12OMC=${1:?usage: bench.sh OMC OUTDIR CORE [CHECKPOINT_DIR]}
13OUT=${2:?usage: bench.sh OMC OUTDIR CORE [CHECKPOINT_DIR]}
14CORE=${3:?usage: bench.sh OMC OUTDIR CORE [CHECKPOINT_DIR]}
15CK=${4:-$HOME/models/qwen3.8-flash-next-fp8-7fb48d70}
16REPS=${REPS:-50}
17RUNS=${RUNS:-7}
18mkdir -p "$OUT"
19W=$OUT/work
20mkdir -p "$W"
21ERC=$W/erc
22build "$OMC" "$ROOT/om/coder/erc.om" "$ERC" || { echo "ERC1 BENCH FAIL: compile"; exit 1; }
23
24conditions() { # LABEL
25 {
26 echo "== $1 $(date -u +%FT%TZ)"
27 echo "uptime: $(uptime)"
28 echo "nproc: $(nproc)"
29 echo "pinned core $CORE: $(lscpu -e=CPU,MAXMHZ,MODELNAME 2> /dev/null | grep -E "^ *$CORE " | tr -s ' ')"
30 echo "kernel: $(uname -srm)"
31 mapfile -t A < <(grep '^cpu[0-9]' /proc/stat); sleep 2; mapfile -t B < <(grep '^cpu[0-9]' /proc/stat)
32 local i a b k ta tb idle tot line=""
33 for i in "${!A[@]}"; do
34 read -r -a a <<< "${A[$i]}"; read -r -a b <<< "${B[$i]}"; ta=0; tb=0
35 for k in 1 2 3 4 5 6 7 8; do ta=$((ta + a[k])); tb=$((tb + b[k])); done
36 idle=$((b[4] - a[4])); tot=$((tb - ta))
37 line="$line ${a[0]}:$(((tot - idle) * 100 / tot))%"
38 done
39 echo "busy over 2 s:$line"
40 echo "top consumers:"; top -b -n 1 2> /dev/null | sed -n '7,16p'
41 } >> "$OUT/conditions.txt"
42}
43: > "$OUT/conditions.txt"
44
45# three real matrices: gate, up and down of one layer and expert (the first complete layer found)
46mats=""
47for f in "$CK"/model-*.safetensors; do
48 [ -e "$f.aria2" ] && continue
49 n=$(od -An -t u8 -N8 "$f" | tr -d ' ')
50 head -c $((8 + n)) "$f" | tail -c "$n" | jq -r --arg f "$f" --argjson base $((8 + n)) '
51 to_entries[] | select(.key | test("^model\\.language_model\\.layers\\.12\\.mlp\\.experts\\.7\\.(gate|up|down)_proj\\.weight$"))
52 | [$f, .key, ($base + .value.data_offsets[0]), (.value.shape | map(tostring) | join(" "))] | @tsv' >> "$W/sel.tsv"
53done
54[ "$(wc -l < "$W/sel.tsv")" = 3 ] || { echo "ERC1 BENCH FAIL: layer 12 expert 7 not complete in the checkpoint"; exit 1; }
55
56conditions "before"
57printf 'tensor\tbytes\tcoded_bytes\trun\tmode\treps\tns\tbytes_per_s\n' > "$OUT/runs.tsv"
58while IFS=$'\t' read -r shard name off shape; do
59 set -- $shape; r=$1; c=$2
60 "$ERC" encode "$shard" "$off" "$r" "$c" "$W/b.erc" > /dev/null || exit 1
61 ez=$(stat -c %s "$W/b.erc")
62 for run in $(seq 1 "$RUNS"); do
63 out=$(flock "$HOME/handoffs/hive/queen/pool-$CORE.lock" flock "/tmp/omega-pool-$CORE.lock" taskset -c "$CORE" "$ERC" bench "$W/b.erc" "$REPS") || { echo "ERC1 BENCH FAIL: bench"; exit 1; }
64 echo "$out" | while read -r l; do
65 mode=$(echo "$l" | sed 's/^mode=\([a-z0-9_]*\) .*/\1/')
66 ns=$(echo "$l" | sed 's/.* ns=\([0-9]*\) .*/\1/')
67 bps=$(echo "$l" | sed 's/.*bytes_per_s=//')
68 printf '%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n' "$name" "$((r * c))" "$ez" "$run" "$mode" "$REPS" "$ns" "$bps" >> "$OUT/runs.tsv"
69 done
70 done
71done < "$W/sel.tsv"
72conditions "after"
73
74# per mode and matrix: min, median and max of the runs, bytes per second, then MB/s (10^6 bytes) by aien-calc
75: > "$OUT/summary.txt"
76for mode in rans_only row_crc16_and_rans row_crc16_rans_matrix_crc32; do
77 for name in $(cut -f2 "$W/sel.tsv"); do
78 vals=$(grep -P "^$name\t[0-9]+\t[0-9]+\t[0-9]+\t$mode\t" "$OUT/runs.tsv" | cut -f8 | sort -n)
79 lo=$(echo "$vals" | head -1); hi=$(echo "$vals" | tail -1); med=$(echo "$vals" | sed -n "$(((RUNS + 1) / 2))p")
80 echo "$mode $name min=$lo median=$med max=$hi bytes_per_s" >> "$OUT/summary.txt"
81 done
82done
83# a rate of 0 or a missing run is a failure, not a number
84echo "--- MB/s (10^6 bytes per second) of the median run, aien-calc" >> "$OUT/summary.txt"
85for mode in rans_only row_crc16_and_rans row_crc16_rans_matrix_crc32; do
86 for name in $(cut -f2 "$W/sel.tsv"); do
87 med=$(grep -P "^$name\t[0-9]+\t[0-9]+\t[0-9]+\t$mode\t" "$OUT/runs.tsv" | cut -f8 | sort -n | sed -n "$(((RUNS + 1) / 2))p")
88 echo "$mode $name median $(aien-calc eval "$med/1000000" | sed -n 's/^decimal *//p') MB/s ($(aien-calc eval "$med/1000000" | sed -n 's/^receipt //p'))" >> "$OUT/summary.txt"
89 done
90done
91cat "$OUT/summary.txt"
92rm -f "$W/b.erc"
93echo "ERC1 BENCH DONE runs=$RUNS reps=$REPS core=$CORE"