Skip to content

Commit ef8819e

Browse files
authored
[mlir] Extend tile_using_for verifier to fix a crash (#98366)
This patch adds a check for the correct number of `loops` results of the `transform.structured.tile_using_for` Op to the verifier, fixing a crash. Fix #98008
1 parent db27905 commit ef8819e

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2888,8 +2888,14 @@ void transform::TileUsingForOp::build(
28882888
LogicalResult transform::TileUsingForOp::verify() {
28892889
if (getMixedSizes().size() != getScalableSizes().size())
28902890
return emitOpError("expected same number of sizes (")
2891-
<< getMixedSizes().size() << ") and scalable sizes ()"
2891+
<< getMixedSizes().size() << ") and scalable sizes ("
28922892
<< getScalableSizes().size() << ")";
2893+
ArrayRef<int64_t> staticSizes = getStaticSizes();
2894+
unsigned numExpectedLoops = staticSizes.size() - llvm::count(staticSizes, 0);
2895+
if (getLoops().size() != numExpectedLoops)
2896+
return emitOpError("expected number of loops to tile (")
2897+
<< numExpectedLoops << ") to match number of `loops` results ("
2898+
<< getLoops().size() << ")";
28932899
return success();
28942900
}
28952901

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,3 +253,23 @@ module attributes {transform.with_named_sequence} {
253253
transform.yield
254254
}
255255
}
256+
257+
// -----
258+
259+
module attributes {transform.with_named_sequence} {
260+
transform.named_sequence @__transform_main(%arg1: !transform.any_op {transform.readonly}) {
261+
%0 = transform.structured.match ops{["linalg.matmul"]} in %arg1 : (!transform.any_op) -> !transform.any_op
262+
// expected-error @below {{op expected number of loops to tile (3) to match number of `loops` results (1)}}
263+
%1, %loops = transform.structured.tile_using_for %0 tile_sizes [4, 4, 4] : (!transform.any_op) -> (!transform.any_op, !transform.any_op)
264+
transform.yield
265+
}
266+
}
267+
268+
func.func @tile_linalg_matmul(
269+
%arg0: tensor<128x128xf32>, %arg1: tensor<128x128xf32>, %arg2: tensor<128x128xf32>)
270+
-> tensor<128x128xf32> {
271+
%0 = linalg.matmul ins(%arg0, %arg1: tensor<128x128xf32>, tensor<128x128xf32>)
272+
outs(%arg2: tensor<128x128xf32>)
273+
-> tensor<128x128xf32>
274+
return %0 : tensor<128x128xf32>
275+
}

0 commit comments

Comments
 (0)