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

[RUNTIME] Fast path for single thread run to allow app level threading #7454

Merged
merged 2 commits into from
Feb 18, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions src/runtime/thread_pool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -363,21 +363,30 @@ TVM_REGISTER_GLOBAL("runtime.config_threadpool").set_body([](TVMArgs args, TVMRe
} // namespace tvm

int TVMBackendParallelLaunch(FTVMParallelLambda flambda, void* cdata, int num_task) {
int num_workers = tvm::runtime::threading::MaxConcurrency();
if (num_workers == 1) {
std::atomic<int32_t> sync_counter{0};
TVMParallelGroupEnv env;
env.num_task = 1;
env.sync_handle = &sync_counter;
(*flambda)(0, &env, cdata);
return 0;
} else {
#if !TVM_THREADPOOL_USE_OPENMP
int res = tvm::runtime::ThreadPool::ThreadLocal()->Launch(flambda, cdata, num_task, 1);
return res;
int res = tvm::runtime::ThreadPool::ThreadLocal()->Launch(flambda, cdata, num_task, 1);
return res;
#else
int num_workers = tvm::runtime::threading::MaxConcurrency();
if (num_task == 0) num_task = num_workers;
omp_set_num_threads(num_task);
if (num_task == 0) num_task = num_workers;
omp_set_num_threads(num_task);
#pragma omp parallel num_threads(num_task)
{
TVMParallelGroupEnv env;
env.num_task = num_task;
(*flambda)(omp_get_thread_num(), &env, cdata);
}
return 0;
{
TVMParallelGroupEnv env;
env.num_task = num_task;
(*flambda)(omp_get_thread_num(), &env, cdata);
}
return 0;
#endif
}
}

int TVMBackendParallelBarrier(int task_id, TVMParallelGroupEnv* penv) {
Expand Down