[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.
This commit is contained in:
parent
36a6afdd2c
commit
bbcfe6f431
@ -3269,22 +3269,24 @@ DiagnosedSilenceableFailure transform::FlattenElementwiseLinalgOp::applyToOne(
|
|||||||
transform::ApplyToEachResultList &results,
|
transform::ApplyToEachResultList &results,
|
||||||
transform::TransformState &state) {
|
transform::TransformState &state) {
|
||||||
rewriter.setInsertionPoint(target);
|
rewriter.setInsertionPoint(target);
|
||||||
if (!isElementwise(target)) {
|
if (!isElementwise(target))
|
||||||
failed(rewriter.notifyMatchFailure(
|
return mlir::emitSilenceableFailure(target->getLoc())
|
||||||
target, "only elementwise flattening is supported"));
|
<< "only elementwise flattening is supported";
|
||||||
return emitDefaultSilenceableFailure(target);
|
|
||||||
}
|
|
||||||
// If rank <= 1, do nothing
|
// If rank <= 1, do nothing
|
||||||
if (target.getNumLoops() <= 1) {
|
if (target.getNumLoops() <= 1) {
|
||||||
results.push_back(target);
|
results.push_back(target);
|
||||||
return DiagnosedSilenceableFailure::success();
|
return DiagnosedSilenceableFailure::success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Attempt to flatten all dims to one.
|
||||||
ReassociationIndices reassociation(target.getNumLoops());
|
ReassociationIndices reassociation(target.getNumLoops());
|
||||||
std::iota(reassociation.begin(), reassociation.end(), 0);
|
std::iota(reassociation.begin(), reassociation.end(), 0);
|
||||||
auto maybeFlattened =
|
auto maybeFlattened =
|
||||||
collapseOpIterationDims(target, reassociation, rewriter);
|
collapseOpIterationDims(target, reassociation, rewriter);
|
||||||
if (failed(maybeFlattened))
|
if (failed(maybeFlattened))
|
||||||
return emitDefaultSilenceableFailure(target);
|
return mlir::emitSilenceableFailure(target->getLoc())
|
||||||
|
<< "attempted to flatten, but failed";
|
||||||
results.push_back(maybeFlattened->collapsedOp);
|
results.push_back(maybeFlattened->collapsedOp);
|
||||||
rewriter.replaceOp(target, maybeFlattened->results);
|
rewriter.replaceOp(target, maybeFlattened->results);
|
||||||
return DiagnosedSilenceableFailure::success();
|
return DiagnosedSilenceableFailure::success();
|
||||||
|
33
mlir/test/Dialect/Linalg/flatten-unsupported.mlir
Normal file
33
mlir/test/Dialect/Linalg/flatten-unsupported.mlir
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
// RUN: mlir-opt %s -transform-interpreter -split-input-file -verify-diagnostics
|
||||||
|
|
||||||
|
func.func @non_elementwise(%arg0: memref<2x3xf32>, %arg1: memref<3x4xf32>, %arg2: memref<2x4xf32>) {
|
||||||
|
// expected-error @below {{only elementwise flattening is supported}}
|
||||||
|
linalg.matmul ins(%arg0, %arg1 : memref<2x3xf32>, memref<3x4xf32>) outs(%arg2: memref<2x4xf32>)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
module attributes {transform.with_named_sequence} {
|
||||||
|
transform.named_sequence @__transform_main(%arg1: !transform.any_op {transform.readonly}) {
|
||||||
|
%0 = transform.structured.match interface{LinalgOp} in %arg1 : (!transform.any_op) -> !transform.any_op
|
||||||
|
%flattened = transform.structured.flatten_elementwise %0
|
||||||
|
: (!transform.any_op) -> !transform.any_op
|
||||||
|
transform.yield
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----
|
||||||
|
|
||||||
|
func.func @unsupported_memref(%arg0: memref<32x7xf32, strided<[7, 2]>>, %arg1: memref<32x7xf32, strided<[7, 2]>>, %arg2: memref<32x7xf32, strided<[7, 2]>>) {
|
||||||
|
// expected-error @below {{attempted to flatten, but failed}}
|
||||||
|
linalg.map {arith.addf} ins(%arg0, %arg1: memref<32x7xf32, strided<[7, 2]>>, memref<32x7xf32, strided<[7, 2]>>) outs(%arg2: memref<32x7xf32, strided<[7, 2]>>)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
module attributes {transform.with_named_sequence} {
|
||||||
|
transform.named_sequence @__transform_main(%arg1: !transform.any_op {transform.readonly}) {
|
||||||
|
%0 = transform.structured.match interface{LinalgOp} in %arg1 : (!transform.any_op) -> !transform.any_op
|
||||||
|
%flattened = transform.structured.flatten_elementwise %0
|
||||||
|
: (!transform.any_op) -> !transform.any_op
|
||||||
|
transform.yield
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user