2# Builds matmul_blis.c to public/matmul/matmul_blis_{st,mt}.{js,wasm}, linking
3# the WASM libflame + BLIS static libraries from a sibling libflame2wasm
4# checkout (concept-collection/libflame2wasm). Override its location with
5# LIBFLAME=/path/to/libflame2wasm.
6#
7# Produce those .a files first with libflame2wasm's build-all-wasm.sh, which
8# yields install/lib/{libflame.a,libflame-mt.a,libblis-st.a} and
9# blis/lib/generic/libblis.a. The matmul_blis_* outputs here are NOT committed
10# (see .gitignore); CI rebuilds them (see .github/workflows/deploy.yml).
11#
12# Requires: emsdk (expected at ~/emsdk, or already on PATH).
13set -euo pipefail
15cd "$(dirname "$0")"
16LIBFLAME=${LIBFLAME:-../../../libflame2wasm}
18if [ ! -f "$LIBFLAME/install/lib/libflame.a" ]; then
19 echo "error: prebuilt libraries not found under $LIBFLAME (set LIBFLAME=...)" >&2
20 exit 1
21fi
23if ! command -v emcc >/dev/null 2>&1; then
24 source ~/emsdk/emsdk_env.sh
25fi
27OUT=../public/matmul
28mkdir -p "$OUT"
30COMMON="-O2 -sMODULARIZE -sENVIRONMENT=web,worker,node \
31 -sEXPORTED_FUNCTIONS=_matmul_blis,_malloc,_free \
32 -sEXPORTED_RUNTIME_METHODS=HEAPF64"
34# Single-threaded: BLIS(st) linked first so its BLAS symbols win over
35# libflame's f2c reference BLAS. No threads -> no SharedArrayBuffer needed.
36emcc $COMMON matmul_blis.c \
37 -sEXPORT_NAME=createMatmulBlisST \
38 -sALLOW_MEMORY_GROWTH \
39 "$LIBFLAME/install/lib/libblis-st.a" \
40 "$LIBFLAME/install/lib/libflame.a" \
41 -o "$OUT/matmul_blis_st.js"
43# Threaded: everything compiled with -pthread; fixed shared memory (growth is
44# costly with shared memory). Pool must cover max threads + margin.
45emcc $COMMON -pthread -DBLIS_MT matmul_blis.c \
46 -sEXPORT_NAME=createMatmulBlisMT \
47 -sPTHREAD_POOL_SIZE=20 \
48 -sINITIAL_MEMORY=768MB \
49 "$LIBFLAME/blis/lib/generic/libblis.a" \
50 "$LIBFLAME/install/lib/libflame-mt.a" \
51 -o "$OUT/matmul_blis_mt.js"
53echo "Built public/matmul/matmul_blis_{st,mt}.{js,wasm}"