[MLIR][KernelGen] Lower `tf.Sinh` to MLHLO

PiperOrigin-RevId: 332425724
This commit is contained in:
A. Unique TensorFlower 2020-09-18 04:25:55 -07:00 committed by TensorFlow MLIR Team
parent cfbd7a18b2
commit 4002077261
3 changed files with 55 additions and 1 deletions

View File

@ -366,6 +366,20 @@ def HLOClient_AcosOp : HLOClient_UnaryElementwiseOp<"acos", [],
}];
}
def HLOClient_SinhOp : HLOClient_UnaryElementwiseOp<"sinh", [],
HLO_FpOrComplexTensor> {
let summary = "Sinh operation";
let description = [{
Returns `Sinh(operand)` element-wise.
$$
\sinh(x) = (e^x - e^-x) / 2 if |x| < 1
= e^(x + log(1/2)) - e^(-x + log(1/2)) otherwise.
$$
}];
}
def HLOClient_TanOp : HLOClient_UnaryElementwiseOp<"tan", [],
HLO_FpOrComplexTensor> {
let summary = "Tan operation";

View File

@ -49,6 +49,45 @@ def : Pat<(HLOClient_AcosOp $input),
),
(HLO_ConstantLike<"M_PI"> $input))>;
// Express `sinh` as
// sinh(x) = (e^x - e^-x) / 2 if |x| < 1
// = e^(x + log(1/2)) - e^(-x + log(1/2)) otherwise.
def : Pat<(HLOClient_SinhOp $input),
(HLO_SelectOp
(HLO_CompareOp
(HLO_AbsOp $input),
(HLO_ConstantLike<"1"> $input),
HLO_COMPARISON_DIRECTION_LT
),
(HLO_DivOp
(HLO_SubOp
(HLO_ExpOp $input),
(HLO_ExpOp
(HLO_NegOp $input)
)
),
(HLO_ConstantLike<"2"> $input)
),
(HLO_SubOp
(HLO_ExpOp
(HLO_AddOp
$input,
(HLO_LogOp
(HLO_ConstantLike<"0.5"> $input)
)
)
),
(HLO_ExpOp
(HLO_SubOp
(HLO_LogOp
(HLO_ConstantLike<"0.5"> $input)
),
$input
)
)
)
)>;
// Express tan in MHLO dialect as
// tan(x) = sin(x) / cos(x).
def : Pat<(HLOClient_TanOp $input),

View File

@ -47,7 +47,8 @@ namespace {
sep fn(ShiftRightLogicalOp) sep fn(SubOp)
// TODO(herhut): Generate these out of op definitions.
#define MAP_CHLO_OPERATION_CWISE_UNARY(fn, sep) fn(TanOp) sep fn(AcosOp)
#define MAP_CHLO_OPERATION_CWISE_UNARY(fn, sep) \
fn(TanOp) sep fn(AcosOp) sep fn(SinhOp)
template <typename OpTy>
inline void AddLegalOpOnRankedTensor(ConversionTarget *target) {