#!/usr/bin/env bash # Builds matmul_blis.c to public/matmul/matmul_blis_{st,mt}.{js,wasm}, linking # the WASM libflame + BLIS static libraries from a sibling libflame2wasm # checkout. Override its location with LIBFLAME=/path/to/libflame2wasm. # # Produce those .a files first with libflame2wasm's build-all-wasm.sh, which # yields install/lib/{libflame.a,libflame-mt.a,libblis-st.a} and # blis/lib/generic/libblis.a. The matmul_blis_* outputs here are NOT committed # (see .gitignore); CI rebuilds them (see .github/workflows/deploy.yml). # # 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}"