Skip to content

Commit

Permalink
[js/web] wait for threadpool initialization (#18952)
Browse files Browse the repository at this point in the history
### Description

a replacement of #18683. try to resolve #18689.

By specifying "-s PTHREAD_POOL_SIZE" flag in emscripten, it forces the
threadpool to initialize before the webassembly instance is available.
  • Loading branch information
fs-eire authored Jan 4, 2024
1 parent 867b9d8 commit b18abaa
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmake/onnxruntime_webassembly.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ else()
target_link_options(onnxruntime_webassembly PRIVATE
"SHELL:-s EXPORT_NAME=ortWasmThreaded"
"SHELL:-s DEFAULT_PTHREAD_STACK_SIZE=131072"
"SHELL:-s PTHREAD_POOL_SIZE=Module[\\\"numThreads\\\"]"
)
else()
target_link_options(onnxruntime_webassembly PRIVATE
Expand Down
1 change: 1 addition & 0 deletions js/web/lib/wasm/binding/ort-wasm.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export interface OrtWasmModule extends EmscriptenModule {
// #endregion

// #region config
numThreads?: number;
mainScriptUrlOrBlob?: string|Blob;
// #endregion

Expand Down
1 change: 1 addition & 0 deletions js/web/lib/wasm/wasm-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ export const initializeWebAssembly = async(flags: Env.WebAssemblyFlags): Promise
};

if (!BUILD_DEFS.DISABLE_WASM_THREAD && useThreads) {
config.numThreads = numThreads;
if (typeof Blob === 'undefined') {
config.mainScriptUrlOrBlob = path.join(__dirname, 'ort-wasm-threaded.js');
} else {
Expand Down

0 comments on commit b18abaa

Please sign in to comment.