diff --git a/docs/maxusai/tasks/mmq-29953-guard-timing.sh b/docs/maxusai/tasks/mmq-29953-guard-timing.sh new file mode 100755 index 00000000000..fb5ded4097f --- /dev/null +++ b/docs/maxusai/tasks/mmq-29953-guard-timing.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +# What the y-tile guard costs at compile time: mmq.cu on #29953's head (3070d927f) with the guard patch, nvcc 12.8, +# sm_120, built REPS times with the guard on and REPS times with it compiled out, interleaved so drifting host load +# hits both alike. Prints each time and the medians. One build is too noisy to quote (first run 9.8 vs 8.9 s, second +# 11.2 vs 7.9 s). +set -u +cd "$(dirname "$0")" || exit 1 +HERE=$PWD +REPS=${REPS:-5} +WT=$HERE/wt-29953-guard-timing +OUT=$HERE/guard-timing-results +CUDA_HOME=${CUDA_HOME:-/usr/local/cuda-12.8} +unset CPATH C_INCLUDE_PATH CPLUS_INCLUDE_PATH +rm -rf "$WT" "$OUT"; mkdir -p "$OUT"; git -C llama.cpp worktree prune +git -C llama.cpp worktree add --quiet --detach "$WT" 3070d927f6c172242d56a2c1fb897e838e7b2632 || exit 1 +trap 'cd "$HERE"; git -C llama.cpp worktree remove --force "$WT" 2>/dev/null' EXIT +cd "$WT" && git apply "$HERE/mmq-29953-y-tile-guard.patch" || exit 1 +CU=ggml/src/ggml-cuda/mmq.cu +cp "$CU" "$OUT/on.cu" +sed 's/^# define GGML_CUDA_MMQ_Y_TILE_GUARD_ON$/\/\/ off/; s/^# define GGML_CUDA_MMQ_Y_TILE_GUARD_ON$/\/\/ off/' "$OUT/on.cu" > "$OUT/off.cu" +cmp -s "$OUT/on.cu" "$OUT/off.cu" && { echo "the off variant is identical to on: sed matched nothing"; exit 1; } +echo "host load at start (1/5/15 min): $(cut -d' ' -f1-3 /proc/loadavg), $(nproc) cores" +build() { cp "$OUT/$1.cu" "$CU"; local t0 t1; t0=$(date +%s.%N) + "$CUDA_HOME/bin/nvcc" -Wno-deprecated-gpu-targets -std=c++17 -gencode arch=compute_120,code=sm_120 \ + -I. -Iggml/include -Iggml/src -Iggml/src/ggml-cuda -c "$CU" -o "$OUT/mmq.o" > "$OUT/$1.log" 2>&1 || { echo "build $1 failed"; exit 1; } + t1=$(date +%s.%N); awk -v a="$t0" -v b="$t1" 'BEGIN{printf "%.2f", b-a}'; } +on=(); off=() +for r in $(seq 1 "$REPS"); do + a=$(build on); b=$(build off); on+=("$a"); off+=("$b") + printf 'rep %d: guard on %ss, off %ss\n' "$r" "$a" "$b" +done +med() { printf '%s\n' "$@" | sort -n | awk '{v[NR]=$1} END {print (NR%2 ? v[(NR+1)/2] : (v[NR/2]+v[NR/2+1])/2)}'; } +echo "median: guard on $(med "${on[@]}")s, off $(med "${off[@]}")s, over $REPS interleaved reps" +echo "host load at end (1/5/15 min): $(cut -d' ' -f1-3 /proc/loadavg)" diff --git a/docs/maxusai/tasks/mmq-29953-guard-verify.sh b/docs/maxusai/tasks/mmq-29953-guard-verify.sh new file mode 100755 index 00000000000..ca1c10f4bea --- /dev/null +++ b/docs/maxusai/tasks/mmq-29953-guard-verify.sh @@ -0,0 +1,102 @@ +#!/usr/bin/env bash +# A compile-time guard for MMQ's y tile on top of llama.cpp#29953's head (3070d927f): material for upstream, GPU-free. +# +# mmq-29953-y-tile-guard.patch routes the src1 padding and the shared-memory y tile through one helper, +# ggml_cuda_mmq_get_nbytes_y_tile(), and asserts at compile time -- for every config table and type -- that the +# helper covers the y load loop's extent, written from the loop with exact ceiling division. Five nvcc builds of +# mmq.cu for sm_120, each scored by WHY it failed, not just whether: +# 1. the head as is, unpatched -> must compile (baseline time) +# 2. the head with the patch -> must compile +# 3. helper shrunk to J blocks -> must FAIL by the guard, naming every table (the published #29953's rule) +# 4. helper rounded to one warp's ints -> must FAIL by the guard, naming every table +# 5. one blackwell config at 192 threads-> must FAIL by the guard naming ONLY blackwell: GGML_PAD is a bit mask +# that assumes a power-of-two granularity, the tables only assert +# nthreads % 32 == 0, and the guard's exact arithmetic sees the gap +# nvcc's front end stops at 100 errors by default, which cut mutation 3's table list to the first five tables; +# --error_limit lifts that so every table that fails is named. +# Usage: mmq-29953-guard-verify.sh (from its own directory, with a llama.cpp clone at ./llama.cpp that has +# 3070d927f fetched; results go to ./verify-29953-guard-results) +set -u +cd "$(dirname "$0")" || exit 1 +HERE=$PWD +PATCH=$HERE/mmq-29953-y-tile-guard.patch +WT=$HERE/wt-29953-guard-verify +OUT=$HERE/verify-29953-guard-results +CUDA_HOME=${CUDA_HOME:-/usr/local/cuda-12.8} +HEAD29953=3070d927f6c172242d56a2c1fb897e838e7b2632 +unset CPATH C_INCLUDE_PATH CPLUS_INCLUDE_PATH +rm -rf "$OUT"; mkdir -p "$OUT" +echo "host load at start (1/5/15 min): $(cut -d' ' -f1-3 /proc/loadavg), $(nproc) cores" + +rm -rf "$WT"; git -C llama.cpp worktree prune +git -C llama.cpp worktree add --quiet --detach "$WT" "$HEAD29953" || exit 1 +trap 'cd "$HERE"; git -C llama.cpp worktree remove --force "$WT" 2>/dev/null' EXIT +cd "$WT" || exit 1 +CU=ggml/src/ggml-cuda/mmq.cu; CUH=ggml/src/ggml-cuda/mmq.cuh; BW=ggml/src/ggml-cuda/mmq-config-blackwell.cuh + +build() { #