Skip to content

Commit 395bdeb

Browse files
Revert "[openmp][nfc] Refactor shared/lds smartstack for spirv (#131905)"
This reverts commit c02b935. Failed a check-offload test under CI
1 parent 206f78d commit 395bdeb

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

offload/DeviceRTL/src/State.cpp

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -75,48 +75,43 @@ extern "C" {
7575
///
7676
struct SharedMemorySmartStackTy {
7777
/// Initialize the stack. Must be called by all threads.
78-
static void init(bool IsSPMD);
78+
void init(bool IsSPMD);
7979

8080
/// Allocate \p Bytes on the stack for the encountering thread. Each thread
8181
/// can call this function.
82-
static void *push(uint64_t Bytes);
82+
void *push(uint64_t Bytes);
8383

8484
/// Deallocate the last allocation made by the encountering thread and pointed
8585
/// to by \p Ptr from the stack. Each thread can call this function.
86-
static void pop(void *Ptr, uint64_t Bytes);
86+
void pop(void *Ptr, uint64_t Bytes);
8787

8888
private:
8989
/// Compute the size of the storage space reserved for a thread.
90-
static uint32_t computeThreadStorageTotal() {
90+
uint32_t computeThreadStorageTotal() {
9191
uint32_t NumLanesInBlock = mapping::getNumberOfThreadsInBlock();
9292
return utils::alignDown((state::SharedScratchpadSize / NumLanesInBlock),
9393
allocator::ALIGNMENT);
9494
}
9595

9696
/// Return the top address of the warp data stack, that is the first address
9797
/// this warp will allocate memory at next.
98-
static void *getThreadDataTop(uint32_t TId) {
99-
return (void *)&Data[computeThreadStorageTotal() * TId + Usage[TId]];
98+
void *getThreadDataTop(uint32_t TId) {
99+
return &Data[computeThreadStorageTotal() * TId + Usage[TId]];
100100
}
101101

102102
/// The actual storage, shared among all warps.
103-
104-
[[gnu::aligned(allocator::ALIGNMENT)]] [[clang::loader_uninitialized]]
105-
static Local<unsigned char> Data[state::SharedScratchpadSize];
106-
[[gnu::aligned(allocator::ALIGNMENT)]] [[clang::loader_uninitialized]]
107-
static Local<unsigned char> Usage[mapping::MaxThreadsPerTeam];
103+
[[gnu::aligned(
104+
allocator::ALIGNMENT)]] unsigned char Data[state::SharedScratchpadSize];
105+
[[gnu::aligned(
106+
allocator::ALIGNMENT)]] unsigned char Usage[mapping::MaxThreadsPerTeam];
108107
};
109108

110-
Local<unsigned char>
111-
SharedMemorySmartStackTy::Data[state::SharedScratchpadSize];
112-
Local<unsigned char>
113-
SharedMemorySmartStackTy::Usage[mapping::MaxThreadsPerTeam];
114-
115109
static_assert(state::SharedScratchpadSize / mapping::MaxThreadsPerTeam <= 256,
116110
"Shared scratchpad of this size not supported yet.");
117111

118-
/// The single shared memory scratchpad.
119-
using SharedMemorySmartStack = SharedMemorySmartStackTy;
112+
/// The allocation of a single shared memory scratchpad.
113+
[[clang::loader_uninitialized]] static Local<SharedMemorySmartStackTy>
114+
SharedMemorySmartStack;
120115

121116
void SharedMemorySmartStackTy::init(bool IsSPMD) {
122117
Usage[mapping::getThreadIdInBlock()] = 0;
@@ -168,11 +163,11 @@ void SharedMemorySmartStackTy::pop(void *Ptr, uint64_t Bytes) {
168163
void *memory::getDynamicBuffer() { return DynamicSharedBuffer; }
169164

170165
void *memory::allocShared(uint64_t Bytes, const char *Reason) {
171-
return SharedMemorySmartStack::push(Bytes);
166+
return SharedMemorySmartStack.push(Bytes);
172167
}
173168

174169
void memory::freeShared(void *Ptr, uint64_t Bytes, const char *Reason) {
175-
SharedMemorySmartStack::pop(Ptr, Bytes);
170+
SharedMemorySmartStack.pop(Ptr, Bytes);
176171
}
177172

178173
void *memory::allocGlobal(uint64_t Bytes, const char *Reason) {
@@ -252,7 +247,7 @@ int returnValIfLevelIsActive(int Level, int Val, int DefaultVal,
252247

253248
void state::init(bool IsSPMD, KernelEnvironmentTy &KernelEnvironment,
254249
KernelLaunchEnvironmentTy &KernelLaunchEnvironment) {
255-
SharedMemorySmartStack::init(IsSPMD);
250+
SharedMemorySmartStack.init(IsSPMD);
256251
if (mapping::isInitialThreadInLevel0(IsSPMD)) {
257252
TeamState.init(IsSPMD);
258253
ThreadStates = nullptr;

0 commit comments

Comments
 (0)