Commit Graph

17205 Commits

Author SHA1 Message Date
Felix Schneider
8d5c1b4562 [mlir][CRunnerUtils] Fix iterators accessing MemRefs with non-zero offset
MemRef descriptors contain - among others - a field called `alignedPtr` or `data` and a field called `offset`. The actual buffer of the MemRef starts at `offset` elements after `alignedPtr`. In the CRunnerUtils, there exist helper classes to iterate over MemRefs' elements but the `offset` is not handled consistently so that accessing a MemRef with an `offset` != 0 via an iterator will lead to incorrect results.

The problem is that "offset" can be understood in two ways, firstly as the offset of the beginning of the MemRef with respect to the `alignedPtr`, ie what the `offset` field means in the MemRef descriptor, and secondly as the offset of some element within the MemRef relative to the first element of the MemRef, which could more accurately be called something like `linearIndex`.

The `offset` field within `StridedMemRefIterator` and `DynamicMemRefIterator` are interpreted the first way, therefore the offsets passed to the constructors of these classes need to account for the already existing offset in the descriptor on top of any potential "shift" within the MemRef.
This patch takes care of that and adds some basic tests that catch problems with indexing MemRefs with an `offset`.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D157008
2023-09-14 13:14:13 +02:00
Felix Schneider
55088efe06 [mlir][memref] Fix MemrefToLLVM lowering pattern for memref.transpose
The lowering pattern to LLVM for memref.transpose has a bug where
instead of transposing from (source) -> (dest) it actually transposes
(dest) -> (source). This patch fixes the bug and updates the test.

Fix https://github.com/llvm/llvm-project/issues/65145

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D159290
2023-09-14 13:12:55 +02:00
Martin Erhart
01334d1abb
[mlir][bufferization] Add an ownership based buffer deallocation pass (#66337)
Add a new Buffer Deallocation pass with the intend to replace the old
one. For now it is added as a separate pass alongside in order to allow
downstream users to migrate over gradually. This new pass has the goal
of inserting fewer clone operations and supporting additional use-cases.
Please refer to the Buffer Deallocation section in the updated
Bufferization.md file for more information on how this new pass works.
2023-09-14 12:13:37 +02:00
Sergio Afonso
9058762789
[OpenMP][Flang][MLIR] Lowering of requires directive from MLIR to LLVM IR
Default atomic ordering information is processed in the OpenMP dialect
to LLVM IR lowering stage at every spot where an operation can be
affected by it. The rest of clauses are stored globally in the
OpenMPIRBuilderConfig object before starting that lowering stage, so
that the OMPIRBuilder can conditionally modify code generation
depending on these. At the end of the process, the omp.requires
attribute is itself lowered into a global constructor that passes these
clauses as flags to the OpenMP runtime.

Depends on D147217, D147218 and D158278.

Differential Revision: https://reviews.llvm.org/D147219
2023-09-14 10:35:44 +01:00
Sergio Afonso
094a63a20b
[OpenMP][OMPIRBuilder] OpenMPIRBuilder support for requires directive
This patch updates the `OpenMPIRBuilderConfig` structure to hold all
available 'requires' clauses, and it replicates part of the code
generation for the 'requires' registration function from clang in the
`OMPIRBuilder`, to be used with flang.

Porting the rest of features of the clang implementation to the IRBuilder
and sharing it between clang and flang remains for a future patch, due to the
complexity of the logic selecting the attributes of the generated
registration function.

Differential Revision: https://reviews.llvm.org/D147217
2023-09-14 10:33:54 +01:00
vic
a9d0f5e2f0
[mlir] Allow loop-like operations in AbstractDenseForwardDataFlowAnalysis (#66179)
Remove assertion violated by loop-like operations.

Signed-off-by: Victor Perez <victor.perez@codeplay.com>
2023-09-14 10:30:40 +02:00
Matthias Springer
a1ef5a9437
[mlir][bufferization] Empty tensor elimination based on SubsetOpInterface (#65766)
This commit generalizes empty tensor elimination to operate on subset
ops. No new test cases are added because all current subset ops were
already supported previously. From this perspective, this change is NFC.

A new interface method (and a helper method) are added to
`SubsetInsertionOpInterface` to build the subset of the destination
tensor.
2023-09-14 09:45:22 +02:00
Cullen Rhodes
f75d46a7ec
[mlir][ArmSME] Lower vector.outerproduct to FMOPA/BFMOPA (#65621)
This patch adds support for lowering vector.outerproduct to the ArmSME
MOPA intrinsic for the following types:

  vector<[8]xf16>,  vector<[8]xf16>  -> vector<[8]x[8]xf16>
  vector<[8]xbf16>, vector<[8]xbf16> -> vector<[8]x[8]xbf16>
  vector<[4]xf32>,  vector<[4]xf32>  -> vector<[4]x[4]xf32>
  vector<[2]xf64>,  vector<[2]xf64>  -> vector<[2]x[2]xf64>

The FP variants are lowered to FMOPA (non-widening) [1] and BFloat to
BFMOPA
(non-widening) [2].

Note at the ISA level these variants are implemented by different
architecture features, these are listed below:

  FMOPA (non-widening)
    * half-precision   - +sme2p1,+sme-f16f16
    * single-precision - +sme
    * double-precision - +sme-f64f64
  BFMOPA (non-widening)
    * half-precision   - +sme2p1,+b16b16

There's currently no way to target different features when lowering to
ArmSME. Integration tests are added for F32 and F64. We use QEMU to run
the integration tests but SME2 support isn't available yet, it's
targeted for 9.0, so integration tests for these variants excluded.

Masking is currently unsupported.

Depends on #65450.

[1] https://developer.arm.com/documentation/ddi0602/2023-06/SME-Instructions/FMOPA--non-widening---Floating-point-outer-product-and-accumulate-
[2] https://developer.arm.com/documentation/ddi0602/2023-06/SME-Instructions/BFMOPA--non-widening---BFloat16-floating-point-outer-product-and-accumulate-
2023-09-14 08:31:52 +01:00
Aart Bik
0f65df732c
[mlir][sparse] remove the MLIR PyTACO tests (#66302)
Rationale:

This test was really fun to compare the MLIR sparsifier with TACO using
the PyTACO format. However, the underlying mechanism is rapidly growing
outdated with our recent developments. Rather than maintaining the old
code, we are moving toward the newer, better approaches. So if you are
sad this is gone, stay tuned, something better is coming!
2023-09-13 15:54:49 -07:00
Daniil Dudkin
8f5d519458 [mlir][vector] Implement Workaround Lowerings for Masked fm**imum Reductions
This patch is part of a larger initiative aimed at fixing floating-point `max` and `min` operations in MLIR: https://discourse.llvm.org/t/rfc-fix-floating-point-max-and-min-operations-in-mlir/72671.

Within LLVM, there are no masked reduction counterparts for vector reductions such as `fmaximum` and `fminimum`.
More information can be found here: https://github.com/llvm/llvm-project/issues/64940#issuecomment-1690694156.

To address this issue in MLIR, where we need to generate appropriate lowerings for these cases, we employ regular non-masked intrinsics.
However, we modify the input vector using the `arith.select` operation to effectively deactivate undesired elements using a "neutral mask value".
The neutral mask value is the smallest possible value for the `fmaximum` reduction and the largest possible value for the `fminimum` reduction.

Depends on D158618

Reviewed By: dcaballe

Differential Revision: https://reviews.llvm.org/D158773
2023-09-13 22:49:08 +00:00
Daniil Dudkin
709b27427b [mlir][vector] Bring back maxf/minf reductions
This patch is part of a larger initiative aimed at fixing floating-point `max` and `min` operations in MLIR: https://discourse.llvm.org/t/rfc-fix-floating-point-max-and-min-operations-in-mlir/72671.

In line with the mentioned RFC, this patch  tackles tasks 2.3 and 2.4.
It adds LLVM conversions for the `maxf`/`minf` reductions to the non-NaN-propagating LLVM intrinsics.

Depends on D158618

Reviewed By: dcaballe

Differential Revision: https://reviews.llvm.org/D158659
2023-09-13 22:49:07 +00:00
Daniil Dudkin
4a831250b8 [mlir][vector] Rename vector reductions: maxfmaximumf, minfminimumf
This patch is part of a larger initiative aimed at fixing floating-point `max` and `min` operations in MLIR: https://discourse.llvm.org/t/rfc-fix-floating-point-max-and-min-operations-in-mlir/72671.

Here, we are addressing task 2.1 from the plan, which involves renaming the vector reductions to align with the semantics of the corresponding LLVM intrinsics.

Reviewed By: dcaballe

Differential Revision: https://reviews.llvm.org/D158618
2023-09-13 22:49:07 +00:00
Aart Bik
9918d2556c
[mlir][sparse] remove sparse output python example (#66298)
Rationale:
This was actually just a pure "string based" test
with very little actual python usage. The output
sparse tensor was handled via the deprecated
convertFromMLIRSparseTensor method.
2023-09-13 15:11:35 -07:00
Daniil Dudkin
c46a04339a
[mlir][arith] Rename AtomicRMWKind's maxfmaximumf, minfminimumf (#66135)
This patch is part of a larger initiative aimed at fixing floating-point
`max` and `min` operations in MLIR:
https://discourse.llvm.org/t/rfc-fix-floating-point-max-and-min-operations-in-mlir/72671.

This commit renames `maxf` and `minf` enumerators of `AtomicRMWKind`
to better reflect the current naming scheme and the goals of the RFC.
2023-09-14 01:09:37 +03:00
Aart Bik
2505904901
[mlir][sparse] fix typo in sparse_tensor.unpack op (#66287)
SparseVector->COO
2023-09-13 14:51:03 -07:00
Markus Böck
be59265bbd
[mlir] Make extraClassOf compile with attribute and type interfaces (#66292)
Using `extraClassOf` currently does not work with attribute or type
interfaces as the generated code calls `getInterfaceFor`, a private
method of `AttributeInterface` and `TypeInterface` respectively.

This PR fixes this by applying the same change that has been done to
`OpInterface` in the past: Make `getInterfaceFor` a protected member of
the class, allowing the generated code in subclasses to use it.

An attribute and type interface with `extraClassOf` have been added as
interfaces in the test dialect to ensure it compiles without errors.
2023-09-13 23:38:39 +02:00
Jakub Kuderski
d6d4a526f4
[mlir][spirv][gpu] Clean up wmma to coop matrix NV conversion. NFC. (#66278)
This is a cleanup in preparation for adding a second conversion path
using the KHR cooperative matrix extension.

Make the existing lowering explicit about emitting ops from the NV coop
matrix extension. Clean up surrounding code.
2023-09-13 15:51:26 -04:00
Peiming Liu
098f46dce3
[sparse] allow unpack op to return 0-ranked tensor type. (#66269)
Many frontends canonicalize scalar into 0-ranked tensor, it change will
hopefully make the operation easier to use for those cases.
2023-09-13 11:33:01 -07:00
frgossen
1cddbf8cf5
Revert Add host-supports-nvptx requirement to lit tests (#66102 and #66129) (#66225) 2023-09-13 12:20:38 -04:00
Krzysztof Drewniak
df852599f3 [mlir] Split up VectorToLLVM pass
Currently, the VectorToLLVM patterns are built into a library along
with the corresponding pass, which also pulls in all the
platform-specific vector dialects (like AMXDialect) to apply all the
vector to LLVM conversions.

This causes dependency bloat when writing libraries - for example the
GPU to LLVM passes, which use the vector to LLVM patterns, don't need
the X86Vector dialect to be present at all.

This commit partitions the library into VectorToLLVM and
VectorToLLVMPass, where the latter pulls in all the other vector
transformations.

Reviewed By: nicolasvasilache, mehdi_amini

Differential Revision: https://reviews.llvm.org/D158287
2023-09-13 16:09:56 +00:00
Krzysztof Drewniak
ba6d7a0f25 [mlir][AMDGPU] Add gfx941 to buffer atomics emulation
Reviewed By: fmorac

Differential Revision: https://reviews.llvm.org/D152299
2023-09-13 16:07:07 +00:00
Yinying Li
dbe1be9aa4
[mlir][sparse] Migrate tests to use new syntax (#66146)
lvlTypes = [ "compressed" ] to map = (d0) -> (d0 : compressed)
lvlTypes = [ "dense" ] to map = (d0) -> (d0 : dense)
2023-09-13 11:41:25 -04:00
lorenzo chelini
d65885ae63
[MLIR][Linalg] Bail out if the tiles provided are more than the number (#66007)
Currently, the compiler crashes if the number of tiles provided exceeds
the number of loops.
2023-09-13 10:41:03 -04:00
Martin Erhart
c199f7dc62 Revert "[mlir][bufferization] Remove allow-return-allocs and create-deallocs pass options, remove bufferization.escape attribute"
This reverts commit 6a91dfedeb.

This caused problems in downstream projects. We are reverting to give
them more time for integration.
2023-09-13 13:53:48 +00:00
Martin Erhart
94c8faeaff Revert "[mlir][bufferization] Update linalg integration tests to lower ops created by bufferization-to-memref pass"
This reverts commit 6f35401f86.

This caused problems in downstream projects. We are reverting to give
them more time for integration.
2023-09-13 13:53:48 +00:00
Martin Erhart
520407a7c8 Revert "[mlir][bufferization] Improve buffer deallocation pass"
This reverts commit 1bebb60a75.

This caused problems in downstream projects. We are reverting to give
them more time for integration.
2023-09-13 13:53:48 +00:00
Martin Erhart
792caac0f8 Revert "[mlir][bufferization][NFC] Introduce BufferDeallocationOpInterface"
This reverts commit 29d86175e6.

This caused problems in downstream projects. We are reverting to give
them more time for integration.
2023-09-13 13:53:47 +00:00
Martin Erhart
9782232ec7 Revert "[mlir][bufferization] BufferDeallocationOpInterface: support custom ownership update logic"
This reverts commit 89117f1807.

This caused problems in downstream projects. We are reverting to give
them more time for integration.
2023-09-13 13:53:47 +00:00
Martin Erhart
ccb16acd46 Revert "[mlir][bufferization] Implement BufferDeallocationopInterface for scf.forall.in_parallel"
This reverts commit 1356e853d4.

This caused problems in downstream projects. We are reverting to give
them more time for integration.
2023-09-13 13:53:47 +00:00
Martin Erhart
7995a4701d Revert "[mlir][bufferization] Define a pipeline for buffer deallocation"
This reverts commit f0c4663942.

This caused problems in downstream projects. We are reverting to give
them more time for integration.
2023-09-13 13:53:47 +00:00
Martin Erhart
99cd1e7004 Revert "[mlir][bufferization] Remove unused function"
This reverts commit cb5fe6ce75.

This caused problems in downstream projects. We are reverting to give
them more time for integration.
2023-09-13 13:53:47 +00:00
Guray Ozen
ba81cd10d6
[MLIR] Fix the tma_load test (#66208)
clang was used for local testing. The PR changes it to `mlir-cpu-runner`
2023-09-13 15:33:42 +02:00
Guray Ozen
38faecc692
[MLIR] SM_90 integration test of TMA with 128b Swizzling (#65953)
An integration test for the 128b Swizzling TMA.

TMA with 128B Swizzle loads data as follows (each numbered cell is 16
bytes). The program tests this pattern for `128x64xf16` type.

```
|-------------------------------|
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 1 | 0 | 3 | 2 | 5 | 4 | 7 | 6 |
| 2 | 3 | 0 | 1 | 6 | 7 | 4 | 5 |
| 3 | 2 | 1 | 0 | 7 | 6 | 5 | 4 |
| 4 | 5 | 6 | 7 | 0 | 1 | 2 | 3 |
| 5 | 4 | 7 | 6 | 1 | 0 | 3 | 2 |
| 6 | 7 | 4 | 5 | 2 | 3 | 0 | 1 |
|-------------------------------|
| ... pattern repeats ...       |
|-------------------------------|
```
2023-09-13 15:22:48 +02:00
Guray Ozen
6360d09531
[MLIR][NVVM] Fix the register number of predicate (#65970)
The register number of predicate is calculated incorrectly. This PR
fixes that.
2023-09-13 15:04:31 +02:00
David Truby
a6857156df
[mlir] Add pass to add comdat to all linkonce functions (#65270)
This adds a new pass to add an Any comdat to each linkonce
and linkonce_odr function in the LLVM dialect. These comdats are
necessary on Windows
to allow the default system linker to link binaries containing these
functions.
2023-09-13 13:05:05 +01:00
Matthias Springer
076e238c2c
[mlir][IR] SingleBlockImplicitTerminator derives from TraitBase (#66189)
This was an oversight in 0ac21e654f.
2023-09-13 13:34:50 +02:00
Matthias Springer
8143307b33
[mlir][bufferization] Generalize tensor slice rules to subset ops (#65619)
This commit generalizes the special
tensor.extract_slice/tensor.insert_slice bufferization rules to tensor
subset ops.

Ops that insert a tensor into a tensor at a specified subset (e.g.,
tensor.insert_slice, tensor.scatter) can implement the
`SubsetInsertionOpInterface`.

Apart from adding a new op interface (extending the API), this change is
NFC. The only ops that currently implement the new interface are
tensor.insert_slice and tensor.parallel_insert_slice, and those ops were
are supported by One-Shot Bufferize.
2023-09-13 12:27:19 +02:00
Martin Erhart
cb5fe6ce75 [mlir][bufferization] Remove unused function 2023-09-13 09:30:24 +00:00
Martin Erhart
f0c4663942 [mlir][bufferization] Define a pipeline for buffer deallocation
Since buffer deallocation requires a few passes to be run in a somewhat fixed
sequence, it makes sense to have a pipeline for convenience (and to reduce the
number of transform ops to represent default deallocation).

Reviewed By: springerm

Differential Revision: https://reviews.llvm.org/D159432
2023-09-13 09:30:24 +00:00
Martin Erhart
1356e853d4 [mlir][bufferization] Implement BufferDeallocationopInterface for scf.forall.in_parallel
The scf.forall.in_parallel terminator operation has a nested graph region with
the NoTerminator trait. Such regions are not supported by the default
implementations. Therefore, this commit adds a specialized implementation for
this operation which only covers the case where the nested region is empty.
This is because after bufferization, ops like tensor.parallel_insert_slice were
already converted to memref operations residing int the scf.forall only and the
nested region of scf.forall.in_parallel ends up empty.

Reviewed By: springerm

Differential Revision: https://reviews.llvm.org/D158979
2023-09-13 09:30:24 +00:00
Martin Erhart
89117f1807 [mlir][bufferization] BufferDeallocationOpInterface: support custom ownership update logic
Add a method to the BufferDeallocationOpInterface that allows operations to
implement the interface and provide custom logic to compute the ownership
indicators of values it defines. As a demonstrating example, this new method is
implemented by the `arith.select` operation.

Reviewed By: springerm

Differential Revision: https://reviews.llvm.org/D158828
2023-09-13 09:30:23 +00:00
Martin Erhart
29d86175e6 [mlir][bufferization][NFC] Introduce BufferDeallocationOpInterface
This new interface allows operations to implement custom handling of ownership
values and insertion of dealloc operations which is useful when an op cannot
implement the interfaces supported by default by the buffer deallocation pass
(e.g., because they are not exactly compatible or because there are some
additional semantics to it that would render the default implementations in
buffer deallocation invalid, or because no interfaces exist for this kind of
behavior and it's not worth introducing one plus a default implementation in
buffer deallocation). Additionally, it can also be used to provide more
efficient handling for a specific op than the interface based default
implementations can.

Reviewed By: springerm

Differential Revision: https://reviews.llvm.org/D158756
2023-09-13 09:30:23 +00:00
Martin Erhart
1bebb60a75 [mlir][bufferization] Improve buffer deallocation pass
Add a new Buffer Deallocation pass replacing the old one with the goal of
inserting fewer clone operations and supporting additional use-cases.
Please refer to the Buffer Deallocation section in the updated
Bufferization.md file for more information on how this new pass works.

Reviewed By: springerm

Differential Revision: https://reviews.llvm.org/D158421
2023-09-13 09:30:23 +00:00
Martin Erhart
6f35401f86 [mlir][bufferization] Update linalg integration tests to lower ops created by bufferization-to-memref pass
This commit prepares the linalg integration tests to be run with the new
BufferDeallocation pass which requires the bufferization-to-memref pass
to be run afterwards.
The bufferization-to-memref pass may create ops of the SCF, Func, Arith,
and MemRef dialects. Currently, not all integration tests execute all the
conversion passes necessary to lower these dialects to LLVM.

Reviewed By: springerm

Differential Revision: https://reviews.llvm.org/D156663
2023-09-13 09:30:22 +00:00
Martin Erhart
6a91dfedeb [mlir][bufferization] Remove allow-return-allocs and create-deallocs pass options, remove bufferization.escape attribute
This is the first commit in a series with the goal to rework the
BufferDeallocation pass. Currently, this pass heavily relies on copies
to perform correct deallocations, which leads to very slow code and
potentially high memory usage. Additionally, there are unsupported cases
such as returning memrefs which this series of commits aims to add
support for as well.

This first commit removes the deallocation capabilities of
one-shot-bufferization.One-shot-bufferization should never deallocate any
memrefs as this should be entirely handled by the buffer-deallocation pass
going forward. This means the allow-return-allocs pass option will
default to true now, create-deallocs defaults to false and they, as well
as the escape attribute indicating whether a memref escapes the current region,
will be removed.

The documentation should w.r.t. these pass option changes should also be
updated in this commit.

Reviewed By: springerm

Differential Revision: https://reviews.llvm.org/D156662
2023-09-13 09:30:22 +00:00
Peiming Liu
64df1c08d0
[sparse] allow unpack op to return any integer type. (#66161) 2023-09-12 17:27:51 -07:00
Jakub Kuderski
4c4bdf0c3a
[mlir][spirv] Fix remaining coop matrix verification corner cases (#66137)
- Check `MakePointer*` load/store attribute values.
- Support coop matrix types in `MatrixTimesScalar` verification.
- Add test cases for all the remaining ops that accept coop matrix types.
- Split NV and KHR tests.
2023-09-12 17:04:03 -04:00
Aart Bik
3635c74375
[mlir][gpu][sparse] gracefully accept zero size allocation (#66127)
This cleans up a unnecessary code that changes zero size allocation to
avoid the following error message

'cuMemAlloc(&ptr, sizeBytes)' failed with 'CUDA_ERROR_INVALID_VALUE'
2023-09-12 13:07:24 -07:00
frgossen
1c5161911c
Add host-supports-nvptx requirement to lit tests (#66129) 2023-09-12 15:18:29 -04:00
Yunlong Liu
af562fd27f
Splits cleanup block lowered by AsyncToAsyncRuntime. (#66123)
Splits the cleanup block lowered from AsyncToAsyncRuntime.

The incentive of this change is to clarify the CFG branched by
`async.coro.suspend`.

The `async.coro.suspend` op branches into 3 blocks, depending on the
state of the coroutine:
1) suspend
2) resume
3) cleanup

The behavior before this change is that after the coroutine is resumed
and completed, it will jump to a shared cleanup block for destroying the
states of coroutines. The CFG looks like the following,

Entry block
        |                    \
   resume             |
        |                    |
            Cleanup
                   |
                End

This CFG can potentially be problematic, because the `Cleanup` block is
a shared block and it is not dominated by `resume`. For instance, if
some pass wants to add some specific cleanup mechanism to resume, it can
be confused and add them to the shared `Cleanup`, which leads to the
"operand not dominate its use" error because of the existence of the
other "Entry->cleanup" path.

After this change, the CFG will look like the following,

The overall structure of the lowered CFG can be the following,

  Entry (calling async.coro.suspend)
       |                    \
  Resume           Destroy (duplicate of Cleanup)
       |                     |
  Cleanup             |
       |                    /
     End (ends the corontine)

In this case, the Cleanup block tied to the Resume block will be
isolated from the other path and it is strictly dominated by "Resume".
2023-09-12 11:42:16 -07:00
frgossen
a3b894287f
Add host-supports-nvptx requirement to lit tests (#66102) 2023-09-12 12:21:36 -04:00
Jakub Kuderski
08425def7d
[mlir][spirv] Improve coop matrix attribute handling (#66020)
- Fix values of Matrix Operand bit enums.
- Add verification for the aligned Memory Operand attributes. Mark the
'Aligned' enumerant as not supported.

The target test passes validation with `spirv-val`.
2023-09-12 11:05:08 -04:00
Matthias Springer
91464e1d6a
[mlir][bufferization][NFC] Rename copy_tensor op to materialize_in_destination (#65467)
The previous name was badly chosen. The op is used to ensure that a
computation materializes in the future buffer of a certain tensor.
2023-09-12 15:20:41 +02:00
Andrzej Warzyński
22f96ab6fb
[mlir][vector] Refine vector.transfer_read hoisting/forwarding (#65770)
Make sure that when analysing a `vector.transfer_read` that's a
candidate for either hoisting or store-to-load forwarding,
`memref.collapse_shape` Ops are correctly included in the alias
analysis. This is done by either
* making sure that relevant users are taken into account, or
* source Ops are correctly identified.
2023-09-12 10:33:58 +01:00
Mehdi Amini
6ba42ae0eb
Fix some AffineOps to properly declare their inherent affinemap Attribute (#66050)
This makes it more consistent with properties.
2023-09-12 02:13:50 -07:00
Mehdi Amini
830b9b072d Update some uses of getAttr() to be explicit about Inherent vs Discardable (NFC) 2023-09-12 01:33:47 -07:00
Markus Böck
cedeb31e6d
[mlir] Support null interface to base conversion (#65988)
The current implicit conversion operator from an interface to a "base
interface" of the interface unconditionally calls `this->getImpl()`
which leads to accessing a null pointer if the interface instance is a
null instance.

This PR changes the ODS generated interface instance to explicitly check
and then return a null interface instance if the `this` instance is a
null instance.
2023-09-12 08:42:47 +02:00
Daniil Dudkin
8a6e54c9b3
[mlir][arith] Rename operations: maxfmaximumf, minfminimumf (#65800)
This patch is part of a larger initiative aimed at fixing floating-point `max` and `min` operations in MLIR: https://discourse.llvm.org/t/rfc-fix-floating-point-max-and-min-operations-in-mlir/72671.

This commit addresses Task 1.2 of the mentioned RFC. By renaming these operations, we align their names with LLVM intrinsics that have corresponding semantics.
2023-09-11 22:02:19 -07:00
yinying-lisa-li
c3160f86e7
[mlir][sparse] Fix bug in new syntax parser (#66024)
Currently, dimlvlmap with identity affine map will be treated as empty
affine map. But the new syntax would treat it as an actual identity
affine map such as {d0} -> {d0}. This mismatch could raise an error when
we are comparing sparse encodings.
2023-09-11 19:13:15 -04:00
Stella Laurenzo
7055df7b4f
[mlir] Make it possible to build a DenseResourceElementsAttr from untyped memory. (#66009)
Exposes the existing `get(ShapedType, StringRef, AsmResourceBlob)`
builder publicly (was protected) and adds a CAPI
`mlirUnmanagedDenseBlobResourceElementsAttrGet`.

While such a generic construction interface is a big help when it comes
to interop, it is also necessary for creating resources that don't have
a standard C type (i.e. f16, the f8s, etc).

Previously reviewed/approved as part of https://reviews.llvm.org/D157064
2023-09-11 14:10:03 -07:00
MaheshRavishankar
fd8349cdb3
[mlir][Linalg] Move linalg.fill -> linalg.pack pattern into fill canonicalization patterns. (#66002)
This pattern fits better with the other canonicalization patterns that
exist for `linalg.fill`.
2023-09-11 13:41:38 -07:00
Valentin Clement (バレンタイン クレメン)
996171a412
[mlir][openacc] Model acc cache directive as data entry operands on acc.loop (#65521)
The `cache` directive may appear at the top of (inside of) a loop. It
specifies array elements or subarrays that should be fetched into the
highest level of the cache for the body of the loop.

The `cache` directive is modeled as a data entry operands attached to
the acc.loop operation.
2023-09-11 13:38:03 -07:00
Fabian Mora
1828deb752
[mlir][gpu] Deprecate gpu::Serialization* passes. (#65857)
Deprecate the `gpu-to-cubin` & `gpu-to-hsaco` passes in favor of the
`TargetAttr` workflow. This patch removes remaining upstream uses of the
aforementioned passes, including the option to use them in `mlir-opt`. A
future patch will remove these passes entirely.

The passes can be re-enabled in `mlir-opt` by adding the CMake flag: `-DMLIR_ENABLE_DEPRECATED_GPU_SERIALIZATION=1`.
2023-09-11 16:32:15 -04:00
Mehdi Amini
8c2bff1ab9
Lazy initialize diagnostic when handling MLIR properties (#65868)
Instead of eagerly creating a diagnostic that will be discarded in the
normal case, switch to lazy initialization on error.
2023-09-11 13:22:35 -07:00
Lorenzo Chelini
33deb28006 [MLIR][Linalg] Improve documentation in LinalgInterfaces.td (NFC)
ShapeType::kDynamic -> ShapedType::kDynamic
2023-09-11 19:46:20 +02:00
Benjamin Maxwell
ccef726d09 [mlir][VectorOps] Don't drop scalable dims when lowering transfer_reads/writes (in VectorToLLVM)
This is a follow-on to D158753, and allows the lowering of a
transfer read/write of n-D vectors with a single trailing scalable dimension
to primitive vector ops.

The final conversion to LLVM depends on D158517 and D158752, without
these patches type conversion will fail (or an assert is hit in the LLVM
backend) if the final IR contains an array of scalable vectors.

This patch adds `transform.apply_patterns.vector.lower_create_mask`
which allows the lowering of vector.create_mask/constant_mask to be
tested independently of --convert-vector-to-llvm.

Reviewed By: c-rhodes, awarzynski, dcaballe

Differential Revision: https://reviews.llvm.org/D159482
2023-09-11 16:47:51 +00:00
Jakub Kuderski
1258c3f214
[mlir][spirv] Support spirv.coopmatrix type (de-)serialization (#65831)
Extend SPIR-V target serialization and deserialization to handle coop
matrix types. Add a roundtrip test. In addition to `FileCheck` checks,
the resulting spirv binary also passes `spir-val` (external tool).

Also fix a type attribute bug surfaced by the `CooperativeMatrixLength`
op.

Multiple matrix operand attributes will be handled in a future patch to
reduce the scope.
2023-09-11 12:23:18 -04:00
stefankoncarevic
fbf67bfaf0 [mlir][GPU] Handle LLVM pointer attributes on memref arguments.
Handle pointer attributes (noalias, nonnull, readonly, writeonly,
dereferencable, dereferencable_or_null). "noalias" attribute is
ignore for non-bare pointer.

Reviewed By: krzysz00

Differential Revision: https://reviews.llvm.org/D157082
2023-09-11 15:10:55 +00:00
Matthias Springer
5b96fcb5b8
[mlir][Interfaces][NFC] DestinationStyleOpInterface: Improve documentation (#65927)
Mention that sizes of dynamic dims of tied OpResults/operands match at
runtime.
2023-09-11 15:00:31 +02:00
Martin Lücke
6d2b2b8eaf [MLIR][PDL] Add Bytecode support for negated native constraints
Differential Revision: https://reviews.llvm.org/D153878
2023-09-11 12:57:41 +00:00
Guray Ozen
ad4411230a
[MLIR] Make SM_90 integration tests use TargetAttr (#65926)
The 'TargetAttr' workflow was recently introduced to serialization for
'MLIR->LLVM->PTX'. #65857 removes previous passes (gpu::Serialization*
passes) because they are duplicates.

This PR removes the use of gpu::Serialization* passes in SM_90
integration tests, and enables the 'TargetAttr' workflow.

It also moves the transform dialect specific test to a new folder.
2023-09-11 14:34:03 +02:00
Matthias Springer
339753de12
[mlir][vector][NFC] isDisjointTransferIndices: Use getConstantIntValue (#65931)
Use `getConstantIntValue` instead of matching for `arith::ConstantOp`.
2023-09-11 13:30:36 +02:00
Andrzej Warzyński
718af88376
[mlir][vector] Extend mask calculation for vector.contract (#65733)
Make sure that when calculating the expected mask for `vector.contract`,
scalable sizes are correctly taken into account.

Depends on: #65724
2023-09-11 11:34:47 +01:00
Cullen Rhodes
38eb55a130
[mlir][llvm] Return failure from type converter for n-D scalable vectors (#65450)
This patch changes vector type conversion to return failure on n-D
scalable vector types instead of asserting.

This is an alternative approach to #65261 that aims to enable lowering
of Vector ops directly to ArmSME intrinsics where possible, and seems
more consistent with other type conversions. It's trivial to hit the
assert at the moment and it could be interpreted as n-D scalable vector
types being a bug, when they're valid types in the Vector dialect.

By returning failure it will generally fail more gracefully,
particularly for release builds or other builds where assertions are
disabled.
2023-09-11 09:31:48 +01:00
Andrzej Warzyński
7ec8fd4cc7
[mlir][Vector] Make vector.contract work with scalable vectors (#65724)
This is just a small fix that makes sure that `vector.contract` works
with scalable vectors.

Rather than duplicating all the roundtrip tests for vector.contract, I'm
treating scalable vectors as an edge case and just adding a couple to
verify that this works.
2023-09-11 09:14:25 +01:00
Kai Sasaki
be5b66670d
[mlir][complex] Support fastmath in the binary op conversion. (#65702)
Complex dialect arithmetic operations are now able to recognize the
given fastmath flags. This PR lets the conversion from complex to
standard keep the fastmath flag passed to arith dialect ops.

See:

https://discourse.llvm.org/t/rfc-fastmath-flags-support-in-complex-dialect/71981
2023-09-11 15:57:24 +09:00
Kohei Yamaguchi
ca8cf90c8c
[mlir][tensor] Check the EmptyOp's dynamicSize to be non-negative (#65577)
This patch addresses a crash that occurs when negative dynamic sizes are
provided in tensor.emptyOp by adding a check to ensure that dynamic
sizes are non-negative.

Fixes #64064
2023-09-10 18:38:54 -07:00
Tianlan Zhou
057564fec5
Fix some typos in comments: evalute -> evaluate (NFC) (#65906) 2023-09-11 04:11:06 +08:00
Christian Sigg
710b5a1232
Fix logic to detect cl::option equality. (#65754)
This is a new attempt of https://reviews.llvm.org/D159481, this time as
GitHub PR.

`GenericOptionValue::compare()` should return `true` for a match.

- `OptionValueBase::compare()` always returns `false` and shouldn't
match anything.
- `OptionValueCopy::compare()` returns `false` if not `Valid` which
corresponds to no match.

Also adding some tests.
2023-09-10 12:25:19 +02:00
Fabian Mora
444abb396c
[mlir][gpu] Add a symbol table field to TargetOptions and adjust GpuModuleToBinary (#65797)
This patch adds the option of building an optional symbol table for the
top operation in the `gpu-module-to-binary` pass. The table is not
created by default as most targets don't need it; instead, it is lazily
built. The table is passed through a callback in `TargetOptions`.

This patch is required to integrate #65539 .
2023-09-09 19:59:20 -04:00
Mehdi Amini
6f5ebfb987 Fix MLIR integration test that requires ARM SVE to reproduce
Fix-forward for a9f3009758
2023-09-09 15:29:00 -07:00
Mehdi Amini
a9f3009758
Switch MLIR to use the internal LIT shell by default (#65415) 2023-09-09 13:51:27 -07:00
Fabian Mora
119c489cc1 Reland [mlir][test][gpu] Migrate CUDA tests to the TargetAttr compilation workflow (llvm#65768)
The revert happened due to a build bot failure that threw 'CUDA_ERROR_UNSUPPORTED_PTX_VERSION'.
The failure's root cause was a pass using "+ptx76" for compilation and an old CUDA driver
on the bot. This commit relands the patch with "+ptx60".

Original Gh PR: #65768
Original commit message:
    Migrate tests referencing `gpu-to-cubin` to the new compilation workflow
    using `TargetAttrs`. The `test-lower-to-nvvm` pass pipeline was modified
    to use the new compilation workflow to simplify the introduction of
    future tests.

    The `createLowerGpuOpsToNVVMOpsPass` function was removed, as it didn't
    allow for passing all options available in the `ConvertGpuOpsToNVVMOp`
    pass.
2023-09-09 12:45:21 +00:00
Fabian Mora
2c596ea951
Revert "[mlir][test][gpu] Migrate CUDA tests to the TargetAttr compilation workflow (#65768) (#65848)
This reverts commit d21b67293b.
2023-09-09 07:14:19 -04:00
Fabian Mora
d21b67293b
[mlir][test][gpu] Migrate CUDA tests to the TargetAttr compilation workflow (#65768)
Migrate tests referencing `gpu-to-cubin` to the new compilation workflow
using `TargetAttrs`. The `test-lower-to-nvvm` pass pipeline was modified
to use the new compilation workflow to simplify the introduction of
future tests.

The `createLowerGpuOpsToNVVMOpsPass` function was removed, as it didn't
allow for passing all options available in the `ConvertGpuOpsToNVVMOp`
pass.
2023-09-09 07:03:38 -04:00
Amy Wang
0aa459fc8a
[MLIR][Tensor] Add Destination style RewritePattern for DimOp. (#65780)
This enables canonicalization to fold away unnecessary tensor.dim ops
which in turn enables folding away of other operations, as can be seen
in conv_tensors_dynamic where affine.min operations were folded away.
2023-09-09 06:01:56 -04:00
Fabian Mora
5db8990cda
[mlir][test][gpu] Migrate ROCM tests to the TargetAttr compilation workflow (#65805)
Migrate tests referencing `gpu-to-hsaco` to the new compilation workflow
using TargetAttrs.
2023-09-08 21:26:43 -04:00
Markus Böck
0f052a972e
[mlir] Make StringRefParameter roundtrippable (#65813)
The current printer of `StringRefParameter` simply prints out the
content of the string as is without escaping it any way. This leads to
it generating invalid syntax, causing parser errors when read in again.

This PR fixes that by adding `printString` to `AsmPrinter`, allowing one
to print a string that can be parsed with `parseString`, using the same
escaping syntax as `StringAttr`.
2023-09-09 00:06:38 +02:00
Fabian Mora
ec9f218173
[mlir][gpu][target] Use promises to verify TargetAttrs IR correctness. (#65787)
This patch employs the updated promise mechanism to enforce Target
Attribute IR constraints. Due to this patch, TargetAttributes
implementations no longer have to be registered before executing
translation to LLVM IR in cases where they are not needed, like when
translating `gpu.binary` operations.
2023-09-08 17:21:45 -04:00
Jakub Kuderski
d01f559ce9
[mlir] Fix c++20 compat warning. NFC. (#65801)
`concept` is a c++20 keyword and makes some buildbots fail:
https://lab.llvm.org/buildbot/#/builders/160/builds/24345
2023-09-08 16:23:36 -04:00
Michael Liao
c86d8963ca [mlir][Interfaces] Fix shared build. NFC 2023-09-08 14:27:35 -04:00
Jakub Kuderski
af9dafeb38
[mlir][spirv] Fix coop matrix store (#65709)
- Fix operand/attribute order
- Use ODS for parsing/printing
- Allow for stride to be any integer type
2023-09-08 13:58:29 -04:00
Matthias Springer
c5624dc055
[mlir][Interfaces] ValueBoundsOpInterface: Handle all destination style ops (#65736)
This commit provides a default implementation for all ops that implement
the `DestinationStyleOpInterface`. Result values of such ops are tied to
operand, and those have the same type.
2023-09-08 19:46:40 +02:00
Jakub Kuderski
53b3be7ecb
[mlir][spirv] Fix coop matrix load (#65712)
- Fix order of operands/attributes
- Allow for stride to be any integer type
- Use ODS for parsing/printing
- Update examples and tests
- Fix a typo in SPIR-V tblgen code
2023-09-08 13:29:12 -04:00
Benjamin Maxwell
6f95737ed4
[mlir][TOSA] Fix interpretation of --tosa-validate='profile=undefined' (#65738)
Due to a copy-paste error in 32b7c1ff this was incorrectly mapped to
`TosaProfileEnum::MainTraining` rather than `TosaProfileEnum::Undefined`.
2023-09-08 16:11:19 +01:00
Markus Böck
feb7beaf70
[mlir][LLVM] Model side effects of volatile and atomic load-store (#65730)
According to the LLVM language reference, both volatile memory
operations and atomic operations (except unordered) do not simply read
memory but also perform write operations on arbitrary memory[0][1].

In the case of volatile memory operations, this is the case due to the
read possibly having target specific properties. A common real-world
situation where this happens is reading memory mapped registers on an
MCU for example. Atomic operations are more special. They form a kind of
memory barrier which from the perspective of the optimizer/lang-ref
makes writes from other threads visible in the current thread. Any kind
of synchronization can therefore conservatively be modeled as a
write-effect.

This PR therefore adjusts the side effects of `llvm.load` and
`llvm.store` to add unknown global read and write effects if they are
either atomic or volatile.

Regarding testing: I am not sure how to best test this change for
`llvm.store` and the "globalness" of the effect that isn't just a unit
test checking that the output matches exactly. For the time being, I
added a test making sure that `llvm.load` does not get DCEd in
aforementioned cases.

Related logic in LLVM proper:

3398744a61/llvm/lib/IR/Instruction.cpp (L638-L676)


3398744a61/llvm/include/llvm/IR/Instructions.h (L258-L262)

[0] https://llvm.org/docs/LangRef.html#volatile-memory-accesses
[1] https://llvm.org/docs/Atomics.html#monotonic
2023-09-08 13:50:49 +02:00
Vinicius Couto Espindola
01192a09bb
[mlir][llvm] Add zeroinitializer constant (#65508)
This patch adds support for the zeroinitializer constant to LLVM
dialect. It's meant to simplify zero-initialization of aggregate types
in MLIR, although it can also be used with non-aggregate types.
2023-09-08 13:03:39 +02:00
Benjamin Maxwell
2a82dfd704 [mlir][VectorOps] Don't drop scalable dims when lowering transfer_reads/writes (in VectorToSCF)
This allows the lowering of > rank 1 transfer_reads/writes to equivalent
lower-rank ones when the trailing dimension is scalable. The resulting
ops still cannot be completely lowered as they depend on arrays of
scalable vectors being enabled, and a few related fixes (see D158517).

This patch also explicitly disables lowering transfer_reads/writes with
a leading scalable dimension, as more changes would be needed to handle
that correctly and it is unclear if it is required.

Examples of ops that can now be further lowered:

  %vec = vector.transfer_read %arg0[%c0, %c0], %cst, %mask
		 {in_bounds = [true, true]} : memref<3x?xf32>, vector<3x[4]xf32>

  vector.transfer_write %vec, %arg0[%c0, %c0], %mask
		 {in_bounds = [true, true]} : vector<3x[4]xf32>, memref<3x?xf32>

Reviewed By: c-rhodes, awarzynski, dcaballe

Differential Revision: https://reviews.llvm.org/D158753
2023-09-08 09:43:17 +00:00
lorenzo chelini
e5137e7c33
[MLIR][Linalg] Retire tile_to_scf_for (#65633)
Both `TileOp` and `TileToScfForOp` use the tiling interface and the
`tileUsingSCFForOp` method. This duplication was introduced in
44cfea0279
as a way to retire `linalg::tileLinalgOp,` now there is not more need
for this duplication, and it seems that `tileOp` has more recent
changes, thus retire `TileToScfForOp.`
2023-09-07 16:13:23 -04:00
Natasha Kononenko
cf29d0a737 [mlir][tosa]Create a check for i64 input in apply_scale lowering in TosaToArith
Reviewed By: rsuderman

Differential Revision: https://reviews.llvm.org/D159473
2023-09-07 11:08:52 -07:00