Skip to content

Commit 680c71b

Browse files
committed
[OpenMP] Clean up for hidden helper task
This patch makes some clean up for code of hidden helper task. Reviewed By: protze.joachim Differential Revision: https://reviews.llvm.org/D107008
1 parent 9f5d6ea commit 680c71b

File tree

3 files changed

+26
-39
lines changed

3 files changed

+26
-39
lines changed

openmp/runtime/src/kmp.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2421,13 +2421,6 @@ struct kmp_taskdata { /* aligned during dynamic allocation */
24212421
kmp_depnode_t
24222422
*td_depnode; // Pointer to graph node if this task has dependencies
24232423
kmp_task_team_t *td_task_team;
2424-
// The global thread id of the encountering thread. We need it because when a
2425-
// regular task depends on a hidden helper task, and the hidden helper task
2426-
// is finished on a hidden helper thread, it will call __kmp_release_deps to
2427-
// release all dependences. If now the task is a regular task, we need to pass
2428-
// the encountering gtid such that the task will be picked up and executed by
2429-
// its encountering team instead of hidden helper team.
2430-
kmp_int32 encountering_gtid;
24312424
size_t td_size_alloc; // Size of task structure, including shareds etc.
24322425
#if defined(KMP_GOMP_COMPAT)
24332426
// 4 or 8 byte integers for the loop bounds in GOMP_taskloop

openmp/runtime/src/kmp_taskdeps.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,10 @@ static inline void __kmp_release_deps(kmp_int32 gtid, kmp_taskdata_t *task) {
144144
// encountering thread's queue; otherwise, it can be pushed to its own
145145
// queue.
146146
if (!next_taskdata->td_flags.hidden_helper) {
147-
__kmpc_give_task(
148-
successor->dn.task,
149-
__kmp_tid_from_gtid(next_taskdata->encountering_gtid));
147+
kmp_int32 encountering_gtid =
148+
next_taskdata->td_alloc_thread->th.th_info.ds.ds_gtid;
149+
kmp_int32 encountering_tid = __kmp_tid_from_gtid(encountering_gtid);
150+
__kmpc_give_task(successor->dn.task, encountering_tid);
150151
} else {
151152
__kmp_omp_task(gtid, successor->dn.task, false);
152153
}

openmp/runtime/src/kmp_tasking.cpp

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,7 +1192,6 @@ kmp_task_t *__kmp_task_alloc(ident_t *loc_ref, kmp_int32 gtid,
11921192
kmp_task_t *task;
11931193
kmp_taskdata_t *taskdata;
11941194
kmp_info_t *thread = __kmp_threads[gtid];
1195-
kmp_info_t *encountering_thread = thread;
11961195
kmp_team_t *team = thread->th.th_team;
11971196
kmp_taskdata_t *parent_task = thread->th.th_current_task;
11981197
size_t shareds_offset;
@@ -1204,15 +1203,6 @@ kmp_task_t *__kmp_task_alloc(ident_t *loc_ref, kmp_int32 gtid,
12041203
if (__kmp_enable_hidden_helper) {
12051204
if (!TCR_4(__kmp_init_hidden_helper))
12061205
__kmp_hidden_helper_initialize();
1207-
1208-
// For a hidden helper task encountered by a regular thread, we will push
1209-
// the task to the (gtid%__kmp_hidden_helper_threads_num)-th hidden helper
1210-
// thread.
1211-
if (!KMP_HIDDEN_HELPER_THREAD(gtid)) {
1212-
thread = __kmp_threads[KMP_GTID_TO_SHADOW_GTID(gtid)];
1213-
// We don't change the parent-child relation for hidden helper task as
1214-
// we need that to do per-task-region synchronization.
1215-
}
12161206
} else {
12171207
// If the hidden helper task is not enabled, reset the flag to FALSE.
12181208
flags->hidden_helper = FALSE;
@@ -1235,8 +1225,7 @@ kmp_task_t *__kmp_task_alloc(ident_t *loc_ref, kmp_int32 gtid,
12351225
// Untied task encountered causes the TSC algorithm to check entire deque of
12361226
// the victim thread. If no untied task encountered, then checking the head
12371227
// of the deque should be enough.
1238-
KMP_CHECK_UPDATE(
1239-
encountering_thread->th.th_task_team->tt.tt_untied_task_encountered, 1);
1228+
KMP_CHECK_UPDATE(thread->th.th_task_team->tt.tt_untied_task_encountered, 1);
12401229
}
12411230

12421231
// Detachable tasks are not proxy tasks yet but could be in the future. Doing
@@ -1250,32 +1239,30 @@ kmp_task_t *__kmp_task_alloc(ident_t *loc_ref, kmp_int32 gtid,
12501239
}
12511240
/* are we running in a sequential parallel or tskm_immediate_exec... we need
12521241
tasking support enabled */
1253-
if ((encountering_thread->th.th_task_team) == NULL) {
1242+
if ((thread->th.th_task_team) == NULL) {
12541243
/* This should only happen if the team is serialized
12551244
setup a task team and propagate it to the thread */
12561245
KMP_DEBUG_ASSERT(team->t.t_serialized);
12571246
KA_TRACE(30,
12581247
("T#%d creating task team in __kmp_task_alloc for proxy task\n",
12591248
gtid));
1260-
__kmp_task_team_setup(
1261-
encountering_thread, team,
1262-
1); // 1 indicates setup the current team regardless of nthreads
1263-
encountering_thread->th.th_task_team =
1264-
team->t.t_task_team[encountering_thread->th.th_task_state];
1249+
// 1 indicates setup the current team regardless of nthreads
1250+
__kmp_task_team_setup(thread, team, 1);
1251+
thread->th.th_task_team = team->t.t_task_team[thread->th.th_task_state];
12651252
}
1266-
kmp_task_team_t *task_team = encountering_thread->th.th_task_team;
1253+
kmp_task_team_t *task_team = thread->th.th_task_team;
12671254

12681255
/* tasking must be enabled now as the task might not be pushed */
12691256
if (!KMP_TASKING_ENABLED(task_team)) {
12701257
KA_TRACE(
12711258
30,
12721259
("T#%d enabling tasking in __kmp_task_alloc for proxy task\n", gtid));
1273-
__kmp_enable_tasking(task_team, encountering_thread);
1274-
kmp_int32 tid = encountering_thread->th.th_info.ds.ds_tid;
1260+
__kmp_enable_tasking(task_team, thread);
1261+
kmp_int32 tid = thread->th.th_info.ds.ds_tid;
12751262
kmp_thread_data_t *thread_data = &task_team->tt.tt_threads_data[tid];
12761263
// No lock needed since only owner can allocate
12771264
if (thread_data->td.td_deque == NULL) {
1278-
__kmp_alloc_task_deque(encountering_thread, thread_data);
1265+
__kmp_alloc_task_deque(thread, thread_data);
12791266
}
12801267
}
12811268

@@ -1300,11 +1287,11 @@ kmp_task_t *__kmp_task_alloc(ident_t *loc_ref, kmp_int32 gtid,
13001287

13011288
// Avoid double allocation here by combining shareds with taskdata
13021289
#if USE_FAST_MEMORY
1303-
taskdata = (kmp_taskdata_t *)__kmp_fast_allocate(
1304-
encountering_thread, shareds_offset + sizeof_shareds);
1290+
taskdata = (kmp_taskdata_t *)__kmp_fast_allocate(thread, shareds_offset +
1291+
sizeof_shareds);
13051292
#else /* ! USE_FAST_MEMORY */
1306-
taskdata = (kmp_taskdata_t *)__kmp_thread_malloc(
1307-
encountering_thread, shareds_offset + sizeof_shareds);
1293+
taskdata = (kmp_taskdata_t *)__kmp_thread_malloc(thread, shareds_offset +
1294+
sizeof_shareds);
13081295
#endif /* USE_FAST_MEMORY */
13091296

13101297
task = KMP_TASKDATA_TO_TASK(taskdata);
@@ -1331,7 +1318,7 @@ kmp_task_t *__kmp_task_alloc(ident_t *loc_ref, kmp_int32 gtid,
13311318

13321319
taskdata->td_task_id = KMP_GEN_TASK_ID();
13331320
taskdata->td_team = thread->th.th_team;
1334-
taskdata->td_alloc_thread = encountering_thread;
1321+
taskdata->td_alloc_thread = thread;
13351322
taskdata->td_parent = parent_task;
13361323
taskdata->td_level = parent_task->td_level + 1; // increment nesting level
13371324
KMP_ATOMIC_ST_RLX(&taskdata->td_untied_count, 0);
@@ -1345,10 +1332,16 @@ kmp_task_t *__kmp_task_alloc(ident_t *loc_ref, kmp_int32 gtid,
13451332
copy_icvs(&taskdata->td_icvs, &taskdata->td_parent->td_icvs);
13461333

13471334
taskdata->td_flags = *flags;
1348-
taskdata->encountering_gtid = gtid;
13491335
taskdata->td_task_team = thread->th.th_task_team;
13501336
taskdata->td_size_alloc = shareds_offset + sizeof_shareds;
13511337
taskdata->td_flags.tasktype = TASK_EXPLICIT;
1338+
// If it is hidden helper task, we need to set the team and task team
1339+
// correspondingly.
1340+
if (flags->hidden_helper) {
1341+
kmp_info_t *shadow_thread = __kmp_threads[KMP_GTID_TO_SHADOW_GTID(gtid)];
1342+
taskdata->td_team = shadow_thread->th.th_team;
1343+
taskdata->td_task_team = shadow_thread->th.th_task_team;
1344+
}
13521345

13531346
// GEH - TODO: fix this to copy parent task's value of tasking_ser flag
13541347
taskdata->td_flags.tasking_ser = (__kmp_tasking_mode == tskm_immediate_exec);
@@ -3957,7 +3950,7 @@ void __kmpc_give_task(kmp_task_t *ptask, kmp_int32 start = 0) {
39573950

39583951
// This should be similar to start_k = __kmp_get_random( thread ) % nthreads
39593952
// but we cannot use __kmp_get_random here
3960-
kmp_int32 start_k = start;
3953+
kmp_int32 start_k = start % nthreads;
39613954
kmp_int32 pass = 1;
39623955
kmp_int32 k = start_k;
39633956

0 commit comments

Comments
 (0)