[Mlir-commits] [mlir] [MLIR] Expose approximation patterns for tanh/erf. (PR #82750)
Johannes Reifferscheid
llvmlistbot at llvm.org
Fri Feb 23 03:01:27 PST 2024
https://github.com/jreiffers updated https://github.com/llvm/llvm-project/pull/82750
>From 7b4e5a43e780bad1d523eb7519b27c26818958da Mon Sep 17 00:00:00 2001
From: Johannes Reifferscheid <jreiffers at google.com>
Date: Fri, 23 Feb 2024 11:49:10 +0100
Subject: [PATCH] [MLIR] Expose approximation patterns for tanh/erf.
These patterns can already be used via
populateMathPolynomialApproximationPatterns, but that includes a number
of other patterns that may not be needed.
There are already similar functions for expansion.
For now only adding tanh and erf since I have a concrete use case for
these two.
---
mlir/include/mlir/Dialect/Math/Transforms/Passes.h | 3 +++
.../Math/Transforms/PolynomialApproximation.cpp | 10 ++++++++++
2 files changed, 13 insertions(+)
diff --git a/mlir/include/mlir/Dialect/Math/Transforms/Passes.h b/mlir/include/mlir/Dialect/Math/Transforms/Passes.h
index 010dde5ea73847..11b2c7a7afa2f7 100644
--- a/mlir/include/mlir/Dialect/Math/Transforms/Passes.h
+++ b/mlir/include/mlir/Dialect/Math/Transforms/Passes.h
@@ -45,6 +45,9 @@ struct MathPolynomialApproximationOptions {
bool enableAvx2 = false;
};
+void populatePolynomialApproximateTanhPattern(RewritePatternSet &patterns);
+void populatePolynomialApproximateErfPattern(RewritePatternSet &patterns);
+
void populateMathPolynomialApproximationPatterns(
RewritePatternSet &patterns,
const MathPolynomialApproximationOptions &options = {});
diff --git a/mlir/lib/Dialect/Math/Transforms/PolynomialApproximation.cpp b/mlir/lib/Dialect/Math/Transforms/PolynomialApproximation.cpp
index 71e4e13103f514..962cb28b7c2ab9 100644
--- a/mlir/lib/Dialect/Math/Transforms/PolynomialApproximation.cpp
+++ b/mlir/lib/Dialect/Math/Transforms/PolynomialApproximation.cpp
@@ -1471,6 +1471,16 @@ RsqrtApproximation::matchAndRewrite(math::RsqrtOp op,
//----------------------------------------------------------------------------//
+void mlir::populatePolynomialApproximateTanhPattern(
+ RewritePatternSet &patterns) {
+ patterns.add<TanhApproximation>(patterns.getContext());
+}
+
+void mlir::populatePolynomialApproximateErfPattern(
+ RewritePatternSet &patterns) {
+ patterns.add<ErfPolynomialApproximation>(patterns.getContext());
+}
+
void mlir::populateMathPolynomialApproximationPatterns(
RewritePatternSet &patterns,
const MathPolynomialApproximationOptions &options) {
More information about the Mlir-commits
mailing list