Files
gpu/dex/bench/build_metal.sh
zeekayandHanzo Dev b1e39595f7 bench(dex): GPU-native deterministic per-book matcher harnesses
Standalone microbenchmarks for the deterministic CLOB matcher (one thread per
book, sequential price-time priority, parity-checked vs OpenMP CPU) across all
three GPU makers: CUDA, HIP, Metal.

Optimization: order-major SoA layout coalesces warp reads (adjacent books read
contiguous words instead of DEPTH-strided). Pure memory-access change; identical
deterministic fills (parity MATCH at every N).

Measured, tuned per backend (taker orders/sec):
- AMD Radeon 8060S (HIP, SoA preload TPB=64): 12.76B  (1.94B baseline, 6.6x)
- NVIDIA GB10      (CUDA, SoA lowreg TPB=32):  9.13B  (1.54B baseline, 5.9x)
- Apple M4 Max     (Metal, AoS TPB=256):       5.60B  (SoA neutral on unified mem)
- Apple M1 Max     (Metal):                    2.80B

Findings: coalescing is a discrete/APU-memory win (neutral-to-negative on Apple
unified memory); NVIDIA is occupancy-bound (prefers lowreg/small blocks) while
AMD is bandwidth-rich (prefers register-resident preload) — opposite optima.

Includes dex_tune.cu (TPB x variant sweep) + per-backend build/tune scripts.

Co-authored-by: Hanzo Dev <[email protected]>
2026-07-01 23:59:20 -07:00

20 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
# build_metal.sh — build the deterministic per-book DEX matcher for Apple Silicon (Metal).
# Verified on ra (Apple M1 Max, 64GB) and dbc (Apple M4 Max, 128GB).
# NOTE: on Apple unified memory the coalesced-SoA rewrite is NEUTRAL-to-NEGATIVE (the large
# shared cache already absorbs the strided AoS access); AoS is the tuned default here. Both are
# built so you can confirm on your own silicon.
# Usage: ./build_metal.sh [N] (N = number of books/markets, default 2000000)
set -e
LIBOMP=${LIBOMP:-$( (command -v brew >/dev/null && brew --prefix libomp) 2>/dev/null || echo /opt/homebrew/opt/libomp)}
SDK=$(xcrun --show-sdk-path)
here=$(cd "$(dirname "$0")" && pwd)
N=${1:-2000000}
cc() { xcrun clang++ -O3 -std=c++17 -isysroot "$SDK" -I"$LIBOMP/include" -L"$LIBOMP/lib" \
-Xpreprocessor -fopenmp -lomp -framework Metal -framework Foundation -o "$1" "$2"; }
cc /tmp/dex_books "$here/dex_books.mm"
cc /tmp/dex_books_opt "$here/dex_books_opt.mm"
export DYLD_LIBRARY_PATH=$LIBOMP/lib
echo "--- baseline (AoS) — tuned default on Apple ---"; /tmp/dex_books "$N"
echo "--- coalesced SoA (discrete-GPU optimization) ---"; /tmp/dex_books_opt "$N"