Skip to content

Commit

Permalink
[Runtime] ParallelFor skipping thread backend for unit extent (apache…
Browse files Browse the repository at this point in the history
…#16508)

This PR skips launching multiple parallel threads in
`parallel_for_with_threading_backend` when the input
extent is 1, in which case we can just use the current
thread to run the given function.
  • Loading branch information
MasterJH5574 authored Feb 2, 2024
1 parent 5c68932 commit b5f4410
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions include/tvm/runtime/threading_backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ inline void parallel_launch_with_threading_backend(T flambda) {

template <typename T>
inline void parallel_for_with_threading_backend(T flambda, int64_t begin, int64_t end) {
if (end - begin == 1) {
flambda(begin);
return;
}

auto flaunch = [begin, end, flambda](int task_id, int num_task) {
// For each thread, do static division and call into flambda.
int64_t total_len = end - begin;
Expand Down

0 comments on commit b5f4410

Please sign in to comment.