Skip to content

Commit ff6a3f2

Browse files
dchauhan-armyuxuanchen1997
authored andcommitted
[TOSA] Add lowering for tosa.sin and tosa.cos (#99651)
Summary: Lower tosa ops to `mlir::math::SinOp` and `mlir::math::CosOp` as part of the tosa to linalg conversion. Added lit tests for conversion. Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60251318
1 parent 8f264db commit ff6a3f2

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,14 @@ static Value createLinalgBodyCalculationForElementwiseOp(
298298
if (isa<tosa::ExpOp>(op) && isa<FloatType>(elementTy))
299299
return rewriter.create<mlir::math::ExpOp>(loc, resultTypes, args);
300300

301+
// tosa::SinOp
302+
if (isa<tosa::SinOp>(op) && isa<FloatType>(elementTy))
303+
return rewriter.create<mlir::math::SinOp>(loc, resultTypes, args);
304+
305+
// tosa::CosOp
306+
if (isa<tosa::CosOp>(op) && isa<FloatType>(elementTy))
307+
return rewriter.create<mlir::math::CosOp>(loc, resultTypes, args);
308+
301309
// tosa::TanhOp
302310
if (isa<tosa::TanhOp>(op) && isa<FloatType>(elementTy))
303311
return rewriter.create<mlir::math::TanhOp>(loc, resultTypes, args);
@@ -2598,6 +2606,8 @@ void mlir::tosa::populateTosaToLinalgConversionPatterns(
25982606
PointwiseConverter<tosa::LogOp>,
25992607
PointwiseConverter<tosa::ExpOp>,
26002608
PointwiseConverter<tosa::AbsOp>,
2609+
PointwiseConverter<tosa::SinOp>,
2610+
PointwiseConverter<tosa::CosOp>,
26012611
PointwiseConverter<tosa::TanhOp>,
26022612
PointwiseConverter<tosa::ErfOp>,
26032613
PointwiseConverter<tosa::BitwiseAndOp>,

mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,14 @@ func.func @test_simple_f32(%arg0: tensor<1xf32>) -> () {
545545
// CHECK: math.erf
546546
%24 = tosa.erf %0 : (tensor<1xf32>) -> tensor<1xf32>
547547

548+
// CHECK: linalg.generic
549+
// CHECK: math.sin
550+
%25 = tosa.sin %arg0 : (tensor<1xf32>) -> tensor<1xf32>
551+
552+
// CHECK: linalg.generic
553+
// CHECK: math.cos
554+
%26 = tosa.cos %arg0 : (tensor<1xf32>) -> tensor<1xf32>
555+
548556
return
549557
}
550558

0 commit comments

Comments
 (0)