This is an archive of the discontinued LLVM Phabricator instance.

[OpenMP][OMPT] Fix `target enter data` callback ordering & reported device num
ClosedPublic

Authored by mhalk on Aug 10 2023, 5:11 AM.

Details

Summary

This patch fixes: https://github.com/llvm/llvm-project/issues/64738
We observed multiple issues, primarily that the DeviceId was reported as -1
in certain scenarios. The reason for this is simply that the device is not
initialized at that point. Hence, we need to move the RAII object creation just
after the checkDeviceAndCtors, closer to the actual call we want to observe.

This also solves an odering issue where one target enter data callback would
be executed before the Init callback.
Additionally, this change will also fix that the callbacks corresponding to
enter / exit data and update in conjunction with nowait would not result
in the emission of an OMPT callback.

Added a testcase to cover initialized device number and omp target constructs.

Diff Detail

Event Timeline

mhalk created this revision.Aug 10 2023, 5:11 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 10 2023, 5:11 AM
mhalk requested review of this revision.Aug 10 2023, 5:11 AM
Herald added a project: Restricted Project. · View Herald Transcript
mhalk updated this revision to Diff 549050.Aug 10 2023, 8:04 AM

Clarify the intent of the test and returning a nullptr in the helper function.

Thyre added a subscriber: Thyre.Aug 10 2023, 8:08 AM
dhruvachak added inline comments.Aug 15 2023, 5:42 PM
openmp/libomptarget/src/interface.cpp
111

Can't you have the RAII here? That way, you don't need the new/delete.
You can add an assert that the type is one of the expected 3.
InterfaceRAII(

TargetDataFunction == targetDataBegin ? 
RegionInterface.getCallbacks<ompt_target_enter_data>() :
TargetDataFunction == targetDataEnd ?
RegionInterface.getCallbacks<ompt_target_exit_data>() :
RegionInterface.getCallbacks<ompt_target_update>(),
DeviceId,
OMPT_GET_RETURN_ADDRESS(0));
mhalk updated this revision to Diff 550771.Aug 16 2023, 8:35 AM

Removed helper function in favor of assert + callback selection via ternary ops.
Thanks @dhruvachak, was not quite sure if that would be acceptable.
Either way, this seems less invasive to me.

mhalk updated this revision to Diff 550802.Aug 16 2023, 10:25 AM

Rebase + edit commit message to link issue https://github.com/llvm/llvm-project/issues/64738

mhalk edited the summary of this revision. (Show Details)Aug 16 2023, 10:26 AM
mhalk updated this revision to Diff 550810.Aug 16 2023, 10:59 AM

Change testcase to use EMI callbacks.

Discovered a possible segfault which triggers only when using EMI callbacks.
Caused by target_task_data=(nil) and seems to be fixed by this patch, too.

dhruvachak accepted this revision.Aug 21 2023, 2:48 PM

Looks good.

This revision is now accepted and ready to land.Aug 21 2023, 2:48 PM