@@ -191,22 +191,19 @@ class Allocation {
191191 // / Virtual: triton.call
192192 enum class BufferKind { Explicit, Scratch, Virtual };
193193
194- // / MT: thread-safe
195- inline static std::atomic<BufferId> nextId = 0 ;
196-
197194 BufferKind kind;
198195 BufferId id;
196+ Operation *owner;
199197 size_t size;
200198 size_t alignment;
201199 size_t offset;
202200
203201 bool operator ==(const BufferT &other) const { return id == other.id ; }
204202 bool operator <(const BufferT &other) const { return id < other.id ; }
205203
206- BufferT () : BufferT(BufferKind::Explicit, 0 ) {}
207- BufferT (BufferKind kind, size_t size, size_t alignment = 4 ,
208- size_t offset = 0 )
209- : kind(kind), id(nextId++), size(size), alignment(alignment),
204+ BufferT (BufferKind kind, BufferId id, Operation *owner, size_t size,
205+ size_t alignment = 4 , size_t offset = 0 )
206+ : kind(kind), id(id), owner(owner), size(size), alignment(alignment),
210207 offset (offset) {}
211208
212209 size_t setOffsetAligned (size_t newOffset) {
@@ -226,14 +223,16 @@ class Allocation {
226223private:
227224 template <BufferT::BufferKind Kind, typename KeyType, typename ... Args>
228225 void addBuffer (KeyType &key, Args &&...args) {
229- auto buffer = BufferT (Kind, std::forward<Args>(args)...);
230- bufferSet[buffer.id ] = std::move (buffer);
226+ BufferId nextId = bufferIdCounter++;
227+ auto [it, inserted] = bufferSet.insert_or_assign (
228+ nextId, BufferT (Kind, nextId, key, std::forward<Args>(args)...));
229+ BufferT *buffer = &it->second ;
231230 if constexpr (Kind == BufferT::BufferKind::Explicit) {
232- valueBuffer[key] = &bufferSet[ buffer. id ] ;
231+ valueBuffer[key] = buffer;
233232 } else if constexpr (Kind == BufferT::BufferKind::Virtual) {
234- opVirtual[key] = &bufferSet[ buffer. id ] ;
233+ opVirtual[key] = buffer;
235234 } else {
236- opScratch[key] = &bufferSet[ buffer. id ] ;
235+ opScratch[key] = buffer;
237236 }
238237 }
239238
@@ -250,6 +249,8 @@ class Allocation {
250249 BufferSetT bufferSet;
251250 size_t sharedMemorySize = 0 ;
252251
252+ size_t bufferIdCounter = 0 ;
253+
253254 friend class triton ::AllocationAnalysis;
254255};
255256
0 commit comments