bergamot-translator/build-wasm.sh
Abhishek Aggarwal e34420647d
Upgrade emsdk to 3.1.8 (#414)
* Rework WASM compilation options

Necessary to work with newer versions of emscripten that are more picky about which option goes to the compiler, and which to the linker. Also took the opportunity to remove the need for the patching of the bergamot-translation-worker.js file, this can now easily be done through supported apis. Furthermore, I tried to downsize the generated javascript and wasm code a bit.

Initial estimates show that bergamot-translator compiled with emscripten 3.0.0 runs at about 3x the speed of 2.0.9 (when using embedded intgemm). Speed-up when using mozIntGemm is less dramatic.

* Updated marian-dev submodule
* Revert changes specific to patching external gemm modules for wasm
* Better Compilation and Link flags

 - Added "-O3" optimization flag for linking as well
 - "-g2" only for release and debug builds
 - "-g1" for release builds
 - Replaced deprecated "--bind" flag with "-lembind"
 - Removed redundant link flag

* Upgraded emsdk to 3.1.8
* Enclosed EXPORTED_FUNCTIONS values in a list
* Fixed the remaining 2.0.9 reference in circle ci build script
* Updated README

Co-authored-by: Jelmer van der Linde <jelmer@ikhoefgeen.nl>
2022-04-20 00:39:32 +01:00

86 lines
2.1 KiB
Bash
Executable File

#!/usr/bin/env bash
set -e
set -x
# Usage
Usage="Build translator to wasm (with/without wormhole).
Usage: $(basename "$0") [WORMHOLE]
where:
WORMHOLE An optional string argument
- when specified on command line, builds wasm artifacts with wormhole
- when not specified (the default behaviour), builds wasm artifacts without wormhole."
if [ "$#" -gt 1 ]; then
echo "Illegal number of parameters passed"
echo "$Usage"
exit
fi
WORMHOLE=false
if [ "$#" -eq 1 ]; then
if [ "$1" = "WORMHOLE" ]; then
WORMHOLE=true
else
echo "Illegal parameter passed"
echo "$Usage"
exit
fi
fi
# Run script from the context of the script-containing directory
cd "$(dirname $0)"
# Prerequisite: Download and Install Emscripten using following instructions (unless the EMSDK env var is already set)
if [ "$EMSDK" == "" ]; then
EMSDK_UPDATE_REQUIRED=0
if [ ! -d "emsdk" ]; then
git clone https://github.com/emscripten-core/emsdk.git
EMSDK_UPDATE_REQUIRED=1
else
cd emsdk
git fetch
# Only pull if necessary
if [ $(git rev-parse HEAD) != $(git rev-parse @{u}) ]; then
git pull --ff-only
EMSDK_UPDATE_REQUIRED=1
fi
cd -
fi
if [ "$EMSDK_UPDATE_REQUIRED" == "1" ]; then
cd emsdk
./emsdk install 3.1.8
./emsdk activate 3.1.8
cd -
fi
source ./emsdk/emsdk_env.sh
fi
# Compile
# 1. Create a folder where you want to build all the artifacts and compile
BUILD_DIRECTORY="build-wasm"
if [ ! -d ${BUILD_DIRECTORY} ]; then
mkdir ${BUILD_DIRECTORY}
fi
cd ${BUILD_DIRECTORY}
if [ "$WORMHOLE" = true ]; then
emcmake cmake -DCOMPILE_WASM=on ../
else
emcmake cmake -DCOMPILE_WASM=on -DWORMHOLE=off ../
fi
emmake make -j2
# 2. Enable SIMD Wormhole via Wasm instantiation API in generated artifacts
if [ "$WORMHOLE" = true ]; then
bash ../wasm/patch-artifacts-enable-wormhole.sh
fi
# 3. Import GEMM library from a separate wasm module
bash ../wasm/patch-artifacts-import-gemm-module.sh
# The artifacts (.js and .wasm files) will be available in the build directory
exit 0