OSDN Git Service

[OpenMP] Added the support for hidden helper task in RTL
authorShilei Tian <tianshilei1992@gmail.com>
Sat, 16 Jan 2021 19:12:38 +0000 (14:12 -0500)
committerShilei Tian <tianshilei1992@gmail.com>
Sat, 16 Jan 2021 19:13:35 +0000 (14:13 -0500)
commited939f853da1f2266f00ea087f778fda88848f73
treed8c87924e5e5caf08c9c209e2920bec41a6bd365
parent49b96cd9ef2f81d193641796b8a85781292faf7a
[OpenMP] Added the support for hidden helper task in RTL

The basic design is to create an outer-most parallel team. It is not a regular team because it is only created when the first hidden helper task is encountered, and is only responsible for the execution of hidden helper tasks.  We first use `pthread_create` to create a new thread, let's call it the initial and also the main thread of the hidden helper team. This initial thread then initializes a new root, just like what RTL does in initialization. After that, it directly calls `__kmpc_fork_call`. It is like the initial thread encounters a parallel region. The wrapped function for this team is, for main thread, which is the initial thread that we create via `pthread_create` on Linux, waits on a condition variable. The condition variable can only be signaled when RTL is being destroyed. For other work threads, they just do nothing. The reason that main thread needs to wait there is, in current implementation, once the main thread finishes the wrapped function of this team, it starts to free the team which is not what we want.

Two environment variables, `LIBOMP_NUM_HIDDEN_HELPER_THREADS` and `LIBOMP_USE_HIDDEN_HELPER_TASK`, are also set to configure the number of threads and enable/disable this feature. By default, the number of hidden helper threads is 8.

Here are some open issues to be discussed:
1. The main thread goes to sleeping when the initialization is finished. As Andrey mentioned, we might need it to be awaken from time to time to do some stuffs. What kind of update/check should be put here?

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D77609
13 files changed:
openmp/runtime/src/kmp.h
openmp/runtime/src/kmp_global.cpp
openmp/runtime/src/kmp_runtime.cpp
openmp/runtime/src/kmp_settings.cpp
openmp/runtime/src/kmp_taskdeps.h
openmp/runtime/src/kmp_tasking.cpp
openmp/runtime/src/kmp_wait_release.h
openmp/runtime/src/z_Linux_util.cpp
openmp/runtime/test/tasking/hidden_helper_task/common.h [new file with mode: 0644]
openmp/runtime/test/tasking/hidden_helper_task/depend.cpp [new file with mode: 0644]
openmp/runtime/test/tasking/hidden_helper_task/gtid.cpp [new file with mode: 0644]
openmp/runtime/test/tasking/hidden_helper_task/taskgroup.cpp [new file with mode: 0644]
openmp/runtime/test/worksharing/for/kmp_sch_simd_guided.c