Skip to content

Commit ea45235

Browse files
committed
[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
1 parent 96c6349 commit ea45235

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

openmp/runtime/src/kmp_taskdeps.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ static inline void __kmp_dephash_free(kmp_info_t *thread, kmp_dephash_t *h) {
8585
#endif
8686
}
8787

88+
extern void __kmpc_give_task(kmp_task_t *ptask, kmp_int32 start);
89+
8890
static inline void __kmp_release_deps(kmp_int32 gtid, kmp_taskdata_t *task) {
8991
kmp_info_t *thread = __kmp_threads[gtid];
9092
kmp_depnode_t *node = task->td_depnode;
@@ -143,7 +145,9 @@ static inline void __kmp_release_deps(kmp_int32 gtid, kmp_taskdata_t *task) {
143145
// encountering thread's queue; otherwise, it can be pushed to its own
144146
// queue.
145147
if (!next_taskdata->td_flags.hidden_helper) {
146-
__kmp_omp_task(task->encountering_gtid, successor->dn.task, false);
148+
__kmpc_give_task(
149+
successor->dn.task,
150+
__kmp_tid_from_gtid(next_taskdata->encountering_gtid));
147151
} else {
148152
__kmp_omp_task(gtid, successor->dn.task, false);
149153
}

openmp/runtime/src/kmp_tasking.cpp

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3920,26 +3920,10 @@ void __kmpc_proxy_task_completed(kmp_int32 gtid, kmp_task_t *ptask) {
39203920
gtid, taskdata));
39213921
}
39223922

3923-
/*!
3924-
@ingroup TASKING
3925-
@param ptask Task which execution is completed
3926-
3927-
Execute the completion of a proxy task from a thread that could not belong to
3928-
the team.
3929-
*/
3930-
void __kmpc_proxy_task_completed_ooo(kmp_task_t *ptask) {
3923+
void __kmpc_give_task(kmp_task_t *ptask, kmp_int32 start = 0) {
39313924
KMP_DEBUG_ASSERT(ptask != NULL);
39323925
kmp_taskdata_t *taskdata = KMP_TASK_TO_TASKDATA(ptask);
39333926

3934-
KA_TRACE(
3935-
10,
3936-
("__kmp_proxy_task_completed_ooo(enter): proxy task completing ooo %p\n",
3937-
taskdata));
3938-
3939-
KMP_DEBUG_ASSERT(taskdata->td_flags.proxy == TASK_PROXY);
3940-
3941-
__kmp_first_top_half_finish_proxy(taskdata);
3942-
39433927
// Enqueue task to complete bottom half completion from a thread within the
39443928
// corresponding team
39453929
kmp_team_t *team = taskdata->td_team;
@@ -3948,7 +3932,7 @@ void __kmpc_proxy_task_completed_ooo(kmp_task_t *ptask) {
39483932

39493933
// This should be similar to start_k = __kmp_get_random( thread ) % nthreads
39503934
// but we cannot use __kmp_get_random here
3951-
kmp_int32 start_k = 0;
3935+
kmp_int32 start_k = start;
39523936
kmp_int32 pass = 1;
39533937
kmp_int32 k = start_k;
39543938

@@ -3962,6 +3946,29 @@ void __kmpc_proxy_task_completed_ooo(kmp_task_t *ptask) {
39623946
pass = pass << 1;
39633947

39643948
} while (!__kmp_give_task(thread, k, ptask, pass));
3949+
}
3950+
3951+
/*!
3952+
@ingroup TASKING
3953+
@param ptask Task which execution is completed
3954+
3955+
Execute the completion of a proxy task from a thread that could not belong to
3956+
the team.
3957+
*/
3958+
void __kmpc_proxy_task_completed_ooo(kmp_task_t *ptask) {
3959+
KMP_DEBUG_ASSERT(ptask != NULL);
3960+
kmp_taskdata_t *taskdata = KMP_TASK_TO_TASKDATA(ptask);
3961+
3962+
KA_TRACE(
3963+
10,
3964+
("__kmp_proxy_task_completed_ooo(enter): proxy task completing ooo %p\n",
3965+
taskdata));
3966+
3967+
KMP_DEBUG_ASSERT(taskdata->td_flags.proxy == TASK_PROXY);
3968+
3969+
__kmp_first_top_half_finish_proxy(taskdata);
3970+
3971+
__kmpc_give_task(ptask);
39653972

39663973
__kmp_second_top_half_finish_proxy(taskdata);
39673974

0 commit comments

Comments
 (0)