-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
[ThreadPool] Solve thread transitions issue #4344
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am positive with adding an ENV VAR to specify exclude_work0_
. But we should try to reason what default value we should set. We may have use cases which run on only one or two threads. In such a scenario, setting exclude_work0_
to be false would not be ideal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above comment. Thanks.
@FrozenGene please act on the review comments |
sorry for the late reply because of other things. have changed the comments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest setting the default value to be true
, due to the following reason: "We may have use cases which run on only one or two threads. In such a scenario, setting exclude_work0_ to be false would not be ideal."
Hmm...I think Auto Tuning and OpenCV + TVM is very common and many users will forget this things, so I prefer it be |
I think there seems to be two concerns:
The problematic case seems can be resolved by not binding the master thread, but still include as part of the worker thread. By default, we bind the rest of the threads but not the master one. |
Another way to resolve the problem, which might be better, would be register the fork handler, which reset the affinity at fork time. https://pubs.opengroup.org/onlinepubs/009695399/functions/pthread_atfork.html |
At least the Auto tuning case is about binding the master thread or not, which we have discussed here. After reviewing all these use cases, I think by default we probably 1) don't bind the master thread; 2) exclude work0, i.e. bind the first task to core 0. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM except for the minor editing issues inline.
src/runtime/threading_backend.cc
Outdated
} | ||
pthread_atfork(nullptr, nullptr, ThreadGroup::Impl::BindMasterThreadToCore0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function may not be available under android. let us only do it under linux
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some final nits
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will keep an eye on this today to catch up the 0.6 release.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am signing off. Just one side note, as we have more and more ENV VARs, each of which has its default value and a number of possible configurations, we probably should have a place to summarize them.
Thanks @FrozenGene for the work |
I agree it. Like this: https://mxnet.apache.org/api/faq/env_var |
Thanks @FrozenGene @yidawang @tqchen this is merged |
* [ThreadPool] Solve thread transitions issue * Use pthread_atfork to avoid master thread affinity be derived by child. * Code Format * comment of exclude_worker0_ * set full cpu affinity * Redundant blank line * CPPLint * CPPLint namespace * CPPLint * Fix the wrong logic of bind master thread.
* [ThreadPool] Solve thread transitions issue * Use pthread_atfork to avoid master thread affinity be derived by child. * Code Format * comment of exclude_worker0_ * set full cpu affinity * Redundant blank line * CPPLint * CPPLint namespace * CPPLint * Fix the wrong logic of bind master thread.
This pr solves thread transitions issue.
When we use OpenCV + TVM, we will produce much thread transitions so that OpenCV + TVM is slow. Auto tuning has issue too. The reason is we bind task 0 to master cpu by default.
More detail / background and reproduceable test case: https://discuss.tvm.ai/t/use-tvm-darknet-to-detect-vidoes-after-relay-build-module-build-cv2-ops-cost-much-more-time/4730/
After this PR, we don't bind task 0 to master cpu by default but export one environment
TVM_EXCLUDE_WORKER0
to set. If users setTVM_EXCLUDE_WORKER0
be 1, we will bind task 0 to master as previous.@vinx13 @yidawang @tqchen