[MLIR][KernelGen] Lower `tf.Sinh` to MLHLO
PiperOrigin-RevId: 332425724
This commit is contained in:
parent
cfbd7a18b2
commit
4002077261
|
@ -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", [],
|
def HLOClient_TanOp : HLOClient_UnaryElementwiseOp<"tan", [],
|
||||||
HLO_FpOrComplexTensor> {
|
HLO_FpOrComplexTensor> {
|
||||||
let summary = "Tan operation";
|
let summary = "Tan operation";
|
||||||
|
|
|
@ -49,6 +49,45 @@ def : Pat<(HLOClient_AcosOp $input),
|
||||||
),
|
),
|
||||||
(HLO_ConstantLike<"M_PI"> $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
|
// Express tan in MHLO dialect as
|
||||||
// tan(x) = sin(x) / cos(x).
|
// tan(x) = sin(x) / cos(x).
|
||||||
def : Pat<(HLOClient_TanOp $input),
|
def : Pat<(HLOClient_TanOp $input),
|
||||||
|
|
|
@ -47,7 +47,8 @@ namespace {
|
||||||
sep fn(ShiftRightLogicalOp) sep fn(SubOp)
|
sep fn(ShiftRightLogicalOp) sep fn(SubOp)
|
||||||
|
|
||||||
// TODO(herhut): Generate these out of op definitions.
|
// 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>
|
template <typename OpTy>
|
||||||
inline void AddLegalOpOnRankedTensor(ConversionTarget *target) {
|
inline void AddLegalOpOnRankedTensor(ConversionTarget *target) {
|
||||||
|
|
Loading…
Reference in New Issue