Skip to content

Commit 221d63a

Browse files
committed
[flang][OpenMP]Ensure host data pointer is copied to
device copy of flang dope vector when USM is enabled and host and device dope vectors are distinct.
1 parent c8f7889 commit 221d63a

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

offload/libomptarget/omptarget.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,16 @@ int targetDataBegin(ident_t *Loc, DeviceTy &Device, int32_t ArgNum,
488488
ArgsBase[I] = TgtPtrBase;
489489
}
490490

491-
if (ArgTypes[I] & OMP_TGT_MAPTYPE_PTR_AND_OBJ && !IsHostPtr)
491+
// The || part of the if condition covers flang dope vectors that
492+
// have different host and target addresses when USM is enabled. The
493+
// pointer to the array is IsHostPtr but the dope vector is not.
494+
// This happens with dope vectors in Fortran modules.
495+
// The pointer has to be copied into the
496+
// target dope vector.
497+
// Perhaps OMP_TGT_MAPTYPE_DESCRIPTOR would help here, not sure.
498+
if ((ArgTypes[I] & OMP_TGT_MAPTYPE_PTR_AND_OBJ) &&
499+
(!IsHostPtr || (PointerTpr.getEntry() != nullptr &&
500+
PointerHstPtrBegin != PointerTgtPtrBegin)))
492501
if (prepareAndSubmitData(Device, HstPtrBegin, HstPtrBase, TgtPtrBegin,
493502
PointerTpr, PointerHstPtrBegin,
494503
PointerTgtPtrBegin,
@@ -1056,6 +1065,7 @@ class PrivateArgumentManagerTy {
10561065
(IsFirstPrivate ? "first-" : ""), DPxPTR(HstPtr));
10571066
return OFFLOAD_FAIL;
10581067
}
1068+
#define OMPTARGET_DEBUG
10591069
#ifdef OMPTARGET_DEBUG
10601070
void *TgtPtrBase = (void *)((intptr_t)TgtPtr + ArgOffset);
10611071
DP("Allocated %" PRId64 " bytes of target memory at " DPxMOD

0 commit comments

Comments
 (0)