[Openmp-commits] [openmp] 680c71b - [OpenMP] Clean up for hidden helper task
Shilei Tian via Openmp-commits
openmp-commits at lists.llvm.org
Wed Aug 4 09:36:48 PDT 2021
Author: Shilei Tian
Date: 2021-08-04T12:36:44-04:00
New Revision: 680c71b127a995389869f51eaef24c7e9d0b2505
URL: https://github.com/llvm/llvm-project/commit/680c71b127a995389869f51eaef24c7e9d0b2505
DIFF: https://github.com/llvm/llvm-project/commit/680c71b127a995389869f51eaef24c7e9d0b2505.diff
LOG: [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
Added:
Modified:
openmp/runtime/src/kmp.h
openmp/runtime/src/kmp_taskdeps.h
openmp/runtime/src/kmp_tasking.cpp
Removed:
################################################################################
diff --git a/openmp/runtime/src/kmp.h b/openmp/runtime/src/kmp.h
index 835d4ad55980..dbf1111a8976 100644
--- a/openmp/runtime/src/kmp.h
+++ b/openmp/runtime/src/kmp.h
@@ -2421,13 +2421,6 @@ struct kmp_taskdata { /* aligned during dynamic allocation */
kmp_depnode_t
*td_depnode; // Pointer to graph node if this task has dependencies
kmp_task_team_t *td_task_team;
- // The global thread id of the encountering thread. We need it because when a
- // regular task depends on a hidden helper task, and the hidden helper task
- // is finished on a hidden helper thread, it will call __kmp_release_deps to
- // release all dependences. If now the task is a regular task, we need to pass
- // the encountering gtid such that the task will be picked up and executed by
- // its encountering team instead of hidden helper team.
- kmp_int32 encountering_gtid;
size_t td_size_alloc; // Size of task structure, including shareds etc.
#if defined(KMP_GOMP_COMPAT)
// 4 or 8 byte integers for the loop bounds in GOMP_taskloop
diff --git a/openmp/runtime/src/kmp_taskdeps.h b/openmp/runtime/src/kmp_taskdeps.h
index 73abf07018f3..02ceae9aa6a4 100644
--- a/openmp/runtime/src/kmp_taskdeps.h
+++ b/openmp/runtime/src/kmp_taskdeps.h
@@ -144,9 +144,10 @@ static inline void __kmp_release_deps(kmp_int32 gtid, kmp_taskdata_t *task) {
// encountering thread's queue; otherwise, it can be pushed to its own
// queue.
if (!next_taskdata->td_flags.hidden_helper) {
- __kmpc_give_task(
- successor->dn.task,
- __kmp_tid_from_gtid(next_taskdata->encountering_gtid));
+ kmp_int32 encountering_gtid =
+ next_taskdata->td_alloc_thread->th.th_info.ds.ds_gtid;
+ kmp_int32 encountering_tid = __kmp_tid_from_gtid(encountering_gtid);
+ __kmpc_give_task(successor->dn.task, encountering_tid);
} else {
__kmp_omp_task(gtid, successor->dn.task, false);
}
diff --git a/openmp/runtime/src/kmp_tasking.cpp b/openmp/runtime/src/kmp_tasking.cpp
index ae9728778bb7..f8cb56e53a59 100644
--- a/openmp/runtime/src/kmp_tasking.cpp
+++ b/openmp/runtime/src/kmp_tasking.cpp
@@ -1192,7 +1192,6 @@ kmp_task_t *__kmp_task_alloc(ident_t *loc_ref, kmp_int32 gtid,
kmp_task_t *task;
kmp_taskdata_t *taskdata;
kmp_info_t *thread = __kmp_threads[gtid];
- kmp_info_t *encountering_thread = thread;
kmp_team_t *team = thread->th.th_team;
kmp_taskdata_t *parent_task = thread->th.th_current_task;
size_t shareds_offset;
@@ -1204,15 +1203,6 @@ kmp_task_t *__kmp_task_alloc(ident_t *loc_ref, kmp_int32 gtid,
if (__kmp_enable_hidden_helper) {
if (!TCR_4(__kmp_init_hidden_helper))
__kmp_hidden_helper_initialize();
-
- // For a hidden helper task encountered by a regular thread, we will push
- // the task to the (gtid%__kmp_hidden_helper_threads_num)-th hidden helper
- // thread.
- if (!KMP_HIDDEN_HELPER_THREAD(gtid)) {
- thread = __kmp_threads[KMP_GTID_TO_SHADOW_GTID(gtid)];
- // We don't change the parent-child relation for hidden helper task as
- // we need that to do per-task-region synchronization.
- }
} else {
// If the hidden helper task is not enabled, reset the flag to FALSE.
flags->hidden_helper = FALSE;
@@ -1235,8 +1225,7 @@ kmp_task_t *__kmp_task_alloc(ident_t *loc_ref, kmp_int32 gtid,
// Untied task encountered causes the TSC algorithm to check entire deque of
// the victim thread. If no untied task encountered, then checking the head
// of the deque should be enough.
- KMP_CHECK_UPDATE(
- encountering_thread->th.th_task_team->tt.tt_untied_task_encountered, 1);
+ KMP_CHECK_UPDATE(thread->th.th_task_team->tt.tt_untied_task_encountered, 1);
}
// 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,
}
/* are we running in a sequential parallel or tskm_immediate_exec... we need
tasking support enabled */
- if ((encountering_thread->th.th_task_team) == NULL) {
+ if ((thread->th.th_task_team) == NULL) {
/* This should only happen if the team is serialized
setup a task team and propagate it to the thread */
KMP_DEBUG_ASSERT(team->t.t_serialized);
KA_TRACE(30,
("T#%d creating task team in __kmp_task_alloc for proxy task\n",
gtid));
- __kmp_task_team_setup(
- encountering_thread, team,
- 1); // 1 indicates setup the current team regardless of nthreads
- encountering_thread->th.th_task_team =
- team->t.t_task_team[encountering_thread->th.th_task_state];
+ // 1 indicates setup the current team regardless of nthreads
+ __kmp_task_team_setup(thread, team, 1);
+ thread->th.th_task_team = team->t.t_task_team[thread->th.th_task_state];
}
- kmp_task_team_t *task_team = encountering_thread->th.th_task_team;
+ kmp_task_team_t *task_team = thread->th.th_task_team;
/* tasking must be enabled now as the task might not be pushed */
if (!KMP_TASKING_ENABLED(task_team)) {
KA_TRACE(
30,
("T#%d enabling tasking in __kmp_task_alloc for proxy task\n", gtid));
- __kmp_enable_tasking(task_team, encountering_thread);
- kmp_int32 tid = encountering_thread->th.th_info.ds.ds_tid;
+ __kmp_enable_tasking(task_team, thread);
+ kmp_int32 tid = thread->th.th_info.ds.ds_tid;
kmp_thread_data_t *thread_data = &task_team->tt.tt_threads_data[tid];
// No lock needed since only owner can allocate
if (thread_data->td.td_deque == NULL) {
- __kmp_alloc_task_deque(encountering_thread, thread_data);
+ __kmp_alloc_task_deque(thread, thread_data);
}
}
@@ -1300,11 +1287,11 @@ kmp_task_t *__kmp_task_alloc(ident_t *loc_ref, kmp_int32 gtid,
// Avoid double allocation here by combining shareds with taskdata
#if USE_FAST_MEMORY
- taskdata = (kmp_taskdata_t *)__kmp_fast_allocate(
- encountering_thread, shareds_offset + sizeof_shareds);
+ taskdata = (kmp_taskdata_t *)__kmp_fast_allocate(thread, shareds_offset +
+ sizeof_shareds);
#else /* ! USE_FAST_MEMORY */
- taskdata = (kmp_taskdata_t *)__kmp_thread_malloc(
- encountering_thread, shareds_offset + sizeof_shareds);
+ taskdata = (kmp_taskdata_t *)__kmp_thread_malloc(thread, shareds_offset +
+ sizeof_shareds);
#endif /* USE_FAST_MEMORY */
task = KMP_TASKDATA_TO_TASK(taskdata);
@@ -1331,7 +1318,7 @@ kmp_task_t *__kmp_task_alloc(ident_t *loc_ref, kmp_int32 gtid,
taskdata->td_task_id = KMP_GEN_TASK_ID();
taskdata->td_team = thread->th.th_team;
- taskdata->td_alloc_thread = encountering_thread;
+ taskdata->td_alloc_thread = thread;
taskdata->td_parent = parent_task;
taskdata->td_level = parent_task->td_level + 1; // increment nesting level
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,
copy_icvs(&taskdata->td_icvs, &taskdata->td_parent->td_icvs);
taskdata->td_flags = *flags;
- taskdata->encountering_gtid = gtid;
taskdata->td_task_team = thread->th.th_task_team;
taskdata->td_size_alloc = shareds_offset + sizeof_shareds;
taskdata->td_flags.tasktype = TASK_EXPLICIT;
+ // If it is hidden helper task, we need to set the team and task team
+ // correspondingly.
+ if (flags->hidden_helper) {
+ kmp_info_t *shadow_thread = __kmp_threads[KMP_GTID_TO_SHADOW_GTID(gtid)];
+ taskdata->td_team = shadow_thread->th.th_team;
+ taskdata->td_task_team = shadow_thread->th.th_task_team;
+ }
// GEH - TODO: fix this to copy parent task's value of tasking_ser flag
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) {
// This should be similar to start_k = __kmp_get_random( thread ) % nthreads
// but we cannot use __kmp_get_random here
- kmp_int32 start_k = start;
+ kmp_int32 start_k = start % nthreads;
kmp_int32 pass = 1;
kmp_int32 k = start_k;
More information about the Openmp-commits
mailing list