@@ -75,43 +75,48 @@ extern "C" {
7575// /
7676struct SharedMemorySmartStackTy {
7777 // / Initialize the stack. Must be called by all threads.
78- void init (bool IsSPMD);
78+ static void init (bool IsSPMD);
7979
8080 // / Allocate \p Bytes on the stack for the encountering thread. Each thread
8181 // / can call this function.
82- void *push (uint64_t Bytes);
82+ static 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- void pop (void *Ptr, uint64_t Bytes);
86+ static void pop (void *Ptr, uint64_t Bytes);
8787
8888private:
8989 // / Compute the size of the storage space reserved for a thread.
90- uint32_t computeThreadStorageTotal () {
90+ static 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- void *getThreadDataTop (uint32_t TId) {
99- return &Data[computeThreadStorageTotal () * TId + Usage[TId]];
98+ static void *getThreadDataTop (uint32_t TId) {
99+ return ( void *) &Data[computeThreadStorageTotal () * TId + Usage[TId]];
100100 }
101101
102102 // / The actual storage, shared among all warps.
103- [[gnu::aligned(
104- allocator::ALIGNMENT)]] unsigned char Data[state::SharedScratchpadSize];
105- [[gnu::aligned(
106- allocator::ALIGNMENT)]] unsigned char Usage[mapping::MaxThreadsPerTeam];
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];
107108};
108109
110+ Local<unsigned char >
111+ SharedMemorySmartStackTy::Data[state::SharedScratchpadSize];
112+ Local<unsigned char >
113+ SharedMemorySmartStackTy::Usage[mapping::MaxThreadsPerTeam];
114+
109115static_assert (state::SharedScratchpadSize / mapping::MaxThreadsPerTeam <= 256 ,
110116 " Shared scratchpad of this size not supported yet." );
111117
112- // / The allocation of a single shared memory scratchpad.
113- [[clang::loader_uninitialized]] static Local<SharedMemorySmartStackTy>
114- SharedMemorySmartStack;
118+ // / The single shared memory scratchpad.
119+ using SharedMemorySmartStack = SharedMemorySmartStackTy;
115120
116121void SharedMemorySmartStackTy::init (bool IsSPMD) {
117122 Usage[mapping::getThreadIdInBlock ()] = 0 ;
@@ -163,11 +168,11 @@ void SharedMemorySmartStackTy::pop(void *Ptr, uint64_t Bytes) {
163168void *memory::getDynamicBuffer () { return DynamicSharedBuffer; }
164169
165170void *memory::allocShared (uint64_t Bytes, const char *Reason) {
166- return SharedMemorySmartStack. push (Bytes);
171+ return SharedMemorySmartStack:: push (Bytes);
167172}
168173
169174void memory::freeShared (void *Ptr, uint64_t Bytes, const char *Reason) {
170- SharedMemorySmartStack. pop (Ptr, Bytes);
175+ SharedMemorySmartStack:: pop (Ptr, Bytes);
171176}
172177
173178void *memory::allocGlobal (uint64_t Bytes, const char *Reason) {
@@ -247,7 +252,7 @@ int returnValIfLevelIsActive(int Level, int Val, int DefaultVal,
247252
248253void state::init (bool IsSPMD, KernelEnvironmentTy &KernelEnvironment,
249254 KernelLaunchEnvironmentTy &KernelLaunchEnvironment) {
250- SharedMemorySmartStack. init (IsSPMD);
255+ SharedMemorySmartStack:: init (IsSPMD);
251256 if (mapping::isInitialThreadInLevel0 (IsSPMD)) {
252257 TeamState.init (IsSPMD);
253258 ThreadStates = nullptr ;
0 commit comments