Files
leleka/scripts/e2e/codex/speed/verify-hc-down-kernel-microbench-vs-upstream/build.sh
T
Pavlo RatushnyiandClaude Sonnet 5.5 aa2f237590 speed: kernel micro-benchmark of upstream gr_down_v3 (masks 0/5/133) against chain_gr_down_t2w8_nb4 (ledger U5)
Harness (one TU including upstream fused_gr.cu whole, ours from the sealed PTX through the driver API plus an nvcc cubin),
GPU queue stub, and the method note with input sha256. Not run on the GPU yet.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-09 23:26:26 +01:00

26 lines
2.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# Builds the micro-benchmark on the 5090 server (no GPU needed). Run from anywhere:
# bash build.sh /data/leleka-e2e/spd-gap/microbench/verify-hc-down-kernel-microbench-vs-upstream
# Layout under that directory (see MANIFEST there):
# upstream-src/ git archive of strata-upstream/main (include/, src/kernels/cuda/fused_gr.cu, s26_tsum.cuh), unmodified
# ours-src/ git archive of the repository commit (crates/cuda-driver/src/chain_window.{cu,ptx}, engine/strata/include)
# harness/ this directory of the repository (scripts/e2e/codex/speed/verify-hc-down-kernel-microbench-vs-upstream/):
# microbench.cu, upstream_down_launch.inc, compare_outputs.inc, summarize.py, build.sh, and
# ours-shim/ = the 112-byte FusedGrArgs header the sealed chain kernels were built against (see its comment)
# build/ microbench (binary), chain_window.cubin, chain_window.regen.ptx
set -euo pipefail
ROOT=${1:?directory}
NVCC=${NVCC:-$HOME/cuda-toolkits/13.2.2/bin/nvcc}
cd "$ROOT/build"
# 1. our kernels from source with the flags of extra-seal-plan.json (chain_window): PTX (to check it is the sealed one) and a cubin
OURS_FLAGS="-O3 -arch=sm_120 -std=c++17 --fmad=true --ftz=false -I$ROOT/harness/ours-shim -I$ROOT/ours-src/engine/strata/include"
nice -n 10 "$NVCC" -ptx $OURS_FLAGS "$ROOT/ours-src/crates/cuda-driver/src/chain_window.cu" -o chain_window.regen.ptx
nice -n 10 "$NVCC" -cubin $OURS_FLAGS "$ROOT/ours-src/crates/cuda-driver/src/chain_window.cu" -o chain_window.cubin
# the regenerated PTX equals the sealed one except for the hash in the mangled anonymous-namespace names and the sampler kernel (not used here)
norm() { grep -v '^//' "$1" | tr -d '\0' | sed -E 's/GLOBAL__N__[0-9a-f]+_/GLOBAL__N__X_/g'; }
diff <(norm chain_window.regen.ptx) <(norm "$ROOT/ours-src/crates/cuda-driver/src/chain_window.ptx") | grep -c '^[<>]' | sed 's/^/regenerated-vs-sealed PTX: differing lines (mangled-name hash excluded): /' || true
# 2. the micro-benchmark: upstream fused_gr.cu included whole, flags of a Release build for compute capability 12.0 (cmake/backends/cuda.cmake: architecture 120)
nice -n 10 "$NVCC" -O3 -DNDEBUG -std=c++17 -arch=sm_120 -diag-suppress 128 -I"$ROOT/upstream-src/include" -I"$ROOT/upstream-src/src/kernels/cuda" -I"$ROOT/harness" \
"$ROOT/harness/microbench.cu" -o microbench -lcuda
ls -l microbench chain_window.cubin