Skip to content

Commit

Permalink
Update the capitalization for Wasm across the project
Browse files Browse the repository at this point in the history
  • Loading branch information
gregtatum committed Aug 17, 2023
1 parent 8f4ff8a commit 2b4a48f
Show file tree
Hide file tree
Showing 17 changed files with 46 additions and 49 deletions.
4 changes: 1 addition & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- checkout

- run:
name: Build WASM
name: Build Wasm
command: |
bash build-wasm.sh
Expand Down Expand Up @@ -77,5 +77,3 @@ workflows:
ignore: /.*/
requires:
- build


2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ jobs:
run: |
ccache -s # Print current cache stats
- name: Import GEMM library from a separate wasm module
- name: Import GEMM library from a separate Wasm module
working-directory: build-wasm
run: bash ../wasm/patch-artifacts-import-gemm-module.sh

Expand Down
21 changes: 10 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ endif()

if(NOT COMPILE_WASM)
# Setting BUILD_ARCH to native invokes CPU intrinsic detection logic below.
# Prevent invoking that logic for WASM builds.
# Prevent invoking that logic for Wasm builds.
set(BUILD_ARCH native CACHE STRING "Compile for this CPU architecture.")

# Unfortunately MSVC supports a limited subset of BUILD_ARCH flags. Instead try to guess
Expand Down Expand Up @@ -68,10 +68,10 @@ endif(MSVC)
include(CMakeDependentOption)

# Project specific cmake options
option(COMPILE_WASM "Compile for WASM" OFF)
cmake_dependent_option(USE_WASM_COMPATIBLE_SOURCE "Use wasm compatible sources" OFF "NOT COMPILE_WASM" ON)
option(COMPILE_WASM "Compile for Wasm" OFF)
cmake_dependent_option(USE_WASM_COMPATIBLE_SOURCE "Use Wasm compatible sources" OFF "NOT COMPILE_WASM" ON)

# WASM disables a million libraries, which also includes the unit test-library.
# Wasm disables a million libraries, which also includes the unit test-library.
cmake_dependent_option(COMPILE_UNIT_TESTS "Compile unit tests" OFF "USE_WASM_COMPATIBLE_SOURCE" ON)
option(COMPILE_TESTS "Compile bergamot-tests" OFF)
cmake_dependent_option(ENABLE_CACHE_STATS "Enable stats on cache" ON "COMPILE_TESTS" OFF)
Expand All @@ -85,7 +85,7 @@ SET(SSPLIT_COMPILE_LIBRARY_ONLY ON CACHE BOOL "Do not compile ssplit tests")
if (USE_WASM_COMPATIBLE_SOURCE)
SET(COMPILE_LIBRARY_ONLY ON CACHE BOOL "Build only the Marian library and exclude all executables.")
SET(USE_MKL OFF CACHE BOOL "Compile with MKL support")
# # Setting the ssplit-cpp submodule specific cmake options for wasm
# # Setting the ssplit-cpp submodule specific cmake options for Wasm
SET(SSPLIT_USE_INTERNAL_PCRE2 ON CACHE BOOL "Use internal PCRE2 instead of system PCRE2")
endif()

Expand Down Expand Up @@ -115,9 +115,9 @@ if(COMPILE_WASM)
# See https://github.com/emscripten-core/emscripten/blob/main/src/settings.js
list(APPEND WASM_COMPILE_FLAGS
-O3
# Preserve whitespaces in JS even for release builds; this doesn't increase wasm binary size
# Preserve whitespaces in JS even for release builds; this doesn't increase Wasm binary size
$<$<CONFIG:Release>:-g1>
# Relevant Debug info only for release with debug builds as this increases wasm binary size
# Relevant Debug info only for release with debug builds as this increases Wasm binary size
$<$<CONFIG:RelWithDebInfo>:-g2>
-fPIC
-mssse3
Expand All @@ -128,9 +128,9 @@ if(COMPILE_WASM)
)
list(APPEND WASM_LINK_FLAGS
-O3
# Preserve whitespaces in JS even for release builds; this doesn't increase wasm binary size
# Preserve whitespaces in JS even for release builds; this doesn't increase Wasm binary size
$<$<CONFIG:Release>:-g1>
# Relevant Debug info only for release with debug builds as this increases wasm binary size
# Relevant Debug info only for release with debug builds as this increases Wasm binary size
$<$<CONFIG:RelWithDebInfo>:-g2>
-lembind
# Save some code, and some speed
Expand All @@ -154,7 +154,7 @@ if(COMPILE_WASM)
# Export all of the intgemm functions in case we need to fall back to using the embedded intgemm
-sEXPORTED_FUNCTIONS=[_int8PrepareAFallback,_int8PrepareBFallback,_int8PrepareBFromTransposedFallback,_int8PrepareBFromQuantizedTransposedFallback,_int8PrepareBiasFallback,_int8MultiplyAndAddBiasFallback,_int8SelectColumnsOfBFallback]
# Necessary for mozintgemm linking. This prepares the `wasmMemory` variable ahead of time as
# opposed to delegating that task to the wasm binary itself. This way we can link MozIntGEMM
# opposed to delegating that task to the Wasm binary itself. This way we can link MozIntGEMM
# module to the same memory as the main bergamot-translator module.
-sIMPORTED_MEMORY=1
# Dynamic execution is either frowned upon or blocked inside browser extensions
Expand All @@ -180,4 +180,3 @@ option(COMPILE_PYTHON "Compile python bindings. Intended to be activated with se
if(COMPILE_PYTHON)
add_subdirectory(bindings/python)
endif(COMPILE_PYTHON)

2 changes: 1 addition & 1 deletion build-wasm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ cd ${BUILD_DIRECTORY}
emcmake cmake -DCOMPILE_WASM=on ../
emmake make -j2

# 2. Import GEMM library from a separate wasm module
# 2. 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
Expand Down
2 changes: 1 addition & 1 deletion doc/marian-integration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ MKL/OpenBLAS.
Building bergamot-translator
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Web Assembly (WASM) reduces building to only using a subset of
Web Assembly (Wasm) reduces building to only using a subset of
functionalities of marian, the translation library powering
bergamot-translator. When developing bergamot-translator it is important
that the sources added be compatible with marian. Therefore, it is
Expand Down
2 changes: 1 addition & 1 deletion src/tests/blocking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ int main(int argc, char *argv[]) {
models.push_back(model);
}

/// WASM is one special case where WASM path is being checked, involving translateMultiple and a multi-line feed.
/// Wasm is one special case where Wasm path is being checked, involving translateMultiple and a multi-line feed.
/// Hence we do not bind it at a single input-blob single Response constraint imposed by the TestSuite.
testSuite.run(config.opMode, models);

Expand Down
6 changes: 3 additions & 3 deletions src/tests/wasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ void wasm(BlockingService &service, std::shared_ptr<TranslationModel> &model) {
std::vector<ResponseOptions> responseOptions;
std::vector<std::string> texts;

// WASM always requires HTML and alignment.
// Wasm always requires HTML and alignment.
// TODO(jerinphilip): Fix this, bring in actual tests.
// responseOptions.HTML = true;
// responseOptions.alignment = true; // Necessary for HTML
Expand Down Expand Up @@ -35,14 +35,14 @@ int main(int argc, char *argv[]) {

for (auto &modelConfigPath : config.modelConfigPaths) {
TranslationModel::Config modelConfig = parseOptionsFromFilePath(modelConfigPath);
// Anything WASM is expected to use the byte-array-loads. So we hard-code grabbing MemoryBundle from FS and use the
// Anything Wasm is expected to use the byte-array-loads. So we hard-code grabbing MemoryBundle from FS and use the
// MemoryBundle capable constructor.
MemoryBundle memoryBundle = getMemoryBundleFromConfig(modelConfig);
std::shared_ptr<TranslationModel> model = std::make_shared<TranslationModel>(modelConfig, std::move(memoryBundle));
models.push_back(model);
}

/// WASM is one special case where WASM path is being checked, involving translateMultiple and a multi-line feed.
/// Wasm is one special case where Wasm path is being checked, involving translateMultiple and a multi-line feed.
/// Hence we do not bind it at a single input-blob single Response constraint imposed by the TestSuite.
if (config.opMode == "wasm") {
wasm(service, models.front());
Expand Down
2 changes: 1 addition & 1 deletion src/translator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ add_library(bergamot-translator STATIC
xh_scanner.cpp
)
if (USE_WASM_COMPATIBLE_SOURCE)
# Using wasm compatible sources should include this compile definition;
# Using Wasm compatible sources should include this compile definition;
# Has to be done here because we are including marian headers + some sources
# in local repository use these definitions
target_compile_definitions(bergamot-translator PUBLIC USE_SSE2 WASM_COMPATIBLE_SOURCE)
Expand Down
2 changes: 1 addition & 1 deletion wasm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ add_executable(bergamot-translator-worker
bindings/response_bindings.cpp
)

# Generate version file that can be included in the wasm artifacts
# Generate version file that can be included in the Wasm artifacts
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/project_version.js.in
${CMAKE_CURRENT_BINARY_DIR}/project_version.js @ONLY)

Expand Down
4 changes: 2 additions & 2 deletions wasm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ All the instructions below are meant to run from the current directory.

## Using JS APIs

See [node-test.js](./node-test.js) for an annotated example of how to use the WASM module. Most of the code from it can also be used in a browser context.
See [node-test.js](./node-test.js) for an annotated example of how to use the Wasm module. Most of the code from it can also be used in a browser context.

Alternatively refer to the file `test_page/js/worker.js` that demonstrates how to use the bergamot translator in JavaScript via a `<script>` tag.

Expand All @@ -30,7 +30,7 @@ Alternatively refer to the file `test_page/js/worker.js` that demonstrates how t
bash start_server.sh ../../build-wasm
```

Provide the folder containing the wasm artifacts as the first argument of `start_server.sh` script (`../../build-wasm` in this case).
Provide the folder containing the Wasm artifacts as the first argument of `start_server.sh` script (`../../build-wasm` in this case).

* Open any browser (tested with latest Chrome/Firefox/Safari)

Expand Down
4 changes: 2 additions & 2 deletions wasm/module/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const translator = new LatencyOptimisedTranslator({
- `workerUrl` - url to `translator-worker.js`. Defaults to `"worker/translator-worker.js"` relative to the path of `translator.js`.
- `downloadTimeout` - Maximum time we're attempting to download model files before failing. Defaults to `60000` or 60 seconds. Set to `0` to disable.
- `cacheSize` - Maximum number of sentences in kept translation cache (per worker, workers do not share their cache). This is an ideal maximum as it is a hash-map, in practice about 1/3th is occupied. If set to `0`, translation cache is disabled (the default).
- `useNativeIntGemm` - Try to link to native IntGEMM implementation when loading the WASM binary. This is only implemented in the privileged extension context of Firefox Nightly. If it fails, it will always fall back to the included implementation. Defaults to `false`.
- `useNativeIntGemm` - Try to link to native IntGEMM implementation when loading the Wasm binary. This is only implemented in the privileged extension context of Firefox Nightly. If it fails, it will always fall back to the included implementation. Defaults to `false`.
### translate()
Expand Down Expand Up @@ -235,4 +235,4 @@ const translator = new BatchTranslator(options, new CustomBacking(options));
# Supported languages
See https://github.com/mozilla/firefox-translations-models#currently-supported-languages. You may need to set the `registryUrl` option to point to the latest release.
See https://github.com/mozilla/firefox-translations-models#currently-supported-languages. You may need to set the `registryUrl` option to point to the latest release.
8 changes: 4 additions & 4 deletions wasm/module/translator.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export class CancelledError extends Error {}
* call and that are unrecoverable.
* @type {(error: Error)}
*/
this.onerror = this.options.onerror || (err => console.error('WASM Translation Worker error:', err));
this.onerror = this.options.onerror || (err => console.error('Wasm Translation Worker error:', err));
}

/**
Expand Down Expand Up @@ -164,7 +164,7 @@ export class CancelledError extends Error {}
// … and general errors
worker.addEventListener('error', this.onerror.bind(this));

// Await initialisation. This will also nicely error out if the WASM
// Await initialisation. This will also nicely error out if the Wasm
// runtime fails to load.
await call('initialize', this.options);

Expand Down Expand Up @@ -248,7 +248,7 @@ export class CancelledError extends Error {}
/**
* Downloads a translation model and returns a set of
* ArrayBuffers. These can then be passed to a TranslationWorker thread
* to instantiate a TranslationModel inside the WASM vm.
* to instantiate a TranslationModel inside the Wasm vm.
* @param {{from:string, to:string}}
* @param {{signal:AbortSignal?}?}
* @return {Promise<{
Expand Down Expand Up @@ -520,7 +520,7 @@ export class BatchTranslator {
*/
this.batchSize = Math.max(options?.batchSize || 8, 1);

this.onerror = options?.onerror || (err => console.error('WASM Translation Worker error:', err));
this.onerror = options?.onerror || (err => console.error('Wasm Translation Worker error:', err));
}

/**
Expand Down
16 changes: 8 additions & 8 deletions wasm/module/worker/translator-worker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Wrapper around the dirty bits of Bergamot's WASM bindings.
* Wrapper around the dirty bits of Bergamot's Wasm bindings.
*/

// Global because importScripts is global.
Expand Down Expand Up @@ -170,7 +170,7 @@ class BergamotTranslatorWorker {

/**
* Instantiates a new translation worker with optional options object.
* If this call succeeds, the WASM runtime is loaded and ready.
* If this call succeeds, the Wasm runtime is loaded and ready.
*
* Available options are:
* useNativeIntGemm: {true | false} defaults to false. If true, it will
Expand All @@ -193,7 +193,7 @@ class BergamotTranslatorWorker {
/**
* Tries to load native IntGEMM module for bergamot-translator. If that
* fails because it or any of the expected functions is not available, it
* falls back to using the naive implementations that come with the wasm
* falls back to using the naive implementations that come with the Wasm
* binary itself through `linkFallbackIntGemm()`.
* @param {{env: {memory: WebAssembly.Memory}}} info
* @return {{[method:string]: (...any) => any}}
Expand All @@ -217,7 +217,7 @@ class BergamotTranslatorWorker {
}

/**
* Links intgemm functions that are already available in the wasm binary,
* Links intgemm functions that are already available in the Wasm binary,
* but just exports them under the name that is expected by
* bergamot-translator.
* @param {{env: {memory: WebAssembly.Memory}}} info
Expand All @@ -232,7 +232,7 @@ class BergamotTranslatorWorker {
}

/**
* Internal method. Reads and instantiates the WASM binary. Returns a
* Internal method. Reads and instantiates the Wasm binary. Returns a
* promise for the exported Module object that contains all the classes
* and functions exported by bergamot-translator.
* @return {Promise<BergamotTranslator>}
Expand Down Expand Up @@ -337,7 +337,7 @@ class BergamotTranslatorWorker {
if (buffers.config)
Object.assign(modelConfig, buffers.config);

// WASM marian is only compiled with support for shiftedAll.
// Wasm marian is only compiled with support for shiftedAll.
if (modelConfig['gemm-precision'] === 'int8')
modelConfig['gemm-precision'] = 'int8shiftAll';

Expand Down Expand Up @@ -375,7 +375,7 @@ class BergamotTranslatorWorker {

/**
* Internal function. Copies the data from an ArrayBuffer into memory that
* can be used inside the WASM vm by Marian.
* can be used inside the Wasm vm by Marian.
* @param {{ArrayBuffer}} buffer
* @param {number} alignmentSize
* @return {BergamotTranslator.AlignedMemory}
Expand Down Expand Up @@ -417,7 +417,7 @@ class BergamotTranslatorWorker {
input.delete();
options.delete();

// Convert the Response WASM wrappers into native JavaScript types we
// Convert the Response Wasm wrappers into native JavaScript types we
// can send over the 'wire' (message passing) in the same format as we
// use in bergamot-translator.
const translations = texts.map((_, i) => ({
Expand Down
6 changes: 3 additions & 3 deletions wasm/node-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const fs = require('fs');
// implement `fetch("file://...")` yet.
const wasmBinary = fs.readFileSync('./bergamot-translator-worker.wasm');

// Read wasm runtime code that bridges the bergmot-translator binary with JS.
// Read Wasm runtime code that bridges the bergmot-translator binary with JS.
const wasmRuntime = fs.readFileSync('./bergamot-translator-worker.js', {encoding: 'utf8'});

// Initialise the `Module` object. By adding methods and options to this, we can
Expand All @@ -39,7 +39,7 @@ global.Module = {
eval.call(global, wasmRuntime);

/**
* Called from inside the bergamot-translation-worker.js script once the wasm
* Called from inside the bergamot-translation-worker.js script once the Wasm
* module is initialized. At this point that `Module` object that was
* initialised above will have all the classes defined in the
* bergamot-translator API available on it.
Expand Down Expand Up @@ -67,7 +67,7 @@ async function onRuntimeInitialized() {
];

// Download model data and load it into aligned memory. AlignedMemory is a
// necessary wrapper around allocated memory inside the WASM environment.
// necessary wrapper around allocated memory inside the Wasm environment.
// The value of `alignment` is specific for which part of the model we're
// loading. See https://en.wikipedia.org/wiki/Data_structure_alignment for a
// more general explanation.
Expand Down
6 changes: 3 additions & 3 deletions wasm/patch-artifacts-import-gemm-module.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/bin/bash
usage="Patch wasm artifacts to import gemm implementation for wasm.
usage="Patch Wasm artifacts to import gemm implementation for Wasm.
Usage: $(basename "$0") [ARTIFACTS_FOLDER]
where:
ARTIFACTS_FOLDER Folder containing wasm artifacts
ARTIFACTS_FOLDER Folder containing Wasm artifacts
(An optional argument, if unspecified the default is: current folder)"

if [ "$#" -gt 1 ]; then
Expand All @@ -13,7 +13,7 @@ if [ "$#" -gt 1 ]; then
exit
fi

# Parse wasm artifacts folder if provided via script argument or set it to default
# Parse Wasm artifacts folder if provided via script argument or set it to default
ARTIFACTS_FOLDER=$PWD
if [ "$#" -eq 1 ]; then
if [ ! -e "$1" ]; then
Expand Down
2 changes: 1 addition & 1 deletion wasm/test_page/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ async function main() {

// Intentionally do this after querying backing.registry to make sure that
// that request is fired off first. Now we can start thinking about loading
// the WASM binary etc.
// the Wasm binary etc.
const translator = new LatencyOptimisedTranslator(options, backing);

let abortController = new AbortController();
Expand Down
6 changes: 3 additions & 3 deletions wasm/test_page/start_server.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/bin/bash

usage="Copy wasm artifacts from the given folder and start httpserver
usage="Copy Wasm artifacts from the given folder and start httpserver
Usage: $(basename "$0") [ARTIFACTS_SOURCE_FOLDER]
where:
ARTIFACTS_SOURCE_FOLDER Directory containing pre-built wasm artifacts"
ARTIFACTS_SOURCE_FOLDER Directory containing pre-built Wasm artifacts"

SCRIPT_ABSOLUTE_PATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"

Expand All @@ -21,7 +21,7 @@ if [ ! -e "$1" ]; then
exit
fi

# Prepare a list all wasm artifacts to be copied and copy them to the destination folder
# Prepare a list all Wasm artifacts to be copied and copy them to the destination folder
ARTIFACTS_BASE_NAME="bergamot-translator-worker"
ARTIFACTS="$1/$ARTIFACTS_BASE_NAME.js $1/$ARTIFACTS_BASE_NAME.wasm"
ARTIFACTS_DESTINATION_FOLDER=$SCRIPT_ABSOLUTE_PATH/../module/worker
Expand Down

0 comments on commit 2b4a48f

Please sign in to comment.