This is an archive of the discontinued LLVM Phabricator instance.

[libomptarget] Keep the Shadow Pointer Map up-to-date
ClosedPublic

Authored by grokos on Jul 13 2021, 3:46 PM.

Details

Summary

D105812 introduced a regression where if a PTR_AND_OBJ entry was mapped on the device, later the OBJ was deallocated and then reallocated at a different address, the Shadow Pointer Map would still contain an entry for the PTR but pointing to the old address. This caused test env/base_ptr_ref_count.c to fail.

Diff Detail

Event Timeline

grokos requested review of this revision.Jul 13 2021, 3:46 PM
grokos created this revision.

@jdenny So it seems we found a valid OpenMP program that suffered from the corner case you warned about in D105812.

Don't we just update the map afterwards?

No. If the old entry exists in ShadowPtrMap then UpdateDevPtr will remain false, so no update will take place. This patch changes that condition: if either the entry is not in the map or it exists but contains stale data, an update should be performed.

I mean when OBJ is deallocated, it is not removed from the map?

No, only when the PTR is deallocated is the entry removed from the map. But in env/base_ptr_ref_count.c the PTR is a global declare target pointer, so it stays in the map for the lifetime of the application.

jdenny accepted this revision.Jul 14 2021, 5:54 AM

Other than my comment suggestion, LGTM. Thanks.

openmp/libomptarget/src/omptarget.cpp
569

Can you extend this comment a bit more to address @tianshilei1992's question? That is, explain that the shadow map entry is added/removed only when the PTR is allocated/deallocated on the device, but TgtPtrVal becomes stale when the OBJ is allocated/deallocated on the device. I found this point confusing as well.

This revision is now accepted and ready to land.Jul 14 2021, 5:54 AM
grokos updated this revision to Diff 358581.Jul 14 2021, 6:26 AM

Made the comment more detailed to explain why this patch is needed.

jdenny accepted this revision.Jul 14 2021, 6:42 AM

Still LGTM. Thanks for the comment.

This revision was automatically updated to reflect the committed changes.