From 85f92a16515c4fe71df7866a18879866776ace47 Mon Sep 17 00:00:00 2001 From: Lucy Fox Date: Tue, 24 Nov 2020 10:55:01 -0800 Subject: [PATCH] [KernelGen] Lower tf.Erf and tf.Erfc ops to CHLO. This does not include the lowerings from CHLO to LMHLO. PiperOrigin-RevId: 344091604 --- include/mlir-hlo/Dialect/mhlo/IR/chlo_ops.td | 26 +++++++++++++++++++ .../mhlo/transforms/transform_unranked_hlo.cc | 5 ++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/include/mlir-hlo/Dialect/mhlo/IR/chlo_ops.td b/include/mlir-hlo/Dialect/mhlo/IR/chlo_ops.td index a65d825..a017794 100644 --- a/include/mlir-hlo/Dialect/mhlo/IR/chlo_ops.td +++ b/include/mlir-hlo/Dialect/mhlo/IR/chlo_ops.td @@ -417,6 +417,32 @@ def HLOClient_ConstantLikeOp : HLOClient_Op<"constant_like", let hasCanonicalizer = 1; } +def HLOClient_ErfOp : HLOClient_UnaryElementwiseOp<"erf", + [NoSideEffect, SameOperandsAndResultShape], + HLO_FpTensor> { + let summary = "Erfc operator"; + + let description = [{ + Computes the Gauss error function of `x` element-wise. + + erf(x) = erf_impl(x) if |x| < 1 + = 1 - erfc_impl(x) otherwise + }]; +} + +def HLOClient_ErfcOp : HLOClient_UnaryElementwiseOp<"erfc", + [NoSideEffect, SameOperandsAndResultShape], + HLO_FpTensor> { + let summary = "Erfc operator"; + + let description = [{ + Computes an approximation of the error function complement (1 - erf(x)). + + erfc(x) = erfc_impl(x) if |x| > 1 + = 1 - erf_impl(x) otherwise + }]; +} + //===----------------------------------------------------------------------===// // Broadcasting compare op //===----------------------------------------------------------------------===// diff --git a/lib/Dialect/mhlo/transforms/transform_unranked_hlo.cc b/lib/Dialect/mhlo/transforms/transform_unranked_hlo.cc index 544bd71..45691af 100644 --- a/lib/Dialect/mhlo/transforms/transform_unranked_hlo.cc +++ b/lib/Dialect/mhlo/transforms/transform_unranked_hlo.cc @@ -49,8 +49,9 @@ namespace { sep fn(ShiftRightLogicalOp) sep fn(SubOp) // TODO(herhut): Generate these out of op definitions. -#define MAP_CHLO_OPERATION_CWISE_UNARY(fn, sep) \ - fn(AcosOp) sep fn(AtanOp) sep fn(SinhOp) sep fn(TanOp) +#define MAP_CHLO_OPERATION_CWISE_UNARY(fn, sep) \ + fn(AcosOp) sep fn(AtanOp) sep fn(ErfOp) sep fn(ErfcOp) sep fn(SinhOp) \ + sep fn(TanOp) template inline void AddLegalOpOnRankedTensor(ConversionTarget *target) {