#!/usr/bin/env bash # Builds matmul_blis.c to public/matmul/matmul_blis_{st,mt}.{js,wasm}, linking # the prebuilt libflame + BLIS WASM static libraries from ../../../libflame2wasm. # # Those .a files come from libflame2wasm's own build scripts: # (in ../../libflame2wasm) ./build-wasm.sh -> install/lib/libflame.a # PTHREAD=1 ./build-wasm.sh -> install/lib/libflame-mt.a # ./build-blis-wasm.sh -> install/lib/libblis-st.a # THREADING=pthreads ./build-blis-wasm.sh -> blis/lib/generic/libblis.a # # The outputs are committed to the repo (see .gitignore) so GitHub Pages deploy # doesn't need to rebuild ~30 MB of BLIS/libflame in CI. # # Requires: emsdk (expected at ~/emsdk, or already on PATH). set -euo pipefail cd "$(dirname "$0")" LIBFLAME=${LIBFLAME:-../../../libflame2wasm} if [ ! -f "$LIBFLAME/install/lib/libflame.a" ]; then echo "error: prebuilt libraries not found under $LIBFLAME (set LIBFLAME=...)" >&2 exit 1 fi if ! command -v emcc >/dev/null 2>&1; then source ~/emsdk/emsdk_env.sh fi OUT=../public/matmul mkdir -p "$OUT" COMMON="-O2 -sMODULARIZE -sENVIRONMENT=web,worker,node \ -sEXPORTED_FUNCTIONS=_matmul_blis,_malloc,_free \ -sEXPORTED_RUNTIME_METHODS=HEAPF64" # Single-threaded: BLIS(st) linked first so its BLAS symbols win over # libflame's f2c reference BLAS. No threads -> no SharedArrayBuffer needed. emcc $COMMON matmul_blis.c \ -sEXPORT_NAME=createMatmulBlisST \ -sALLOW_MEMORY_GROWTH \ "$LIBFLAME/install/lib/libblis-st.a" \ "$LIBFLAME/install/lib/libflame.a" \ -o "$OUT/matmul_blis_st.js" # Threaded: everything compiled with -pthread; fixed shared memory (growth is # costly with shared memory). Pool must cover max threads + margin. emcc $COMMON -pthread -DBLIS_MT matmul_blis.c \ -sEXPORT_NAME=createMatmulBlisMT \ -sPTHREAD_POOL_SIZE=20 \ -sINITIAL_MEMORY=768MB \ "$LIBFLAME/blis/lib/generic/libblis.a" \ "$LIBFLAME/install/lib/libflame-mt.a" \ -o "$OUT/matmul_blis_mt.js" echo "Built public/matmul/matmul_blis_{st,mt}.{js,wasm}"