Skip to content

Commit 2f17e8b

Browse files
authored
[Blackwell] Prevent the tmem allocator bitmap to go out of bound (#6032)
There was a a potential memory corruption in the tmem allocator, this makes the code more robust.
1 parent 5d8325f commit 2f17e8b

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/Dialect/TritonNvidiaGPU/Transforms/TensorMemoryAllocation.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ struct MemoryBitMap {
4343
}
4444
void alloc(const TMemChunk &chunk) {
4545
// Ensure the underlying data fits the allocation.
46-
while ((chunk.startCol + chunk.numCols) * chunk.numRows >= elements.size())
46+
while ((chunk.startCol + chunk.numCols) * kNumRows >= elements.size())
4747
elements.resize(2 * elements.size(), false);
4848

4949
for (int i = 0; i < chunk.numCols; i++) {
@@ -92,8 +92,13 @@ struct MemoryBitMap {
9292
}
9393

9494
private:
95-
bool isUsed(int row, int col) const { return elements[row + col * kNumRows]; }
95+
bool isUsed(int row, int col) const {
96+
if (row + col * kNumRows >= elements.size())
97+
return false;
98+
return elements[row + col * kNumRows];
99+
}
96100
void setUsed(int row, int col, bool used) {
101+
assert(row + col * kNumRows < elements.size());
97102
elements[row + col * kNumRows] = used;
98103
}
99104

0 commit comments

Comments
 (0)