[Openmp-commits] [openmp] 7b731f4 - [OpenMP][libomptarget] Delay restore of shadow pointers in structs to after H2D memory copies are completed

Carlo Bertolli via Openmp-commits openmp-commits at lists.llvm.org
Fri Feb 18 08:09:26 PST 2022


Author: Carlo Bertolli
Date: 2022-02-18T10:09:10-06:00
New Revision: 7b731f4d0bfbbac74210f59b782624662a3c7546

URL: https://github.com/llvm/llvm-project/commit/7b731f4d0bfbbac74210f59b782624662a3c7546
DIFF: https://github.com/llvm/llvm-project/commit/7b731f4d0bfbbac74210f59b782624662a3c7546.diff

LOG: [OpenMP][libomptarget] Delay restore of shadow pointers in structs to after H2D memory copies are completed

When using asynchronous plugin calls, shadow pointer restore could happen before the D2H copy for the entire struct has completed, effectively leaving a device pointer in a host struct.
This patch fixes the problem by delaying restore's to after a synchronization happens (target regions) and by calling early synchronization (target update).

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D119968

Added: 
    

Modified: 
    openmp/libomptarget/src/omptarget.cpp

Removed: 
    


################################################################################
diff  --git a/openmp/libomptarget/src/omptarget.cpp b/openmp/libomptarget/src/omptarget.cpp
index 304091e4f2f1..015e69af9058 100644
--- a/openmp/libomptarget/src/omptarget.cpp
+++ b/openmp/libomptarget/src/omptarget.cpp
@@ -802,6 +802,10 @@ int targetDataEnd(ident_t *loc, DeviceTy &Device, int32_t ArgNum,
         // If we copied the struct to the host, we need to restore the pointer.
         if (ArgTypes[I] & OMP_TGT_MAPTYPE_FROM) {
           void **ShadowHstPtrAddr = (void **)Itr->first;
+          // Wait for device-to-host memcopies for whole struct to complete,
+          // before restoring the correct host pointer.
+          if (AsyncInfo.synchronize() != OFFLOAD_SUCCESS)
+            return OFFLOAD_FAIL;
           *ShadowHstPtrAddr = Itr->second.HstPtrVal;
           DP("Restoring original host pointer value " DPxMOD " for host "
              "pointer " DPxMOD "\n",
@@ -885,6 +889,10 @@ static int targetDataContiguous(ident_t *loc, DeviceTy &Device, void *ArgsBase,
 
     auto CB = [&](ShadowPtrListTy::iterator &Itr) {
       void **ShadowHstPtrAddr = (void **)Itr->first;
+      // Wait for device-to-host memcopies for whole struct to complete,
+      // before restoring the correct host pointer.
+      if (AsyncInfo.synchronize() != OFFLOAD_SUCCESS)
+        return OFFLOAD_FAIL;
       *ShadowHstPtrAddr = Itr->second.HstPtrVal;
       DP("Restoring original host pointer value " DPxMOD
          " for host pointer " DPxMOD "\n",


        


More information about the Openmp-commits mailing list