diff --git a/openmp/libomptarget/src/device.h b/openmp/libomptarget/src/device.h --- a/openmp/libomptarget/src/device.h +++ b/openmp/libomptarget/src/device.h @@ -194,7 +194,6 @@ // Return true if data can be copied to DstDevice directly bool isDataExchangable(const DeviceTy &DstDevice); - uint64_t getMapEntryRefCnt(void *HstPtrBegin); LookupResult lookupMapping(void *HstPtrBegin, int64_t Size); TargetPointerResultTy getOrAllocTgtPtr(void *HstPtrBegin, void *HstPtrBase, int64_t Size, diff --git a/openmp/libomptarget/src/device.cpp b/openmp/libomptarget/src/device.cpp --- a/openmp/libomptarget/src/device.cpp +++ b/openmp/libomptarget/src/device.cpp @@ -119,31 +119,6 @@ return OFFLOAD_FAIL; } -// Get ref count of map entry containing HstPtrBegin -uint64_t DeviceTy::getMapEntryRefCnt(void *HstPtrBegin) { - uintptr_t hp = (uintptr_t)HstPtrBegin; - uint64_t RefCnt = 0; - - DataMapMtx.lock(); - if (!HostDataToTargetMap.empty()) { - auto upper = HostDataToTargetMap.upper_bound(hp); - if (upper != HostDataToTargetMap.begin()) { - upper--; - if (hp >= upper->HstPtrBegin && hp < upper->HstPtrEnd) { - DP("DeviceTy::getMapEntry: requested entry found\n"); - RefCnt = upper->getRefCount(); - } - } - } - DataMapMtx.unlock(); - - if (RefCnt == 0) { - DP("DeviceTy::getMapEntry: requested entry not found\n"); - } - - return RefCnt; -} - LookupResult DeviceTy::lookupMapping(void *HstPtrBegin, int64_t Size) { uintptr_t hp = (uintptr_t)HstPtrBegin; LookupResult lr; @@ -220,8 +195,13 @@ if (LR.Flags.IsContained || ((LR.Flags.ExtendsBefore || LR.Flags.ExtendsAfter) && IsImplicit)) { auto &HT = *LR.Entry; + assert(HT.getRefCount() > 0 && "expected existing RefCount > 0"); if (UpdateRefCount) + // After this, RefCount > 1. HT.incRefCount(); + else + // It might have been allocated with the parent, but it's still new. + IsNew = HT.getRefCount() == 1; uintptr_t Ptr = HT.TgtPtrBegin + ((uintptr_t)HstPtrBegin - HT.HstPtrBegin); INFO(OMP_INFOTYPE_MAPPING_EXISTS, DeviceID, "Mapping exists%s with HstPtrBegin=" DPxMOD ", TgtPtrBegin=" DPxMOD diff --git a/openmp/libomptarget/src/omptarget.cpp b/openmp/libomptarget/src/omptarget.cpp --- a/openmp/libomptarget/src/omptarget.cpp +++ b/openmp/libomptarget/src/omptarget.cpp @@ -539,20 +539,8 @@ bool copy = false; if (!(PM->RTLs.RequiresFlags & OMP_REQ_UNIFIED_SHARED_MEMORY) || HasCloseModifier) { - if (TPR.Flags.IsNewEntry || (arg_types[i] & OMP_TGT_MAPTYPE_ALWAYS)) { + if (TPR.Flags.IsNewEntry || (arg_types[i] & OMP_TGT_MAPTYPE_ALWAYS)) copy = true; - } else if ((arg_types[i] & OMP_TGT_MAPTYPE_MEMBER_OF) && - !(arg_types[i] & OMP_TGT_MAPTYPE_PTR_AND_OBJ)) { - // Copy data only if the "parent" struct has RefCount==1. - // If this is a PTR_AND_OBJ entry, the OBJ is not part of the struct, - // so exclude it from this check. - int32_t parent_idx = getParentIndex(arg_types[i]); - uint64_t parent_rc = Device.getMapEntryRefCnt(args[parent_idx]); - assert(parent_rc > 0 && "parent struct not found"); - if (parent_rc == 1) { - copy = true; - } - } } if (copy && !IsHostPtr) {