Skip to content

[OpenMP][NFC] Move mapping related logic into Mapping.h #74009

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 1, 2023

Conversation

jdoerfert
Copy link
Member

No description provided.

@jdoerfert jdoerfert added openmp openmp:libomptarget OpenMP offload runtime labels Dec 1, 2023
@jdoerfert jdoerfert requested review from shiltian and jhuber6 December 1, 2023 00:11
@llvmbot
Copy link
Member

llvmbot commented Dec 1, 2023

@llvm/pr-subscribers-openmp

Author: Johannes Doerfert (jdoerfert)

Changes

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 --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

@jdoerfert jdoerfert merged commit 51fc854 into llvm:main Dec 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
openmp:libomptarget OpenMP offload runtime openmp
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants