[Openmp-commits] [PATCH] D94170: [libomptarget][ve] Workaround for the libomptarget memory manager cleanup

Manoel Roemmer via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Wed Jan 6 05:29:52 PST 2021


manorom created this revision.
manorom requested review of this revision.
Herald added a project: OpenMP.
Herald added a subscriber: openmp-commits.

The target memory manager, introduced to libomptarget with rG0289696751e9a959b2413ca26624fc6c91be1eea <https://reviews.llvm.org/rG0289696751e9a959b2413ca26624fc6c91be1eea>, will try to free target memory it allocated, using `__tgt_rtl_data_delete()`, when the host program shuts down.
This is a problem for the VE plugin because it cleans up all its target resources when its destructor is called, which happens before the Memory Manager destructor frees is executed. This means that there is no VE process handle when the Memory Manager tries to free its allocated target memory and the call to `veo_free_mem()` causes a program crash.

This patch adds a workaround for this problem. It simply makes `__tgt_rtl_data_delete()` return `OFFLOAD_SUCCESS` immediately if the plugin has already cleaned up its target memory.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D94170

Files:
  openmp/libomptarget/plugins/ve/src/rtl.cpp


Index: openmp/libomptarget/plugins/ve/src/rtl.cpp
===================================================================
--- openmp/libomptarget/plugins/ve/src/rtl.cpp
+++ openmp/libomptarget/plugins/ve/src/rtl.cpp
@@ -38,6 +38,8 @@
 
 #include "../../common/elf_common.c"
 
+static bool isInit = true;
+
 struct DynLibTy {
   char *FileName;
   uint64_t VeoLibHandle;
@@ -129,6 +131,8 @@
   }
 
   ~RTLDeviceInfoTy() {
+    isInit = false;
+    DP("Closing VEO contexts\n");
     for (auto &ctx : Contexts) {
       if (ctx != NULL) {
         if (veo_context_close(ctx) != 0) {
@@ -137,6 +141,7 @@
       }
     }
 
+    DP("Destroying VEO process handles\n");
     for (auto &hdl : ProcHandles) {
       if (hdl != NULL) {
         veo_proc_destroy(hdl);
@@ -390,6 +395,10 @@
 // De-allocate the data referenced by target ptr on the device. In case of
 // success, return zero. Otherwise, return an error code.
 int32_t __tgt_rtl_data_delete(int32_t ID, void *TargetPtr) {
+  if (!isInit) {
+    // Workaround for memory manager
+    return OFFLOAD_SUCCESS;
+  }
   int ret =  veo_free_mem(DeviceInfo.ProcHandles[ID], (uint64_t)TargetPtr);
 
   if (ret != 0) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94170.314865.patch
Type: text/x-patch
Size: 1161 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20210106/c2d62a5f/attachment.bin>


More information about the Openmp-commits mailing list