diff --git a/mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td b/mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td index a7373d8b710f1..50fb6d4687ca1 100644 --- a/mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td +++ b/mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td @@ -1708,8 +1708,8 @@ def Tosa_ReduceMinOp : Tosa_InferTensorTypeOp<"reduce_min"> { //===----------------------------------------------------------------------===// // Operator: reduce_prod //===----------------------------------------------------------------------===// -def Tosa_ReduceProdOp : Tosa_InferTensorTypeOp<"reduce_prod"> { - let summary = "Reduce Prod operator"; +def Tosa_ReduceProductOp : Tosa_InferTensorTypeOp<"reduce_product"> { + let summary = "Reduce Product operator"; let description = [{ Reduce a tensor along the given axis by computing the product of the axis. diff --git a/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp b/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp index 607667fcc6945..b8699fb3da53d 100644 --- a/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp +++ b/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp @@ -1050,10 +1050,10 @@ static TypedAttr createInitialValueForReduceOp(Operation *op, Type elementTy, if (isa(op) && isa(elementTy)) return rewriter.getIntegerAttr(elementTy, 0); - if (isa(op) && isa(elementTy)) + if (isa(op) && isa(elementTy)) return rewriter.getFloatAttr(elementTy, 1.0); - if (isa(op) && isa(elementTy)) + if (isa(op) && isa(elementTy)) return rewriter.getIntegerAttr(elementTy, 1); if (isa(op) && isa(elementTy)) @@ -1107,11 +1107,11 @@ static Value createLinalgBodyCalculationForReduceOp(Operation *op, return rewriter.create(loc, args); } - if (isa(op) && isa(elementTy)) { + if (isa(op) && isa(elementTy)) { return rewriter.create(loc, args); } - if (isa(op) && isa(elementTy)) { + if (isa(op) && isa(elementTy)) { return rewriter.create(loc, args); } @@ -2869,7 +2869,7 @@ void mlir::tosa::populateTosaToLinalgConversionPatterns( ReduceConverter, ReduceConverter, ReduceConverter, - ReduceConverter, + ReduceConverter, ArgMaxConverter, GatherConverter, RescaleConverter, diff --git a/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp b/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp index 4da1a7b6252e1..dcba9ef67a008 100644 --- a/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp +++ b/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp @@ -949,7 +949,7 @@ REDUCE_FOLDER(ReduceAllOp) REDUCE_FOLDER(ReduceAnyOp) REDUCE_FOLDER(ReduceMaxOp) REDUCE_FOLDER(ReduceMinOp) -REDUCE_FOLDER(ReduceProdOp) +REDUCE_FOLDER(ReduceProductOp) REDUCE_FOLDER(ReduceSumOp) #undef REDUCE_FOLDER diff --git a/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp b/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp index 20346b4d1fe4b..86ea6788933d4 100644 --- a/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp +++ b/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp @@ -1745,7 +1745,7 @@ REDUCE_SHAPE_INFER(tosa::ReduceAllOp) REDUCE_SHAPE_INFER(tosa::ReduceAnyOp) REDUCE_SHAPE_INFER(tosa::ReduceMaxOp) REDUCE_SHAPE_INFER(tosa::ReduceMinOp) -REDUCE_SHAPE_INFER(tosa::ReduceProdOp) +REDUCE_SHAPE_INFER(tosa::ReduceProductOp) REDUCE_SHAPE_INFER(tosa::ReduceSumOp) #undef REDUCE_SHAPE_INFER COMPATIBLE_RETURN_TYPES(tosa::ConcatOp) @@ -1805,7 +1805,7 @@ LogicalResult tosa::ReduceAllOp::verify() { return verifyReduceOp(*this); } LogicalResult tosa::ReduceAnyOp::verify() { return verifyReduceOp(*this); } LogicalResult tosa::ReduceMaxOp::verify() { return verifyReduceOp(*this); } LogicalResult tosa::ReduceMinOp::verify() { return verifyReduceOp(*this); } -LogicalResult tosa::ReduceProdOp::verify() { return verifyReduceOp(*this); } +LogicalResult tosa::ReduceProductOp::verify() { return verifyReduceOp(*this); } LogicalResult tosa::ReduceSumOp::verify() { return verifyReduceOp(*this); } static LogicalResult NAryInferReturnTypes( diff --git a/mlir/lib/Dialect/Tosa/Transforms/TosaFolders.cpp b/mlir/lib/Dialect/Tosa/Transforms/TosaFolders.cpp index 43e9507b4d95a..1f5a906153cd9 100644 --- a/mlir/lib/Dialect/Tosa/Transforms/TosaFolders.cpp +++ b/mlir/lib/Dialect/Tosa/Transforms/TosaFolders.cpp @@ -408,7 +408,7 @@ void mlir::tosa::populateTosaConstantReduction(MLIRContext *ctx, ctx, aggressiveReduceConstant); patterns.add>( ctx, aggressiveReduceConstant); - patterns.add>( + patterns.add>( ctx, aggressiveReduceConstant); patterns.add>( ctx, aggressiveReduceConstant); diff --git a/mlir/lib/Dialect/Tosa/Transforms/TosaProfileCompliance.cpp b/mlir/lib/Dialect/Tosa/Transforms/TosaProfileCompliance.cpp index 98d7c1dabd100..1d8aaa65c2976 100644 --- a/mlir/lib/Dialect/Tosa/Transforms/TosaProfileCompliance.cpp +++ b/mlir/lib/Dialect/Tosa/Transforms/TosaProfileCompliance.cpp @@ -272,7 +272,7 @@ LogicalResult ProfileInfoDepot::populatationDispatch(Operation *op) { POPULATE_PROFILE_INFO_COMMON(ReduceAny) POPULATE_PROFILE_INFO_COMMON(ReduceMax) POPULATE_PROFILE_INFO_COMMON(ReduceMin) - POPULATE_PROFILE_INFO_COMMON(ReduceProd) + POPULATE_PROFILE_INFO_COMMON(ReduceProduct) POPULATE_PROFILE_INFO_COMMON(ReduceSum) POPULATE_PROFILE_INFO_COMMON(Equal) POPULATE_PROFILE_INFO_COMMON(GreaterEqual) diff --git a/mlir/lib/Dialect/Tosa/Transforms/TosaValidation.cpp b/mlir/lib/Dialect/Tosa/Transforms/TosaValidation.cpp index 708b3fc30c085..436890443ca9a 100644 --- a/mlir/lib/Dialect/Tosa/Transforms/TosaValidation.cpp +++ b/mlir/lib/Dialect/Tosa/Transforms/TosaValidation.cpp @@ -220,7 +220,7 @@ struct TosaValidation : public tosa::impl::TosaValidationBase { CHECK_RANKS_FOR(ReduceAny); CHECK_RANKS_FOR(ReduceMax); CHECK_RANKS_FOR(ReduceMin); - CHECK_RANKS_FOR(ReduceProd); + CHECK_RANKS_FOR(ReduceProduct); CHECK_RANKS_FOR(ReduceSum); // all data layout operators: CHECK_RANKS_FOR(Concat); diff --git a/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir b/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir index 86e6f9ed9264b..78f2e173d7cb1 100644 --- a/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir +++ b/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir @@ -951,7 +951,7 @@ func.func @reduce_float(%arg0: tensor<5x4xf32>) -> () { // CHECK: linalg.fill // CHECK: linalg.reduce // CHECK: arith.mulf - %2 = tosa.reduce_prod %arg0 {axis = 0 : i32} : (tensor<5x4xf32>) -> tensor<1x4xf32> + %2 = tosa.reduce_product %arg0 {axis = 0 : i32} : (tensor<5x4xf32>) -> tensor<1x4xf32> // CHECK: arith.constant 3.40282347E+38 : f32 // CHECK: linalg.fill @@ -1027,7 +1027,7 @@ func.func @reduce_float_dyn_nonzero_batch(%arg0: tensor<5x?x4xf32>) -> () { // CHECK: %[[DIM_1:.+]] = tensor.dim %[[REDUCE]], %[[C1_0]] : tensor<5x?xf32> // CHECK: %[[C1_2:.+]] = arith.constant 1 : index // CHECK: tensor.expand_shape %[[REDUCE]] {{\[}}[0], [1, 2]] output_shape [5, %[[DIM_1]], 1] : tensor<5x?xf32> into tensor<5x?x1xf32> - %0 = tosa.reduce_prod %arg0 {axis = 2 : i32} : (tensor<5x?x4xf32>) -> tensor<5x?x1xf32> + %0 = tosa.reduce_product %arg0 {axis = 2 : i32} : (tensor<5x?x4xf32>) -> tensor<5x?x1xf32> return } @@ -1085,7 +1085,7 @@ func.func @reduce_int(%arg0: tensor<5x4xi32>) -> () { // CHECK: linalg.fill // CHECK: linalg.reduce // CHECK: arith.muli - %2 = tosa.reduce_prod %arg0 {axis = 0 : i32} : (tensor<5x4xi32>) -> tensor<1x4xi32> + %2 = tosa.reduce_product %arg0 {axis = 0 : i32} : (tensor<5x4xi32>) -> tensor<1x4xi32> // CHECK: arith.constant 2147483647 : i32 // CHECK: linalg.fill diff --git a/mlir/test/Dialect/Tosa/availability.mlir b/mlir/test/Dialect/Tosa/availability.mlir index d9d1140bffc0f..968039cbf4661 100644 --- a/mlir/test/Dialect/Tosa/availability.mlir +++ b/mlir/test/Dialect/Tosa/availability.mlir @@ -478,7 +478,7 @@ func.func @test_reduce_min(%arg0: tensor<13x21x3xf32>) -> tensor<1x21x3xf32> { func.func @test_reduce_product(%arg0: tensor<13x21x3xf32>) -> tensor<1x21x3xf32> { // CHECK: profiles: [ [pro_fp] ] // CHECK: extensions: [ [bf16] ] - %0 = tosa.reduce_prod %arg0 {axis = 0 : i32} : (tensor<13x21x3xf32>) -> tensor<1x21x3xf32> + %0 = tosa.reduce_product %arg0 {axis = 0 : i32} : (tensor<13x21x3xf32>) -> tensor<1x21x3xf32> return %0 : tensor<1x21x3xf32> } diff --git a/mlir/test/Dialect/Tosa/canonicalize.mlir b/mlir/test/Dialect/Tosa/canonicalize.mlir index ef1185e11b459..5fcfd1a6cb066 100644 --- a/mlir/test/Dialect/Tosa/canonicalize.mlir +++ b/mlir/test/Dialect/Tosa/canonicalize.mlir @@ -497,19 +497,19 @@ func.func @reduce_min_nofold(%arg0: tensor) -> tensor { // ----- -// CHECK-LABEL: @reduce_prod_fold -func.func @reduce_prod_fold(%arg0: tensor) -> tensor { +// CHECK-LABEL: @reduce_product_fold +func.func @reduce_product_fold(%arg0: tensor) -> tensor { // CHECK: return %arg0 - %0 = tosa.reduce_prod %arg0 {axis = 1 : i32}: (tensor) -> tensor + %0 = tosa.reduce_product %arg0 {axis = 1 : i32}: (tensor) -> tensor return %0 : tensor } // ----- -// CHECK-LABEL: @reduce_prod_nofold -func.func @reduce_prod_nofold(%arg0: tensor) -> tensor { - // CHECK: tosa.reduce_prod - %0 = tosa.reduce_prod %arg0 {axis = 0 : i32}: (tensor) -> tensor +// CHECK-LABEL: @reduce_product_nofold +func.func @reduce_product_nofold(%arg0: tensor) -> tensor { + // CHECK: tosa.reduce_product + %0 = tosa.reduce_product %arg0 {axis = 0 : i32}: (tensor) -> tensor return %0 : tensor } diff --git a/mlir/test/Dialect/Tosa/constant-op-fold.mlir b/mlir/test/Dialect/Tosa/constant-op-fold.mlir index 190aa777d3470..db76eb54a54cf 100644 --- a/mlir/test/Dialect/Tosa/constant-op-fold.mlir +++ b/mlir/test/Dialect/Tosa/constant-op-fold.mlir @@ -721,7 +721,7 @@ func.func @reduce_sum_constant() -> tensor<2x3x1x5xi32> { // CHECK: return %[[VAL_0]] : tensor<1x3xi32> %const = "tosa.const"() <{value = dense<[[1,2,3], [4,5,6]]> : tensor<2x3xi32>}> : () -> tensor<2x3xi32> - %0 = tosa.reduce_prod %const {axis = 0 : i32} : (tensor<2x3xi32>) -> tensor<1x3xi32> + %0 = tosa.reduce_product %const {axis = 0 : i32} : (tensor<2x3xi32>) -> tensor<1x3xi32> return %0 : tensor<1x3xi32> } @@ -734,7 +734,7 @@ func.func @reduce_sum_constant() -> tensor<2x3x1x5xi32> { // CHECK: } %const = "tosa.const"() <{value = dense<[[1,2,3], [4,5,6]]> : tensor<2x3xi32>}> : () -> tensor<2x3xi32> - %0 = tosa.reduce_prod %const {axis = 1 : i32} : (tensor<2x3xi32>) -> tensor<2x1xi32> + %0 = tosa.reduce_product %const {axis = 1 : i32} : (tensor<2x3xi32>) -> tensor<2x1xi32> return %0 : tensor<2x1xi32> } @@ -746,7 +746,7 @@ func.func @reduce_prod_constant() -> tensor<3x1xi32> { // CHECK: return %[[VAL_0]] : tensor<3x1xi32> // CHECK: } %const = "tosa.const"() <{value = dense<[[1, 2, 3], [4, 5, 6], [7, 8, 9]]> : tensor<3x3xi32>}> : () -> tensor<3x3xi32> - %0 = tosa.reduce_prod %const {axis = 1 : i32} : (tensor<3x3xi32>) -> tensor<3x1xi32> + %0 = tosa.reduce_product %const {axis = 1 : i32} : (tensor<3x3xi32>) -> tensor<3x1xi32> return %0 : tensor<3x1xi32> } @@ -758,7 +758,7 @@ func.func @reduce_prod_constant() -> tensor<2x1x4xi32> { // CHECK: return %[[VAL_0]] : tensor<2x1x4xi32> // CHECK: } %const = "tosa.const"() <{value = dense<[[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]], [[13, 14, 15, 16], [17, 18, 19, 20], [21, 22, 23, 24]]]> : tensor<2x3x4xi32>}> : () -> tensor<2x3x4xi32> - %0 = tosa.reduce_prod %const {axis = 1 : i32} : (tensor<2x3x4xi32>) -> tensor<2x1x4xi32> + %0 = tosa.reduce_product %const {axis = 1 : i32} : (tensor<2x3x4xi32>) -> tensor<2x1x4xi32> return %0 : tensor<2x1x4xi32> } @@ -770,7 +770,7 @@ func.func @reduce_prod_constant() -> tensor<1x3x3xi32> { // CHECK: return %[[VAL_0]] : tensor<1x3x3xi32> // CHECK: } %const = "tosa.const"() <{value = dense<[[[1, 2, 3], [4, 5, 6], [7, 8, 9]], [[10, 11, 12], [13, 14, 15], [16, 17, 18]], [[19, 20, 21], [22, 23, 24], [25, 26, 27]]]> : tensor<3x3x3xi32>}> : () -> tensor<3x3x3xi32> - %0 = tosa.reduce_prod %const {axis = 0 : i32} : (tensor<3x3x3xi32>) -> tensor<1x3x3xi32> + %0 = tosa.reduce_product %const {axis = 0 : i32} : (tensor<3x3x3xi32>) -> tensor<1x3x3xi32> return %0 : tensor<1x3x3xi32> } @@ -782,7 +782,7 @@ func.func @reduce_prod_constant() -> tensor<2x2x2x1xi32> { // CHECK: return %[[VAL_0]] : tensor<2x2x2x1xi32> // CHECK: } %const = "tosa.const"() <{value = dense<[[[[1, 2], [3, 4]], [[5, 6], [7, 8]]], [[[9, 10], [11, 12]], [[13, 14], [15, 16]]]]> : tensor<2x2x2x2xi32>}> : () -> tensor<2x2x2x2xi32> - %0 = tosa.reduce_prod %const {axis = 3 : i32} : (tensor<2x2x2x2xi32>) -> tensor<2x2x2x1xi32> + %0 = tosa.reduce_product %const {axis = 3 : i32} : (tensor<2x2x2x2xi32>) -> tensor<2x2x2x1xi32> return %0 : tensor<2x2x2x1xi32> } @@ -794,7 +794,7 @@ func.func @reduce_prod_constant() -> tensor<1x1x1xi32> { // CHECK: return %[[VAL_0]] : tensor<1x1x1xi32> // CHECK: } %const = "tosa.const"() <{value = dense<[[[42]]]> : tensor<1x1x1xi32>}> : () -> tensor<1x1x1xi32> - %0 = tosa.reduce_prod %const {axis = 0 : i32} : (tensor<1x1x1xi32>) -> tensor<1x1x1xi32> + %0 = tosa.reduce_product %const {axis = 0 : i32} : (tensor<1x1x1xi32>) -> tensor<1x1x1xi32> return %0 : tensor<1x1x1xi32> } diff --git a/mlir/test/Dialect/Tosa/invalid.mlir b/mlir/test/Dialect/Tosa/invalid.mlir index 9123f84ab25b8..850c096a59369 100644 --- a/mlir/test/Dialect/Tosa/invalid.mlir +++ b/mlir/test/Dialect/Tosa/invalid.mlir @@ -336,8 +336,8 @@ func.func @test_reduce_min_type_mismatch(%arg0 : tensor<2x3x4x5xf32>) -> () { // ----- func.func @test_reduce_prod_type_mismatch(%arg0 : tensor<2x3x4x5xf32>) -> () { - // expected-error@+1 {{'tosa.reduce_prod' op expect reduced dimension size to be 1, got 3}} - %0 = tosa.reduce_prod %arg0 {axis = 1 : i32} : (tensor<2x3x4x5xf32>) -> tensor<2x3x4x5xf32> + // expected-error@+1 {{'tosa.reduce_product' op expect reduced dimension size to be 1, got 3}} + %0 = tosa.reduce_product %arg0 {axis = 1 : i32} : (tensor<2x3x4x5xf32>) -> tensor<2x3x4x5xf32> return } @@ -376,8 +376,8 @@ func.func @test_reduce_min_invalid_axis(%arg0 : tensor<2x3x4xf32>) -> () { // ----- func.func @test_reduce_prod_invalid_axis(%arg0 : tensor<2x3x4xf32>) -> () { - // expected-error@+1 {{'tosa.reduce_prod' op expect input tensor rank (3) to be larger than reduce axis (3)}} - %0 = tosa.reduce_prod %arg0 {axis = 3 : i32} : (tensor<2x3x4xf32>) -> tensor<2x3x1xf32> + // expected-error@+1 {{'tosa.reduce_product' op expect input tensor rank (3) to be larger than reduce axis (3)}} + %0 = tosa.reduce_product %arg0 {axis = 3 : i32} : (tensor<2x3x4xf32>) -> tensor<2x3x1xf32> return } diff --git a/mlir/test/Dialect/Tosa/level_check.mlir b/mlir/test/Dialect/Tosa/level_check.mlir index 2a6561fea67b5..a1df98d3775e0 100644 --- a/mlir/test/Dialect/Tosa/level_check.mlir +++ b/mlir/test/Dialect/Tosa/level_check.mlir @@ -45,8 +45,8 @@ func.func @test_reduce_min(%arg0: tensor<1x1x1x1x13x21x3xf32>) -> tensor<1x1x1x1 // ----- func.func @test_reduce_prod(%arg0: tensor<1x1x1x1x13x21x3xf32>) -> tensor<1x1x1x1x13x21x3xf32> { - // expected-error@+1 {{'tosa.reduce_prod' op failed level check: operand rank(shape) <= MAX_RANK}} - %0 = "tosa.reduce_prod"(%arg0) {axis = 0 : i32} : (tensor<1x1x1x1x13x21x3xf32>) -> tensor<1x1x1x1x13x21x3xf32> + // expected-error@+1 {{'tosa.reduce_product' op failed level check: operand rank(shape) <= MAX_RANK}} + %0 = "tosa.reduce_product"(%arg0) {axis = 0 : i32} : (tensor<1x1x1x1x13x21x3xf32>) -> tensor<1x1x1x1x13x21x3xf32> return %0 : tensor<1x1x1x1x13x21x3xf32> } diff --git a/mlir/test/Dialect/Tosa/ops.mlir b/mlir/test/Dialect/Tosa/ops.mlir index fe3d2b0a96c6c..a96aa1e383ce5 100644 --- a/mlir/test/Dialect/Tosa/ops.mlir +++ b/mlir/test/Dialect/Tosa/ops.mlir @@ -557,7 +557,7 @@ func.func @test_reduce_min(%arg0: tensor<13x21x3xf32>) -> tensor<21x3xf32> { // ----- // CHECK-LABEL: reduce_product func.func @test_reduce_product(%arg0: tensor<13x21x3xf32>) -> tensor<21x3xf32> { - %0 = tosa.reduce_prod %arg0 {axis = 0 : i32} : (tensor<13x21x3xf32>) -> tensor<1x21x3xf32> + %0 = tosa.reduce_product %arg0 {axis = 0 : i32} : (tensor<13x21x3xf32>) -> tensor<1x21x3xf32> %2 = tosa.const_shape {value = dense<[21, 3]> : tensor<2xindex>} : () -> !tosa.shape<2> %1 = tosa.reshape %0, %2 : (tensor<1x21x3xf32>, !tosa.shape<2>) -> tensor<21x3xf32> return %1 : tensor<21x3xf32> diff --git a/mlir/test/Dialect/Tosa/tosa-infer-shapes.mlir b/mlir/test/Dialect/Tosa/tosa-infer-shapes.mlir index 1821b78091aad..fd464fbe26714 100644 --- a/mlir/test/Dialect/Tosa/tosa-infer-shapes.mlir +++ b/mlir/test/Dialect/Tosa/tosa-infer-shapes.mlir @@ -417,8 +417,8 @@ func.func @test_reduce_float(%arg0 : tensor<2x3x?x?xf32>) -> () { // CHECK: tosa.reduce_min %arg0 {axis = 3 : i32} : (tensor<2x3x?x?xf32>) -> tensor<2x3x?x1xf32> %5 = tosa.reduce_min %arg0 {axis = 3 : i32} : (tensor<2x3x?x?xf32>) -> tensor - // CHECK: tosa.reduce_prod %arg0 {axis = 3 : i32} : (tensor<2x3x?x?xf32>) -> tensor<2x3x?x1xf32> - %6 = tosa.reduce_prod %arg0 {axis = 3 : i32} : (tensor<2x3x?x?xf32>) -> tensor + // CHECK: tosa.reduce_product %arg0 {axis = 3 : i32} : (tensor<2x3x?x?xf32>) -> tensor<2x3x?x1xf32> + %6 = tosa.reduce_product %arg0 {axis = 3 : i32} : (tensor<2x3x?x?xf32>) -> tensor return }