Skip to content

Threaded build of WASM backend should support Node. #3830

@annxingyuan

Description

@annxingyuan

Currently we exclude Node from the threaded build of the WASM backend (#3829). The threaded build fails in Node for several reasons:

  • In Emscripten SDK v.1.39.15 (this is what we're using), the web worker code includes the line Worker = nodeWorkerThreads.Worker, which is problematic because Worker is undefined. Emscripten v.1.39.16 contains a fix for this: emscripten-core/emscripten@cccf9bf. We need to update to 1.39.16 (which means addressing several compile errors).
  • We are currently using the Blob API for the threaded build in order to narrow down the wasm.mainScript to just the Emscripten-generated WASM module, rather than our entire tf-backend-wasm.js bundle (which contains the Emscripten-generated WASM module). We need to narrow it down because the worker ingests wasm.mainScript through importScripts, and the worker can't ingest our whole bundle because it contains TFJS code that the worker doesn't know anything about (hence it immediately throws an error if attempting to ingest the whole bundle because runKernel is undefined). We need to polyfill Blob for Node, the way we do for fetch.
  • Launching a simple node program with the necessary experimental flags to ask for the threaded + SIMD build (e.g. node index.js --experimental-wasm-simd --experimental-wasm-threads --experimental-wasm-bulk-memory) fails with the following message:

requested a shared WebAssembly.Memory but the returned buffer is not a SharedArrayBuffer, indicating that while the browser has SharedArrayBuffer it does not have WebAssembly threads support - you may need to set a flag (on node you may need: --experimental-wasm-threads --experimental-wasm-bulk-memory and also use a recent version)` (from Emscripten).

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions