[Openmp-commits] [openmp] 0c7a487 - [libomptarget] Keep the Shadow Pointer Map up-to-date
George Rokos via Openmp-commits
openmp-commits at lists.llvm.org
Wed Jul 14 15:24:35 PDT 2021
Author: George Rokos
Date: 2021-07-14T15:19:58-07:00
New Revision: 0c7a4870c5b63935b7f0c7cbc380b497341dd203
URL: https://github.com/llvm/llvm-project/commit/0c7a4870c5b63935b7f0c7cbc380b497341dd203
DIFF: https://github.com/llvm/llvm-project/commit/0c7a4870c5b63935b7f0c7cbc380b497341dd203.diff
LOG: [libomptarget] Keep the Shadow Pointer Map up-to-date
D105812 introduced a regression where if a PTR_AND_OBJ entry was mapped on the device, then 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.
Differential Revision: https://reviews.llvm.org/D105947
Added:
Modified:
openmp/libomptarget/src/omptarget.cpp
Removed:
################################################################################
diff --git a/openmp/libomptarget/src/omptarget.cpp b/openmp/libomptarget/src/omptarget.cpp
index 0255f94599ee1..3b1c5a8742f4c 100644
--- a/openmp/libomptarget/src/omptarget.cpp
+++ b/openmp/libomptarget/src/omptarget.cpp
@@ -564,9 +564,20 @@ int targetDataBegin(ident_t *loc, DeviceTy &Device, int32_t arg_num,
Device.ShadowMtx.lock();
auto Entry = Device.ShadowPtrMap.find(Pointer_HstPtrBegin);
- // If this pointer is not in the map we need to insert it.
- if (Entry == Device.ShadowPtrMap.end()) {
- // create shadow pointers for this entry
+ // If this pointer is not in the map we need to insert it. If the map
+ // contains a stale entry, we need to update it (e.g. if the pointee was
+ // deallocated and later on is reallocated at another device address). The
+ // latter scenario is the subject of LIT test env/base_ptr_ref_count.c. An
+ // entry is removed from ShadowPtrMap only when the PTR of a PTR_AND_OBJ
+ // pair is deallocated, not when the OBJ is deallocated. 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. When the
+ // OBJ is deallocated and later on allocated again (at a
diff erent device
+ // address), ShadowPtrMap still contains an entry for Pointer_HstPtrBegin
+ // which is stale, pointing to the old ExpectedTgtPtrBase of the OBJ.
+ if (Entry == Device.ShadowPtrMap.end() ||
+ Entry->second.TgtPtrVal != ExpectedTgtPtrBase) {
+ // create or update shadow pointers for this entry
Device.ShadowPtrMap[Pointer_HstPtrBegin] = {
HstPtrBase, PointerTgtPtrBegin, ExpectedTgtPtrBase};
UpdateDevPtr = true;
More information about the Openmp-commits
mailing list