[Openmp-commits] [openmp] 59b6849 - [OpenMP] Replace global InfoLevel with a reference to an internal one.

via Openmp-commits openmp-commits at lists.llvm.org
Fri Apr 23 06:44:12 PDT 2021


Author: Joseph Huber
Date: 2021-04-23T09:43:46-04:00
New Revision: 59b68490122ae6ef92b1ebe45e8a5f2f7d88a401

URL: https://github.com/llvm/llvm-project/commit/59b68490122ae6ef92b1ebe45e8a5f2f7d88a401
DIFF: https://github.com/llvm/llvm-project/commit/59b68490122ae6ef92b1ebe45e8a5f2f7d88a401.diff

LOG: [OpenMP] Replace global InfoLevel with a reference to an internal one.

Summary:
This patch improves the implementation of D100774 by replacing the global
variable introduced with a function that returns a reference to an internal
one. This removes the need to define the variable in every plugin that uses it.

Reviewed By: JonChesterfield

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

Added: 
    

Modified: 
    openmp/libomptarget/include/Debug.h
    openmp/libomptarget/plugins/amdgpu/src/rtl.cpp
    openmp/libomptarget/plugins/cuda/src/rtl.cpp
    openmp/libomptarget/plugins/generic-elf-64bit/src/rtl.cpp
    openmp/libomptarget/plugins/remote/src/rtl.cpp
    openmp/libomptarget/src/interface.cpp

Removed: 
    


################################################################################
diff  --git a/openmp/libomptarget/include/Debug.h b/openmp/libomptarget/include/Debug.h
index 6c9a94ab8eee0..6dd2f0e11a0fa 100644
--- a/openmp/libomptarget/include/Debug.h
+++ b/openmp/libomptarget/include/Debug.h
@@ -65,22 +65,22 @@ enum OpenMPInfoType : uint32_t {
 #define USED
 #endif
 
-// Interface to the InfoLevel variable defined by each library.
-extern std::atomic<uint32_t> InfoLevel;
-
 // Add __attribute__((used)) to work around a bug in gcc 5/6.
-USED static inline uint32_t getInfoLevel() {
+USED inline std::atomic<uint32_t> &getInfoLevelInternal() {
+  static std::atomic<uint32_t> InfoLevel;
   static std::once_flag Flag{};
   std::call_once(Flag, []() {
     if (char *EnvStr = getenv("LIBOMPTARGET_INFO"))
       InfoLevel.store(std::stoi(EnvStr));
   });
 
-  return InfoLevel.load();
+  return InfoLevel;
 }
 
+USED inline uint32_t getInfoLevel() { return getInfoLevelInternal().load(); }
+
 // Add __attribute__((used)) to work around a bug in gcc 5/6.
-USED static inline uint32_t getDebugLevel() {
+USED inline uint32_t getDebugLevel() {
   static uint32_t DebugLevel = 0;
   static std::once_flag Flag{};
   std::call_once(Flag, []() {

diff  --git a/openmp/libomptarget/plugins/amdgpu/src/rtl.cpp b/openmp/libomptarget/plugins/amdgpu/src/rtl.cpp
index 326fb7527361c..a6b426dc05579 100644
--- a/openmp/libomptarget/plugins/amdgpu/src/rtl.cpp
+++ b/openmp/libomptarget/plugins/amdgpu/src/rtl.cpp
@@ -1966,6 +1966,3 @@ int32_t __tgt_rtl_synchronize(int32_t device_id, __tgt_async_info *AsyncInfo) {
   }
   return OFFLOAD_SUCCESS;
 }
-
-// AMDGPU plugin's internal InfoLevel.
-std::atomic<uint32_t> InfoLevel;

diff  --git a/openmp/libomptarget/plugins/cuda/src/rtl.cpp b/openmp/libomptarget/plugins/cuda/src/rtl.cpp
index 2e73fb0f73d60..7834f771dd97b 100644
--- a/openmp/libomptarget/plugins/cuda/src/rtl.cpp
+++ b/openmp/libomptarget/plugins/cuda/src/rtl.cpp
@@ -1252,12 +1252,10 @@ int32_t __tgt_rtl_synchronize(int32_t device_id,
 }
 
 void __tgt_rtl_set_info_flag(uint32_t NewInfoLevel) {
+  std::atomic<uint32_t> &InfoLevel = getInfoLevelInternal();
   InfoLevel.store(NewInfoLevel);
 }
 
 #ifdef __cplusplus
 }
 #endif
-
-// Cuda plugin's internal InfoLevel.
-std::atomic<uint32_t> InfoLevel;

diff  --git a/openmp/libomptarget/plugins/generic-elf-64bit/src/rtl.cpp b/openmp/libomptarget/plugins/generic-elf-64bit/src/rtl.cpp
index c3e0f15a4a33a..27cb39c5dcf6a 100644
--- a/openmp/libomptarget/plugins/generic-elf-64bit/src/rtl.cpp
+++ b/openmp/libomptarget/plugins/generic-elf-64bit/src/rtl.cpp
@@ -335,6 +335,3 @@ int32_t __tgt_rtl_run_target_region(int32_t device_id, void *tgt_entry_ptr,
 #ifdef __cplusplus
 }
 #endif
-
-// Elf-64 plugin's internal InfoLevel.
-std::atomic<uint32_t> InfoLevel;

diff  --git a/openmp/libomptarget/plugins/remote/src/rtl.cpp b/openmp/libomptarget/plugins/remote/src/rtl.cpp
index 1e25e7561ccf5..26f172a1fdcf7 100644
--- a/openmp/libomptarget/plugins/remote/src/rtl.cpp
+++ b/openmp/libomptarget/plugins/remote/src/rtl.cpp
@@ -173,6 +173,3 @@ int32_t __tgt_rtl_run_target_team_region_async(
 #ifdef __cplusplus
 }
 #endif
-
-// Remote Offloading interal InfoLevel.
-std::atomic<uint32_t> InfoLevel;

diff  --git a/openmp/libomptarget/src/interface.cpp b/openmp/libomptarget/src/interface.cpp
index 0817276f7e800..853be82c893e6 100644
--- a/openmp/libomptarget/src/interface.cpp
+++ b/openmp/libomptarget/src/interface.cpp
@@ -459,12 +459,10 @@ EXTERN void __kmpc_push_target_tripcount_mapper(ident_t *loc, int64_t device_id,
 }
 
 EXTERN void __tgt_set_info_flag(uint32_t NewInfoLevel) {
+  std::atomic<uint32_t> &InfoLevel = getInfoLevelInternal();
   InfoLevel.store(NewInfoLevel);
   for (auto &R : PM->RTLs.AllRTLs) {
     if (R.set_info_flag)
       R.set_info_flag(NewInfoLevel);
   }
 }
-
-// Libomptarget's InfoLevel storage.
-std::atomic<uint32_t> InfoLevel;


        


More information about the Openmp-commits mailing list