[Mlir-commits] [mlir] 9d86722 - [TOSA] Add lowering for `tosa.sin` and `tosa.cos` (#99651)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Jul 19 08:11:27 PDT 2024
Author: Dhruv Chauhan
Date: 2024-07-19T16:11:23+01:00
New Revision: 9d86722eeecbb1dd6a53c10f7c44fdc317de6809
URL: https://github.com/llvm/llvm-project/commit/9d86722eeecbb1dd6a53c10f7c44fdc317de6809
DIFF: https://github.com/llvm/llvm-project/commit/9d86722eeecbb1dd6a53c10f7c44fdc317de6809.diff
LOG: [TOSA] Add lowering for `tosa.sin` and `tosa.cos` (#99651)
Lower tosa ops to `mlir::math::SinOp` and `mlir::math::CosOp` as part of
the tosa to linalg conversion.
Added lit tests for conversion.
Added:
Modified:
mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp
mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp b/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp
index 1442f2ad72255..ba259d4b84fce 100644
--- a/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp
+++ b/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp
@@ -298,6 +298,14 @@ static Value createLinalgBodyCalculationForElementwiseOp(
if (isa<tosa::ExpOp>(op) && isa<FloatType>(elementTy))
return rewriter.create<mlir::math::ExpOp>(loc, resultTypes, args);
+ // tosa::SinOp
+ if (isa<tosa::SinOp>(op) && isa<FloatType>(elementTy))
+ return rewriter.create<mlir::math::SinOp>(loc, resultTypes, args);
+
+ // tosa::CosOp
+ if (isa<tosa::CosOp>(op) && isa<FloatType>(elementTy))
+ return rewriter.create<mlir::math::CosOp>(loc, resultTypes, args);
+
// tosa::TanhOp
if (isa<tosa::TanhOp>(op) && isa<FloatType>(elementTy))
return rewriter.create<mlir::math::TanhOp>(loc, resultTypes, args);
@@ -2598,6 +2606,8 @@ void mlir::tosa::populateTosaToLinalgConversionPatterns(
PointwiseConverter<tosa::LogOp>,
PointwiseConverter<tosa::ExpOp>,
PointwiseConverter<tosa::AbsOp>,
+ PointwiseConverter<tosa::SinOp>,
+ PointwiseConverter<tosa::CosOp>,
PointwiseConverter<tosa::TanhOp>,
PointwiseConverter<tosa::ErfOp>,
PointwiseConverter<tosa::BitwiseAndOp>,
diff --git a/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir b/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir
index 5187d79fd4c0b..0e35f8ea9d0cd 100644
--- a/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir
+++ b/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir
@@ -545,6 +545,14 @@ func.func @test_simple_f32(%arg0: tensor<1xf32>) -> () {
// CHECK: math.erf
%24 = tosa.erf %0 : (tensor<1xf32>) -> tensor<1xf32>
+ // CHECK: linalg.generic
+ // CHECK: math.sin
+ %25 = tosa.sin %arg0 : (tensor<1xf32>) -> tensor<1xf32>
+
+ // CHECK: linalg.generic
+ // CHECK: math.cos
+ %26 = tosa.cos %arg0 : (tensor<1xf32>) -> tensor<1xf32>
+
return
}
More information about the Mlir-commits
mailing list