memlnaut-nisps/playground/wasm/build.sh
w1n5t0n f225c7c2a6 feat(wasm): add batch inference, extended training, pin mask, eval loss, and layer stats bindings
Five new C functions for the WASM module:
- nisps_mlp_infer_batch: N-point batch inference in a single call
- nisps_mlp_train_ex: training with per-iteration loss history output
- nisps_mlp_move_weights_ex: moveWeights with output pin mask to skip pinned nodes
- nisps_mlp_eval_loss: compute MSE loss without updating weights
- nisps_mlp_get_layer_stats: per-layer weight magnitude, dead, and saturation stats
2026-04-03 17:11:49 +01:00

47 lines
1.3 KiB
Bash
Executable file

#!/bin/bash
# Build nisps-core WASM module for the playground
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
NISPS_CORE="$SCRIPT_DIR/../../nisps-core/include"
OUT_DIR="$SCRIPT_DIR"
echo "Building nisps WASM module..."
emcc "$SCRIPT_DIR/nisps_bindings.cpp" \
-I"$NISPS_CORE" \
-std=c++20 \
-O2 \
-s EXPORTED_FUNCTIONS='[
"_nisps_mlp_create",
"_nisps_mlp_destroy",
"_nisps_mlp_weight_count",
"_nisps_mlp_get_weights",
"_nisps_mlp_set_weights",
"_nisps_mlp_inference",
"_nisps_mlp_train",
"_nisps_mlp_draw_weights_spread",
"_nisps_mlp_move_weights_spread",
"_nisps_mlp_infer_batch",
"_nisps_mlp_train_ex",
"_nisps_mlp_move_weights_ex",
"_nisps_mlp_eval_loss",
"_nisps_mlp_get_layer_stats",
"_nisps_alloc",
"_nisps_free",
"_nisps_alloc_int",
"_nisps_free_int",
"_malloc",
"_free"
]' \
-s EXPORTED_RUNTIME_METHODS='["cwrap","HEAPF32","HEAP32"]' \
-s MODULARIZE=1 \
-s EXPORT_NAME=NispsModule \
-s EXPORT_ES6=1 \
-s ENVIRONMENT='web,worker' \
-s ALLOW_MEMORY_GROWTH=1 \
-s INITIAL_MEMORY=16777216 \
-o "$OUT_DIR/nisps.js"
echo "Built: $OUT_DIR/nisps.js + $OUT_DIR/nisps.wasm"
echo "Size: $(du -h "$OUT_DIR/nisps.wasm" | cut -f1)"