[Mlir-commits] [mlir] 2ae27dc - [mlir][Linalg] Use ConfinedAttr for dimensions of ReduceOp.

Adrian Kuegel llvmlistbot at llvm.org
Mon Oct 10 00:38:22 PDT 2022


Author: Adrian Kuegel
Date: 2022-10-10T09:37:59+02:00
New Revision: 2ae27dc9489ffffec58d116d9ea389830000c1fa

URL: https://github.com/llvm/llvm-project/commit/2ae27dc9489ffffec58d116d9ea389830000c1fa
DIFF: https://github.com/llvm/llvm-project/commit/2ae27dc9489ffffec58d116d9ea389830000c1fa.diff

LOG: [mlir][Linalg] Use ConfinedAttr for dimensions of ReduceOp.

We can use the new DenseArrayStrictlySorted constraint.

Differential Revision: https://reviews.llvm.org/D135246

Added: 
    

Modified: 
    mlir/include/mlir/Dialect/Linalg/IR/LinalgStructuredOps.td
    mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
    mlir/test/Dialect/Linalg/invalid.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Dialect/Linalg/IR/LinalgStructuredOps.td b/mlir/include/mlir/Dialect/Linalg/IR/LinalgStructuredOps.td
index 1691291971666..c37d97834e838 100644
--- a/mlir/include/mlir/Dialect/Linalg/IR/LinalgStructuredOps.td
+++ b/mlir/include/mlir/Dialect/Linalg/IR/LinalgStructuredOps.td
@@ -261,7 +261,8 @@ def ReduceOp : LinalgStructuredBase_Op<"reduce", [
     // Output arg
     Variadic<TensorOrMemref>:$inits,
 
-    DenseI64ArrayAttr:$dimensions
+    ConfinedAttr<DenseI64ArrayAttr,
+                 [DenseArrayStrictlySorted<DenseI64ArrayAttr>]>:$dimensions
   );
   let results = (outs Variadic<TensorOrMemref>);
   let regions = (region SizedRegion<1>:$combiner);

diff  --git a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
index ba60572986c43..47619ebf0b415 100644
--- a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
+++ b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
@@ -1340,20 +1340,12 @@ LogicalResult ReduceOp::verify() {
   auto initType = getInits()[0].getType().cast<ShapedType>();
 
   DenseSet<int64_t> dimensionsToReduce;
-  int64_t lastDimension = -1;
   for (int64_t dimension : dimensionsRef) {
     if (dimension < 0 || dimension >= inputType.getRank()) {
       return emitOpError()
              << "dimensions for reduction should be in the range [0, "
              << inputType.getRank() - 1 << "].";
     }
-    if (dimension <= lastDimension) {
-      return emitOpError()
-             << "reduction dimensions are not in increasing order: "
-             << dimensionsRef;
-    }
-
-    lastDimension = dimension;
     dimensionsToReduce.insert(dimension);
   }
 

diff  --git a/mlir/test/Dialect/Linalg/invalid.mlir b/mlir/test/Dialect/Linalg/invalid.mlir
index 16c772975075a..9ae761e639e41 100644
--- a/mlir/test/Dialect/Linalg/invalid.mlir
+++ b/mlir/test/Dialect/Linalg/invalid.mlir
@@ -426,7 +426,7 @@ func.func @reduce_dimensions_out_of_range(%input: tensor<16x32x64xf32>,
 
 func.func @reduce_duplicate_dimensions(%input: tensor<16x32x64xf32>,
     %init: tensor<16xf32>)  -> tensor<16xf32> {
-  // expected-error @+1 {{'linalg.reduce' op reduction dimensions are not in increasing order: 1, 1}}
+  // expected-error @+1 {{'linalg.reduce' op attribute 'dimensions' failed to satisfy constraint: i64 dense array attribute should be in increasing order}}
   %reduce = linalg.reduce
       ins(%input:tensor<16x32x64xf32>)
       outs(%init:tensor<16xf32>)
@@ -442,7 +442,7 @@ func.func @reduce_duplicate_dimensions(%input: tensor<16x32x64xf32>,
 
 func.func @reduce_non_increasing_dimensions(%input: tensor<16x32x64xf32>,
     %init: tensor<16xf32>)  -> tensor<16xf32> {
-  // expected-error @+1 {{'linalg.reduce' op reduction dimensions are not in increasing order: 2, 1}}
+  // expected-error @+1 {{'linalg.reduce' op attribute 'dimensions' failed to satisfy constraint: i64 dense array attribute should be in increasing order}}
   %reduce = linalg.reduce
       ins(%input:tensor<16x32x64xf32>)
       outs(%init:tensor<16xf32>)


        


More information about the Mlir-commits mailing list