[Openmp-commits] [openmp] 1cea309 - [OpenMP][NFC] Move DebugKind to make it reusable from the host

Johannes Doerfert via Openmp-commits openmp-commits at lists.llvm.org
Fri Oct 20 19:29:12 PDT 2023


Author: Johannes Doerfert
Date: 2023-10-20T19:28:09-07:00
New Revision: 1cea309b7e2256746c72f3177e1a5b226bed4f83

URL: https://github.com/llvm/llvm-project/commit/1cea309b7e2256746c72f3177e1a5b226bed4f83
DIFF: https://github.com/llvm/llvm-project/commit/1cea309b7e2256746c72f3177e1a5b226bed4f83.diff

LOG: [OpenMP][NFC] Move DebugKind to make it reusable from the host

Added: 
    

Modified: 
    openmp/libomptarget/DeviceRTL/include/Configuration.h
    openmp/libomptarget/DeviceRTL/include/Debug.h
    openmp/libomptarget/DeviceRTL/src/Configuration.cpp
    openmp/libomptarget/DeviceRTL/src/State.cpp
    openmp/libomptarget/include/Environment.h
    openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.cpp

Removed: 
    


################################################################################
diff  --git a/openmp/libomptarget/DeviceRTL/include/Configuration.h b/openmp/libomptarget/DeviceRTL/include/Configuration.h
index 4a68a2f1d46bf6f..45e5cead231f724 100644
--- a/openmp/libomptarget/DeviceRTL/include/Configuration.h
+++ b/openmp/libomptarget/DeviceRTL/include/Configuration.h
@@ -13,17 +13,12 @@
 #ifndef OMPTARGET_CONFIGURATION_H
 #define OMPTARGET_CONFIGURATION_H
 
+#include "Environment.h"
 #include "Types.h"
 
 namespace ompx {
 namespace config {
 
-enum DebugKind : uint32_t {
-  Assertion = 1U << 0,
-  FunctionTracing = 1U << 1,
-  CommonIssues = 1U << 2,
-};
-
 /// Return the number of devices in the system, same number as returned on the
 /// host by omp_get_num_devices.
 uint32_t getNumDevices();
@@ -50,7 +45,7 @@ uint64_t getIndirectCallTableSize();
 uint64_t getHardwareParallelism();
 
 /// Return if debugging is enabled for the given debug kind.
-bool isDebugMode(DebugKind Level);
+bool isDebugMode(DeviceDebugKind Level);
 
 /// Indicates if this kernel may require thread-specific states, or if it was
 /// explicitly disabled by the user.

diff  --git a/openmp/libomptarget/DeviceRTL/include/Debug.h b/openmp/libomptarget/DeviceRTL/include/Debug.h
index 4eb904775326128..bd4d40e8f24fd5b 100644
--- a/openmp/libomptarget/DeviceRTL/include/Debug.h
+++ b/openmp/libomptarget/DeviceRTL/include/Debug.h
@@ -28,7 +28,7 @@ void __assert_fail_internal(const char *expr, const char *msg, const char *file,
 
 #define ASSERT(expr, msg)                                                      \
   {                                                                            \
-    if (config::isDebugMode(config::DebugKind::Assertion) && !(expr))          \
+    if (config::isDebugMode(DeviceDebugKind::Assertion) && !(expr))            \
       __assert_fail_internal(#expr, msg, __FILE__, __LINE__,                   \
                              __PRETTY_FUNCTION__);                             \
     else                                                                       \

diff  --git a/openmp/libomptarget/DeviceRTL/src/Configuration.cpp b/openmp/libomptarget/DeviceRTL/src/Configuration.cpp
index a792e5be568e6ee..ab1608b1cfb0ae9 100644
--- a/openmp/libomptarget/DeviceRTL/src/Configuration.cpp
+++ b/openmp/libomptarget/DeviceRTL/src/Configuration.cpp
@@ -12,7 +12,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "Configuration.h"
-#include "Environment.h"
 #include "State.h"
 #include "Types.h"
 
@@ -32,7 +31,7 @@ using namespace ompx;
     CONSTANT(__omp_rtl_device_environment);
 
 uint32_t config::getDebugKind() {
-  return __omp_rtl_debug_kind & __omp_rtl_device_environment.DebugKind;
+  return __omp_rtl_debug_kind & __omp_rtl_device_environment.DeviceDebugKind;
 }
 
 uint32_t config::getNumDevices() {
@@ -64,8 +63,8 @@ uint64_t config::getIndirectCallTableSize() {
   return __omp_rtl_device_environment.IndirectCallTableSize;
 }
 
-bool config::isDebugMode(config::DebugKind Kind) {
-  return config::getDebugKind() & Kind;
+bool config::isDebugMode(DeviceDebugKind Kind) {
+  return config::getDebugKind() & uint32_t(Kind);
 }
 
 bool config::mayUseThreadStates() { return !__omp_rtl_assume_no_thread_state; }

diff  --git a/openmp/libomptarget/DeviceRTL/src/State.cpp b/openmp/libomptarget/DeviceRTL/src/State.cpp
index c34adfb94d7c731..68fe0b383548e53 100644
--- a/openmp/libomptarget/DeviceRTL/src/State.cpp
+++ b/openmp/libomptarget/DeviceRTL/src/State.cpp
@@ -137,7 +137,7 @@ void *SharedMemorySmartStackTy::push(uint64_t Bytes) {
     return Ptr;
   }
 
-  if (config::isDebugMode(config::DebugKind::CommonIssues))
+  if (config::isDebugMode(DeviceDebugKind::CommonIssues))
     PRINT("Shared memory stack full, fallback to dynamic allocation of global "
           "memory will negatively impact performance.\n");
   void *GlobalMemory = memory::allocGlobal(
@@ -172,7 +172,7 @@ void memory::freeShared(void *Ptr, uint64_t Bytes, const char *Reason) {
 
 void *memory::allocGlobal(uint64_t Bytes, const char *Reason) {
   void *Ptr = malloc(Bytes);
-  if (config::isDebugMode(config::DebugKind::CommonIssues) && Ptr == nullptr)
+  if (config::isDebugMode(DeviceDebugKind::CommonIssues) && Ptr == nullptr)
     PRINT("nullptr returned by malloc!\n");
   return Ptr;
 }

diff  --git a/openmp/libomptarget/include/Environment.h b/openmp/libomptarget/include/Environment.h
index 6606d7838cafa72..48a0fa933bdd8c0 100644
--- a/openmp/libomptarget/include/Environment.h
+++ b/openmp/libomptarget/include/Environment.h
@@ -25,8 +25,15 @@ using IdentTy = ident_t;
 
 #include "llvm/Frontend/OpenMP/OMPDeviceConstants.h"
 
+enum class DeviceDebugKind : uint32_t {
+  Assertion = 1U << 0,
+  FunctionTracing = 1U << 1,
+  CommonIssues = 1U << 2,
+  AllocationTracker = 1U << 3,
+};
+
 struct DeviceEnvironmentTy {
-  uint32_t DebugKind;
+  uint32_t DeviceDebugKind;
   uint32_t NumDevices;
   uint32_t DeviceNum;
   uint32_t DynamicMemSize;

diff  --git a/openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.cpp b/openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.cpp
index feae44b9b57f570..c8fb8d552f429a0 100644
--- a/openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.cpp
+++ b/openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.cpp
@@ -10,6 +10,7 @@
 
 #include "PluginInterface.h"
 #include "Debug.h"
+#include "Environment.h"
 #include "GlobalHandler.h"
 #include "JIT.h"
 #include "elf_common.h"
@@ -687,7 +688,7 @@ Error GenericDeviceTy::setupDeviceEnvironment(GenericPluginTy &Plugin,
     return CallTablePairOrErr.takeError();
 
   DeviceEnvironmentTy DeviceEnvironment;
-  DeviceEnvironment.DebugKind = OMPX_DebugKind;
+  DeviceEnvironment.DeviceDebugKind = OMPX_DebugKind;
   DeviceEnvironment.NumDevices = Plugin.getNumDevices();
   // TODO: The device ID used here is not the real device ID used by OpenMP.
   DeviceEnvironment.DeviceNum = DeviceId;


        


More information about the Openmp-commits mailing list