[OpenMP] Fix initializer not working on AMDGPU
authorJoseph Huber <jhuber6@vols.utk.edu>
Tue, 16 Nov 2021 04:04:55 +0000 (23:04 -0500)
committerJoseph Huber <jhuber6@vols.utk.edu>
Tue, 16 Nov 2021 13:17:15 +0000 (08:17 -0500)
The RAII class used for debugging RTL entry used a shared variable to
keep track of the current depth. This used a global initializer, which
isn't supported on AMDGPU. This patch removes the initializer and
instead sets it to zero when the state is initialized in the runtime.

Reviewed By: jdoerfert, JonChesterfield

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

openmp/libomptarget/DeviceRTL/include/Debug.h
openmp/libomptarget/DeviceRTL/src/Debug.cpp
openmp/libomptarget/DeviceRTL/src/State.cpp

index f66d566..18c43f3 100644 (file)
@@ -57,6 +57,8 @@ int printf(const char *format, ...);
 struct DebugEntryRAII {
   DebugEntryRAII(const char *File, const unsigned Line, const char *Function);
   ~DebugEntryRAII();
+
+  static void init();
 };
 
 #endif
index fc9b2ed..79be728 100644 (file)
@@ -55,7 +55,7 @@ int32_t __llvm_omp_vprintf(const char *Format, void *Arguments, uint32_t Size) {
 }
 
 /// Current indentation level for the function trace. Only accessed by thread 0.
-static uint32_t Level = 0;
+static uint32_t Level;
 #pragma omp allocate(Level) allocator(omp_pteam_mem_alloc)
 
 DebugEntryRAII::DebugEntryRAII(const char *File, const unsigned Line,
@@ -78,4 +78,6 @@ DebugEntryRAII::~DebugEntryRAII() {
     Level--;
 }
 
+void DebugEntryRAII::init() { Level = 0; }
+
 #pragma omp end declare target
index a16fa1b..d6ae00b 100644 (file)
@@ -366,8 +366,10 @@ void *&state::lookupPtr(ValueKind Kind, bool IsReadonly) {
 
 void state::init(bool IsSPMD) {
   SharedMemorySmartStack.init(IsSPMD);
-  if (mapping::isInitialThreadInLevel0(IsSPMD))
+  if (mapping::isInitialThreadInLevel0(IsSPMD)) {
     TeamState.init(IsSPMD);
+    DebugEntryRAII::init();
+  }
 
   ThreadStates[mapping::getThreadIdInBlock()] = nullptr;
 }