[Openmp-commits] [openmp] 56f36f8 - [OpenMP][OMPT] Fix memory leak when using GCC compatibility code

Jonathan Peyton via Openmp-commits openmp-commits at lists.llvm.org
Thu Aug 11 13:26:36 PDT 2022


Author: Jonathan Peyton
Date: 2022-08-11T15:26:09-05:00
New Revision: 56f36f85e029d6947d07d7d174801104785149a7

URL: https://github.com/llvm/llvm-project/commit/56f36f85e029d6947d07d7d174801104785149a7
DIFF: https://github.com/llvm/llvm-project/commit/56f36f85e029d6947d07d7d174801104785149a7.diff

LOG: [OpenMP][OMPT] Fix memory leak when using GCC compatibility code

Serialized parallels allocate lightweight task teams on the heap
but never free them in the corresponding join. This patch adds a wrapper
around the allocation (if ompt enabled) and also adds the corresponding
free in the join call.

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

Added: 
    

Modified: 
    openmp/runtime/src/kmp_runtime.cpp

Removed: 
    


################################################################################
diff  --git a/openmp/runtime/src/kmp_runtime.cpp b/openmp/runtime/src/kmp_runtime.cpp
index b8d470528798d..a429ed1d4a304 100644
--- a/openmp/runtime/src/kmp_runtime.cpp
+++ b/openmp/runtime/src/kmp_runtime.cpp
@@ -1947,12 +1947,14 @@ int __kmp_fork_call(ident_t *loc, int gtid,
         }
       } else if (call_context == fork_context_gnu) {
 #if OMPT_SUPPORT
-        ompt_lw_taskteam_t lwt;
-        __ompt_lw_taskteam_init(&lwt, master_th, gtid, &ompt_parallel_data,
-                                return_address);
+        if (ompt_enabled.enabled) {
+          ompt_lw_taskteam_t lwt;
+          __ompt_lw_taskteam_init(&lwt, master_th, gtid, &ompt_parallel_data,
+                                  return_address);
 
-        lwt.ompt_task_info.frame.exit_frame = ompt_data_none;
-        __ompt_lw_taskteam_link(&lwt, master_th, 1);
+          lwt.ompt_task_info.frame.exit_frame = ompt_data_none;
+          __ompt_lw_taskteam_link(&lwt, master_th, 1);
+        }
 // don't use lw_taskteam after linking. content was swaped
 #endif
 
@@ -2396,6 +2398,9 @@ void __kmp_join_call(ident_t *loc, int gtid
 
 #if OMPT_SUPPORT
     if (ompt_enabled.enabled) {
+      if (fork_context == fork_context_gnu) {
+        __ompt_lw_taskteam_unlink(master_th);
+      }
       __kmp_join_restore_state(master_th, parent_team);
     }
 #endif


        


More information about the Openmp-commits mailing list