[Mlir-commits] [mlir] 702608f - [mlir] emit better errors in transform.structured.interchange (#67315)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon Sep 25 06:36:12 PDT 2023


Author: Oleksandr "Alex" Zinenko
Date: 2023-09-25T15:36:07+02:00
New Revision: 702608f4d8b7d30b029c7d77ab54bb0bd3368fc1

URL: https://github.com/llvm/llvm-project/commit/702608f4d8b7d30b029c7d77ab54bb0bd3368fc1
DIFF: https://github.com/llvm/llvm-project/commit/702608f4d8b7d30b029c7d77ab54bb0bd3368fc1.diff

LOG: [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.

Added: 
    

Modified: 
    mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
    mlir/test/Dialect/Linalg/transform-op-interchange.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp b/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
index 8bfd731fcc81213..66bbaed3797f3ba 100644
--- a/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
+++ b/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
@@ -1037,12 +1037,21 @@ transform::InterchangeOp::applyToOne(transform::TransformRewriter &rewriter,
     results.push_back(target);
     return DiagnosedSilenceableFailure::success();
   }
+
+  unsigned numLoops = cast<LinalgOp>(target.getOperation()).getNumLoops();
+  if (interchangeVector.size() != numLoops) {
+    return emitSilenceableError()
+           << getIteratorInterchangeAttrName() << " has length ("
+           << interchangeVector.size()
+           << ") 
diff erent from the number of loops in the target operation ("
+           << numLoops << ")";
+  }
   FailureOr<GenericOp> res =
       interchangeGenericOp(rewriter, target,
                            SmallVector<unsigned>(interchangeVector.begin(),
                                                  interchangeVector.end()));
   if (failed(res))
-    return DiagnosedSilenceableFailure::definiteFailure();
+    return emitDefiniteFailure() << "failed to apply";
   results.push_back(res->getOperation());
   return DiagnosedSilenceableFailure::success();
 }

diff  --git a/mlir/test/Dialect/Linalg/transform-op-interchange.mlir b/mlir/test/Dialect/Linalg/transform-op-interchange.mlir
index 7966b22a257ab5c..3efb76afdfea76e 100644
--- a/mlir/test/Dialect/Linalg/transform-op-interchange.mlir
+++ b/mlir/test/Dialect/Linalg/transform-op-interchange.mlir
@@ -38,3 +38,25 @@ transform.sequence failures(propagate) {
   // expected-error @below {{transform applied to the wrong op kind}}
   transform.structured.interchange %0 iterator_interchange = [1, 0] : (!transform.any_op) -> !transform.any_op
 }
+
+// -----
+
+func.func @too_many_iters(%0: tensor<?x?xf32>, %1: tensor<?x?xf32>) -> tensor<?x?xf32> {
+  %r = linalg.generic {
+    indexing_maps = [affine_map<(d0, d1) -> (d0, d1)>, affine_map<(d0, d1) -> (d0, d1)>],
+    iterator_types = ["parallel", "parallel"]
+  } ins(%0: tensor<?x?xf32>) outs(%1: tensor<?x?xf32>) {
+  ^bb0(%2: f32, %3: f32):
+    %4 = arith.mulf %2, %2 : f32
+    linalg.yield %4 : f32
+  } -> tensor<?x?xf32>
+  return %r : tensor<?x?xf32>
+}
+
+transform.sequence failures(propagate) {
+^bb0(%arg0: !transform.any_op):
+  %0 = transform.structured.match ops{["linalg.generic"]} in %arg0 : (!transform.any_op) -> !transform.any_op
+  // expected-error @below {{"iterator_interchange" has length (3) 
diff erent from the number of loops in the target operation (2)}}
+  transform.structured.interchange %0 iterator_interchange = [2,1,0] : (!transform.any_op) -> !transform.any_op
+  transform.yield
+}


        


More information about the Mlir-commits mailing list