Skip to content

Commit 9bf843b

Browse files
committed
Revert "[OpenMP] Added the support for hidden helper task in RTL"
This reverts commit ed939f8.
1 parent 83aa93e commit 9bf843b

File tree

13 files changed

+25
-979
lines changed

13 files changed

+25
-979
lines changed

openmp/runtime/src/kmp.h

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -2334,8 +2334,7 @@ typedef struct kmp_tasking_flags { /* Total struct must be exactly 32 bits */
23342334
unsigned priority_specified : 1; /* set if the compiler provides priority
23352335
setting for the task */
23362336
unsigned detachable : 1; /* 1 == can detach */
2337-
unsigned hidden_helper : 1; /* 1 == hidden helper task */
2338-
unsigned reserved : 8; /* reserved for compiler use */
2337+
unsigned reserved : 9; /* reserved for compiler use */
23392338

23402339
/* Library flags */ /* Total library flags must be 16 bits */
23412340
unsigned tasktype : 1; /* task is either explicit(1) or implicit (0) */
@@ -2383,18 +2382,6 @@ struct kmp_taskdata { /* aligned during dynamic allocation */
23832382
kmp_depnode_t
23842383
*td_depnode; // Pointer to graph node if this task has dependencies
23852384
kmp_task_team_t *td_task_team;
2386-
// The parent task team. Usually we could access it via
2387-
// parent_task->td_task_team, but it is possible to be nullptr because of late
2388-
// initialization. Sometimes we must use it. Since the td_task_team of the
2389-
// encountering thread is never nullptr, we set it when this task is created.
2390-
kmp_task_team_t *td_parent_task_team;
2391-
// The global thread id of the encountering thread. We need it because when a
2392-
// regular task depends on a hidden helper task, and the hidden helper task
2393-
// is finished on a hidden helper thread, it will call __kmp_release_deps to
2394-
// release all dependences. If now the task is a regular task, we need to pass
2395-
// the encountering gtid such that the task will be picked up and executed by
2396-
// its encountering team instead of hidden helper team.
2397-
kmp_int32 encountering_gtid;
23982385
size_t td_size_alloc; // Size of task structure, including shareds etc.
23992386
#if defined(KMP_GOMP_COMPAT)
24002387
// 4 or 8 byte integers for the loop bounds in GOMP_taskloop
@@ -2462,16 +2449,10 @@ typedef struct kmp_base_task_team {
24622449
kmp_int32 tt_max_threads; // # entries allocated for threads_data array
24632450
kmp_int32 tt_found_proxy_tasks; // found proxy tasks since last barrier
24642451
kmp_int32 tt_untied_task_encountered;
2465-
// There is hidden helper thread encountered in this task team so that we must
2466-
// wait when waiting on task team
2467-
kmp_int32 tt_hidden_helper_task_encountered;
24682452

24692453
KMP_ALIGN_CACHE
24702454
std::atomic<kmp_int32> tt_unfinished_threads; /* #threads still active */
24712455

2472-
KMP_ALIGN_CACHE
2473-
std::atomic<kmp_int32> tt_unfinished_hidden_helper_tasks;
2474-
24752456
KMP_ALIGN_CACHE
24762457
volatile kmp_uint32
24772458
tt_active; /* is the team still actively executing tasks */
@@ -2936,7 +2917,6 @@ extern volatile int __kmp_init_parallel;
29362917
extern volatile int __kmp_init_monitor;
29372918
#endif
29382919
extern volatile int __kmp_init_user_locks;
2939-
extern volatile int __kmp_init_hidden_helper_threads;
29402920
extern int __kmp_init_counter;
29412921
extern int __kmp_root_counter;
29422922
extern int __kmp_version;
@@ -4005,45 +3985,6 @@ static inline void __kmp_resume_if_hard_paused() {
40053985

40063986
extern void __kmp_omp_display_env(int verbose);
40073987

4008-
// 1: it is initializing hidden helper team
4009-
extern volatile int __kmp_init_hidden_helper;
4010-
// 1: the hidden helper team is done
4011-
extern volatile int __kmp_hidden_helper_team_done;
4012-
// 1: enable hidden helper task
4013-
extern kmp_int32 __kmp_enable_hidden_helper;
4014-
// Main thread of hidden helper team
4015-
extern kmp_info_t *__kmp_hidden_helper_main_thread;
4016-
// Descriptors for the hidden helper threads
4017-
extern kmp_info_t **__kmp_hidden_helper_threads;
4018-
// Number of hidden helper threads
4019-
extern kmp_int32 __kmp_hidden_helper_threads_num;
4020-
// Number of hidden helper tasks that have not been executed yet
4021-
extern std::atomic<kmp_int32> __kmp_unexecuted_hidden_helper_tasks;
4022-
4023-
extern void __kmp_hidden_helper_initialize();
4024-
extern void __kmp_hidden_helper_threads_initz_routine();
4025-
extern void __kmp_do_initialize_hidden_helper_threads();
4026-
extern void __kmp_hidden_helper_threads_initz_wait();
4027-
extern void __kmp_hidden_helper_initz_release();
4028-
extern void __kmp_hidden_helper_threads_deinitz_wait();
4029-
extern void __kmp_hidden_helper_threads_deinitz_release();
4030-
extern void __kmp_hidden_helper_main_thread_wait();
4031-
extern void __kmp_hidden_helper_worker_thread_wait();
4032-
extern void __kmp_hidden_helper_worker_thread_signal();
4033-
extern void __kmp_hidden_helper_main_thread_release();
4034-
4035-
// Check whether a given thread is a hidden helper thread
4036-
#define KMP_HIDDEN_HELPER_THREAD(gtid) \
4037-
((gtid) >= 1 && (gtid) <= __kmp_hidden_helper_threads_num)
4038-
4039-
#define KMP_HIDDEN_HELPER_WORKER_THREAD(gtid) \
4040-
((gtid) > 1 && (gtid) <= __kmp_hidden_helper_threads_num)
4041-
4042-
// Map a gtid to a hidden helper thread. The first hidden helper thread, a.k.a
4043-
// main thread, is skipped.
4044-
#define KMP_GTID_TO_SHADOW_GTID(gtid) \
4045-
((gtid) % (__kmp_hidden_helper_threads_num - 1) + 2)
4046-
40473988
#ifdef __cplusplus
40483989
}
40493990
#endif

openmp/runtime/src/kmp_global.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ volatile int __kmp_init_gtid = FALSE;
4646
volatile int __kmp_init_common = FALSE;
4747
volatile int __kmp_init_middle = FALSE;
4848
volatile int __kmp_init_parallel = FALSE;
49-
volatile int __kmp_init_hidden_helper = FALSE;
50-
volatile int __kmp_init_hidden_helper_threads = FALSE;
51-
volatile int __kmp_hidden_helper_team_done = FALSE;
5249
#if KMP_USE_MONITOR
5350
volatile int __kmp_init_monitor =
5451
0; /* 1 - launched, 2 - actually started (Windows* OS only) */

openmp/runtime/src/kmp_runtime.cpp

Lines changed: 12 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -3639,37 +3639,15 @@ int __kmp_register_root(int initial_thread) {
36393639
}
36403640
}
36413641

3642-
// When hidden helper task is enabled, __kmp_threads is organized as follows:
3643-
// 0: initial thread, also a regular OpenMP thread.
3644-
// [1, __kmp_hidden_helper_threads_num]: slots for hidden helper threads.
3645-
// [__kmp_hidden_helper_threads_num + 1, __kmp_threads_capacity): slots for
3646-
// regular OpenMP threads.
3647-
if (TCR_4(__kmp_init_hidden_helper_threads)) {
3648-
// Find an available thread slot for hidden helper thread. Slots for hidden
3649-
// helper threads start from 1 to __kmp_hidden_helper_threads_num.
3650-
for (gtid = 1; TCR_PTR(__kmp_threads[gtid]) != NULL &&
3651-
gtid <= __kmp_hidden_helper_threads_num;
3652-
gtid++)
3653-
;
3654-
KMP_ASSERT(gtid <= __kmp_hidden_helper_threads_num);
3655-
KA_TRACE(1, ("__kmp_register_root: found slot in threads array for "
3656-
"hidden helper thread: T#%d\n",
3657-
gtid));
3658-
} else {
3659-
/* find an available thread slot */
3660-
// Don't reassign the zero slot since we need that to only be used by
3661-
// initial thread. Slots for hidden helper threads should also be skipped.
3662-
if (initial_thread && __kmp_threads[0] == NULL) {
3663-
gtid = 0;
3664-
} else {
3665-
for (gtid = __kmp_hidden_helper_threads_num + 1;
3666-
TCR_PTR(__kmp_threads[gtid]) != NULL; gtid++)
3667-
;
3668-
}
3669-
KA_TRACE(
3670-
1, ("__kmp_register_root: found slot in threads array: T#%d\n", gtid));
3671-
KMP_ASSERT(gtid < __kmp_threads_capacity);
3672-
}
3642+
/* find an available thread slot */
3643+
/* Don't reassign the zero slot since we need that to only be used by initial
3644+
thread */
3645+
for (gtid = (initial_thread ? 0 : 1); TCR_PTR(__kmp_threads[gtid]) != NULL;
3646+
gtid++)
3647+
;
3648+
KA_TRACE(1,
3649+
("__kmp_register_root: found slot in threads array: T#%d\n", gtid));
3650+
KMP_ASSERT(gtid < __kmp_threads_capacity);
36733651

36743652
/* update global accounting */
36753653
__kmp_all_nth++;
@@ -4320,20 +4298,8 @@ kmp_info_t *__kmp_allocate_thread(kmp_root_t *root, kmp_team_t *team,
43204298
#endif
43214299

43224300
KMP_MB();
4323-
4324-
{
4325-
int new_start_gtid = TCR_4(__kmp_init_hidden_helper_threads)
4326-
? 1
4327-
: __kmp_hidden_helper_threads_num + 1;
4328-
4329-
for (new_gtid = new_start_gtid; TCR_PTR(__kmp_threads[new_gtid]) != NULL;
4330-
++new_gtid) {
4331-
KMP_DEBUG_ASSERT(new_gtid < __kmp_threads_capacity);
4332-
}
4333-
4334-
if (TCR_4(__kmp_init_hidden_helper_threads)) {
4335-
KMP_DEBUG_ASSERT(new_gtid <= __kmp_hidden_helper_threads_num);
4336-
}
4301+
for (new_gtid = 1; TCR_PTR(__kmp_threads[new_gtid]) != NULL; ++new_gtid) {
4302+
KMP_DEBUG_ASSERT(new_gtid < __kmp_threads_capacity);
43374303
}
43384304

43394305
/* allocate space for it. */
@@ -6267,15 +6233,6 @@ void __kmp_internal_end_thread(int gtid_req) {
62676233
return;
62686234
}
62696235

6270-
// If hidden helper team has been initialized, we need to deinit it
6271-
if (TCR_4(__kmp_init_hidden_helper)) {
6272-
TCW_SYNC_4(__kmp_hidden_helper_team_done, TRUE);
6273-
// First release the main thread to let it continue its work
6274-
__kmp_hidden_helper_main_thread_release();
6275-
// Wait until the hidden helper team has been destroyed
6276-
__kmp_hidden_helper_threads_deinitz_wait();
6277-
}
6278-
62796236
KMP_MB(); /* Flush all pending memory write invalidates. */
62806237

62816238
/* find out who we are and what we should do */
@@ -7152,41 +7109,6 @@ void __kmp_parallel_initialize(void) {
71527109
__kmp_release_bootstrap_lock(&__kmp_initz_lock);
71537110
}
71547111

7155-
void __kmp_hidden_helper_initialize() {
7156-
if (TCR_4(__kmp_init_hidden_helper))
7157-
return;
7158-
7159-
// __kmp_parallel_initialize is required before we initialize hidden helper
7160-
if (!TCR_4(__kmp_init_parallel))
7161-
__kmp_parallel_initialize();
7162-
7163-
// Double check. Note that this double check should not be placed before
7164-
// __kmp_parallel_initialize as it will cause dead lock.
7165-
__kmp_acquire_bootstrap_lock(&__kmp_initz_lock);
7166-
if (TCR_4(__kmp_init_hidden_helper)) {
7167-
__kmp_release_bootstrap_lock(&__kmp_initz_lock);
7168-
return;
7169-
}
7170-
7171-
// Set the count of hidden helper tasks to be executed to zero
7172-
KMP_ATOMIC_ST_REL(&__kmp_unexecuted_hidden_helper_tasks, 0);
7173-
7174-
// Set the global variable indicating that we're initializing hidden helper
7175-
// team/threads
7176-
TCW_SYNC_4(__kmp_init_hidden_helper_threads, TRUE);
7177-
7178-
// Platform independent initialization
7179-
__kmp_do_initialize_hidden_helper_threads();
7180-
7181-
// Wait here for the finish of initialization of hidden helper teams
7182-
__kmp_hidden_helper_threads_initz_wait();
7183-
7184-
// We have finished hidden helper initialization
7185-
TCW_SYNC_4(__kmp_init_hidden_helper, TRUE);
7186-
7187-
__kmp_release_bootstrap_lock(&__kmp_initz_lock);
7188-
}
7189-
71907112
/* ------------------------------------------------------------------------ */
71917113

71927114
void __kmp_run_before_invoked_task(int gtid, int tid, kmp_info_t *this_thr,
@@ -8532,62 +8454,11 @@ int __kmp_pause_resource(kmp_pause_status_t level) {
85328454
}
85338455
}
85348456

8457+
85358458
void __kmp_omp_display_env(int verbose) {
85368459
__kmp_acquire_bootstrap_lock(&__kmp_initz_lock);
85378460
if (__kmp_init_serial == 0)
85388461
__kmp_do_serial_initialize();
85398462
__kmp_display_env_impl(!verbose, verbose);
85408463
__kmp_release_bootstrap_lock(&__kmp_initz_lock);
85418464
}
8542-
8543-
// Globals and functions for hidden helper task
8544-
kmp_info_t **__kmp_hidden_helper_threads;
8545-
kmp_info_t *__kmp_hidden_helper_main_thread;
8546-
kmp_int32 __kmp_hidden_helper_threads_num = 8;
8547-
std::atomic<kmp_int32> __kmp_unexecuted_hidden_helper_tasks;
8548-
kmp_int32 __kmp_enable_hidden_helper = TRUE;
8549-
8550-
namespace {
8551-
std::atomic<kmp_int32> __kmp_hit_hidden_helper_threads_num;
8552-
8553-
void __kmp_hidden_helper_wrapper_fn(int *gtid, int *, ...) {
8554-
// This is an explicit synchronization on all hidden helper threads in case
8555-
// that when a regular thread pushes a hidden helper task to one hidden
8556-
// helper thread, the thread has not been awaken once since they're released
8557-
// by the main thread after creating the team.
8558-
KMP_ATOMIC_INC(&__kmp_hit_hidden_helper_threads_num);
8559-
while (KMP_ATOMIC_LD_ACQ(&__kmp_hit_hidden_helper_threads_num) !=
8560-
__kmp_hidden_helper_threads_num)
8561-
;
8562-
8563-
// If main thread, then wait for signal
8564-
if (__kmpc_master(nullptr, *gtid)) {
8565-
// First, unset the initial state and release the initial thread
8566-
TCW_4(__kmp_init_hidden_helper_threads, FALSE);
8567-
__kmp_hidden_helper_initz_release();
8568-
__kmp_hidden_helper_main_thread_wait();
8569-
// Now wake up all worker threads
8570-
for (int i = 1; i < __kmp_hit_hidden_helper_threads_num; ++i) {
8571-
__kmp_hidden_helper_worker_thread_signal();
8572-
}
8573-
}
8574-
}
8575-
} // namespace
8576-
8577-
void __kmp_hidden_helper_threads_initz_routine() {
8578-
// Create a new root for hidden helper team/threads
8579-
const int gtid = __kmp_register_root(TRUE);
8580-
__kmp_hidden_helper_main_thread = __kmp_threads[gtid];
8581-
__kmp_hidden_helper_threads = &__kmp_threads[gtid];
8582-
__kmp_hidden_helper_main_thread->th.th_set_nproc =
8583-
__kmp_hidden_helper_threads_num;
8584-
8585-
KMP_ATOMIC_ST_REL(&__kmp_hit_hidden_helper_threads_num, 0);
8586-
8587-
__kmpc_fork_call(nullptr, 0, __kmp_hidden_helper_wrapper_fn);
8588-
8589-
// Set the initialization flag to FALSE
8590-
TCW_SYNC_4(__kmp_init_hidden_helper, FALSE);
8591-
8592-
__kmp_hidden_helper_threads_deinitz_release();
8593-
}

openmp/runtime/src/kmp_settings.cpp

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -503,11 +503,6 @@ int __kmp_initial_threads_capacity(int req_nproc) {
503503
if (nth < (4 * __kmp_xproc))
504504
nth = (4 * __kmp_xproc);
505505

506-
// If hidden helper task is enabled, we initialize the thread capacity with
507-
// extra
508-
// __kmp_hidden_helper_threads_num.
509-
nth += __kmp_hidden_helper_threads_num;
510-
511506
if (nth > __kmp_max_nth)
512507
nth = __kmp_max_nth;
513508

@@ -1166,33 +1161,6 @@ static void __kmp_stg_parse_num_threads(char const *name, char const *value,
11661161
K_DIAG(1, ("__kmp_dflt_team_nth == %d\n", __kmp_dflt_team_nth));
11671162
} // __kmp_stg_parse_num_threads
11681163

1169-
static void __kmp_stg_parse_num_hidden_helper_threads(char const *name,
1170-
char const *value,
1171-
void *data) {
1172-
__kmp_stg_parse_int(name, value, 0, 16, &__kmp_hidden_helper_threads_num);
1173-
// If the number of hidden helper threads is zero, we disable hidden helper
1174-
// task
1175-
if (__kmp_hidden_helper_threads_num == 0) {
1176-
__kmp_enable_hidden_helper = FALSE;
1177-
}
1178-
} // __kmp_stg_parse_num_hidden_helper_threads
1179-
1180-
static void __kmp_stg_print_num_hidden_helper_threads(kmp_str_buf_t *buffer,
1181-
char const *name,
1182-
void *data) {
1183-
__kmp_stg_print_int(buffer, name, __kmp_hidden_helper_threads_num);
1184-
} // __kmp_stg_print_num_hidden_helper_threads
1185-
1186-
static void __kmp_stg_parse_use_hidden_helper(char const *name,
1187-
char const *value, void *data) {
1188-
__kmp_stg_parse_bool(name, value, &__kmp_enable_hidden_helper);
1189-
} // __kmp_stg_parse_use_hidden_helper
1190-
1191-
static void __kmp_stg_print_use_hidden_helper(kmp_str_buf_t *buffer,
1192-
char const *name, void *data) {
1193-
__kmp_stg_print_bool(buffer, name, __kmp_enable_hidden_helper);
1194-
} // __kmp_stg_print_use_hidden_helper
1195-
11961164
static void __kmp_stg_print_num_threads(kmp_str_buf_t *buffer, char const *name,
11971165
void *data) {
11981166
if (__kmp_env_format) {
@@ -5024,11 +4992,6 @@ static kmp_setting_t __kmp_stg_table[] = {
50244992
__kmp_stg_print_omp_cancellation, NULL, 0, 0},
50254993
{"OMP_ALLOCATOR", __kmp_stg_parse_allocator, __kmp_stg_print_allocator,
50264994
NULL, 0, 0},
5027-
{"LIBOMP_USE_HIDDEN_HELPER_TASK", __kmp_stg_parse_use_hidden_helper,
5028-
__kmp_stg_print_use_hidden_helper, NULL, 0, 0},
5029-
{"LIBOMP_NUM_HIDDEN_HELPER_THREADS",
5030-
__kmp_stg_parse_num_hidden_helper_threads,
5031-
__kmp_stg_print_num_hidden_helper_threads, NULL, 0, 0},
50324995

50334996
#if OMPT_SUPPORT
50344997
{"OMP_TOOL", __kmp_stg_parse_omp_tool, __kmp_stg_print_omp_tool, NULL, 0,

openmp/runtime/src/kmp_taskdeps.h

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ static inline void __kmp_release_deps(kmp_int32 gtid, kmp_taskdata_t *task) {
119119
KMP_RELEASE_DEPNODE(gtid, node);
120120

121121
kmp_depnode_list_t *next;
122-
kmp_taskdata_t *next_taskdata;
123122
for (kmp_depnode_list_t *p = node->dn.successors; p; p = next) {
124123
kmp_depnode_t *successor = p->node;
125124
kmp_int32 npredecessors = KMP_ATOMIC_DEC(&successor->dn.npredecessors) - 1;
@@ -132,24 +131,7 @@ static inline void __kmp_release_deps(kmp_int32 gtid, kmp_taskdata_t *task) {
132131
KA_TRACE(20, ("__kmp_release_deps: T#%d successor %p of %p scheduled "
133132
"for execution.\n",
134133
gtid, successor->dn.task, task));
135-
// If a regular task depending on a hidden helper task, when the
136-
// hidden helper task is done, the regular task should be executed by
137-
// its encountering team.
138-
if (KMP_HIDDEN_HELPER_THREAD(gtid)) {
139-
// Hidden helper thread can only execute hidden helper tasks
140-
KMP_ASSERT(task->td_flags.hidden_helper);
141-
next_taskdata = KMP_TASK_TO_TASKDATA(successor->dn.task);
142-
// If the dependent task is a regular task, we need to push to its
143-
// encountering thread's queue; otherwise, it can be pushed to its own
144-
// queue.
145-
if (!next_taskdata->td_flags.hidden_helper) {
146-
__kmp_omp_task(task->encountering_gtid, successor->dn.task, false);
147-
} else {
148-
__kmp_omp_task(gtid, successor->dn.task, false);
149-
}
150-
} else {
151-
__kmp_omp_task(gtid, successor->dn.task, false);
152-
}
134+
__kmp_omp_task(gtid, successor->dn.task, false);
153135
}
154136
}
155137

0 commit comments

Comments
 (0)