/ concept-collection / matmul-bench
Sign in
concept-collection / matmul-bench
matmul-bench / CLAUDE.md
5.8 KBPreviewCodeBlameHistoryRaw

CLAUDE.md#

Tips for future agents working in this repo.

Architecture#

wasm/matmul.c        naive + blocked/SIMD (f64x2) kernels, plus a pthreads
                     matmul_blocked_mt (rows split across threads, -DMATMUL_MT).
                     wasm/build-wasm.sh (emsdk) builds it twice:
                       - st ES module -> wasm/dist/matmul.{js,wasm}
                       - threaded     -> public/matmul/matmul_mt.{js,wasm}
blis/matmul_blis.c   thin wrapper over libFLAME's dgemm_ (BLIS-backed); built
                     st + mt (pthreads) by blis/build-blis-wasm.sh, linking the
                     prebuilt .a libraries from the sibling libflame2wasm
                     checkout (../../../libflame2wasm), into
                     public/matmul/matmul_blis_{st,mt}.{js,wasm} (committed)
native/bench_native.c  same style dgemm benchmark, linked against OpenBLAS,
                     run standalone outside the browser
src/methods/         one file per method, all implementing the MatmulMethod
                     interface in types.ts (id, precision, available(), run?())
src/methods/benchWorker.ts + workerClient.ts
                     JS and both non-threaded custom WASM kernels run inside a
                     Vite module Web Worker — naive JS/WASM at n=2048 take ~10s
                     and would freeze the tab on the main thread. WebGPU runs on
                     the main thread (async). The worker regenerates inputs from
                     (n, seed) rather than receiving them over postMessage.
src/methods/threadedClient.ts + public/matmul/worker.js
                     ALL pthread-capable modules (threaded custom C, BLIS st +
                     mt) run in ONE shared classic worker (not a Vite module
                     worker) — threaded builds spawn pthread workers from it
                     (nested workers), and importScripts of the emscripten glue
                     is the proven path (mirrors libflame2wasm's bench_worker.js).
                     worker.js has a kind->module REGISTRY; every module exports
                     a (a,b,c,n,nthreads) function (st builds ignore nthreads).
                     Served verbatim from public/, out of Vite's module graph.
src/components/      BenchmarkRunner (orchestrates runs, thread selector) +
                     ResultsTable
src/data/nativeReference.ts  hardcoded numbers from native/bench_native,
                     hand-copied in — no runtime fetch
public/coi-serviceworker.js  vendored (gzuidhof, MIT) — adds COOP/COEP so
                     SharedArrayBuffer works on GitHub Pages (no header control)

Key gotchas#

Testing#

moveopenescclose