[Openmp-commits] [openmp] ea45235 - [OpenMP] Refined the logic to give a regular task from a hidden helper task
Shilei Tian via Openmp-commits
openmp-commits at lists.llvm.org
Thu Jul 22 16:21:34 PDT 2021
Author: Shilei Tian
Date: 2021-07-22T19:21:29-04:00
New Revision: ea452353c013b95dbe9d64ff59a97597b2549f19
URL: https://github.com/llvm/llvm-project/commit/ea452353c013b95dbe9d64ff59a97597b2549f19
DIFF: https://github.com/llvm/llvm-project/commit/ea452353c013b95dbe9d64ff59a97597b2549f19.diff
LOG: [OpenMP] Refined the logic to give a regular task from a hidden helper task
In current implementation, if a regular task depends on a hidden helper task,
and when the hidden helper task is releasing its dependences, it directly calls
`__kmp_omp_task`. This could cause a problem that if `__kmp_push_task` returns
`TASK_NOT_PUSHED`, the task will be executed immediately. However, the hidden
helper threads are assumed to only execute hidden helper tasks. This could cause
problems because when calling `__kmp_omp_task`, the encountering gtid, which is
not the real one of the thread, is passed.
This patch uses `__kmp_give_task`, but because it is a static function, a new
wrapper `__kmpc_give_task` is added.
Reviewed By: AndreyChurbanov
Differential Revision: https://reviews.llvm.org/D106572
Added:
Modified:
openmp/runtime/src/kmp_taskdeps.h
openmp/runtime/src/kmp_tasking.cpp
Removed:
################################################################################
diff --git a/openmp/runtime/src/kmp_taskdeps.h b/openmp/runtime/src/kmp_taskdeps.h
index 2f103453eb992..d1576dd5b7910 100644
--- a/openmp/runtime/src/kmp_taskdeps.h
+++ b/openmp/runtime/src/kmp_taskdeps.h
@@ -85,6 +85,8 @@ static inline void __kmp_dephash_free(kmp_info_t *thread, kmp_dephash_t *h) {
#endif
}
+extern void __kmpc_give_task(kmp_task_t *ptask, kmp_int32 start);
+
static inline void __kmp_release_deps(kmp_int32 gtid, kmp_taskdata_t *task) {
kmp_info_t *thread = __kmp_threads[gtid];
kmp_depnode_t *node = task->td_depnode;
@@ -143,7 +145,9 @@ 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) {
- __kmp_omp_task(task->encountering_gtid, successor->dn.task, false);
+ __kmpc_give_task(
+ successor->dn.task,
+ __kmp_tid_from_gtid(next_taskdata->encountering_gtid));
} 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 030bf1d5aa07c..bb41768dab850 100644
--- a/openmp/runtime/src/kmp_tasking.cpp
+++ b/openmp/runtime/src/kmp_tasking.cpp
@@ -3920,26 +3920,10 @@ void __kmpc_proxy_task_completed(kmp_int32 gtid, kmp_task_t *ptask) {
gtid, taskdata));
}
-/*!
- at ingroup TASKING
- at param ptask Task which execution is completed
-
-Execute the completion of a proxy task from a thread that could not belong to
-the team.
-*/
-void __kmpc_proxy_task_completed_ooo(kmp_task_t *ptask) {
+void __kmpc_give_task(kmp_task_t *ptask, kmp_int32 start = 0) {
KMP_DEBUG_ASSERT(ptask != NULL);
kmp_taskdata_t *taskdata = KMP_TASK_TO_TASKDATA(ptask);
- KA_TRACE(
- 10,
- ("__kmp_proxy_task_completed_ooo(enter): proxy task completing ooo %p\n",
- taskdata));
-
- KMP_DEBUG_ASSERT(taskdata->td_flags.proxy == TASK_PROXY);
-
- __kmp_first_top_half_finish_proxy(taskdata);
-
// Enqueue task to complete bottom half completion from a thread within the
// corresponding team
kmp_team_t *team = taskdata->td_team;
@@ -3948,7 +3932,7 @@ void __kmpc_proxy_task_completed_ooo(kmp_task_t *ptask) {
// This should be similar to start_k = __kmp_get_random( thread ) % nthreads
// but we cannot use __kmp_get_random here
- kmp_int32 start_k = 0;
+ kmp_int32 start_k = start;
kmp_int32 pass = 1;
kmp_int32 k = start_k;
@@ -3962,6 +3946,29 @@ void __kmpc_proxy_task_completed_ooo(kmp_task_t *ptask) {
pass = pass << 1;
} while (!__kmp_give_task(thread, k, ptask, pass));
+}
+
+/*!
+ at ingroup TASKING
+ at param ptask Task which execution is completed
+
+Execute the completion of a proxy task from a thread that could not belong to
+the team.
+*/
+void __kmpc_proxy_task_completed_ooo(kmp_task_t *ptask) {
+ KMP_DEBUG_ASSERT(ptask != NULL);
+ kmp_taskdata_t *taskdata = KMP_TASK_TO_TASKDATA(ptask);
+
+ KA_TRACE(
+ 10,
+ ("__kmp_proxy_task_completed_ooo(enter): proxy task completing ooo %p\n",
+ taskdata));
+
+ KMP_DEBUG_ASSERT(taskdata->td_flags.proxy == TASK_PROXY);
+
+ __kmp_first_top_half_finish_proxy(taskdata);
+
+ __kmpc_give_task(ptask);
__kmp_second_top_half_finish_proxy(taskdata);
More information about the Openmp-commits
mailing list