[Openmp-commits] [openmp] 51fc854 - [OpenMP][NFC] Move mapping related logic into Mapping.h (#74009)

via Openmp-commits openmp-commits at lists.llvm.org
Thu Nov 30 17:08:48 PST 2023


Author: Johannes Doerfert
Date: 2023-11-30T17:08:41-08:00
New Revision: 51fc8544c7a267e5621eadfebf758f46b015ebd4

URL: https://github.com/llvm/llvm-project/commit/51fc8544c7a267e5621eadfebf758f46b015ebd4
DIFF: https://github.com/llvm/llvm-project/commit/51fc8544c7a267e5621eadfebf758f46b015ebd4.diff

LOG: [OpenMP][NFC] Move mapping related logic into Mapping.h (#74009)

Added: 
    

Modified: 
    openmp/libomptarget/include/OpenMP/Mapping.h
    openmp/libomptarget/include/PluginManager.h
    openmp/libomptarget/src/device.cpp
    openmp/libomptarget/src/rtl.cpp

Removed: 
    


################################################################################
diff  --git a/openmp/libomptarget/include/OpenMP/Mapping.h b/openmp/libomptarget/include/OpenMP/Mapping.h
index b01831c61f6c823..9a1ecb808792071 100644
--- a/openmp/libomptarget/include/OpenMP/Mapping.h
+++ b/openmp/libomptarget/include/OpenMP/Mapping.h
@@ -13,6 +13,7 @@
 #ifndef OMPTARGET_OPENMP_MAPPING_H
 #define OMPTARGET_OPENMP_MAPPING_H
 
+#include "Shared/EnvironmentVar.h"
 #include "omptarget.h"
 
 #include <cstdint>
@@ -26,6 +27,24 @@ class AsyncInfoTy;
 
 using map_var_info_t = void *;
 
+class MappingConfig {
+
+  MappingConfig() {
+    BoolEnvar ForceAtomic = BoolEnvar("LIBOMPTARGET_MAP_FORCE_ATOMIC", true);
+    UseEventsForAtomicTransfers = ForceAtomic;
+  }
+
+public:
+  static const MappingConfig &get() {
+    static MappingConfig MP;
+    return MP;
+  };
+
+  /// Flag to indicate if we use events to ensure the atomicity of
+  /// map clauses or not. Can be modified with an environment variable.
+  bool UseEventsForAtomicTransfers = true;
+};
+
 /// Information about shadow pointers.
 struct ShadowPtrInfoTy {
   void **HstPtrAddr = nullptr;

diff  --git a/openmp/libomptarget/include/PluginManager.h b/openmp/libomptarget/include/PluginManager.h
index e9b5169510fc4dc..c92884d8e27df7a 100644
--- a/openmp/libomptarget/include/PluginManager.h
+++ b/openmp/libomptarget/include/PluginManager.h
@@ -93,9 +93,6 @@ struct PluginAdaptorManagerTy {
 
 /// Struct for the data required to handle plugins
 struct PluginManager {
-  PluginManager(bool UseEventsForAtomicTransfers)
-      : UseEventsForAtomicTransfers(UseEventsForAtomicTransfers) {}
-
   /// RTLs identified on the host
   PluginAdaptorManagerTy RTLs;
 
@@ -121,10 +118,6 @@ struct PluginManager {
   kmp_target_offload_kind_t TargetOffloadPolicy = tgt_default;
   std::mutex TargetOffloadMtx; ///< For TargetOffloadPolicy
 
-  /// Flag to indicate if we use events to ensure the atomicity of
-  /// map clauses or not. Can be modified with an environment variable.
-  const bool UseEventsForAtomicTransfers;
-
   // Work around for plugins that call dlopen on shared libraries that call
   // tgt_register_lib during their initialisation. Stash the pointers in a
   // vector until the plugins are all initialised and then register them.

diff  --git a/openmp/libomptarget/src/device.cpp b/openmp/libomptarget/src/device.cpp
index da7d33b3f40c629..31499cbf9317d1e 100644
--- a/openmp/libomptarget/src/device.cpp
+++ b/openmp/libomptarget/src/device.cpp
@@ -35,7 +35,7 @@ using namespace llvm::omp::target::ompt;
 int HostDataToTargetTy::addEventIfNecessary(DeviceTy &Device,
                                             AsyncInfoTy &AsyncInfo) const {
   // First, check if the user disabled atomic map transfer/malloc/dealloc.
-  if (!PM->UseEventsForAtomicTransfers)
+  if (!MappingConfig::get().UseEventsForAtomicTransfers)
     return OFFLOAD_SUCCESS;
 
   void *Event = getEvent();

diff  --git a/openmp/libomptarget/src/rtl.cpp b/openmp/libomptarget/src/rtl.cpp
index 42d147d1c1453f2..3cc7ac381640d2e 100644
--- a/openmp/libomptarget/src/rtl.cpp
+++ b/openmp/libomptarget/src/rtl.cpp
@@ -48,19 +48,7 @@ extern void ompt::connectLibrary();
 __attribute__((constructor(101))) void init() {
   DP("Init target library!\n");
 
-  bool UseEventsForAtomicTransfers = true;
-  if (const char *ForceAtomicMap = getenv("LIBOMPTARGET_MAP_FORCE_ATOMIC")) {
-    std::string ForceAtomicMapStr(ForceAtomicMap);
-    if (ForceAtomicMapStr == "false" || ForceAtomicMapStr == "FALSE")
-      UseEventsForAtomicTransfers = false;
-    else if (ForceAtomicMapStr != "true" && ForceAtomicMapStr != "TRUE")
-      fprintf(stderr,
-              "Warning: 'LIBOMPTARGET_MAP_FORCE_ATOMIC' accepts only "
-              "'true'/'TRUE' or 'false'/'FALSE' as options, '%s' ignored\n",
-              ForceAtomicMap);
-  }
-
-  PM = new PluginManager(UseEventsForAtomicTransfers);
+  PM = new PluginManager();
 
 #ifdef OMPT_SUPPORT
   // Initialize OMPT first


        


More information about the Openmp-commits mailing list