[OpenMP] libomp: fix UB when LIBOMP_NUM_HIDDEN_HELPER_THREADS=1.The __kmp_hidden_helper_threads_num set to N+1 if user requested N threads.Thus number of worker hidden helper threads corresponds t
[OpenMP] libomp: fix UB when LIBOMP_NUM_HIDDEN_HELPER_THREADS=1.The __kmp_hidden_helper_threads_num set to N+1 if user requested N threads.Thus number of worker hidden helper threads corresponds to user request,main thread of helper team excluded as it does not participate in actual work.This also fixes divide-by-0 issue in the code.Fixes #48656Differential Revision: https://reviews.llvm.org/D119586
show more ...
[OpenMP] Fix task wait doesn't work as expected in serialized teamAs discussed in D107121, task wait doesn't work when a regular task T depends ona detached task or a hidden helper task T' in a se
[OpenMP] Fix task wait doesn't work as expected in serialized teamAs discussed in D107121, task wait doesn't work when a regular task T depends ona detached task or a hidden helper task T' in a serialized team. The root cause is,since the team is serialized, the last task will not be tracked by`td_incomplete_child_tasks`. When T' is finished, it first releases itsdependences, and then decrements its parent counter. So far so good. For the threadthat is running task wait, if at the moment it is still spinning and trying toexecute tasks, it is fine because it can detect the new task and execute it.However, if it happends to finish the function `flag.execute_tasks(...)`, it willbe broken because `td_incomplete_child_tasks` is 0 now.In this patch, we update the rule to track children tasks a little bit. If thetask team encounters a proxy task or a hidden helper task, all following taskswill be tracked.Reviewed By: AndreyChurbanovDifferential Revision: https://reviews.llvm.org/D107496
[openmp] [test] Add missing <limits> include to capacity_nthreadsDifferential Revision: https://reviews.llvm.org/D105474
[OpenMP] libomp: fixed implementation of OMP 5.1 inoutset task dependence typeRefactored code of dependence processing and added new inoutset dependence type.Compiler can set dependence flag to 0x
[OpenMP] libomp: fixed implementation of OMP 5.1 inoutset task dependence typeRefactored code of dependence processing and added new inoutset dependence type.Compiler can set dependence flag to 0x8 when call __kmpc_omp_task_with_deps.All dependence flags library gets so far and corresponding dependence types:1 - IN, 2 - OUT, 3 - INOUT, 4 - MUTEXINOUTSET, 8 - INOUTSET.Differential Revision: https://reviews.llvm.org/D97085
Revert "[OpenMP] libomp: implement OpenMP 5.1 inoutset task dependence type"This reverts commit a1f550e052543f75acac9089b760cbc61729131f.Revert in order to fix backwards compatibility breakageca
Revert "[OpenMP] libomp: implement OpenMP 5.1 inoutset task dependence type"This reverts commit a1f550e052543f75acac9089b760cbc61729131f.Revert in order to fix backwards compatibility breakagecaused by type size change for task dependence flag.
[OpenMP] libomp: implement OpenMP 5.1 inoutset task dependence typeRefactored code of dependence processing and added new inoutset dependence type.Compiler can set dependence flag to 0x8 when call
[OpenMP] libomp: implement OpenMP 5.1 inoutset task dependence typeRefactored code of dependence processing and added new inoutset dependence type.Compiler can set dependence flag to 0x8 when call __kmpc_omp_task_with_deps.Size of type of the dependence flag changed from 1 to 4 bytes in clang.All dependence flags library gets so far and corresponding dependence types:1 - IN, 2 - OUT, 3 - INOUT, 4 - MUTEXINOUTSET, 8 - INOUTSET.Differential Revision: https://reviews.llvm.org/D97085
[OpenMP] Fixed a crash in hidden helper threadIt is reported that after enabling hidden helper thread, the programcan hit the assertion `new_gtid < __kmp_threads_capacity` sometimes. The rootcaus
[OpenMP] Fixed a crash in hidden helper threadIt is reported that after enabling hidden helper thread, the programcan hit the assertion `new_gtid < __kmp_threads_capacity` sometimes. The rootcause is explained as follows. Let's say the default `__kmp_threads_capacity` is`N`. If hidden helper thread is enabled, `__kmp_threads_capacity` will be offsetto `N+8` by default. If the number of threads we need exceeds `N+8`, e.g. via`num_threads` clause, we need to expand `__kmp_threads`. In`__kmp_expand_threads`, the expansion starts from `__kmp_threads_capacity`, andrepeatedly doubling it until the new capacity meets the requirement. Let'sassume the new requirement is `Y`. If `Y` happens to meet the constraint`(N+8)*2^X=Y` where `X` is the number of iterations, the new capacity is notenough because we have 8 slots for hidden helper threads.Here is an example.```#include <vector>int main(int argc, char *argv[]) { constexpr const size_t N = 1344; std::vector<int> data(N);#pragma omp parallel for for (unsigned i = 0; i < N; ++i) { data[i] = i; }#pragma omp parallel for num_threads(N) for (unsigned i = 0; i < N; ++i) { data[i] += i; } return 0;}```My CPU is 20C40T, then `__kmp_threads_capacity` is 160. After offset,`__kmp_threads_capacity` becomes 168. `1344 = (160+8)*2^3`, then the assertionshit.Reviewed By: protze.joachimDifferential Revision: https://reviews.llvm.org/D98838
[OpenMP] Added the support for hidden helper task in RTLThe 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 t
[OpenMP] Added the support for hidden helper task in RTLThe 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: jdoerfertDifferential Revision: https://reviews.llvm.org/D77609
Revert "[OpenMP] Added the support for hidden helper task in RTL"This reverts commit ed939f853da1f2266f00ea087f778fda88848f73.