Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

navigator.hardwareConcurrency and native pthread gets different thread pool size #4995

Closed
axinging opened this issue Apr 27, 2021 · 1 comment
Labels
type:bug Something isn't working

Comments

@axinging
Copy link
Contributor

axinging commented Apr 27, 2021

(On Intel i7-9700)
By navigator.hardwareConcurrency: #4994, the WASM_THREAD_POOL_SIZE is 4. WASM_THREAD_POOL_SIZE is got by:

Math.min(4, Math.max(1, (navigator.hardwareConcurrency || 1) / 2));

By native pthread: #4942, the WASM_THREAD_POOL_SIZE is 1. WASM_THREAD_POOL_SIZE is got by:

// emscripten_num_logical_cores corresponds to navigator.hardwareConcurrency.
// Many x86-64 processors have 2 threads per core, so we are dividing by 2.
#ifdef __EMSCRIPTEN_PTHREADS__
int num_cores = emscripten_num_logical_cores() / 2;
#else
int num_cores = 1;
#endif

int min_num_threads = 1;
int max_num_threads = 4;
int thread_pool_size =  // thread_pool_size is WASM_THREAD_POOL_SIZE
    std::min(std::max(num_cores, min_num_threads), max_num_threads);

Does this possible due to #ifdef EMSCRIPTEN_PTHREADS?

BTW, code has rebased, and #4957 is included.

Reproduce steps:

  1. Use local wasm:
+++ b/e2e/benchmarks/local-benchmark/index.html
@@ -91,7 +91,7 @@ limitations under the License.
   <script src="https://unpkg.com/@tensorflow/tfjs-backend-webgl@latest/dist/tf-backend-webgl.js"></script>
   <script src="https://unpkg.com/@tensorflow/tfjs-layers@latest/dist/tf-layers.js"></script>
   <script src="https://unpkg.com/@tensorflow/tfjs-converter@latest/dist/tf-converter.js"></script>
-  <script src="https://unpkg.com/@tensorflow/tfjs-backend-wasm@latest/dist/tf-backend-wasm.js"></script>
+  <script src="../../../tfjs-backend-wasm/dist/tf-backend-wasm.js"></script>
  1. Build:
    cd tfjs-backend-wasm
    tfjs-backend-wasm$ yarn & yarn build-npm
    cd ../e2e
    e2e$ yarn build-deps
  2. Serup server
    cd ../../
    npx http-server
  3. Open http://127.0.0.1:8080/tfjs/e2e/benchmarks/local-benchmark/
@axinging axinging added the type:bug Something isn't working label Apr 27, 2021
@google-ml-butler
Copy link

Are you satisfied with the resolution of your issue?
Yes
No

@axinging axinging reopened this Apr 27, 2021
@tensorflow tensorflow deleted a comment from google-ml-butler bot Apr 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant