[Openmp-commits] [openmp] [OpenMP][NFC] Merge MemoryManager into PluginInterface (PR #73678)

Johannes Doerfert via Openmp-commits openmp-commits at lists.llvm.org
Tue Nov 28 10:11:31 PST 2023


https://github.com/jdoerfert created https://github.com/llvm/llvm-project/pull/73678

Similar to #73677, there is no benefit from keeping MemoryManager seperate; it's tied into the current design. Except the move I also replaced the getenv call with our Env handling.

>From d1c67dfe2dece07585baa16ee952619edd913309 Mon Sep 17 00:00:00 2001
From: Johannes Doerfert <johannes at jdoerfert.de>
Date: Tue, 28 Nov 2023 10:07:59 -0800
Subject: [PATCH] [OpenMP][NFC] Merge MemoryManager into PluginInterface

Similar to #73677, there is no benefit from keeping MemoryManager
seperate; it's tied into the current design. Except the move I also
replaced the getenv call with our Env handling.
---
 .../plugins-nextgen/CMakeLists.txt            |  1 -
 .../plugins-nextgen/amdgpu/CMakeLists.txt     |  1 -
 .../plugins-nextgen/common/CMakeLists.txt     |  1 -
 .../common/MemoryManager/CMakeLists.txt       | 11 --------
 .../common/OMPT/CMakeLists.txt                |  1 -
 .../common/PluginInterface/CMakeLists.txt     |  1 -
 .../MemoryManager.h                           | 27 ++++++++++---------
 .../plugins-nextgen/cuda/CMakeLists.txt       |  1 -
 8 files changed, 14 insertions(+), 30 deletions(-)
 delete mode 100644 openmp/libomptarget/plugins-nextgen/common/MemoryManager/CMakeLists.txt
 rename openmp/libomptarget/plugins-nextgen/common/{MemoryManager => PluginInterface}/MemoryManager.h (95%)

diff --git a/openmp/libomptarget/plugins-nextgen/CMakeLists.txt b/openmp/libomptarget/plugins-nextgen/CMakeLists.txt
index 966f51621c322d5..a27dd0a4ca9186c 100644
--- a/openmp/libomptarget/plugins-nextgen/CMakeLists.txt
+++ b/openmp/libomptarget/plugins-nextgen/CMakeLists.txt
@@ -47,7 +47,6 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "${tmachine}$")
 
         LINK_LIBS
         PRIVATE
-        MemoryManager
         PluginInterface
         ${LIBOMPTARGET_DEP_LIBFFI_LIBRARIES}
         ${OPENMP_PTHREAD_LIB}
diff --git a/openmp/libomptarget/plugins-nextgen/amdgpu/CMakeLists.txt b/openmp/libomptarget/plugins-nextgen/amdgpu/CMakeLists.txt
index 94a0084db6077ad..af967bc386f67dc 100644
--- a/openmp/libomptarget/plugins-nextgen/amdgpu/CMakeLists.txt
+++ b/openmp/libomptarget/plugins-nextgen/amdgpu/CMakeLists.txt
@@ -80,7 +80,6 @@ add_llvm_library(omptarget.rtl.amdgpu SHARED
 
   LINK_LIBS
   PRIVATE
-  MemoryManager
   PluginInterface
   ${LIBOMPTARGET_DEP_LIBRARIES}
   ${OPENMP_PTHREAD_LIB}
diff --git a/openmp/libomptarget/plugins-nextgen/common/CMakeLists.txt b/openmp/libomptarget/plugins-nextgen/common/CMakeLists.txt
index 3d1f2634e6bc496..f0645d0d1753817 100644
--- a/openmp/libomptarget/plugins-nextgen/common/CMakeLists.txt
+++ b/openmp/libomptarget/plugins-nextgen/common/CMakeLists.txt
@@ -12,4 +12,3 @@
 
 add_subdirectory(OMPT)
 add_subdirectory(PluginInterface)
-add_subdirectory(MemoryManager)
diff --git a/openmp/libomptarget/plugins-nextgen/common/MemoryManager/CMakeLists.txt b/openmp/libomptarget/plugins-nextgen/common/MemoryManager/CMakeLists.txt
deleted file mode 100644
index 7f2e7c7c8d39fe0..000000000000000
--- a/openmp/libomptarget/plugins-nextgen/common/MemoryManager/CMakeLists.txt
+++ /dev/null
@@ -1,11 +0,0 @@
-##===----------------------------------------------------------------------===##
-#
-# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-# See https://llvm.org/LICENSE.txt for license information.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-#
-##===----------------------------------------------------------------------===##
-
-add_library(MemoryManager INTERFACE)
-
-target_include_directories(MemoryManager INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
diff --git a/openmp/libomptarget/plugins-nextgen/common/OMPT/CMakeLists.txt b/openmp/libomptarget/plugins-nextgen/common/OMPT/CMakeLists.txt
index db79c6d3e550ee5..be4c743665b3e97 100644
--- a/openmp/libomptarget/plugins-nextgen/common/OMPT/CMakeLists.txt
+++ b/openmp/libomptarget/plugins-nextgen/common/OMPT/CMakeLists.txt
@@ -52,7 +52,6 @@ endif()
 target_link_libraries(OMPT
   PUBLIC
     ${llvm_libs}
-    MemoryManager
 )
 
 # Define the TARGET_NAME and DEBUG_PREFIX.
diff --git a/openmp/libomptarget/plugins-nextgen/common/PluginInterface/CMakeLists.txt b/openmp/libomptarget/plugins-nextgen/common/PluginInterface/CMakeLists.txt
index 4ff4dee3c0875f7..84a7dc8ea72ddc3 100644
--- a/openmp/libomptarget/plugins-nextgen/common/PluginInterface/CMakeLists.txt
+++ b/openmp/libomptarget/plugins-nextgen/common/PluginInterface/CMakeLists.txt
@@ -63,7 +63,6 @@ endif()
 target_link_libraries(PluginInterface
   PUBLIC
     ${llvm_libs}
-    MemoryManager
 )
 
 # Include the RPC server from the `libc` project if availible.
diff --git a/openmp/libomptarget/plugins-nextgen/common/MemoryManager/MemoryManager.h b/openmp/libomptarget/plugins-nextgen/common/PluginInterface/MemoryManager.h
similarity index 95%
rename from openmp/libomptarget/plugins-nextgen/common/MemoryManager/MemoryManager.h
rename to openmp/libomptarget/plugins-nextgen/common/PluginInterface/MemoryManager.h
index 37ef80a1af3ae22..2d23d959f6c0ba0 100644
--- a/openmp/libomptarget/plugins-nextgen/common/MemoryManager/MemoryManager.h
+++ b/openmp/libomptarget/plugins-nextgen/common/PluginInterface/MemoryManager.h
@@ -10,8 +10,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_OPENMP_LIBOMPTARGET_PLUGINS_COMMON_MEMORYMANAGER_MEMORYMANAGER_H
-#define LLVM_OPENMP_LIBOMPTARGET_PLUGINS_COMMON_MEMORYMANAGER_MEMORYMANAGER_H
+#ifndef LLVM_OPENMP_LIBOMPTARGET_PLUGINS_COMMON_MEMORYMANAGER_H
+#define LLVM_OPENMP_LIBOMPTARGET_PLUGINS_COMMON_MEMORYMANAGER_H
 
 #include <cassert>
 #include <functional>
@@ -22,6 +22,8 @@
 #include <vector>
 
 #include "Debug.h"
+#include "Utilities.h"
+#include "omptarget.h"
 
 /// Base class of per-device allocator.
 class DeviceAllocatorTy {
@@ -322,16 +324,15 @@ class MemoryManagerTy {
   /// manager explicitly by setting the var to 0. If user doesn't specify
   /// anything, returns <0, true>.
   static std::pair<size_t, bool> getSizeThresholdFromEnv() {
-    size_t Threshold = 0;
-
-    if (const char *Env =
-            std::getenv("LIBOMPTARGET_MEMORY_MANAGER_THRESHOLD")) {
-      Threshold = std::stoul(Env);
-      if (Threshold == 0) {
-        DP("Disabled memory manager as user set "
-           "LIBOMPTARGET_MEMORY_MANAGER_THRESHOLD=0.\n");
-        return std::make_pair(0, false);
-      }
+    static llvm::omp::target::UInt32Envar MemoryManagerThreshold(
+        "LIBOMPTARGET_MEMORY_MANAGER_THRESHOLD", 0);
+
+    size_t Threshold = MemoryManagerThreshold.get();
+
+    if (MemoryManagerThreshold.isPresent() && Threshold == 0) {
+      DP("Disabled memory manager as user set "
+         "LIBOMPTARGET_MEMORY_MANAGER_THRESHOLD=0.\n");
+      return std::make_pair(0, false);
     }
 
     return std::make_pair(Threshold, true);
@@ -343,4 +344,4 @@ class MemoryManagerTy {
 constexpr const size_t MemoryManagerTy::BucketSize[];
 constexpr const int MemoryManagerTy::NumBuckets;
 
-#endif // LLVM_OPENMP_LIBOMPTARGET_PLUGINS_COMMON_MEMORYMANAGER_MEMORYMANAGER_H
+#endif // LLVM_OPENMP_LIBOMPTARGET_PLUGINS_COMMON_MEMORYMANAGER_H
diff --git a/openmp/libomptarget/plugins-nextgen/cuda/CMakeLists.txt b/openmp/libomptarget/plugins-nextgen/cuda/CMakeLists.txt
index d0e6b26888d5532..3e1d11ac365df64 100644
--- a/openmp/libomptarget/plugins-nextgen/cuda/CMakeLists.txt
+++ b/openmp/libomptarget/plugins-nextgen/cuda/CMakeLists.txt
@@ -34,7 +34,6 @@ add_llvm_library(omptarget.rtl.cuda SHARED
   Object
 
   LINK_LIBS PRIVATE
-  MemoryManager
   PluginInterface
   ${OPENMP_PTHREAD_LIB}
 



More information about the Openmp-commits mailing list