From 59b68490122ae6ef92b1ebe45e8a5f2f7d88a401 Mon Sep 17 00:00:00 2001 From: Joseph Huber Date: Thu, 22 Apr 2021 15:29:28 -0400 Subject: [PATCH] [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 --- openmp/libomptarget/include/Debug.h | 12 ++++++------ openmp/libomptarget/plugins/amdgpu/src/rtl.cpp | 3 --- openmp/libomptarget/plugins/cuda/src/rtl.cpp | 4 +--- openmp/libomptarget/plugins/generic-elf-64bit/src/rtl.cpp | 3 --- openmp/libomptarget/plugins/remote/src/rtl.cpp | 3 --- openmp/libomptarget/src/interface.cpp | 4 +--- 6 files changed, 8 insertions(+), 21 deletions(-) diff --git a/openmp/libomptarget/include/Debug.h b/openmp/libomptarget/include/Debug.h index 6c9a94a..6dd2f0e 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 InfoLevel; - // Add __attribute__((used)) to work around a bug in gcc 5/6. -USED static inline uint32_t getInfoLevel() { +USED inline std::atomic &getInfoLevelInternal() { + static std::atomic 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 326fb75..a6b426d 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 InfoLevel; diff --git a/openmp/libomptarget/plugins/cuda/src/rtl.cpp b/openmp/libomptarget/plugins/cuda/src/rtl.cpp index 2e73fb0..7834f77 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 &InfoLevel = getInfoLevelInternal(); InfoLevel.store(NewInfoLevel); } #ifdef __cplusplus } #endif - -// Cuda plugin's internal InfoLevel. -std::atomic InfoLevel; diff --git a/openmp/libomptarget/plugins/generic-elf-64bit/src/rtl.cpp b/openmp/libomptarget/plugins/generic-elf-64bit/src/rtl.cpp index c3e0f15..27cb39c 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 InfoLevel; diff --git a/openmp/libomptarget/plugins/remote/src/rtl.cpp b/openmp/libomptarget/plugins/remote/src/rtl.cpp index 1e25e75..26f172a 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 InfoLevel; diff --git a/openmp/libomptarget/src/interface.cpp b/openmp/libomptarget/src/interface.cpp index 0817276..853be82 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 &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 InfoLevel; -- 2.7.4