mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-11 17:48:34 +00:00
Adjust the threading logic in ThreadPool::ParallelFor (#3178)
1. Do not reuse the main thread. 2. Do not plus one when mlas calculate the number of tasks to schedule. (It was me put the plus one there) This is the second try of #1839 It's known that this change has negative performance impact on some of the models.
This commit is contained in:
parent
f49912c42a
commit
a02638eb46
2 changed files with 3 additions and 4 deletions
|
|
@ -43,17 +43,16 @@ void ThreadPool::ParallelFor(int32_t total, std::function<void(int32_t)> fn) {
|
|||
|
||||
// TODO: Eigen supports a more efficient ThreadPoolDevice mechanism
|
||||
// We will simply rely on the work queue and stealing in the short term.
|
||||
Barrier barrier(static_cast<unsigned int>(total - 1));
|
||||
Barrier barrier(static_cast<unsigned int>(total));
|
||||
std::function<void(int32_t)> handle_iteration = [&barrier, &fn](int iteration) {
|
||||
fn(iteration);
|
||||
barrier.Notify();
|
||||
};
|
||||
|
||||
for (int32_t id = 1; id < total; ++id) {
|
||||
for (int32_t id = 0; id < total; ++id) {
|
||||
Schedule([=, &handle_iteration]() { handle_iteration(id); });
|
||||
}
|
||||
|
||||
fn(0);
|
||||
barrier.Wait();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -669,7 +669,7 @@ MlasGetMaximumThreadCount(
|
|||
MLAS_UNREFERENCED_PARAMETER(ThreadPool);
|
||||
#else
|
||||
if (ThreadPool != nullptr) {
|
||||
return ThreadPool->NumThreads() + 1;
|
||||
return ThreadPool->NumThreads();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue