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