From 331f20428c6c94f6c485ab5210a9bf8dc9391f04 Mon Sep 17 00:00:00 2001 From: Yulong Wang Date: Wed, 26 May 2021 15:46:50 -0700 Subject: [PATCH] [js/web] only apply max thread number when it's omitted (#7834) --- js/web/lib/backend-wasm.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/js/web/lib/backend-wasm.ts b/js/web/lib/backend-wasm.ts index 9c97d47c423db..35d34b27fb24a 100644 --- a/js/web/lib/backend-wasm.ts +++ b/js/web/lib/backend-wasm.ts @@ -20,11 +20,10 @@ export const initializeFlags = (): void => { env.wasm.initTimeout = 0; } - if (typeof env.wasm.numThreads !== 'number' || !Number.isInteger(env.wasm.numThreads) || env.wasm.numThreads < 0) { + if (typeof env.wasm.numThreads !== 'number' || !Number.isInteger(env.wasm.numThreads) || env.wasm.numThreads <= 0) { const numCpuLogicalCores = typeof navigator === 'undefined' ? cpus().length : navigator.hardwareConcurrency; - env.wasm.numThreads = Math.ceil((numCpuLogicalCores || 1) / 2); + env.wasm.numThreads = Math.min(4, Math.ceil((numCpuLogicalCores || 1) / 2)); } - env.wasm.numThreads = Math.min(4, env.wasm.numThreads); }; class OnnxruntimeWebAssemblyBackend implements Backend {