Add a pattern for expanding tanh op into exp form.
A tanh is expanded into:
- 1-exp^{-2x} / 1+exp^{-2x}, if x => 0
- exp^{2x}-1 / exp^{2x}+1 , if x < 0.
Differential D81618
[mlir] Add support for lowering tanh to LLVMIR. hanchung on Jun 10 2020, 3:57 PM. Authored by
Details Add a pattern for expanding tanh op into exp form.
Diff Detail
Event TimelineComment Actions Didn't go through the code yet. high level comments:
tanh(x) = 1-exp^{-2x} / 1+exp^{-2x}, x => 0 tanh(x) = exp^{2x}-1 / exp^{2x}+1, x < 0 Comment Actions It looks like this is better done as an intra-dialect transform, everything that you need is available in the standard dialect so the code can just expand std.tanh to a set of std. operations and then use the regular conversion. We already do so for atomics https://github.com/llvm/llvm-project/blob/master/mlir/lib/Dialect/StandardOps/Transforms/ExpandAtomic.cpp, we can put ExpandTanh.cpp next to it. Comment Actions
Unless we assume libc is linked, there's no tanh function. Comment Actions It depends on the LLVM backend. LLVM models _all_ intrinsics as function calls, but it does not necessarily mean they actually become function calls in the generated assembly (e.g., llvm.intr.fma won't). Comment Actions Thanks!
Comment Actions Address comments.
Comment Actions Reverted in a9a21bb4b682474248dc85f9e7db4b260d249ab9 ; the standalone test was broken Comment Actions It passed with bazel on my local machine, I'll take a look at what happened, sorry about that. |
Does something actually use it as a pass? I only see the pattern to be used inside Linalg conversion. If there is no direct user of this pass, let's put it under test/lib/Transforms.