From 89a1af749166627704cdf9d676455d32616c2c06 Mon Sep 17 00:00:00 2001 From: Matthias Gehre Date: Thu, 23 Mar 2023 01:08:43 +0000 Subject: [PATCH] [mlir][tosa] TosaToLinalg: Lower TOSA.Cast via RoundEven according to TOSA spec 0.60.0 TOSA now specifies rounding of ties to even in section 1.8.2., "Main Inference Profile" Reviewed By: eric-k256, rsuderman Differential Revision: https://reviews.llvm.org/D146617 --- mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp | 12 +----------- mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir | 7 +------ 2 files changed, 2 insertions(+), 17 deletions(-) diff --git a/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp b/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp index 271a095..be24f5e 100644 --- a/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp +++ b/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp @@ -471,11 +471,6 @@ createLinalgBodyCalculationForElementwiseOp(Operation *op, ValueRange args, } if (arith::FPToSIOp::areCastCompatible(srcTy, dstTy)) { - auto zero = rewriter.create( - loc, rewriter.getF32FloatAttr(0.0f)); - auto half = rewriter.create( - loc, rewriter.getF32FloatAttr(0.5f)); - auto intMin = rewriter.create( loc, rewriter.getF32FloatAttr( APInt::getSignedMinValue(dstTy.getIntOrFloatBitWidth()) @@ -486,12 +481,7 @@ createLinalgBodyCalculationForElementwiseOp(Operation *op, ValueRange args, APInt::getSignedMaxValue(dstTy.getIntOrFloatBitWidth()) .getSExtValue())); - auto added = rewriter.create(loc, args[0], half); - auto subbed = rewriter.create(loc, args[0], half); - auto negative = rewriter.create( - loc, arith::CmpFPredicate::OLT, args[0], zero); - auto rounded = - rewriter.create(loc, negative, subbed, added); + auto rounded = rewriter.create(loc, args[0]); auto clamped = clampFloatHelper(loc, rounded, intMin, intMax, rewriter); diff --git a/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir b/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir index 133999e..476131b 100644 --- a/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir +++ b/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir @@ -237,14 +237,9 @@ func.func @test_simple_f32(%arg0: tensor<1xf32>) -> () { %19 = "tosa.sigmoid"(%0) : (tensor<1xf32>) -> tensor<1xf32> // CHECK: linalg.generic - // CHECK: arith.constant 0.000000e+00 - // CHECK: arith.constant 5.000000e-01 // CHECK: arith.constant -2.14748365E+9 // CHECK: arith.constant 2.14748365E+9 - // CHECK: arith.addf - // CHECK: arith.subf - // CHECK: arith.cmpf olt - // CHECK: select + // CHECK: math.roundeven // CHECK: arith.minf // CHECK: arith.maxf // CHECK: arith.fptosi -- 2.7.4