This is an archive of the discontinued LLVM Phabricator instance.

[OpenMP] Refined the logic to give a regular task from a hidden helper task
ClosedPublic

Authored by tianshilei1992 on Jul 22 2021, 9:58 AM.

Details

Summary

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.

Diff Detail

Event Timeline

tianshilei1992 created this revision.Jul 22 2021, 9:58 AM
tianshilei1992 requested review of this revision.Jul 22 2021, 9:58 AM
Herald added a project: Restricted Project. · View Herald Transcript
openmp/runtime/src/kmp_taskdeps.h
150

I found an interesting thing. If the encountering tid is not passed as a start point, the start point will be 0. In this case, it can happen that thread 0 tries to steal from thread 1, meanwhile thread 1 tries to steal from thread 0. Dead lock. @AndreyChurbanov Is it expected?

LGTM

(Though I didn't test it. Hope it won't break testing.)

openmp/runtime/src/kmp_taskdeps.h
150

Stealing from different queues cannot deadlock because each queue uses its own lock while stealing from it or putting a task into it.

AndreyChurbanov accepted this revision.Jul 22 2021, 1:27 PM
This revision is now accepted and ready to land.Jul 22 2021, 1:27 PM
This revision was landed with ongoing or failed builds.Jul 22 2021, 4:21 PM
This revision was automatically updated to reflect the committed changes.
tianshilei1992 marked an inline comment as done.
tianshilei1992 added inline comments.Jul 22 2021, 4:24 PM
openmp/runtime/src/kmp_taskdeps.h
150

Yeah, what I thought is not right. In fact, it is dead lock because all regular threads are waiting for the lock of a task queue (actually it is the thread with gtid 1 (tid 1), whom all tasks are given to), but all helper threads have already done their jobs.