19551 Commits

Author SHA1 Message Date
Kai Sasaki
8c9d814b66
[mlir][complex] Fastmath flag for complex angle (#88658)
See
https://discourse.llvm.org/t/rfc-fastmath-flags-support-in-complex-dialect/71981
2024-04-17 09:19:15 +09:00
Prashant Kumar
ce5381e22a
[mlir][vector] Determine vector sizes from the result shape in the ca… (#88249)
…se of tensor pack

When the vector sizes are not passed as inputs to the vector transform
operation, the vector sizes are queried from the static result shape in
the case of tensor.pack op.
2024-04-17 05:36:40 +05:30
Peiming Liu
8aa061ffc7
[mlir][sparse][NFC] switching to using let argments/results in td files (#88994)
followed the same style used in "TensorOps.td".
2024-04-16 15:18:47 -07:00
Jeremy Kun
ed7038ef33
specify dialect in polynomial docs (#88933)
I figured out how to test this with `make mlir-doc doxygen-mlir`
2024-04-16 12:24:19 -07:00
Kazu Hirata
c9731a3dcc [mlir] Fix a warning about an extraneous semicolon
This patch fixes:

  mlir/lib/Dialect/XeGPU/IR/XeGPUOps.cpp:58:2: error: extra ';'
  outside of a function is incompatible with C++98
  [-Werror,-Wc++98-compat-extra-semi]
2024-04-16 12:10:05 -07:00
Chao Chen
b01879ec1f
[MLIR][XeGPU] Add XeGPU scattered ops (#86594)
- Extended TensorDescAttr with scattered attribute
- Add scattered ops: CreateDescOp, PrefetchOp, LoadGatherOp,
StoreScatterOp, UpdateOffsetOp
- Add a block op: UpdateNdOffsetOp

---------

Co-authored-by: Mehdi Amini <joker.eph@gmail.com>
Co-authored-by: Adam Siemieniuk <adam.siemieniuk@intel.com>
2024-04-16 13:44:14 -05:00
Peiming Liu
481bd5d416
[mlir][sparse] introduce sparse_tensor.extract_iteration_space operation. (#88554)
A `sparse_tensor.extract_space %tensor at %iterator` extracts a *sparse*
iteration space defined `%tensor`, the operation to traverse the
iteration space will be introduced in following PRs.
2024-04-16 11:32:30 -07:00
Peiming Liu
b9556532c7
Revert "[mlir][sparse] introduce sparse_tensor.iterate operation" (#88953)
Reverts llvm/llvm-project#88807 (merged by mistake)
2024-04-16 11:31:33 -07:00
Peiming Liu
8debcf03c5
[mlir][sparse] introduce sparse_tensor.iterate operation (#88807)
A `sparse_tensor.iterate` iterates over a sparse iteration space
extracted from `sparse_tensor.extract_iteration_space` operation
introduced in https://github.com/llvm/llvm-project/pull/88554.

*DO NOT MERGE* before https://github.com/llvm/llvm-project/pull/88554
2024-04-16 11:31:09 -07:00
Jeremy Kun
5a34ff12b8
fix Polynomial.td doc filename (#88900)
Not sure how best to test this, but I think it fixes the error
https://github.com/llvm/mlir-www/actions/runs/8699908058/job/23859264085#step:7:1111

Co-authored-by: Jeremy Kun <j2kun@users.noreply.github.com>
Co-authored-by: Jacques Pienaar <jpienaar@google.com>
2024-04-16 07:35:36 -07:00
Spenser Bauman
1c076b43c2
[mlir][tosa] Implement dynamic shape support for tosa.max_pool2d lowering (#87538)
The existing lowering for tosa.max_pool2d only supports dynamic
dimensions when the dynamic dimension is the batch dimension. This
change updates the lowering to support arbitrary dynamic dimensions on
the inputs and outputs of the tosa.max_pool2d operation.

This change also fixes a bug in the implementation of implicit
broadcasting in the tosa-to-linalg pass, which was introducing uses of
constant ops that violated dominance requirements.
2024-04-16 08:14:22 -04:00
Frederik Harwath
ac1f2de7b5
[MLIR][docs] Mention declarePromisedInterface in Interfaces doc (#88689)
Co-authored-by: Frederik Harwath <fharwath@amd.com>
Co-authored-by: Mehdi Amini <joker.eph@gmail.com>
2024-04-16 14:09:25 +02:00
Andrzej Warzyński
711df7b0ae
[vector][mlir] Restrict vector.shuffle to fixed-width vectors (#88733)
At the moment there is no support for vector.shuffle for scalable
vectors - various hooks/helpers related to `vector.shuffle` simply
ignore the scalable flags (e.g. ` ShuffleOp::inferReturnTypes`).

This is unlikely to change any time soon (vector shuffles are known to
be tricky for scalable vectors), hence this patch restricts
`vector.shuffle` to fixed width vectors.
2024-04-16 12:57:59 +01:00
Benjamin Maxwell
dadcaf8227
[mlir][ArmSME] Support decomposing constant splats into ArmSME tiles (#88762)
This adds a simple rewrite/legalization to decompose constant splats
larger than a single ArmSME tile into multiple SME virtual tile sized
splats. E.g. a constant splat to `vector<[8]x[8]xi32>` would decompose
into four `vector<[4]x[4]xi32>` splats.
2024-04-16 12:54:01 +01:00
Jon Chesterfield
ac6b4c618a Reapply "[Verifier] Reject va_start in non-variadic function (#88809)"
This reverts commit f4960da6023b8034ae68925c3223d51624621b37.
Includes a fix for the MLIR test case.
2024-04-16 12:26:08 +01:00
Sergio Afonso
aae08f4f8e
[MLIR][OpenMP] Make omp.taskloop into a loop wrapper (#87253)
This patch updates the definition of `omp.taskloop` to enforce the
restrictions of a wrapper operation.
2024-04-16 10:40:46 +01:00
Ivan Butygin
1ca6b4475c
[mlir][scf] scf.while uplifting: optimize op matching (#88813)
Instead of iterating over potential induction var uses looking for
suitable `arith.addi`, try to trace it back from yield argument.
2024-04-16 12:39:57 +03:00
Sergio Afonso
70fe6ad535
[MLIR][OpenMP] Make omp.distribute into a loop wrapper (#87239)
This patch updates the definition of `omp.distribute` to enforce the
restrictions of a wrapper operation.
2024-04-16 10:24:23 +01:00
Jie Fu
cce026bf8f [mlir][test] Fix -Wsign-compare in TestDialect.cpp (NFC)
llvm-project/mlir/test/lib/Dialect/Test/TestDialect.cpp:597:31:
error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int64_t' (aka 'long') [-Werror,-Wsign-compare]
  if (getVarOperands().size() != expectedNumOperands)
      ~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~~~~~~~~~~~~~~~~~~
1 error generated.
2024-04-16 17:19:45 +08:00
Matthias Springer
40dd3aa91d
[mlir][Interfaces] Variable abstraction for ValueBoundsOpInterface (#87980)
This commit generalizes and cleans up the `ValueBoundsConstraintSet`
API. The API used to provide function overloads for comparing/computing
bounds of:
- index-typed SSA value
- dimension of shaped value
- affine map + operands

This commit removes all overloads. There is now a single entry point for
each `compare` variant and each `computeBound` variant. These functions
now take a `Variable`, which is internally represented as an affine map
and map operands.

This commit also adds support for computing bounds for an affine map +
operands. There was previously no public API for that.
2024-04-16 10:59:02 +02:00
Fr4nk1in
6d234638f9
[docs][mlir] Fix broken links in 'llvm' dialects. (#88704)
Links to `llvm.mlir.global` and `llvm.mlir.addressof` in the ["Globals"
section of LLVM dialect
documentation](https://mlir.llvm.org/docs/Dialects/LLVM/#globals) are
broken.
2024-04-16 00:13:38 +02:00
Ivan Butygin
b153c05cba
[mlir][scf] Uplift scf.while to scf.for (#76108)
Add uplifting from `scf.while` to `scf.for`.

This uplifting expects a very specific ops pattern:
* `before` block consisting of single `arith.cmp` op
* `after` block containing `arith.addi`

We also have a set of patterns to cleanup `scf.while` loops to get them
close to the desired form, they will be added in separate PRs.

This is part of upstreaming `numba-mlir` scf uplifting pipeline: `cf ->
scf.while -> scf.for -> scf.parallel`

Original code:
https://github.com/numba/numba-mlir/blob/main/mlir/lib/Transforms/PromoteToParallel.cpp
2024-04-15 22:16:59 +03:00
Hsiangkai Wang
9dbb6e1978
[mlir][spirv] Add target width to SPIR-V ABI (#88555)
There are execution modes need target width as their extra operands.
SignedZeroInfNanPreserve is one of them. This patch adds `target width`
as one of SPIR-V ABI attributes.
2024-04-15 17:59:17 +01:00
Matthias Springer
f8d314f0ee
[mlir][Interfaces][NFC] Add TableGen test op for value bounds tests (#88717)
This commit is a code cleanup. It defines the test ops the are used for
the `ValueBoundsOpInterface` tests in TableGen, along with proper
verifiers.

---------

Co-authored-by: Benjamin Maxwell <benjamin.maxwell@arm.com>
2024-04-15 18:14:18 +02:00
Jeremy Kun
55b6f17071
Add a polynomial dialect shell, attributes, and types (#72081)
RFC:
https://discourse.llvm.org/t/rfc-a-poly-dialect-for-polynomial-arithmetic/73891

This PR implements the minimal work needed to represent the polynomial
type such that it can be tested with `lit`.

In this PR:

- Dialect shell
- `Polynomial` data structure needed for folding
- Polynomial attributes (`PolynomialAttr` and `RingAttr` which store a polynomial)
- `polynomial.polynomial` type
- Basic lit tests

---------

Co-authored-by: Jeremy Kun <j2kun@users.noreply.github.com>
2024-04-15 09:12:00 -07:00
Johannes Reifferscheid
9da0ef165e
Fix complex tanh overflows. (#88708)
This ports the XLA lowering and was verified using XLA's
exhaustive_unary_test_complex test.
2024-04-15 13:13:01 +02:00
Markus Böck
5b95c9e0ca
[mlir][ODS] Make prop-dict behave closer to attr-dict (#88659)
`attr-dict` currently prints any attribute (inherent or discardable)
that does not occur elsewhere in the assembly format. `prop-dict` on the
other hand, always prints and parses all properties (including inherent
attributes stored as properties) as part of the property dictionary,
regardless of whether the properties or attributes are used elsewhere.
(with the exception of default-valued attributes implemented recently in
https://github.com/llvm/llvm-project/pull/87970).

This PR changes the behavior of `prop-dict` to only print and parse
attributes and properties that do not occur elsewhere in the assembly
format. This is achieved by 1) adding used attributes and properties to
the elision list when printing and 2) using a custom version of
`setPropertiesFromAttr` called `setPropertiesFromParsedAttr` that is
sensitive to the assembly format and auto-generated by ODS.

The current and new behavior of `prop-dict` and `attr-dict` were also
documented.

Happens to also fix https://github.com/llvm/llvm-project/issues/88506
2024-04-15 12:13:06 +02:00
Johannes Reifferscheid
33e60f358c
Fix rsqrt inaccuracies. (#88707)
The current lowering has issues with large/subnormal values. This po
XLA's lowering and was verified using XLA's test suite and the
MLIR-based emitters.

This updates https://github.com/llvm/llvm-project/pull/88691 to also
update the correctness test for rsqrt(0). I checked C++ and Python, they
both agree the result should be (inf, nan). Updated the correctness test
to match this.
2024-04-15 12:04:36 +02:00
Johannes Reifferscheid
b4e7b56403
Revert "Fix rsqrt inaccuracies." (#88705)
Reverts llvm/llvm-project#88691
2024-04-15 11:48:22 +02:00
Sergio Afonso
f2923e31b6
[MLIR][OpenMP] Introduce the LoopWrapperInterface (#87232)
This patch defines a common interface to be shared by all OpenMP loop
wrapper operations. The main restrictions these operations must meet in
order to be considered a wrapper are:

- They contain a single region.
- Their region contains a single block.
- Their block only contains another loop wrapper or `omp.loop_nest` and
a terminator.

The new interface is attached to the `omp.parallel`, `omp.wsloop`,
`omp.simdloop`, `omp.distribute` and `omp.taskloop` operations. It is
not currently enforced that these operations meet the wrapper
restrictions, which would break existing OpenMP loop-generating code.
Rather, this will be introduced progressively in subsequent patches.
2024-04-15 10:33:54 +01:00
Johannes Reifferscheid
8ddaf75074
Fix rsqrt inaccuracies. (#88691)
The current lowering has issues with large/subnormal values. This ports
XLA's lowering and was verified using XLA's test suite and the
MLIR-based emitters.
2024-04-15 11:24:00 +02:00
Billy Zhu
9c3475acc9
[MLIR][LLVM] Fix recursive DI type export memory leak (#88122)
Followup to discussion
https://github.com/llvm/llvm-project/pull/87295#discussion_r1556016667.

The export cache should not cache temporary nodes.
2024-04-14 19:17:20 -07:00
Jacques Pienaar
3c4d955949
[mlir] Add lib to tests for shared build (#88574)
These resulted in link failures:

```
/usr/bin/ld:
tools/mlir/test/CAPI/CMakeFiles/mlir-capi-translation-test.dir/translation.c.o:
in function `main':
translation.c:(.text.main+0x58): undefined reference to
`LLVMContextCreate'
/usr/bin/ld: translation.c:(.text.main+0x9b): undefined reference to
`LLVMDumpModule'
/usr/bin/ld: translation.c:(.text.main+0xa3): undefined reference to
`LLVMDisposeModule'
/usr/bin/ld: translation.c:(.text.main+0xb3): undefined reference to
`LLVMContextDispose'
```

Found in mlir-hs. Not sure why this hasn't been flagged elsewhere.
2024-04-14 06:36:40 -07:00
Kai Sasaki
8891fd5acb
[mlir][complex] Fastmath flag support for complex.tanh (#88571) 2024-04-14 19:52:03 +09:00
Hsiangkai Wang
8d8502a1b6
[mlir][spirv] Add op decoration NoContraction (#88578) 2024-04-13 07:00:46 +01:00
Kunwar Grover
6f1e23b47d
[MLIR][Bufferization] Choose default memory space in tensor copy insertion (#88500)
Tensor copy insertion currently uses memory_space = 0 when creating a
tensor copy using alloc_tensor. This memory space should instead be the
default memory space provided in bufferization options.
2024-04-12 17:56:46 +02:00
Sergio Afonso
78eac46609
[Flang][OpenMP][Lower] Use clause operand structures (#86802)
This patch updates Flang lowering to use the new set of OpenMP clause
operand structures and their groupings into directive-specific sets of
clause operands.

It simplifies the passing of information from the clause processor and
the creation of operations.

The `DataSharingProcessor` is slightly modified to not hold delayed
privatization state. Instead, optional arguments are added to
`processStep1` which are only passed when delayed privatization is used.
This enables using the clause operand structure for `private` and
removes the need for the ad-hoc `DelayedPrivatizationInfo` structure.

The processing of the `schedule` clause is updated to process the
`chunk` modifier rather than requiring two separate calls to the
`ClauseProcessor`.

Lowering of a block-associated `ordered` construct is updated to emit a
TODO error if the `simd` clause is specified, since it is not currently
supported by the `ClauseProcessor` or later compilation stages.

Removed processing of `schedule` from `omp.simdloop`, as it doesn't
apply to `simd` constructs.
2024-04-12 12:42:41 +01:00
Sergio Afonso
0e63672364
[MLIR][OpenMP] Add omp.loop_nest operation (#87083)
This patch introduces an operation intended to hold loop information
associated to the `omp.distribute`, `omp.simdloop`, `omp.taskloop` and
`omp.wsloop` operations. This is a stopgap solution to unblock work on
transitioning these operations to becoming wrappers, as discussed in
[this
RFC](https://discourse.llvm.org/t/rfc-representing-combined-composite-constructs-in-the-openmp-dialect/76986).

Long-term, this operation will likely be replaced by
`omp.canonical_loop`, which is being designed to address missing support
for loop transformations, etc.
2024-04-12 10:35:48 +01:00
Beal Wang
d488b2225d
[mlir][ods] Do not print default-valued properties when the value is equal to the default (#87970)
This diff causes the `tblgen`-erated printProperties() function to skip
printing a `DefaultValuedAttr` property when the value is equal to the
default.

Co-authored-by: Biao Wang <biaow@nvidia.com>
2024-04-12 10:37:50 +02:00
Johannes Reifferscheid
ff9bc3a0fa
Fix overflows in complex sqrt lowering. (#88480)
This ports XLA's complex sqrt lowering. The accuracy was tested with its
exhaustive_unary_test_complex test.

Note: rsqrt is still broken.
2024-04-12 09:42:04 +02:00
pawelszczerbuk
56954a53e5
[MLIR][LoopPipelining] Improve schedule verifier, so it checks also operands of nested operations (#88450)
`verifySchedule` was not looking at the operands of nested operations,
which caused incorrect schedule to be allowed in some cases, potentially
leading to crash during expansion.
There is also minor fix in `cloneAndUpdateOperands` in the pipeline
expander that prevents double visit of the cloned op. This one has no
functional impact, so no test for it.
2024-04-11 17:09:44 -07:00
Alexandre Eichenberger
c42a262560
[MLIR] Bug Fix: affine.prefetch replaceAffineOp invoked during canonicalization (#88346)
Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>
2024-04-11 20:04:26 -04:00
Peiming Liu
62fa12ad24
[mlir][sparse] support querying sparse buffer types from sparse tenso… (#88308)
…r encodings.
2024-04-11 10:26:03 -07:00
Aart Bik
5122a2c232
[mlir][sparse] allow for direct-out passing of sparse tensor buffers (#88327)
In order to support various external frameworks (JAX vs PyTorch) we need
a bit more flexibility in [dis]assembling external buffers to and from
sparse tensors in MLIR land. This PR adds a direct-out option that
avoids the rigid pre-allocated for copy-out semantics.

Note that over time, we expect the [dis]assemble operations to converge
into something that supports all sorts of external frameworks. Until
then, this option helps in experimenting with different options.
2024-04-11 10:07:24 -07:00
Raghu Maddhipatla
298ea9bfd5
[Flang] [OpenMP] [MLIR] [Lowering] Add lowering support for IS_DEVICE_PTR and HAS_DEVICE_ADDR clauses on OMP TARGET directive. (#88206)
Added lowering support for IS_DEVICE_PTR and HAS_DEVICE_ADDR clauses for
OMP TARGET directive and added related tests for these changes.

IS_DEVICE_PTR and HAS_DEVICE_ADDR clauses apply to OMP TARGET directive
OpenMP spec states

The **is_device_ptr** clause indicates that its list items are device
pointers.

The **has_device_addr** clause indicates that its list items already
have device addresses and therefore they may be directly accessed from a
target device.

Whereas USE_DEVICE_PTR and USE_DEVICE_ADDR clauses apply to OMP TARGET
DATA directive and OpenMP spec for them states

Each list item in the **use_device_ptr** clause results in a new list
item that is a device pointer that refers to a device address

Each list item in a **use_device_addr** clause that is present in the
device data environment is treated as if it is implicitly mapped by a
map clause on the construct with a map-type of alloc

Fixed build error caused by Squash merge which needs rebase
2024-04-11 10:26:54 -05:00
Jakub Kuderski
44718311de
[mlir][amdgpu] Remove shared memory optimization pass (#88225)
This implementation has a number of issues and ultimately does not work
on gfx9.
* It does not reduce bank conflicts with wide memory accesses.
* It does not correctly account for when LDS bank conflicts occur on
amdgpu.
* The implementation is too fragile to be used on real-world code. For
example, the code bails out on any `memref.subview` in the root op, even
when the subview is not a user of any of the `memref.alloc` ops.

I do not see how these can be easily fixed, therefore I think it's
better to delete this code.
2024-04-11 11:07:17 -04:00
Johannes Reifferscheid
77dd43570b
Fix complex power for large inputs. (#88387)
For example, 1e30^1.2 currently overflows.

Also forward fastmath flags.

This ports XLA's logic and was verified with its test suite. Note that
rsqrt and sqrt are still broken.
2024-04-11 15:08:54 +02:00
Johannes Reifferscheid
9d9bb7b1b6
Fix complex abs corner cases. (#88373)
The current implementation fails for very small and very large values.
For example, (0, -inf) should return inf, but it returns -inf.

This ports the logic used in XLA. Tested with XLA's
exhaustive_binary_test_f32_f64.
2024-04-11 12:57:46 +02:00
Adrian Kuegel
962534c4b4 [mlir] Apply ClangTidy BugProne patch
This time for real.
2024-04-11 10:28:10 +00:00
Adrian Kuegel
a8b461603b [mlir] Apply ClangTidy BugProne fix
forwarding reference passed to std::move(), which may unexpectedly cause
lvalues to be moved; use std::forward() instead.
2024-04-11 10:25:53 +00:00