[Mlir-commits] [mlir] [TOSA] Add lowering for `tosa.sin` and `tosa.cos` (PR #99651)
Dhruv Chauhan
llvmlistbot at llvm.org
Fri Jul 19 07:39:05 PDT 2024
https://github.com/dchauhan-arm updated https://github.com/llvm/llvm-project/pull/99651
>From 934965d5bc11089fa2d0719418746cd751100e67 Mon Sep 17 00:00:00 2001
From: Dhruv Chauhan <dhruv.chauhan at arm.com>
Date: Fri, 19 Jul 2024 14:07:11 +0100
Subject: [PATCH 1/2] [TOSA] Add lowering for `tosa.sin` and `tosa.cos`
Lower tosa ops to `mlir::math::SinOp` and `mlir::math::CosOp` as part of
the tosa to linalg conversion.
Added lit tests for conversion.
---
mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp | 10 ++++++++++
mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir | 8 ++++++++
2 files changed, 18 insertions(+)
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..4fe6b159fe443 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: sin
+ %25 = tosa.sin %arg0 : (tensor<1xf32>) -> tensor<1xf32>
+
+ // CHECK: linalg.generic
+ // CHECK: cos
+ %26 = tosa.cos %arg0 : (tensor<1xf32>) -> tensor<1xf32>
+
return
}
>From 244558971e343823ebaee793e83bb0268acbdeae Mon Sep 17 00:00:00 2001
From: Dhruv Chauhan <dhruv.chauhan at arm.com>
Date: Fri, 19 Jul 2024 15:38:57 +0100
Subject: [PATCH 2/2] Amend op prefix
---
mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir b/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir
index 4fe6b159fe443..0e35f8ea9d0cd 100644
--- a/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir
+++ b/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir
@@ -546,11 +546,11 @@ func.func @test_simple_f32(%arg0: tensor<1xf32>) -> () {
%24 = tosa.erf %0 : (tensor<1xf32>) -> tensor<1xf32>
// CHECK: linalg.generic
- // CHECK: sin
+ // CHECK: math.sin
%25 = tosa.sin %arg0 : (tensor<1xf32>) -> tensor<1xf32>
// CHECK: linalg.generic
- // CHECK: cos
+ // CHECK: math.cos
%26 = tosa.cos %arg0 : (tensor<1xf32>) -> tensor<1xf32>
return
More information about the Mlir-commits
mailing list