50 Commits

Author SHA1 Message Date
Maksim Levental
b0312be6aa
[mlir][NFC] update mlir/Dialect create APIs (19/n) (#149926)
See https://github.com/llvm/llvm-project/pull/147168 for more info.
2025-07-22 10:13:44 -04:00
William Moses
1b610e69d9
[MLIR][Math] Add floating point value folders (#127947) 2025-02-20 09:59:55 -06:00
Jan Leyonberg
8806311bb7
[MLIR][Math] Add erfc to math dialect (#126439)
This patch adds the erfc op to the math dialect. It also does lowering
of the math.erfc op to libm calls. There is also a f32 polynomial
approximation for the function based on

https://stackoverflow.com/questions/35966695/vectorizable-implementation-of-complementary-error-function-erfcf
This is in turn based on
M. M. Shepherd and J. G. Laframboise, "Chebyshev Approximation of
(1+2x)exp(x^2)erfc x in 0 <= x < INF", Mathematics of Computation, Vol.
36, No. 153, January 1981, pp. 249-253.
The code has a ULP error less than 3, which was tested, and MLIR test
values were verified against the C implementation.
2025-02-18 10:51:37 -05:00
Oleksandr "Alex" Zinenko
79d8a34bc5
[mlir] add some FP classification ops and their lowering to libdevice (#127322)
Introduce a subset of floating point classification ops to the Math
dialect. These ops mirror functions provided by the C math library and,
similarly to the existing `math.copysign`, belong to the math dialect.
Add a lowering of those ops to Nvidia libdevice calls when possible as
the first mechanism to exercise them.
2025-02-16 14:51:21 +01:00
Vivek Khandelwal
b8dca4fa72
[mlir][math] Add math.acosh|asin|asinh|atanh op (#77463)
Signed-Off By: Vivek Khandelwal <vivekkhandelwal1424@gmail.com>
2024-01-10 13:39:32 +01:00
Rob Suderman
aa165edca8
[mlir][math] Added math.sinh with expansions to math.exp (#75517)
Includes end-to-end tests for the cpu running, folders using `libm` and
lowerings to the corresponding `libm` operations.
2023-12-15 11:35:40 -08:00
Sungsoon Cho
762964e97f
Add cosh op to the math dialect. (#75153) 2023-12-13 12:25:37 +01:00
Frederik Harwath
f7250179e2
Implement acos operator in MLIR Math Dialect (#74584)
Required for torch-mlir.
Cf. llvm/torch-mlir#2604 "Implement torch.aten.acos".
2023-12-08 09:08:43 -08:00
Ivan Butygin
5dce74817b [mlir][ub] Add poison support to CommonFolders.h
Return poison from foldBinary/unary if argument(s) is poison. Add ub dialect as dependency to affected dialects (arith, math, spirv, shape).
Add poison materialization to dialects. Add tests for some ops from each dialect.
Not all affected ops are covered as it will involve a huge copypaste.

Differential Revision: https://reviews.llvm.org/D159013
2023-09-07 12:30:29 +02:00
Rahul Kayaith
00e3566d6c [mlir][arith] Add arith.constant materialization helper
This adds `arith::ConstantOp::materialize`, which builds a constant from
an attribute and type only if it would result in a valid op. This is
useful for dialect `materializeConstant` hooks, and allows for removing
the previous `Attribute, Type` builder which was only used during
materialization.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D148491
2023-04-20 16:31:52 -04:00
Kazu Hirata
f8f3db2756 Use APInt::count{l,r}_{zero,one} (NFC) 2023-02-19 22:04:47 -08:00
Kazu Hirata
cbde2124f1 Use APInt::popcount instead of APInt::countPopulation (NFC)
This is for consistency with the C++20-style bit manipulation
functions in <bit>.
2023-02-19 11:29:12 -08:00
Kazu Hirata
0a81ace004 [mlir] Use std::optional instead of llvm::Optional (NFC)
This patch replaces (llvm::|)Optional< with std::optional<.  I'll post
a separate patch to remove #include "llvm/ADT/Optional.h".

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-14 01:25:58 -08:00
Kazu Hirata
a1fe1f5f77 [mlir] Add #include <optional> (NFC)
This patch adds #include <optional> to those files containing
llvm::Optional<...> or Optional<...>.

I'll post a separate patch to actually replace llvm::Optional with
std::optional.

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-13 21:05:06 -08:00
Markus Böck
6c30503ef8 [mlir][math][NFC] Migrate math dialect to the new fold API
See https://discourse.llvm.org/t/psa-new-improved-fold-method-signature-has-landed-please-update-your-downstream-projects/67618 for context

Similar to the patch for the arith dialect, the math dialects fold implementations make heavy use of generic fold functions, hence the change being comparatively mechanical and mostly changing the function signature.

Differential Revision: https://reviews.llvm.org/D141500
2023-01-11 18:11:46 +01:00
Jakub Kuderski
abc362a107 [mlir][arith] Change dialect name from Arithmetic to Arith
Suggested by @lattner in https://discourse.llvm.org/t/rfc-define-precise-arith-semantics/65507/22.

Tested with:
`ninja check-mlir check-mlir-integration check-mlir-mlir-spirv-cpu-runner check-mlir-mlir-vulkan-runner check-mlir-examples`

and `bazel build --config=generic_clang @llvm-project//mlir:all`.

Reviewed By: lattner, Mogball, rriddle, jpienaar, mehdi_amini

Differential Revision: https://reviews.llvm.org/D134762
2022-09-29 11:23:28 -04:00
jacquesguan
6eebdc46e4 [mlir][Math] Add constant folder for ErfOp.
This patch adds constant folder for ErfOp by using erf/erff of libm.

Reviewed By: ftynse, Mogball

Differential Revision: https://reviews.llvm.org/D134017
2022-09-19 10:55:16 +08:00
jacquesguan
71e52a125c [mlir][Math] Add constant folder for SinOp.
This patch adds constant folder for SinOp by using sin/sinf of libm.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D133915
2022-09-16 14:30:05 +08:00
jacquesguan
9d0b90e933 [mlir][Math] Add TruncOp.
This patch adds TruncOp for Math, it returns the operand rounded to the nearest integer not larger in magnitude than the operand. And this patch also adds the correspond llvm intrinsic op.

Reviewed By: Mogball

Differential Revision: https://reviews.llvm.org/D133342
2022-09-09 10:01:28 +08:00
Kai Sasaki
5bb621056b [mlir][math] Canonicalization for math.floor op
Support constant folding for math.floor op as well as math.ceil.

Reviewed By: Mogball

Differential Revision: https://reviews.llvm.org/D133398
2022-09-09 10:21:48 +09:00
jacquesguan
b53bccb18d [mlir][Math] Add constant folder for RoundOp.
This patch uses round/roundf of libm to fold RoundOp of constant.

Differential Revision: https://reviews.llvm.org/D133401
2022-09-08 14:51:17 +08:00
jacquesguan
238e08d643 [mlir][Math] Fix RoundEven constant folder.
Use roundToIntegral instead roundeven of libm to avoid window build failed.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D133402
2022-09-07 12:46:05 +00:00
jacquesguan
ac66d87c4b [mlir][Math] Add constant folder for RoundEvenOp.
This patch uses roundeven/roundevenf of libm to fold RoundEvenOp of constant.

Differential Revision: https://reviews.llvm.org/D133344
2022-09-07 11:13:00 +08:00
jacquesguan
e3434a8627 [mlir][Math] Add constant folder for CosOp.
This patch adds constant folder for CosOp which only supports single and double precision floating-point.

Differential Revision: https://reviews.llvm.org/D131233
2022-09-07 10:54:08 +08:00
Slava Zakharin
cd3a234fa9 [mlir][math] Added constant folding for IPowI operation.
Differential Revision: https://reviews.llvm.org/D130389
2022-08-15 11:31:14 -07:00
Jeff Niu
7d9fc95b85 [mlir][math] Add math.absi op
Adds an integer absolute value op to the math dialect.

When converting to LLVM, this op is lowered to the LLVM `abs` intrinsic.
When converting to SPIRV, this op is lowered to `spv.GL.SAbs`.

Depends on D131325

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D131327
2022-08-08 11:05:01 -04:00
Jeff Niu
00f7096d31 [mlir][math] Rename math.abs -> math.absf
To make room for introducing `math.absi`.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D131325
2022-08-08 11:04:58 -04:00
jacquesguan
40d74fcb55 [mlir][Math] Add constant folder for Atan2Op.
This patch adds constant folder for Atan2Op which only supports single and double precision floating-point.

Differential Revision: https://reviews.llvm.org/D131050
2022-08-05 10:30:58 +08:00
jacquesguan
752c9d0dab [mlir][Math] Add constant folder for AtanOp.
This patch adds constant folder for AtanOp which only supports single and double precision floating-point.

Differential Revision: https://reviews.llvm.org/D130983
2022-08-03 14:10:02 +08:00
jacquesguan
008ea1c201 [mlir][Math] Add constant folder for TanhOp.
This patch adds constant folder for TanhOp which only supports single and double precision floating-point.

Differential Revision: https://reviews.llvm.org/D130960
2022-08-02 19:37:27 +08:00
jacquesguan
f1033a3f47 [mlir][Math] Add constant folder for TanOp.
This patch adds constant folder for TanOp which only supports single and double precision floating-point.

Differential Revision: https://reviews.llvm.org/D130873
2022-08-02 11:20:53 +08:00
jacquesguan
16cb6ce554 [mlir][Math] Add constant folder for ExpM1Op.
This patch adds constant folder for ExpM1Op which only supports single and double precision floating-point.

Differential Revision: https://reviews.llvm.org/D130567
2022-08-01 14:40:50 +08:00
jacquesguan
78015047b2 [mlir][Math] Add constant folder for Exp2Op.
This patch adds constant folder for Exp2Op which only supports single and double precision floating-point.

Differential Revision: https://reviews.llvm.org/D130472
2022-07-26 08:48:48 +08:00
jacquesguan
9e241c70f7 [mlir][Math] Add constant folder for ExpOp.
This patch adds constant folder for ExpOp which only supports single and double precision floating-point.

Differential Revision: https://reviews.llvm.org/D130318
2022-07-25 16:26:48 +08:00
jacquesguan
9c22853ec4 [mlir][Math] Add constant folder for LogOp.
This patch adds constant folder for LogOp which only supports single and double precision floating-point.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D130148
2022-07-21 10:58:32 +08:00
jacquesguan
c3d856bf58 [mlir][Math] Add constant folder for Log1pOp.
This patch adds constant folder for Log1pOp which only supports single and double precision floating-point.

Differential Revision: https://reviews.llvm.org/D129979
2022-07-20 14:59:35 +08:00
jacquesguan
a5cae20bdb [mlir][Math] Add constant folder for Log10Op.
This patch adds constant folder for Log10Op which only support single and double precision floating-point.

Reviewed By: Mogball

Differential Revision: https://reviews.llvm.org/D129740
2022-07-18 10:19:25 +08:00
jacquesguan
4d7d5c5f00 [mlir][Math] Support fold SqrtOp with constant dense.
This patch uses constFoldUnaryOpConditional to replace current folder in order to support constant dense.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D129459
2022-07-12 16:46:19 +08:00
jacquesguan
ad4b7fb3ce [mlir][Math] Support fold Log2Op with constant dense.
This patch is similar to D129108, it adds a conditional unary constant folder which allow to exit when the constants not meet the fold condition. And use it for Log2Op to make it able to fold the constant dense.

Differential Revision: https://reviews.llvm.org/D129251
2022-07-11 10:34:28 +08:00
jacquesguan
362240e09e [mlir][Math] Support fold PowFOp with constant dense.
This patch adds a conditional binary constant folder which allow to exit when the constants not meet the fold condition. And use it for PowFOp to make it able to fold the constant dense.

Differential Revision: https://reviews.llvm.org/D129108
2022-07-07 10:13:08 +08:00
Mehdi Amini
1881d6fc80 Apply clang-tidy fixes for performance-unnecessary-copy-initialization in MathOps.cpp (NFC) 2022-04-19 00:47:58 +00:00
jacquesguan
83bd4fe2e8 [mlir][Math] Replace some constant folder functions with common folder functions.
Differential Revision: https://reviews.llvm.org/D123485
2022-04-12 11:34:47 +00:00
jacquesguan
e609417cdc [mlir][Math] Add more constant folder for Math ops.
This revision add constant folder for abs, copysign, ctlz, cttz and
ctpop.

Differential Revision: https://reviews.llvm.org/D122115
2022-03-22 10:23:15 +08:00
jacquesguan
26c95ae389 [mlir][Math] Add constant folder for sqrt.
Differential Revision: https://reviews.llvm.org/D121980
2022-03-18 16:01:44 +08:00
William S. Moses
164c7afaf5 [MLIR][Math] Add constant folder for powf
Constant fold powf, given two constant operands and a compatible type

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D121845
2022-03-17 14:19:47 -04:00
Mehdi Amini
1c173c9442 Apply clang-tidy fixes for readability-identifier-naming in MathOps.cpp (NFC) 2022-01-14 18:08:42 +00:00
William S. Moses
1773dddadf [MLIR][Math] Enable constant folding of ops
Enable constant folding of ops within the math dialect, and introduce constant folders for ceil and log2

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D117085
2022-01-12 12:19:29 -05:00
William S. Moses
d2c547342c Revert "[MLIR][Math] Enable constant folding of ops"
This reverts commit 2f8b956ab6e63e57fbaa60749c9ba7752b071993.

There is a linker error for mlir-nvidia as seen on
https://lab.llvm.org/buildbot/#/builders/61/builds/19939.

As it's late for me here, I'm oing to rever this for now to be
investigated later.
2022-01-12 02:00:53 -05:00
William S. Moses
2f8b956ab6 [MLIR][Math] Enable constant folding of ops
Enable constant folding of ops within the math dialect, and introduce constant folders for ceil and log2

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D117085
2022-01-12 01:55:48 -05:00
Stephan Herhut
4348d8ab7f [mlir][math] Split off the math dialect.
This does not split transformations, yet. Those will be done as future clean ups.

Differential Revision: https://reviews.llvm.org/D96272
2021-02-12 10:55:12 +01:00