[Openmp-commits] [PATCH] D106572: [OpenMP] Refined the logic to give a regular task from a hidden helper task
Shilei Tian via Phabricator via Openmp-commits
openmp-commits at lists.llvm.org
Thu Jul 22 09:58:15 PDT 2021
tianshilei1992 created this revision.
tianshilei1992 added reviewers: AndreyChurbanov, hbae, protze.joachim.
Herald added subscribers: guansong, yaxunl.
tianshilei1992 requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: openmp-commits, sstefan1.
Herald added a project: OpenMP.
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D106572
Files:
openmp/runtime/src/kmp_taskdeps.h
openmp/runtime/src/kmp_tasking.cpp
Index: openmp/runtime/src/kmp_tasking.cpp
===================================================================
--- openmp/runtime/src/kmp_tasking.cpp
+++ openmp/runtime/src/kmp_tasking.cpp
@@ -3920,6 +3920,34 @@
gtid, taskdata));
}
+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);
+
+ // Enqueue task to complete bottom half completion from a thread within the
+ // corresponding team
+ kmp_team_t *team = taskdata->td_team;
+ kmp_int32 nthreads = team->t.t_nproc;
+ kmp_info_t *thread;
+
+ // 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 pass = 1;
+ kmp_int32 k = start_k;
+
+ do {
+ // For now we're just linearly trying to find a thread
+ thread = team->t.t_threads[k];
+ k = (k + 1) % nthreads;
+
+ // we did a full pass through all the threads
+ if (k == start_k)
+ pass = pass << 1;
+
+ } while (!__kmp_give_task(thread, k, ptask, pass));
+}
+
/*!
@ingroup TASKING
@param ptask Task which execution is completed
@@ -3940,28 +3968,7 @@
__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;
- kmp_int32 nthreads = team->t.t_nproc;
- kmp_info_t *thread;
-
- // 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 pass = 1;
- kmp_int32 k = start_k;
-
- do {
- // For now we're just linearly trying to find a thread
- thread = team->t.t_threads[k];
- k = (k + 1) % nthreads;
-
- // we did a full pass through all the threads
- if (k == start_k)
- pass = pass << 1;
-
- } while (!__kmp_give_task(thread, k, ptask, pass));
+ __kmpc_give_task(ptask);
__kmp_second_top_half_finish_proxy(taskdata);
Index: openmp/runtime/src/kmp_taskdeps.h
===================================================================
--- openmp/runtime/src/kmp_taskdeps.h
+++ openmp/runtime/src/kmp_taskdeps.h
@@ -85,6 +85,8 @@
#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 @@
// 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);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106572.360861.patch
Type: text/x-patch
Size: 3004 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20210722/f5d06fc0/attachment.bin>
More information about the Openmp-commits
mailing list