Files
clang-p2996/openmp/runtime/test/tasking/hidden_helper_task/common.h
Shilei Tian 9d64275ae0 [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
2021-01-25 22:16:17 -05:00

60 lines
1.8 KiB
C++

#include <cassert>
#include <iostream>
#include <string>
extern "C" {
struct ident_t;
using kmp_int32 = int32_t;
using kmp_int64 = int64_t;
using kmp_routine_entry_t = kmp_int32 (*)(kmp_int32, void *);
using kmp_intptr_t = intptr_t;
typedef struct kmp_depend_info {
kmp_intptr_t base_addr;
size_t len;
struct {
bool in : 1;
bool out : 1;
bool mtx : 1;
} flags;
} kmp_depend_info_t;
typedef union kmp_cmplrdata {
kmp_int32 priority;
kmp_routine_entry_t destructors;
} kmp_cmplrdata_t;
typedef struct kmp_task {
void *shareds;
kmp_routine_entry_t routine;
kmp_int32 part_id;
kmp_cmplrdata_t data1;
kmp_cmplrdata_t data2;
} kmp_task_t;
int32_t __kmpc_global_thread_num(void *);
kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32, kmp_int32, size_t,
size_t, kmp_routine_entry_t);
kmp_task_t *__kmpc_omp_target_task_alloc(ident_t *, kmp_int32, kmp_int32,
size_t, size_t, kmp_routine_entry_t,
kmp_int64);
kmp_int32 __kmpc_omp_taskwait(ident_t *, kmp_int32);
kmp_int32 __kmpc_omp_task(ident_t *, kmp_int32, kmp_task_t *);
kmp_int32 __kmpc_omp_task_with_deps(ident_t *loc_ref, kmp_int32 gtid,
kmp_task_t *new_task, kmp_int32 ndeps,
kmp_depend_info_t *dep_list,
kmp_int32 ndeps_noalias,
kmp_depend_info_t *noalias_dep_list);
void __kmpc_taskgroup(ident_t *, kmp_int32);
void __kmpc_end_taskgroup(ident_t *, kmp_int32);
}
static kmp_int32 get_num_hidden_helper_threads() {
static kmp_int32 __kmp_hidden_helper_threads_num = 8;
if (const char *env = std::getenv("LIBOMP_NUM_HIDDEN_HELPER_THREADS")) {
return std::stoi(env);
}
return __kmp_hidden_helper_threads_num;
}