Skip to content

Commit

Permalink
[js/web] only apply max thread number when it's omitted (microsoft#7834)
Browse files Browse the repository at this point in the history
  • Loading branch information
fs-eire authored May 26, 2021
1 parent c5ea590 commit 331f204
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions js/web/lib/backend-wasm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 331f204

Please sign in to comment.