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 @@ -339,30 +339,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,27 +406,6 @@ return clampIntHelper(loc, args[0], minVal, maxVal, rewriter); } - // tosa::ReluNOp - if (isa(op) && elementTy.isa()) { - auto zero = - rewriter.create(loc, FloatAttr::get(elementTy, 0)); - bool losesInfo = false; - APFloat max_apf = op->getAttr("max_fp").cast().getValue(); - max_apf.convert(elementTy.cast().getFloatSemantics(), - APFloat::rmNearestTiesToEven, &losesInfo); - auto n = rewriter.create( - loc, elementTy, rewriter.getFloatAttr(elementTy, max_apf)); - return clampFloatHelper(loc, args[0], zero, n, rewriter); - } - - if (isa(op) && elementTy.isa()) { - auto zero = - rewriter.create(loc, IntegerAttr::get(elementTy, 0)); - auto n = createConstFromIntAttribute(op, "max_int", elementTy, - rewriter); - return clampIntHelper(loc, args[0], zero, n, rewriter); - } - // tosa::SigmoidOp if (isa(op) && elementTy.isa()) { auto one = @@ -2235,7 +2214,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 @@ -981,7 +981,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 @@ -218,17 +218,12 @@ // CHECK: arith.maxf %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.minf - // CHECK: arith.maxf - %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 @@ -242,20 +237,20 @@ // CHECK: arith.minf // CHECK: arith.maxf // 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 } @@ -392,11 +387,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 @@ -405,27 +395,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 } @@ -474,7 +464,7 @@ // CHECK-LABEL: @test_clamp_f16 func.func @test_clamp_f16(%arg0: tensor<1xf16>) -> () { // CHECK: linalg.generic - // CHECK: ^bb0(%[[ARG1:.+]]: f16, + // CHECK: ^bb0(%[[ARG1:.+]]: f16, // CHECK-DAG: %[[C0:.+]] = arith.constant 0.0 // CHECK-DAG: %[[C6:.+]] = arith.constant 6.0 // CHECK-DAG: %[[MIN:.+]] = arith.minf %[[ARG1]], %[[C0]] 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> { 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 }