Skip to content

Commit

Permalink
[mlir][tosa] Rename ReduceProd to ReduceProduct (#128751)
Browse files Browse the repository at this point in the history
This patch renames TOSA ReduceProd operator to ReduceProduct to align
with the TOSA Spec 1.0

Signed-off-by: Tai Ly <[email protected]>
  • Loading branch information
Tai78641 authored Feb 26, 2025
1 parent ca5bb23 commit 177ede2
Show file tree
Hide file tree
Showing 15 changed files with 40 additions and 40 deletions.
4 changes: 2 additions & 2 deletions mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -1740,8 +1740,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.
Expand Down
10 changes: 5 additions & 5 deletions mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1055,10 +1055,10 @@ static TypedAttr createInitialValueForReduceOp(Operation *op, Type elementTy,
if (isa<tosa::ReduceSumOp>(op) && isa<IntegerType>(elementTy))
return rewriter.getIntegerAttr(elementTy, 0);

if (isa<tosa::ReduceProdOp>(op) && isa<FloatType>(elementTy))
if (isa<tosa::ReduceProductOp>(op) && isa<FloatType>(elementTy))
return rewriter.getFloatAttr(elementTy, 1.0);

if (isa<tosa::ReduceProdOp>(op) && isa<IntegerType>(elementTy))
if (isa<tosa::ReduceProductOp>(op) && isa<IntegerType>(elementTy))
return rewriter.getIntegerAttr(elementTy, 1);

if (isa<tosa::ReduceMinOp>(op) && isa<FloatType>(elementTy))
Expand Down Expand Up @@ -1112,11 +1112,11 @@ static Value createLinalgBodyCalculationForReduceOp(Operation *op,
return rewriter.create<arith::AddIOp>(loc, args);
}

if (isa<tosa::ReduceProdOp>(op) && isa<FloatType>(elementTy)) {
if (isa<tosa::ReduceProductOp>(op) && isa<FloatType>(elementTy)) {
return rewriter.create<arith::MulFOp>(loc, args);
}

if (isa<tosa::ReduceProdOp>(op) && isa<IntegerType>(elementTy)) {
if (isa<tosa::ReduceProductOp>(op) && isa<IntegerType>(elementTy)) {
return rewriter.create<arith::MulIOp>(loc, args);
}

Expand Down Expand Up @@ -2874,7 +2874,7 @@ void mlir::tosa::populateTosaToLinalgConversionPatterns(
ReduceConverter<tosa::ReduceMinOp>,
ReduceConverter<tosa::ReduceMaxOp>,
ReduceConverter<tosa::ReduceSumOp>,
ReduceConverter<tosa::ReduceProdOp>,
ReduceConverter<tosa::ReduceProductOp>,
ArgMaxConverter,
GatherConverter,
RescaleConverter,
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1832,7 +1832,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)
Expand Down Expand Up @@ -1892,7 +1892,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(
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/Dialect/Tosa/Transforms/TosaFolders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ void mlir::tosa::populateTosaConstantReduction(MLIRContext *ctx,
ctx, aggressiveReduceConstant);
patterns.add<ReduceConstantOptimization<ReduceMinOp>>(
ctx, aggressiveReduceConstant);
patterns.add<ReduceConstantOptimization<ReduceProdOp>>(
patterns.add<ReduceConstantOptimization<ReduceProductOp>>(
ctx, aggressiveReduceConstant);
patterns.add<ReduceConstantOptimization<ReduceSumOp>>(
ctx, aggressiveReduceConstant);
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/Dialect/Tosa/Transforms/TosaProfileCompliance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/Dialect/Tosa/Transforms/TosaValidation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ struct TosaValidation : public tosa::impl::TosaValidationBase<TosaValidation> {
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);
Expand Down
6 changes: 3 additions & 3 deletions mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mlir/test/Dialect/Tosa/availability.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,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>
}

Expand Down
14 changes: 7 additions & 7 deletions mlir/test/Dialect/Tosa/canonicalize.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -501,19 +501,19 @@ func.func @reduce_min_nofold(%arg0: tensor<?x1xf32>) -> tensor<?x1xf32> {

// -----

// CHECK-LABEL: @reduce_prod_fold
func.func @reduce_prod_fold(%arg0: tensor<?x1xf32>) -> tensor<?x1xf32> {
// CHECK-LABEL: @reduce_product_fold
func.func @reduce_product_fold(%arg0: tensor<?x1xf32>) -> tensor<?x1xf32> {
// CHECK: return %arg0
%0 = tosa.reduce_prod %arg0 {axis = 1 : i32}: (tensor<?x1xf32>) -> tensor<?x1xf32>
%0 = tosa.reduce_product %arg0 {axis = 1 : i32}: (tensor<?x1xf32>) -> tensor<?x1xf32>
return %0 : tensor<?x1xf32>
}

// -----

// CHECK-LABEL: @reduce_prod_nofold
func.func @reduce_prod_nofold(%arg0: tensor<?x1xf32>) -> tensor<?x1xf32> {
// CHECK: tosa.reduce_prod
%0 = tosa.reduce_prod %arg0 {axis = 0 : i32}: (tensor<?x1xf32>) -> tensor<?x1xf32>
// CHECK-LABEL: @reduce_product_nofold
func.func @reduce_product_nofold(%arg0: tensor<?x1xf32>) -> tensor<?x1xf32> {
// CHECK: tosa.reduce_product
%0 = tosa.reduce_product %arg0 {axis = 0 : i32}: (tensor<?x1xf32>) -> tensor<?x1xf32>
return %0 : tensor<?x1xf32>
}

Expand Down
14 changes: 7 additions & 7 deletions mlir/test/Dialect/Tosa/constant-op-fold.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -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>
}

Expand All @@ -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>
}

Expand All @@ -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>
}

Expand All @@ -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>
}

Expand All @@ -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>
}

Expand All @@ -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>
}

Expand All @@ -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>
}

Expand Down
8 changes: 4 additions & 4 deletions mlir/test/Dialect/Tosa/invalid.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,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
}

Expand Down Expand Up @@ -405,8 +405,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
}

Expand Down
4 changes: 2 additions & 2 deletions mlir/test/Dialect/Tosa/level_check.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -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>
}

Expand Down
2 changes: 1 addition & 1 deletion mlir/test/Dialect/Tosa/ops.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,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>
Expand Down
4 changes: 2 additions & 2 deletions mlir/test/Dialect/Tosa/tosa-infer-shapes.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -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<?x?x?x?xf32>

// 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<?x?x?x?xf32>
// 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<?x?x?x?xf32>

return
}
Expand Down

0 comments on commit 177ede2

Please sign in to comment.