[Openmp-commits] [PATCH] D84381: [OpenMP] Wait for kernel prior to memory deallocation

Shilei Tian via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Wed Jul 22 21:17:42 PDT 2020


tianshilei1992 updated this revision to Diff 280025.
tianshilei1992 added a comment.

Fixed an issue that `target` may return before D2H is still in progress


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D84381/new/

https://reviews.llvm.org/D84381

Files:
  openmp/libomptarget/src/omptarget.cpp


Index: openmp/libomptarget/src/omptarget.cpp
===================================================================
--- openmp/libomptarget/src/omptarget.cpp
+++ openmp/libomptarget/src/omptarget.cpp
@@ -927,6 +927,19 @@
     return OFFLOAD_FAIL;
   }
 
+  // This synchronization makes sure that before we deallocate any memory, the
+  // kernel has already finished. Otherwise, data will be freed when they're
+  // still being used.
+  // TODO: If we can separate the memory free and data transfer, we can avoid
+  // this synchronization.
+  if (Device.RTL->synchronize) {
+    rc = Device.RTL->synchronize(device_id, &AsyncInfo);
+    if (rc != OFFLOAD_SUCCESS) {
+      DP("Failed to synchronize.\n");
+      return OFFLOAD_FAIL;
+    }
+  }
+
   // Deallocate (first-)private arrays
   for (auto it : fpArrays) {
     int rt = Device.RTL->data_delete(Device.RTLDeviceID, it);
@@ -944,6 +957,8 @@
     return OFFLOAD_FAIL;
   }
 
+  // This synchronization makes sure that all data transfer have been done
+  // before returning from this function.
   if (Device.RTL->synchronize)
     return Device.RTL->synchronize(device_id, &AsyncInfo);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84381.280025.patch
Type: text/x-patch
Size: 1146 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20200723/6e6e7435/attachment.bin>


More information about the Openmp-commits mailing list