This is an archive of the discontinued LLVM Phabricator instance.

[OpenMP] Fix a few issues with hidden helper task
ClosedPublic

Authored by hbae on Jul 1 2021, 12:25 PM.

Details

Summary

This patch includes the following changes to address a few issues when using hidden helper task.

  • Assertion is triggered when there are inadvertent calls to hidden helper functions on non-Linux OS
  • Added deinit code in __kmp_internal_end_library function to fix random shutdown crashes
  • Moved task data access into the lock-guarded region in __kmp_push_task

Diff Detail

Event Timeline

hbae created this revision.Jul 1 2021, 12:25 PM
hbae requested review of this revision.Jul 1 2021, 12:25 PM
tianshilei1992 accepted this revision.Jul 1 2021, 12:33 PM

LG. Thanks!

openmp/runtime/src/kmp_tasking.cpp
439

Why this needs to be done in lock? After the task is created, we never change this flag, don't we?

This revision is now accepted and ready to land.Jul 1 2021, 12:33 PM
tianshilei1992 added inline comments.Jul 1 2021, 12:36 PM
openmp/runtime/src/kmp_runtime.cpp
6190

Just out of curiosity, why the deinitz in __kmp_internal_end_thread is not enough?

hbae added inline comments.Jul 1 2021, 1:18 PM
openmp/runtime/src/kmp_runtime.cpp
6190

When the runtime shutdown is processed by __kmp_internal_end_library setting __kmp_global.g.g_done, __kmp_internal_end_thread does not have a chance to finalize hidden helper.

openmp/runtime/src/kmp_tasking.cpp
439

Observed some weird situations that the flag value changes after releasing the lock whereas there is nothing wrong in the lock implementation and the lock variable passed to it. Also verified that the flag is correct before invoking the actual task function. I don't have an exact root cause of the problem, so this seems to be the best we can do now.

This revision was automatically updated to reflect the committed changes.
tianshilei1992 added inline comments.Jul 1 2021, 4:19 PM
openmp/runtime/src/kmp_runtime.cpp
6190

Okay, thanks for explanation.

protze.joachim added inline comments.
openmp/runtime/src/kmp_tasking.cpp
439

There is a chance, that another thread steals, executes, and finishes the task and releases the taskdata after the lock is released. So, what you observed might be a read after release.

tianshilei1992 added inline comments.Jul 2 2021, 8:13 AM
openmp/runtime/src/kmp_tasking.cpp
439

Oh, yeah, it could be because the task has already been pushed.

isuruf added a subscriber: isuruf.Jul 27 2021, 5:21 AM

Should this be backported to release/12.x branch? Otherwise openmp on macos is broken in 12.x series.

Should this be backported to release/12.x branch? Otherwise openmp on macos is broken in 12.x series.

Probably not given the fact the LLVM 13 is a few days ahead, but it's up to @jdoerfert

Should this be backported to release/12.x branch? Otherwise openmp on macos is broken in 12.x series.

Probably not given the fact the LLVM 13 is a few days ahead, but it's up to @jdoerfert

@isuruf Feel free to file a bug, attach this commit as fix and ask Tom for backporting. This has been successful in tree for a while now, the only problem porting it back could be that there are other "fixes" missing in 12. That said, it's not up to me but I'm supportive. Make sure the patch cleanly applies to the 12 branch or create a new one to attach to the bug report.