[wasm] Add flag WASM_THREAD_POOL_SIZE #4942
[wasm] Add flag WASM_THREAD_POOL_SIZE #4942axinging wants to merge 1 commit intotensorflow:masterfrom
Conversation
9f2bb46 to
867e5c9
Compare
qjia7
left a comment
There was a problem hiding this comment.
@lina128 @jinjingforever take a look, thanks.
| disposeData: module.cwrap('dispose_data', voidReturnType, ['number']), | ||
| dispose: module.cwrap('dispose', voidReturnType, []), | ||
| getThreadPoolSize: | ||
| module.cwrap('get_thread_pool_size', 'number', [voidType]), |
There was a problem hiding this comment.
nit: Does it work to change [voidType] -> [] so that you don't need to change voidType name?
There was a problem hiding this comment.
Yes, this also works.
| this.wasm.tfjs.init(); | ||
| // Register the used thread pool size flag. Done it here to avoid circular | ||
| // import. | ||
| env().registerFlag('WASM_THREAD_POOL_SIZE', () => { |
There was a problem hiding this comment.
Usually, we register flag in flags_wasm.ts. And call env().set('WASM_THREAD_POOL_SIZE', this.getThreadPoolSize());. But I am not sure if it is always the rules.
There was a problem hiding this comment.
Currently backend_wasm.ts deppends on flags_wasm.ts.
If we put those code in flags_wasm.ts, flags_wasm.ts will also depends on backend_wasm.ts, the test case will pass, but the yarn lint will fail due to circular imports.
There was a problem hiding this comment.
Is there a good way to pass variable in .ts file to .cc? I'm not sure if this can work: move calculation logic to flags_wasm.ts, and register flag there. In backend.cc, provide a set method. Then in backend_wasm.ts, set the threads count by calling the set method.
7b9d5c1 to
d1715b4
Compare
| this.wasm.tfjs.init(); | ||
| // Register the used thread pool size flag. Done it here to avoid circular | ||
| // import. | ||
| env().registerFlag('WASM_THREAD_POOL_SIZE', () => { |
There was a problem hiding this comment.
Is there a good way to pass variable in .ts file to .cc? I'm not sure if this can work: move calculation logic to flags_wasm.ts, and register flag there. In backend.cc, provide a set method. Then in backend_wasm.ts, set the threads count by calling the set method.
| // Register the used thread pool size flag. Done it here to avoid circular | ||
| // import. | ||
| env().registerFlag('WASM_THREAD_POOL_SIZE', () => { | ||
| return this.getThreadPoolSize(); |
There was a problem hiding this comment.
Actually this is not the size of pool, but count of threads in pool. According to https://github.com/Maratyszcza/pthreadpool/blob/master/include/pthreadpool.h#L77, please change the name to threads_count.
f3363a7 to
f574ce7
Compare
bd4edd8 to
a30f6d3
Compare
| #ifdef __EMSCRIPTEN__ | ||
| EMSCRIPTEN_KEEPALIVE | ||
| #endif | ||
| const size_t get_threads_count() { return backend::threads_count; } |
There was a problem hiding this comment.
FYI. There is a pthreadpool API to query the number of threads in a thread pool
https://github.com/Maratyszcza/pthreadpool/blob/master/include/pthreadpool.h#L86
a30f6d3 to
042c9e6
Compare
lina128
left a comment
There was a problem hiding this comment.
Reviewable status:
complete! 1 of 1 approvals obtained (waiting on @axinging, @gyagp, @mattsoulanille, and @qjia7)
tfjs-backend-wasm/src/backend_wasm.ts, line 49 at r4 (raw file):
// Register the used threads count flag. Done it here to avoid circular // import. env().registerFlag('WASM_THREADS_COUNT', () => {
Is this flag tunable?
042c9e6 to
d1715b4
Compare
ac8b4ad to
f9b635c
Compare
Current this flag is untuable. The set pthread pool size logic is not done yet. |
f9b635c to
0717b84
Compare
This flag tells how many threads can be used in multi-thread mode.
0717b84 to
27db3e1
Compare
|
I will close this, and will provide a better solution for this. |
This flag indicates how many threads can be used in multi-thread mode, it helps us understand the performance difference between wasm and webgpu/webgl.
This change is