Skip to content

Commit 097d06f

Browse files
authored
[Utility]: Early exit from updateLayout (#5067)
This PR adds an early exit optimization to the updateLayout function to avoid unnecessary processing when a tensor already has the desired encoding. --------- Signed-off-by: Ettore Tiotto <[email protected]>
1 parent 8255e76 commit 097d06f

File tree

1 file changed

+9
-4
lines changed
  • third_party/intel/lib/TritonIntelGPUTransforms

1 file changed

+9
-4
lines changed

third_party/intel/lib/TritonIntelGPUTransforms/Utility.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,16 @@ bool isExpensiveLoadOrStore(Operation *op) {
120120
if (isSingleValue(base))
121121
return false;
122122

123-
// Loads that use a block pointer are expensive if they cannot be lowered to
124-
// 2D block read operations. Temporarily leverage the
123+
// Loads or stores that use a block pointer are expensive if they cannot be
124+
// lowered to 2D block read/write operations. Temporarily leverage the
125125
// "ttig.block_io" attribute to filter out inexpensive loads.
126126
Attribute blockIOAttr =
127127
op->getAttr(TritonIntelGPUDialect::getBlockIOAttrName());
128128
if (blockIOAttr)
129129
return false;
130130

131-
// Loads that use more threads than elements can be presumed to have a high
132-
// hit-rate that makes them cheap to load.
131+
// Loads or stores that use more threads than elements can be presumed to have
132+
// a high hit-rate that makes them cheap.
133133
if (auto ptrType = getRankedTensorType(base.getType())) {
134134
int numWarps = ttg::lookupNumWarps(op);
135135
auto mod = op->getParentOfType<ModuleOp>();
@@ -197,6 +197,11 @@ LogicalResult getConvertBackwardSlice(
197197

198198
auto updateLayout = [&](Value value, Attribute encoding) {
199199
assert(isTensorOrTensorPointerType(value.getType()));
200+
201+
if (RankedTensorType tensorType = getRankedTensorType(value.getType()))
202+
if (tensorType.getEncoding() == encoding)
203+
return success();
204+
200205
slice.insert(value);
201206
Attribute &existing = layout[value];
202207
if (existing && existing != encoding)

0 commit comments

Comments
 (0)