Skip to content

Commit bbcfe6f

Browse files
authored
[mlir][transform] Emit error message with emitSilenceableFailure (#86146)
The previous implementation used a `notifyMatchFailure` to emit failure message inappropriately and then used the `emitDefaultSilenceableFailure`. This patch changes this to use the more appropriate `emitSilenceableFailure` with error message. Additionally a failure test has been added.
1 parent 36a6afd commit bbcfe6f

File tree

2 files changed

+41
-6
lines changed

2 files changed

+41
-6
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3269,22 +3269,24 @@ DiagnosedSilenceableFailure transform::FlattenElementwiseLinalgOp::applyToOne(
32693269
transform::ApplyToEachResultList &results,
32703270
transform::TransformState &state) {
32713271
rewriter.setInsertionPoint(target);
3272-
if (!isElementwise(target)) {
3273-
failed(rewriter.notifyMatchFailure(
3274-
target, "only elementwise flattening is supported"));
3275-
return emitDefaultSilenceableFailure(target);
3276-
}
3272+
if (!isElementwise(target))
3273+
return mlir::emitSilenceableFailure(target->getLoc())
3274+
<< "only elementwise flattening is supported";
3275+
32773276
// If rank <= 1, do nothing
32783277
if (target.getNumLoops() <= 1) {
32793278
results.push_back(target);
32803279
return DiagnosedSilenceableFailure::success();
32813280
}
3281+
3282+
// Attempt to flatten all dims to one.
32823283
ReassociationIndices reassociation(target.getNumLoops());
32833284
std::iota(reassociation.begin(), reassociation.end(), 0);
32843285
auto maybeFlattened =
32853286
collapseOpIterationDims(target, reassociation, rewriter);
32863287
if (failed(maybeFlattened))
3287-
return emitDefaultSilenceableFailure(target);
3288+
return mlir::emitSilenceableFailure(target->getLoc())
3289+
<< "attempted to flatten, but failed";
32883290
results.push_back(maybeFlattened->collapsedOp);
32893291
rewriter.replaceOp(target, maybeFlattened->results);
32903292
return DiagnosedSilenceableFailure::success();
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// RUN: mlir-opt %s -transform-interpreter -split-input-file -verify-diagnostics
2+
3+
func.func @non_elementwise(%arg0: memref<2x3xf32>, %arg1: memref<3x4xf32>, %arg2: memref<2x4xf32>) {
4+
// expected-error @below {{only elementwise flattening is supported}}
5+
linalg.matmul ins(%arg0, %arg1 : memref<2x3xf32>, memref<3x4xf32>) outs(%arg2: memref<2x4xf32>)
6+
return
7+
}
8+
9+
module attributes {transform.with_named_sequence} {
10+
transform.named_sequence @__transform_main(%arg1: !transform.any_op {transform.readonly}) {
11+
%0 = transform.structured.match interface{LinalgOp} in %arg1 : (!transform.any_op) -> !transform.any_op
12+
%flattened = transform.structured.flatten_elementwise %0
13+
: (!transform.any_op) -> !transform.any_op
14+
transform.yield
15+
}
16+
}
17+
18+
// -----
19+
20+
func.func @unsupported_memref(%arg0: memref<32x7xf32, strided<[7, 2]>>, %arg1: memref<32x7xf32, strided<[7, 2]>>, %arg2: memref<32x7xf32, strided<[7, 2]>>) {
21+
// expected-error @below {{attempted to flatten, but failed}}
22+
linalg.map {arith.addf} ins(%arg0, %arg1: memref<32x7xf32, strided<[7, 2]>>, memref<32x7xf32, strided<[7, 2]>>) outs(%arg2: memref<32x7xf32, strided<[7, 2]>>)
23+
return
24+
}
25+
26+
module attributes {transform.with_named_sequence} {
27+
transform.named_sequence @__transform_main(%arg1: !transform.any_op {transform.readonly}) {
28+
%0 = transform.structured.match interface{LinalgOp} in %arg1 : (!transform.any_op) -> !transform.any_op
29+
%flattened = transform.structured.flatten_elementwise %0
30+
: (!transform.any_op) -> !transform.any_op
31+
transform.yield
32+
}
33+
}

0 commit comments

Comments
 (0)