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

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


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-openmp

Author: Johannes Doerfert (jdoerfert)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/74009.diff


4 Files Affected:

- (modified) openmp/libomptarget/include/OpenMP/Mapping.h (+19) 
- (modified) openmp/libomptarget/include/PluginManager.h (-7) 
- (modified) openmp/libomptarget/src/device.cpp (+1-1) 
- (modified) openmp/libomptarget/src/rtl.cpp (+1-13) 


``````````diff
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 3a1c97fc52c95df..6fe408eba25ce89 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

``````````

</details>


https://github.com/llvm/llvm-project/pull/74009


More information about the Openmp-commits mailing list