Skip to content

Commit 702608f

Browse files
authored
[mlir] emit better errors in transform.structured.interchange (#67315)
The implementation doesn't emit any diagnostics as it is shared with the pattern-based implementation. Check preconditions early and emit diagnostics from the transform op instead. Without this change, the op would produce a definite failure and no error message.
1 parent 247b7d0 commit 702608f

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1037,12 +1037,21 @@ transform::InterchangeOp::applyToOne(transform::TransformRewriter &rewriter,
10371037
results.push_back(target);
10381038
return DiagnosedSilenceableFailure::success();
10391039
}
1040+
1041+
unsigned numLoops = cast<LinalgOp>(target.getOperation()).getNumLoops();
1042+
if (interchangeVector.size() != numLoops) {
1043+
return emitSilenceableError()
1044+
<< getIteratorInterchangeAttrName() << " has length ("
1045+
<< interchangeVector.size()
1046+
<< ") different from the number of loops in the target operation ("
1047+
<< numLoops << ")";
1048+
}
10401049
FailureOr<GenericOp> res =
10411050
interchangeGenericOp(rewriter, target,
10421051
SmallVector<unsigned>(interchangeVector.begin(),
10431052
interchangeVector.end()));
10441053
if (failed(res))
1045-
return DiagnosedSilenceableFailure::definiteFailure();
1054+
return emitDefiniteFailure() << "failed to apply";
10461055
results.push_back(res->getOperation());
10471056
return DiagnosedSilenceableFailure::success();
10481057
}

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,25 @@ transform.sequence failures(propagate) {
3838
// expected-error @below {{transform applied to the wrong op kind}}
3939
transform.structured.interchange %0 iterator_interchange = [1, 0] : (!transform.any_op) -> !transform.any_op
4040
}
41+
42+
// -----
43+
44+
func.func @too_many_iters(%0: tensor<?x?xf32>, %1: tensor<?x?xf32>) -> tensor<?x?xf32> {
45+
%r = linalg.generic {
46+
indexing_maps = [affine_map<(d0, d1) -> (d0, d1)>, affine_map<(d0, d1) -> (d0, d1)>],
47+
iterator_types = ["parallel", "parallel"]
48+
} ins(%0: tensor<?x?xf32>) outs(%1: tensor<?x?xf32>) {
49+
^bb0(%2: f32, %3: f32):
50+
%4 = arith.mulf %2, %2 : f32
51+
linalg.yield %4 : f32
52+
} -> tensor<?x?xf32>
53+
return %r : tensor<?x?xf32>
54+
}
55+
56+
transform.sequence failures(propagate) {
57+
^bb0(%arg0: !transform.any_op):
58+
%0 = transform.structured.match ops{["linalg.generic"]} in %arg0 : (!transform.any_op) -> !transform.any_op
59+
// expected-error @below {{"iterator_interchange" has length (3) different from the number of loops in the target operation (2)}}
60+
transform.structured.interchange %0 iterator_interchange = [2,1,0] : (!transform.any_op) -> !transform.any_op
61+
transform.yield
62+
}

0 commit comments

Comments
 (0)