[js/web] only apply max thread number when it's omitted (#7834)

This commit is contained in:
Yulong Wang 2021-05-26 15:46:50 -07:00 committed by GitHub
parent c5ea5907c0
commit 331f20428c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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 {