From: Carlo Bertolli Date: Fri, 18 Feb 2022 15:55:49 +0000 (-0600) Subject: [OpenMP][libomptarget] Delay restore of shadow pointers in structs to after H2D memor... X-Git-Tag: upstream/15.0.7~15908 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7b731f4d0bfbbac74210f59b782624662a3c7546;p=platform%2Fupstream%2Fllvm.git [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 --- diff --git a/openmp/libomptarget/src/omptarget.cpp b/openmp/libomptarget/src/omptarget.cpp index 304091e..015e69a 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",