diff --git a/mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td b/mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td --- a/mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td +++ b/mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td @@ -340,30 +340,6 @@ let hasCanonicalizer = 1; } -//===----------------------------------------------------------------------===// -// Operator: reluN -//===----------------------------------------------------------------------===// -def Tosa_ReluNOp : Tosa_Op<"reluN", [ - DeclareOpInterfaceMethods, - NoSideEffect]> { - let summary = "Computes rectified linear: `max(features, N)`."; - - let description = [{ - ReLU with a scalar maximum value. - }]; - - let arguments = (ins - Tosa_Tensor:$input, - I64Attr:$max_int, - F32Attr:$max_fp - ); - - let results = (outs - Tosa_Tensor:$output - ); -} - //===----------------------------------------------------------------------===// // Operator: sigmoid //===----------------------------------------------------------------------===// diff --git a/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp b/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp --- a/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp +++ b/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp @@ -406,25 +406,6 @@ arith::CmpIPredicate::slt, rewriter); } - // tosa::ReluNOp - if (isa(op) && elementTy.isa()) { - auto zero = - rewriter.create(loc, FloatAttr::get(elementTy, 0)); - auto n = rewriter.create(loc, elementTy, - op->getAttr("max_fp")); - return clampHelper(loc, args[0], zero, n, - arith::CmpFPredicate::OLT, rewriter); - } - - if (isa(op) && elementTy.isa()) { - auto zero = - rewriter.create(loc, IntegerAttr::get(elementTy, 0)); - auto n = createConstFromIntAttribute(op, "max_int", elementTy, - rewriter); - return clampHelper(loc, args[0], zero, n, - arith::CmpIPredicate::slt, rewriter); - } - // tosa::SigmoidOp if (isa(op) && elementTy.isa()) { auto one = @@ -2246,7 +2227,6 @@ PointwiseConverter, PointwiseConverter, PointwiseConverter, - PointwiseConverter, PointwiseConverter, IdentityNConverter, ReduceConverter, diff --git a/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp b/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp --- a/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp +++ b/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp @@ -1485,7 +1485,6 @@ NARY_SHAPE_INFER(tosa::NegateOp) NARY_SHAPE_INFER(tosa::PowOp) NARY_SHAPE_INFER(tosa::ReciprocalOp) -NARY_SHAPE_INFER(tosa::ReluNOp) NARY_SHAPE_INFER(tosa::RescaleOp) NARY_SHAPE_INFER(tosa::ReverseOp) NARY_SHAPE_INFER(tosa::RsqrtOp) diff --git a/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir b/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir --- a/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir +++ b/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir @@ -220,17 +220,12 @@ // CHECK: select %18 = "tosa.clamp"(%0) {min_int = 1 : i64, max_int = 5 : i64, min_fp = 1.0 : f32, max_fp = 5.0 : f32} : (tensor<1xf32>) -> tensor<1xf32> - // CHECK: linalg.generic - // CHECK: arith.cmpf - // CHECK: select - %19 = "tosa.reluN"(%0) {max_int = 5 : i64, max_fp = 5.0 : f32} : (tensor<1xf32>) -> tensor<1xf32> - // CHECK: linalg.generic // CHECK: arith.negf // CHECK: exp // CHECK: arith.addf // CHECK: arith.divf - %20 = "tosa.sigmoid"(%0) : (tensor<1xf32>) -> tensor<1xf32> + %19 = "tosa.sigmoid"(%0) : (tensor<1xf32>) -> tensor<1xf32> // CHECK: linalg.generic // CHECK: arith.constant 0.000000e+00 @@ -246,20 +241,20 @@ // CHECK: arith.cmpf olt // CHECK: select // CHECK: arith.fptosi - %21 = "tosa.cast"(%0) : (tensor<1xf32>) -> tensor<1xi32> + %20 = "tosa.cast"(%0) : (tensor<1xf32>) -> tensor<1xi32> // CHECK: linalg.generic // CHECK: arith.constant 0 // CHECK: arith.cmpf - %22 = "tosa.cast"(%0) : (tensor<1xf32>) -> tensor<1xi1> + %21 = "tosa.cast"(%0) : (tensor<1xf32>) -> tensor<1xi1> // CHECK: linalg.generic // CHECK: arith.truncf - %23 = "tosa.cast"(%0) : (tensor<1xf32>) -> tensor<1xf16> + %22 = "tosa.cast"(%0) : (tensor<1xf32>) -> tensor<1xf16> // CHECK: linalg.generic // CHECK: arith.divf - %24 = "tosa.reciprocal"(%0) : (tensor<1xf32>) -> tensor<1xf32> + %23 = "tosa.reciprocal"(%0) : (tensor<1xf32>) -> tensor<1xf32> return } @@ -396,11 +391,6 @@ // CHECK: select %19 = "tosa.clamp"(%0) {min_int = 1 : i64, max_int = 5 : i64, min_fp = 1.0 : f32, max_fp = 5.0 : f32} : (tensor<1xi32>) -> tensor<1xi32> - // CHECK: linalg.generic - // CHECK: arith.cmpi - // CHECK: select - %20 = "tosa.reluN"(%0) {max_int = 5 : i64, max_fp = 5.0 : f32} : (tensor<1xi32>) -> tensor<1xi32> - // CHECK: linalg.generic // CHECK: arith.constant -32768 // CHECK: arith.constant 32767 @@ -409,27 +399,27 @@ // CHECK: arith.cmpi slt // CHECK: select // CHECK: arith.trunci - %21 = "tosa.cast"(%0) : (tensor<1xi32>) -> tensor<1xi16> + %20 = "tosa.cast"(%0) : (tensor<1xi32>) -> tensor<1xi16> // CHECK: linalg.generic // CHECK: arith.extsi - %22 = "tosa.cast"(%0) : (tensor<1xi32>) -> tensor<1xi64> + %21 = "tosa.cast"(%0) : (tensor<1xi32>) -> tensor<1xi64> // CHECK: linalg.generic // CHECK: arith.constant 0 // CHECK: arith.cmpi - %23 = "tosa.cast"(%0) : (tensor<1xi32>) -> tensor<1xi1> + %22 = "tosa.cast"(%0) : (tensor<1xi32>) -> tensor<1xi1> // CHECK: linalg.generic // CHECK: arith.sitofp - %24 = "tosa.cast"(%0) : (tensor<1xi32>) -> tensor<1xf32> + %23 = "tosa.cast"(%0) : (tensor<1xi32>) -> tensor<1xf32> // CHECK: linalg.generic // CHECK: arith.constant 0 // CHECK: arith.cmpi sgt // CHECK: arith.subi // CHECK: select - %25 = "tosa.abs"(%arg0) : (tensor<1xi32>) -> tensor<1xi32> + %24 = "tosa.abs"(%arg0) : (tensor<1xi32>) -> tensor<1xi32> return } @@ -1236,7 +1226,7 @@ // CHECK-DAG: [[INDEX4:%.+]] = arith.constant 4 : index // CHECK-DAG: [[CST:%.+]] = arith.constant 0.000000e+00 : f32 // CHECK: tensor.pad %arg0 low{{\[}}%{{.*}}, [[INDEX3]]] high{{\[}}[[INDEX2]], [[INDEX4]]] { - // CHECK: ^bb0(%arg1: index, %arg2: index): + // CHECK: ^bb0(%arg1: index, %arg2: index): // CHECK: tensor.yield [[CST]] // CHECK: } : tensor<1x2xf32> to tensor<4x9xf32> %1 = "tosa.pad"(%arg0, %0) : (tensor<1x2xf32>, tensor<2x2xi32>) -> (tensor<4x9xf32>) @@ -1272,7 +1262,7 @@ // CHECK-DAG: [[INDEX4:%.+]] = arith.constant 4 : index // CHECK-DAG: [[CST:%.+]] = arith.constant 4.200000e+01 : f32 // CHECK: tensor.pad %arg0 low{{\[}}%{{.*}}, [[INDEX3]]] high{{\[}}[[INDEX2]], [[INDEX4]]] { - // CHECK: ^bb0(%arg1: index, %arg2: index): + // CHECK: ^bb0(%arg1: index, %arg2: index): // CHECK: tensor.yield [[CST]] // CHECK: } : tensor<1x2xf32> to tensor<4x9xf32> %1 = arith.constant dense<42.0> : tensor diff --git a/mlir/test/Dialect/Tosa/ops.mlir b/mlir/test/Dialect/Tosa/ops.mlir --- a/mlir/test/Dialect/Tosa/ops.mlir +++ b/mlir/test/Dialect/Tosa/ops.mlir @@ -86,14 +86,6 @@ return %0 : tensor<13x21x3xf32> } -// ----- -// CHECK-LABEL: relu -func.func @test_relu(%arg0: tensor<13x21x3xf32>) -> tensor<13x21x3xf32> { - %0 = "tosa.reluN"(%arg0) {max_fp = 3.40282347E+38 : f32, max_int = 0 : i64} : (tensor<13x21x3xf32>) -> tensor<13x21x3xf32> - return %0 : tensor<13x21x3xf32> -} - - // ----- // CHECK-LABEL: sigmoid func.func @test_sigmoid(%arg0: tensor<13x21x3xf32>) -> tensor<13x21x3xf32> { @@ -506,11 +498,11 @@ // CHECK-LABEL: cond_if func.func @test_cond_if(%arg0: tensor, %arg1: tensor, %arg2: tensor) -> tensor { %0 = "tosa.cond_if"(%arg2, %arg0, %arg1) ({ - ^bb0(%arg3: tensor, %arg4: tensor): + ^bb0(%arg3: tensor, %arg4: tensor): %1 = "tosa.add"(%arg3, %arg4) : (tensor, tensor) -> tensor "tosa.yield"(%1) : (tensor) -> () }, { - ^bb0(%arg3: tensor, %arg4: tensor): + ^bb0(%arg3: tensor, %arg4: tensor): %1 = "tosa.sub"(%arg3, %arg4) : (tensor, tensor) -> tensor "tosa.yield"(%1) : (tensor) -> () }) : (tensor, tensor, tensor) -> tensor @@ -522,12 +514,12 @@ func.func @test_while_loop(%arg0: tensor<10xi32>, %arg1: tensor) { %0 = "tosa.const"() {value = dense<0> : tensor} : () -> tensor %1:3 = "tosa.while_loop"(%0, %0, %arg0) ({ - ^bb0(%arg2: tensor, %arg3: tensor, %arg4: tensor<10xi32>): + ^bb0(%arg2: tensor, %arg3: tensor, %arg4: tensor<10xi32>): %2 = "tosa.greater_equal"(%arg3, %arg1) : (tensor, tensor) -> tensor %3 = "tosa.logical_not"(%2) : (tensor) -> tensor "tosa.yield"(%3) : (tensor) -> () }, { - ^bb0(%arg2: tensor, %arg3: tensor, %arg4: tensor<10xi32>): + ^bb0(%arg2: tensor, %arg3: tensor, %arg4: tensor<10xi32>): %2 = "tosa.const"() {value = dense<1> : tensor} : () -> tensor %3 = "tosa.add"(%arg3, %2) : (tensor, tensor) -> tensor %4 = "tosa.reshape"(%2) {new_shape = [1]} : (tensor) -> tensor<1xi32> diff --git a/mlir/test/Dialect/Tosa/tosa-infer-shapes.mlir b/mlir/test/Dialect/Tosa/tosa-infer-shapes.mlir --- a/mlir/test/Dialect/Tosa/tosa-infer-shapes.mlir +++ b/mlir/test/Dialect/Tosa/tosa-infer-shapes.mlir @@ -51,23 +51,20 @@ // CHECK: "tosa.reciprocal"(%arg0) : (tensor<4xf32>) -> tensor<4xf32> %7 = "tosa.reciprocal"(%arg0) : (tensor<4xf32>) -> tensor<*xf32> - // CHECK: "tosa.reluN"(%arg0) {{.+}} : (tensor<4xf32>) -> tensor<4xf32> - %8 = "tosa.reluN"(%arg0) { max_int = 10 : i64, min_int = 0 : i64, min_fp = 0.0 : f32, max_fp = 10.0 : f32 } : (tensor<4xf32>) -> tensor<*xf32> - // CHECK: "tosa.reverse"(%arg0) {axis = 0 : i64} : (tensor<4xf32>) -> tensor<4xf32> - %9 = "tosa.reverse"(%arg0) { axis = 0 : i64 } : (tensor<4xf32>) -> tensor + %8 = "tosa.reverse"(%arg0) { axis = 0 : i64 } : (tensor<4xf32>) -> tensor // CHECK: "tosa.rsqrt"(%arg0) : (tensor<4xf32>) -> tensor<4xf32> - %10 = "tosa.rsqrt"(%arg0) : (tensor<4xf32>) -> tensor<*xf32> + %9 = "tosa.rsqrt"(%arg0) : (tensor<4xf32>) -> tensor<*xf32> // CHECK: "tosa.tanh"(%arg0) : (tensor<4xf32>) -> tensor<4xf32> - %11 = "tosa.tanh"(%arg0) : (tensor<4xf32>) -> tensor<*xf32> + %10 = "tosa.tanh"(%arg0) : (tensor<4xf32>) -> tensor<*xf32> // CHECK: "tosa.sigmoid"(%arg0) : (tensor<4xf32>) -> tensor<4xf32> - %12 = "tosa.sigmoid"(%arg0) : (tensor<4xf32>) -> tensor<*xf32> + %11 = "tosa.sigmoid"(%arg0) : (tensor<4xf32>) -> tensor<*xf32> // CHECK: "tosa.cast"(%arg0) : (tensor<4xf32>) -> tensor<4xi32> - %13 = "tosa.cast"(%arg0) : (tensor<4xf32>) -> tensor<*xi32> + %12 = "tosa.cast"(%arg0) : (tensor<4xf32>) -> tensor<*xi32> return } @@ -90,17 +87,14 @@ // CHECK: "tosa.negate"(%arg0) : (tensor<4xi32>) -> tensor<4xi32> %4 = "tosa.negate"(%arg0) : (tensor<4xi32>) -> tensor<*xi32> - // CHECK: "tosa.reluN"(%arg0) {{.+}} : (tensor<4xi32>) -> tensor<4xi32> - %5 = "tosa.reluN"(%arg0) { max_int = 10 : i64, min_int = 0 : i64, min_fp = 0.0 : f32, max_fp = 10.0 : f32 } : (tensor<4xi32>) -> tensor<*xi32> - // CHECK: "tosa.reverse"(%arg0) {axis = 0 : i64} : (tensor<4xi32>) -> tensor<4xi32> - %6 = "tosa.reverse"(%arg0) { axis = 0 : i64 } : (tensor<4xi32>) -> tensor + %5 = "tosa.reverse"(%arg0) { axis = 0 : i64 } : (tensor<4xi32>) -> tensor // CHECK: "tosa.rescale"(%arg0) {{.+}} : (tensor<4xi32>) -> tensor<4xi16> - %7 = "tosa.rescale"(%arg0) {input_zp = 243 : i32, output_zp = 252 : i32, multiplier = [42 : i32, 43 : i32], shift = [14 : i32, 15 : i32], scale32 = false, double_round = false, per_channel = false} : (tensor<4xi32>) -> (tensor<*xi16>) + %6 = "tosa.rescale"(%arg0) {input_zp = 243 : i32, output_zp = 252 : i32, multiplier = [42 : i32, 43 : i32], shift = [14 : i32, 15 : i32], scale32 = false, double_round = false, per_channel = false} : (tensor<4xi32>) -> (tensor<*xi16>) // CHECK: "tosa.identity"(%arg0) : (tensor<4xi32>) -> tensor<4xi32> - %8 = "tosa.identity"(%arg0) : (tensor<4xi32>) -> tensor + %7 = "tosa.identity"(%arg0) : (tensor<4xi32>) -> tensor return } @@ -1125,7 +1119,7 @@ // CHECK-LABEL: @while_test func.func @while_test(%arg0 : tensor) -> (tensor<*xi32>) { - // CHECK: "tosa.add" + // CHECK: "tosa.add" // CHECK-SAME: (tensor, tensor) -> tensor %0 = "tosa.add"(%arg0, %arg0) : (tensor, tensor) -> tensor<*xi32>