Skip to content

Commit d286e16

Browse files
committed
Revert "[OpenMP][Runtime] remove dead prepareAndSubmitData function from omptarget"
This reverts commit 304b51b.
1 parent d41a144 commit d286e16

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

offload/libomptarget/omptarget.cpp

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,38 @@ int targetDataMapper(ident_t *Loc, DeviceTy &Device, void *ArgBase, void *Arg,
309309
return Rc;
310310
}
311311

312+
static int prepareAndSubmitData(DeviceTy &Device, void *HstPtrBegin,
313+
void *HstPtrBase, void *LocalTgtPtrBegin,
314+
TargetPointerResultTy &PointerTpr,
315+
void *PointerHstPtrBegin,
316+
void *PointerTgtPtrBegin,
317+
AsyncInfoTy &AsyncInfo) {
318+
uint64_t Delta = (uint64_t)HstPtrBegin - (uint64_t)HstPtrBase;
319+
void *ExpectedTgtPtrBase = (void *)((uint64_t)LocalTgtPtrBegin - Delta);
320+
321+
if (PointerTpr.getEntry()->addShadowPointer(
322+
ShadowPtrInfoTy{(void **)PointerHstPtrBegin,
323+
(void **)PointerTgtPtrBegin, ExpectedTgtPtrBase, sizeof(void*)})) {
324+
DP("USM_SPECIAL: Update pointer (" DPxMOD ") -> [" DPxMOD "]\n",
325+
DPxPTR(PointerTgtPtrBegin), DPxPTR(LocalTgtPtrBegin));
326+
327+
void *&LocalTgtPtrBase = AsyncInfo.getVoidPtrLocation();
328+
LocalTgtPtrBase = ExpectedTgtPtrBase;
329+
330+
int Ret =
331+
Device.submitData(PointerTgtPtrBegin, &LocalTgtPtrBase, sizeof(void *),
332+
AsyncInfo, PointerTpr.getEntry());
333+
if (Ret != OFFLOAD_SUCCESS) {
334+
REPORT("Copying data to device failed.\n");
335+
return OFFLOAD_FAIL;
336+
}
337+
if (PointerTpr.getEntry()->addEventIfNecessary(Device, AsyncInfo) !=
338+
OFFLOAD_SUCCESS)
339+
return OFFLOAD_FAIL;
340+
}
341+
return OFFLOAD_SUCCESS;
342+
}
343+
312344
/// Utility function to perform a pointer attachment operation.
313345
///
314346
/// For something like:
@@ -640,7 +672,14 @@ int targetDataBegin(ident_t *Loc, DeviceTy &Device, int32_t ArgNum,
640672
// Perhaps OMP_TGT_MAPTYPE_DESCRIPTOR would help here, not sure.
641673
if ((ArgTypes[I] & OMP_TGT_MAPTYPE_PTR_AND_OBJ) &&
642674
(!IsHostPtr || (PointerTpr.getEntry() != nullptr &&
643-
PointerHstPtrBegin != PointerTgtPtrBegin))) {
675+
PointerHstPtrBegin != PointerTgtPtrBegin)))
676+
if (prepareAndSubmitData(Device, HstPtrBegin, HstPtrBase, TgtPtrBegin,
677+
PointerTpr, PointerHstPtrBegin,
678+
PointerTgtPtrBegin,
679+
AsyncInfo) != OFFLOAD_SUCCESS)
680+
return OFFLOAD_FAIL;
681+
682+
if (ArgTypes[I] & OMP_TGT_MAPTYPE_PTR_AND_OBJ && !IsHostPtr) {
644683
int Ret = performPointerAttachment(
645684
Device, AsyncInfo, reinterpret_cast<void **>(PointerHstPtrBegin),
646685
HstPtrBase, HstPtrBegin,

0 commit comments

Comments
 (0)