Skip to content

Commit 2fafd63

Browse files
[ConSan] Improve comments in TritonInstrumentOps.td (#7907)
Add the description of auxiliary tensors and improve description of ops to tell how the checks are actually performed.
1 parent a8be499 commit 2fafd63

File tree

1 file changed

+29
-16
lines changed

1 file changed

+29
-16
lines changed

include/triton/Dialect/TritonInstrument/IR/TritonInstrumentOps.td

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,25 @@ include "mlir/IR/OpBase.td"
88
include "mlir/Interfaces/SideEffectInterfaces.td"
99
include "triton/Dialect/TritonInstrument/IR/TritonInstrumentAttrDefs.td"
1010

11+
// Concurrency Sanitizer data structures:
12+
// ConSan keeps auxilary data requied for tracking memory accesses in tensors.
13+
// These tensors are stored as a distributed tensor or in global scratch memory.
14+
//
15+
// Tensor name | Storage | Type | Description
16+
// ------------- | ------- | -------- | -----------
17+
// buffers | tensor | <Bxi64> | List of base pointers of all the buffers and sub-buffers in the program
18+
// barriers | tensor | <Mxi64> | List of pointers to all individual mbarriers in the program
19+
// writeState | scratch | <Mxi8> | Marks which buffers are being written to.
20+
// | | | Entries in this tensor are set when write operation is issued. Entries are bitfields, where:
21+
// | | | - bit 0: 1 if the buffer is being written to
22+
// | | | - bit 1: 1 if the write is *not* hwPipelined
23+
// writeBars | scratch | <BxMxi8> | Which barriers track writes to which buffers.
24+
// | | | Entries in this tensor are set when commit with barrier is called.
25+
// readBars | scratch | <BxMxi8> | Which barriers track reads from which buffers.
26+
// | | | Entries in this tensor are set when read operation with barrier is issued.
27+
// asyncCpCommits | scratch | <Bxi8> | Tracks number of outstanding commits for buffers written with cp-async.
28+
// wgmmaCommits | scratch | <Bxi8> | Tracks number of outstanding commits for buffers being read by wgmma.
29+
1130
//
1231
// Interfaces
1332
//
@@ -52,10 +71,6 @@ def TTI_ExperimentalCheckWriteStateOp : TTI_Op<"experimental_check_write_state",
5271
let description = [{
5372
Check if the writeState tensor has non-zero value associated with the buffer.
5473

55-
`writeState` is a tensor of 8b bitfields, where:
56-
- bit 0: 1 if the buffer is being written to
57-
- bit 1: 1 if the write is *not* hwPipelined
58-
5974
If hwPipelined is true, shift the bitfield by 1 to check the second bit - this
6075
means that the error won't be triggered if another pipelined write is outstanding.
6176
}];
@@ -79,7 +94,7 @@ def TTI_ExperimentalCheckWriteStateOp : TTI_Op<"experimental_check_write_state",
7994
def TTI_ExperimentalCheckReadBarriersOp : TTI_Op<"experimental_check_read_barriers", [MemoryEffects<[MemWrite<GlobalMemory>]>]> {
8095
let summary = "check if there are outstanding reads from a buffer guarded by a mbar";
8196
let description = [{
82-
Check if there are outstanding reads from a buffer guarded by a mbar.
97+
Check if any of the entries in readBars in the row corresponding to the buffer is non-zero.
8398
}];
8499
let arguments = (ins
85100
TTG_MemDescType:$buf,
@@ -100,11 +115,7 @@ def TTI_ExperimentalSetWriteStateOp : TTI_Op<"experimental_set_write_state", [Me
100115
let description = [{
101116
Mark a buffer as being written to. It is not yet tracked by a barrier, until
102117
`commit_write_with_barrier` is called, at which point all the buffers being written
103-
to are marked as tracked by the barrier.
104-
105-
`writeState` is a tensor of 8b bitfields, where:
106-
- bit 0: 1 if the buffer is being written to
107-
- bit 1: 1 if the write is *not* hwPipelined
118+
to are marked as tracked by the barrier in writeBars tensor.
108119

109120
If hwPipelined is true, the write won't trigger an error if another pipelined
110121
write is executed later without waiting for the barrier.
@@ -149,7 +160,7 @@ def TTI_ExperimentalCommitWriteWithBarrierOp : TTI_Op<"experimental_commit_write
149160
def TTI_ExperimentalSetReadBarrierOp : TTI_Op<"experimental_set_read_barrier", [MemoryEffects<[MemWrite<GlobalMemory>]>]> {
150161
let summary = "mark a buffer as being read from using mbar as a guard";
151162
let description = [{
152-
Mark a buffer as being read from using mbar as a guard.
163+
Set the entry under [buffer, mbar] in readBars tensor to 1, marking the buffer as tracked by the barrier.
153164
}];
154165
let arguments = (ins
155166
TTG_MemDescType:$buf,
@@ -170,7 +181,8 @@ def TTI_ExperimentalSetReadBarrierOp : TTI_Op<"experimental_set_read_barrier", [
170181
def TTI_ExperimentalClearWriteBarrierOp : TTI_Op<"experimental_clear_write_barrier", [MemoryEffects<[MemWrite<GlobalMemory>]>]> {
171182
let summary = "clear the write state for buffers being guarded by an mbar";
172183
let description = [{
173-
Clear the write state for buffers being guarded by an mbar.
184+
For each buffer that has [buffer, mbar] entry in writeBars tensor, set the corresponding entry in writeState tensor to 0.
185+
Also, set the corresponding entry in writeBars tensor to 0.
174186
}];
175187
let arguments = (ins
176188
TTG_MemDescType:$mbar,
@@ -191,7 +203,7 @@ def TTI_ExperimentalClearWriteBarrierOp : TTI_Op<"experimental_clear_write_barri
191203
def TTI_ExperimentalClearReadBarrierOp : TTI_Op<"experimental_clear_read_barrier", [MemoryEffects<[MemWrite<GlobalMemory>]>]> {
192204
let summary = "clear the read state for buffers being guarded by an mbar";
193205
let description = [{
194-
Clear the read state for buffers being guarded by an mbar.
206+
Set all the entries in the column corresponding to the mbar in readBars tensor to 0.
195207
}];
196208
let arguments = (ins
197209
TTG_MemDescType:$mbar,
@@ -210,7 +222,7 @@ def TTI_ExperimentalClearReadBarrierOp : TTI_Op<"experimental_clear_read_barrier
210222
def TTI_ExperimentalCheckBarrierWritesClearedOp : TTI_Op<"experimental_check_barrier_writes_cleared", [MemoryEffects<[MemWrite<GlobalMemory>]>]> {
211223
let summary = "verify that the barrier is not used to track any writes";
212224
let description = [{
213-
Verify that the barrier is not used to track any writes.
225+
Verify that the column corresponding to the mbar in writeBars tensor is all 0.
214226
}];
215227
let arguments = (ins
216228
TTG_MemDescType:$mbar,
@@ -248,7 +260,8 @@ def TTI_ExperimentalStageAccessForCommitOp : TTI_Op<"experimental_stage_access_f
248260
def TTI_ExperimentalCommitAccessesOp : TTI_Op<"experimental_commit_accesses", [MemoryEffects<[MemWrite<GlobalMemory>]>]> {
249261
let summary = "Commit all the staged accesses for all the buffers.";
250262
let description = [{
251-
Commit all the staged accesses for all the buffers.
263+
Increment the value in outstandingCommits tensor for each entry greater than 0.
264+
Change all the `-1` entries in outstandingCommits tensor to 1, signifying 1 outstanding commit.
252265
}];
253266
let arguments = (ins
254267
TT_PtrLike:$outstandingCommits,
@@ -277,7 +290,7 @@ def TTI_ExperimentalClearOutstandingCommitsOp : TTI_Op<"experimental_clear_outst
277290
def TTI_ExperimentalCheckOutstandingCommitsOp : TTI_Op<"experimental_check_outstanding_commits", [MemoryEffects<[MemWrite<GlobalMemory>]>]> {
278291
let summary = "Check if the buffer has an outstanding commit.";
279292
let description = [{
280-
Check if the buffer has an outstanding commit.
293+
Verify that the entry corresponding to the buffer in outstandingCommits tensor is 0.
281294
}];
282295
let arguments = (ins
283296
TTG_MemDescType:$buf,

0 commit comments

Comments
 (0)