Skip to content

Commit d65885a

Browse files
authored
[MLIR][Linalg] Bail out if the tiles provided are more than the number (#66007)
Currently, the compiler crashes if the number of tiles provided exceeds the number of loops.
1 parent 5db9412 commit d65885a

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2535,6 +2535,15 @@ transform::TileOp::apply(transform::TransformRewriter &rewriter,
25352535
diag.attachNote(op->getLoc()) << "target op";
25362536
return diag;
25372537
}
2538+
if (tileSizes.size() > tilingInterface.getLoopIteratorTypes().size()) {
2539+
DiagnosedSilenceableFailure diag =
2540+
emitSilenceableError()
2541+
<< "too many tiles provided, expected at most "
2542+
<< tilingInterface.getLoopIteratorTypes().size() << " found "
2543+
<< tileSizes.size();
2544+
diag.attachNote(op->getLoc()) << "target op";
2545+
return diag;
2546+
}
25382547

25392548
scf::SCFTilingOptions tilingOptions;
25402549
if (!tileSizes.empty()) {

mlir/test/Dialect/Linalg/transform-op-tile.mlir

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,20 @@ transform.sequence failures(propagate) {
220220
%0 = transform.structured.match ops{["linalg.matmul"]} in %arg1 : (!transform.any_op) -> !transform.any_op
221221
%1, %loops:3 = transform.structured.tile %0 [4, 4, [4]] : (!transform.any_op) -> (!transform.any_op, !transform.any_op, !transform.any_op, !transform.any_op)
222222
}
223+
224+
// -----
225+
226+
func.func @too_many_tiles(%arg0: tensor<128x128xf32>, %arg1: tensor<128x128xf32>,
227+
%arg2: tensor<128x128xf32>) -> tensor<128x128xf32> {
228+
// expected-note @below {{target op}}
229+
%0 = linalg.matmul ins(%arg0, %arg1: tensor<128x128xf32>, tensor<128x128xf32>)
230+
outs(%arg2: tensor<128x128xf32>) -> tensor<128x128xf32>
231+
return %0 : tensor<128x128xf32>
232+
}
233+
234+
transform.sequence failures(propagate) {
235+
^bb0(%arg1: !transform.any_op):
236+
%0 = transform.structured.match ops{["linalg.matmul"]} in %arg1 : (!transform.any_op) -> !transform.any_op
237+
// expected-error @below {{too many tiles provided, expected at most 3 found 4}}
238+
%1, %loops = transform.structured.tile %0 [1, 0, 0, 0] : (!transform.any_op) -> (!transform.any_op, !transform.any_op)
239+
}

0 commit comments

Comments
 (0)