/ concept-collection / matmul-bench
Sign in
concept-collection / matmul-bench
matmul-bench / blis / build-blis-wasm.sh
55 lines · 2.1 KBBlameHistoryRaw
1#!/usr/bin/env bash
2# Builds matmul_blis.c to public/matmul/matmul_blis_{st,mt}.{js,wasm}, linking
3# the prebuilt libflame + BLIS WASM static libraries from ../../../libflame2wasm.
4#
5# Those .a files come from libflame2wasm's own build scripts:
6# (in ../../libflame2wasm) ./build-wasm.sh -> install/lib/libflame.a
7# PTHREAD=1 ./build-wasm.sh -> install/lib/libflame-mt.a
8# ./build-blis-wasm.sh -> install/lib/libblis-st.a
9# THREADING=pthreads ./build-blis-wasm.sh -> blis/lib/generic/libblis.a
11# The outputs are committed to the repo (see .gitignore) so GitHub Pages deploy
12# doesn't need to rebuild ~30 MB of BLIS/libflame in CI.
14# Requires: emsdk (expected at ~/emsdk, or already on PATH).
15set -euo pipefail
17cd "$(dirname "$0")"
18LIBFLAME=${LIBFLAME:-../../../libflame2wasm}
20if [ ! -f "$LIBFLAME/install/lib/libflame.a" ]; then
21 echo "error: prebuilt libraries not found under $LIBFLAME (set LIBFLAME=...)" >&2
22 exit 1
23fi
25if ! command -v emcc >/dev/null 2>&1; then
26 source ~/emsdk/emsdk_env.sh
27fi
29OUT=../public/matmul
30mkdir -p "$OUT"
32COMMON="-O2 -sMODULARIZE -sENVIRONMENT=web,worker,node \
33 -sEXPORTED_FUNCTIONS=_matmul_blis,_malloc,_free \
34 -sEXPORTED_RUNTIME_METHODS=HEAPF64"
36# Single-threaded: BLIS(st) linked first so its BLAS symbols win over
37# libflame's f2c reference BLAS. No threads -> no SharedArrayBuffer needed.
38emcc $COMMON matmul_blis.c \
39 -sEXPORT_NAME=createMatmulBlisST \
40 -sALLOW_MEMORY_GROWTH \
41 "$LIBFLAME/install/lib/libblis-st.a" \
42 "$LIBFLAME/install/lib/libflame.a" \
43 -o "$OUT/matmul_blis_st.js"
45# Threaded: everything compiled with -pthread; fixed shared memory (growth is
46# costly with shared memory). Pool must cover max threads + margin.
47emcc $COMMON -pthread -DBLIS_MT matmul_blis.c \
48 -sEXPORT_NAME=createMatmulBlisMT \
49 -sPTHREAD_POOL_SIZE=20 \
50 -sINITIAL_MEMORY=768MB \
51 "$LIBFLAME/blis/lib/generic/libblis.a" \
52 "$LIBFLAME/install/lib/libflame-mt.a" \
53 -o "$OUT/matmul_blis_mt.js"
55echo "Built public/matmul/matmul_blis_{st,mt}.{js,wasm}"
moveopenescclose