17233 Commits

Author SHA1 Message Date
Aart Bik
c6472f5715
[mlir][sparse] More allocate -> empty tensor migration (#66720)
This also allows tensor.empty in the "conversion" path of the sparse
compiler, further paving the way to
deprecate the bufferization.allocated_tensor() op.
2023-09-19 10:05:40 -07:00
Jakub Kuderski
bdb5c9c3fa
[mlir][spirv][gpu] Convert remaining wmma ops to KHR coop matrix (#66455)
These do not produce extension-specific ops and are handled via common
patterns for both the KHR and the NV coop matrix extension.

Also improve match failure reporting and error handling in type
conversion.
2023-09-19 13:04:34 -04:00
Matthias Springer
9b5ef2bea8
[mlir][Interfaces] LoopLikeOpInterface: Support ops with multiple regions (#66754)
This commit implements `LoopLikeOpInterface` on `scf.while`. This
enables LICM (and potentially other transforms) on `scf.while`.

`LoopLikeOpInterface::getLoopBody()` is renamed to `getLoopRegions` and
can now return multiple regions.

Also fix a bug in the default implementation of
`LoopLikeOpInterface::isDefinedOutsideOfLoop()`, which returned "false"
for some values that are defined outside of the loop (in a nested op, in
such a way that the value does not dominate the loop). This interface is
currently only used for LICM and there is no way to trigger this bug, so
no test is added.
2023-09-19 17:35:38 +02:00
Matthias Springer
d69293c1c8
[mlir][SCF] ForOp: Remove getIterArgNumberForOpOperand (#66629)
This function was inconsistent with the remaining API because it
accepted `OpOperand &` that do not belong to the op. All the other
functions assert. This helper function is also not really necessary, as
the iter_arg number is identical to the result number.
2023-09-19 17:33:40 +02:00
Andrew Gozillon
b05d436ec6 [MLIR][OpenMP] Alterations to LLVM-IR lowering of OpenMP Dialect due to Bounds and MapEntry operations
This patch adjusts the lower to LLVM-IR inside of
OpenMPToLLVMIRTranslation to faciliate the changes made
to Target related operations to add the new Map related
operations. It also includes adjustments to tests to support
these changes, primarily modifying the MLIR as opposed to
the LLVM-IR, the LLVM-IR should be identical after this patch.

Depends on D158735

Reviewers: kiranchandramohan, TIFitis, razvanlupusoru

Differential Revision: https://reviews.llvm.org/D158737
2023-09-19 08:26:47 -05:00
Andrew Gozillon
571df0132d [OpenMP][MLIR] Refactor and extend current map support by adding MapInfoOp and DataBoundsOp operations to the OpenMP Dialect
This patch adds two new operations:

The first is the DataBoundsOp, which is based on OpenACC's DataBoundsOp,
which holds stride, index, extent, lower bound and upper bounds
which will be used in future follow up patches to perform initial
array sectioning of mapped arrays, and Fortran pointer and
allocatable mapping. Similarly to OpenACC, this new OpenMP
DataBoundsOp also comes with a new OpenMP type, which
helps to restrict operations to accepting only
DataBoundsOp as an input or output where necessary
(or other related operations that implement this type as
a return).

The patch also adds the MapInfoOp which rolls up some of
the old map information stored in target
operations into this new operation, and adds new
information that will be utilised in the lowering of mapped
variables, e.g. the aforementioned DataBoundsOp, but also a
new ByCapture OpenMP MLIR attribute, and isImplicit boolean
attribute. Both the ByCapture and isImplicit arguments will
affect the lowering from the OpenMP dialect to LLVM-IR in
minor but important ways, such as shifting the final maptype
or generating different load/store combinations to maintain
semantics with the OpenMP standard and alignment with the
current Clang OpenMP output as best as possible.

This MapInfoOp operation is slightly based on OpenACC's
DataEntryOp, the main difference other than some slightly
different fields (e,g, isImplicit/MapType/ByCapture) is that
OpenACC's data operations "inherit" (the MLIR ODS
equivalent) from this operation, whereas in OpenMP operations
that utilise MapInfoOp's are composed of/contain them.

A series of these MapInfoOp (one per map clause list item) is
now held by target operations that represent OpenMP
directives that utilise map clauses, e.g. TargetOp. MapInfoOp's
do not have their own specialised lowering to LLVM-IR, instead
the lowering is dependent on the particular container of the
MapInfoOp's, e.g. TargetOp has its own lowering to LLVM-IR
which utilised the information stored inside of MapInfoOp's to
affect it's lowering and the end result of the LLVM-IR generated,
which in turn can differ for host and device.

This patch contains these operations, minor changes to the
printing and parsing to support them, changes to tests (only
those relevant to this segment of the patch, other test
additions and changes are in other dependent
patches in this series) and some alterations to the OpenMPToLLVM
rewriter to support the new OpenMP type and operations.

This patch is one in a series that are dependent on each
other:

https://reviews.llvm.org/D158734
https://reviews.llvm.org/D158735
https://reviews.llvm.org/D158737

Reviewers: kiranchandramohan, TIFitis, razvanlupusoru

Differential Revision: https://reviews.llvm.org/D158732
2023-09-19 08:26:46 -05:00
vic
6d1c6ecbdc
[IR] SingleBlock::push_back operations to the back of the block (#66655)
Instead of checking whether the last operation might be a terminator,
always insert operations to the end of the block.

Signed-off-by: Victor Perez <victor.perez@codeplay.com>
2023-09-19 15:06:22 +02:00
Oleksandr "Alex" Zinenko
a2a1dbb518
[mlir] avoid crash in transform.sequence verifier (#66756)
The verifier was unconditionally accessing the body block terminator,
but it's not guaranteed that the block has one in general.
2023-09-19 13:28:53 +02:00
Ingo Müller
86ddbdd3e7
[mlir][linalg][transform][python] Allow no args in MaskedVectorize. (#66541)
The mix-in of this op did not allow to pass in no argument. This special
case is now handled correctly and covered by the tests.
2023-09-19 10:34:47 +02:00
Ingo Müller
159e94a0c3
[mlir][linalg][transform] Add some debug output to vectorization. (NFC) (#66520)
This helps to understand what the problem is when vectorization of
structured ops failes due to mismatching vector sizes.
2023-09-19 10:34:24 +02:00
Matthias Springer
6923a31542
[mlir][IR] Change MutableArrayRange to enumerate OpOperand & (#66622)
In line with #66515, change `MutableArrayRange::begin`/`end` to
enumerate `OpOperand &` instead of `Value`. Also remove
`ForOp::getIterOpOperands`/`setIterArg`, which are now redundant.

Note: `MutableOperandRange` cannot be made a derived class of
`indexed_accessor_range_base` (like `OperandRange`), because
`MutableOperandRange::assign` can change the number of operands in the
range.
2023-09-19 09:09:21 +02:00
Stella Laurenzo
33df617dfd
[mlir] Quality of life improvements to python API types. (#66723)
* Moves several orphaned methods from Operation/OpView -> _OperationBase
so that both hierarchies share them (whether unknown or known to ODS).
* Adds typing information for missing `MLIRError` exception.
* Adds `DiagnosticInfo` typing.
* Adds `DenseResourceElementsAttr` typing that was missing.
2023-09-18 21:30:41 -07:00
Jacques Pienaar
31ebe98e48
[mlir][c] Expose AsmState. (#66693)
Enable usage where capturing AsmState is good (e.g., avoiding creating AsmState over and over again when walking IR and printing).

This also only changes one C API to verify plumbing. But using the AsmState makes the cost more explicit than the flags interface (which hides the traversals and construction here) and also enables a more efficient usage C side.
2023-09-18 20:12:12 -07:00
Spenser Bauman
0a0c7e8978
[mlir][tensor] Bufferize tensor.reshape with non-identity layouts (#65654)
Bufferization of tensor.reshape generates a memref.reshape operation.
memref.reshape requires the source memref to have an identity layout.
The bufferization process may result in the source memref having a
non-identity layout, resulting in a verification failure.

This change causes the bufferization interface for tensor.reshape to
copy the source memref to a new buffer when the source has a
non-identity layout.
2023-09-19 09:50:43 +09:00
MaheshRavishankar
170a25a793
[mlir][TilingInterface] Make the tiling set tile sizes function use OpFoldResult. (#66566) 2023-09-18 17:18:51 -07:00
Rob Suderman
cbd475040f [mlir][mlprogram] Add mlprogram-pipeline-globals optimization pass
Added pass optimizes MLProgram global operations by reducing to only
the minimal load/store operations for global tensors. This avoids
unnecessary global operations throughout a program and potentially
improves operation gusion.

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D159228
2023-09-18 17:11:29 -07:00
Peiming Liu
4176ce61f1
[mlir][sparse] fix logical error when generating sort_coo. (#66690)
To fix issue: https://github.com/llvm/llvm-project/issues/66664
2023-09-18 15:26:01 -07:00
Arjun P
98c994c8e2 Revert "[MLIR][Presburger] Template Matrix to allow MPInt and Fraction (#65272)"
This reverts commit efca035c6d28542ad6374cd8bf17ae7c72407ead.

Reverting due to windows build bot failure:
https://lab.llvm.org/buildbot/#/builders/13/builds/40242/steps/6/logs/stdio
2023-09-18 19:06:32 +01:00
Abhinav271828
efca035c6d
[MLIR][Presburger] Template Matrix to allow MPInt and Fraction (#65272)
The method implementations remain in the .cpp file; explicit instantiations have been added for these two types. 
makeMatrix has been duplicated to makeIntMatrix and makeFracMatrix.
2023-09-18 22:52:22 +05:30
Nicolas Vasilache
04ba475e85
[mlir][Vector] Add a rewrite pattern for better low-precision ext(bit… (#66648)
…cast) expansion

This revision adds a rewrite for sequences of vector `ext(bitcast)` to
use a more efficient sequence of vector operations comprising `shuffle`
and `bitwise` ops.

Such patterns appear naturally when writing quantization /
dequantization functionality with the vector dialect.

The rewrite performs a simple enumeration of each of the bits in the
result vector and determines its provenance in the source vector. The
enumeration is used to generate the proper sequence of `shuffle`,
`andi`, `ori` with shifts`.

The rewrite currently only applies to 1-D non-scalable vectors and bails
out if the final vector element type is not a multiple of 8. This is a
failsafe heuristic determined empirically: if the resulting type is not
an even number of bytes, further complexities arise that are not
improved by this pattern: the heavy lifting still needs to be done by
LLVM.
2023-09-18 19:02:46 +02:00
Aart Bik
d34661309b
[mlir][sparse] fix merge conflict in sddmm test (#66670)
This fixes a merge conflict in
https://github.com/llvm/llvm-project/pull/66563
2023-09-18 09:51:21 -07:00
Aart Bik
6a45339bac
[mlir][sparse] refine sparse fusion with empty tensors materialization (#66563)
This is a minor step towards deprecating bufferization.alloc_tensor().
It replaces the examples with tensor.empty() and adjusts the underlying
rewriting logic to prepare for this upcoming change.
2023-09-18 09:01:11 -07:00
Lukas Sommer
93e0658a83
[mlir][llvm] Use zeroinitializer for TargetExtType (#66510)
Use the recently introduced llvm.mlir.zero operation for values with
LLVM target extension type. Replaces the previous workaround that uses a
single zero-valued integer attribute constant operation.

Signed-off-by: Lukas Sommer <lukas.sommer@codeplay.com>
2023-09-18 17:49:36 +02:00
Kiran Chandramohan
e2733a6767
[Flang][OpenMP] Add trivial conversion pattern for omp.ordered_region (#66085)
Fixes #65570
2023-09-18 16:05:17 +01:00
Martin Erhart
6bf043e743
[mlir][bufferization] Remove allow-return-allocs and create-deallocs pass options, remove bufferization.escape attribute (#66619)
This 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
ownership-based-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. A new `allow-return-allocs-from-loops` option is added as a
temporary workaround for some bufferization limitations.
2023-09-18 16:44:48 +02:00
Jie Fu
dd6dde1166 [mlir][Vector] Fix -Wunused-function in VectorEmulateNarrowType.cpp (NFC)
/data/llvm-project/mlir/lib/Dialect/Vector/Transforms/VectorEmulateNarrowType.cpp:229:21: error: unused function 'operator<<' [-Werror,-Wunused-function]
static raw_ostream &operator<<(raw_ostream &os,
                    ^
1 error generated.
2023-09-18 21:47:33 +08:00
frgossen
06f9ffa050
Fix unused variable (#66644) 2023-09-18 09:35:20 -04:00
Matthias Springer
64839fbd45
[mlir][bufferization] Empty tensor elimination for materialize_in_destination (#65468)
This revision adds support for empty tensor elimination to
"bufferization.materialize_in_destination" by implementing the
`SubsetInsertionOpInterface`.

Furthermore, the One-Shot Bufferize conflict detection is improved for
"bufferization.materialize_in_destination".
2023-09-18 15:34:28 +02:00
Nicolas Vasilache
bf7c490ab7
[mlir][Vector] Add a rewrite pattern for better low-precision bitcast… (#66387)
…(trunci) expansion

This revision adds a rewrite for sequences of vector `bitcast(trunci)`
to use a more efficient sequence of vector operations comprising
`shuffle` and `bitwise` ops.

Such patterns appear naturally when writing quantization /
dequantization functionality with the vector dialect.

The rewrite performs a simple enumeration of each of the bits in the
result vector and determines its provenance in the pre-trunci vector.
The enumeration is used to generate the proper sequence of `shuffle`,
`andi`, `ori` followed by an optional final `trunci`/`extui`.

The rewrite currently only applies to 1-D non-scalable vectors and bails
out if the final vector element type is not a multiple of 8. This is a
failsafe heuristic determined empirically: if the resulting type is not
an even number of bytes, further complexities arise that are not
improved by this pattern: the heavy lifting still needs to be done by
LLVM.
2023-09-18 15:08:18 +02:00
Matthias Springer
08d2ea372f
[mlir][Interfaces][NFC] LoopLikeOpInterface: Consistent TD formatting (#66097)
Format the interface methods consistently in the TableGen file. Also
mention more details about this interface in the description.
2023-09-18 12:45:33 +02:00
Martin Erhart
1a4dd8d362
[mlir][bufferization] Switch tests to new deallocation pass pipeline (#66517)
Use the new ownership based deallocation pass pipeline in the regression
and integration tests. Some one-shot bufferization tests tested one-shot
bufferize and deallocation at the same time. I removed the deallocation
pass there because the deallocation pass is already thoroughly tested by
itself.

Fixed version of #66471
2023-09-18 12:00:27 +02:00
Matthias Springer
0f952cfe24
[mlir][IR] Change MutableOperandRange::operator[] to return an OpOperand & (#66515)
`operator[]` returns `OpOperand &` instead of `Value`.

* This allows users to get OpOperands by name instead of "magic" number.
E.g., `extractSliceOp->getOpOperand(0)` can be written as
`extractSliceOp.getSourceMutable()[0]`.
* `OperandRange` provides a read-only API to operands: `operator[]`
returns `Value`. `MutableOperandRange` now provides a mutable API:
`operator[]` returns `OpOperand &`, which can be used to set operands.

Note: The TableGen code generator could be changed to return `OpOperand
&` (instead of `MutableOperandRange`) for non-variadic and non-optional
arguments in a subsequent change. Then the `[0]` part in the above
example would no longer be necessary.
2023-09-18 09:43:03 +02:00
Matthias Springer
5cf714bb2f
[mlir][SCF] scf.for: Consistent API around initArgs (#66512)
* Always use the auto-generated `getInitArgs` function. Remove the
hand-written `getInitOperands` duplicate.
* Remove `hasIterOperands` and `getNumIterOperands`. The names were
inconsistent because the "arg" is called `initArgs` in TableGen. Use
`getInitArgs().size()` instead.
* Fix verification around ops with no results.
2023-09-18 09:13:43 +02:00
Dudeldu
ed8bd7176d
[MLIR] Allow comparison of opaque properties (#66378)
Add capabilities for comparing opaque properties. This is useful when
dealing with arbitrary operations which can be compare based on their
OperationName. Now you can furthermore compare their properties without
the need to determine their actual type.
2023-09-17 23:46:31 -07:00
Bharathi Ramana Joshi
ccf194b845
[MLIR][Presburger] Implement convertVarKind for PresburgerRelation 2023-09-17 20:02:16 +05:30
Christian Sigg
1c8c365de2
[mlir][bytecode] Check that bytecode source buffer is sufficiently aligned. (#66380)
Before this change, the `ByteCode` test failed on CentOS 7 with
devtoolset-9, because strings happen to be only 8 byte aligned. In
general though, strings have no alignment guarantee.

Increase resource alignment in test to 32 bytes. 
Adjust test to sufficiently align buffer.
Add test to check error when buffer is insufficiently aligned.
2023-09-17 13:46:01 +02:00
Tai Ly
3323702bff
[TOSA] Change EightK MaxScale to 256 (#66536)
This patch changes the MaxScale value for level EightK to 256. Also
updated affected level check tests


Change-Id: Id9cffd5eb9053bb688196cd5b3b55b3ddd2a359c

Signed-off-by: Tai Ly <tai.ly@arm.com>
2023-09-15 13:57:10 -07:00
Yinying Li
3dc621124f
[mlir][sparse] Migrate tests to use new syntax (#66543)
**COO**
`lvlTypes = [ "compressed_nu", "singleton" ]` to `map = (d0, d1) -> (d0
: compressed(nonunique), d1 : singleton)`
`lvlTypes = [ "compressed_nu_no", "singleton_no" ]` to `map = (d0, d1)
-> (d0 : compressed(nonunique, nonordered), d1 : singleton(nonordered))`

**SortedCOO**
`lvlTypes = [ "compressed_nu", "singleton" ]` to `map = (d0, d1) -> (d0
: compressed(nonunique), d1 : singleton)`

**BCOO**
`lvlTypes = [ "dense", "compressed_hi_nu", "singleton" ]` to `map = (d0,
d1, d2) -> (d0 : dense, d1 : compressed(nonunique, high), d2 :
singleton)`

**BCSR**
`lvlTypes = [ "compressed", "compressed", "dense", "dense" ], dimToLvl =
affine_map<(d0, d1) -> (d0 floordiv 2, d1 floordiv 3, d0 mod 2, d1 mod
3)>` to
`map = ( i, j ) ->
      ( i floordiv 2 : compressed,
        j floordiv 3 : compressed,
        i mod 2 : dense,
        j mod 3 : dense
      )`

**Tensor and other supported formats(e.g. CCC, CDC, CCCC)**

Currently, ELL and slice are not supported yet in the new syntax and the
CHECK tests will be updated once printing is set to output the new
syntax.

Previous PRs: #66146, #66309, #66443
2023-09-15 16:12:20 -04:00
Daniil Dudkin
01e80a0f41
[mlir] Add maxnumf and minnumf to AtomicRMWKind (#66442)
This commit adds the mentioned kinds of `AtomicRMWKind`
as well as code generation for them.
2023-09-15 22:41:51 +03:00
Ingo Müller
68033aaac5
[mlir][transform] Fix crash in transform.get_parent_op. (#66492)
The previous implementation crashed if run on a `builtin.module` using
an `op_name` filter (because the initial value of `parent` in the while
loop was a `nullptr`). This PR fixes the crash and adds a test.
2023-09-15 21:32:17 +02:00
Aart Bik
d2e787d5d7
[mlir][sparse][tensor] replace bufferization with empty tensor (#66450)
Rationale:
    A bufferization.alloc_tensor can be directly replaced
    with tensor.empty since these are more or less semantically
    equivalent. The latter is considered a bit more "pure"
    with respect to SSA semantics.
2023-09-15 11:45:42 -07:00
Anton Korobeynikov
51d5d7bbae
Extend retcon.once coroutines lowering to optionally produce a normal result (#66333)
One of the main user of these kind of coroutines is swift. There yield-once (`retcon.once`) coroutines are used to temporary "expose" pointers to internal fields of various objects creating borrow scopes.

However, in some cases it might be useful also to allow these coroutines to produce a normal result, but there is no convenient way to represent this (as compared to switched-resume kind of coroutines where C++ `co_return`
is transformed to a member / callback call on promise object).

The extension is simple: we allow continuation function to have a non-void result and accept optional extra arguments via a special `llvm.coro.end.result` intrinsic that would essentially forward them as normal results.
2023-09-15 09:54:38 -07:00
Prabhdeep Singh Soni
9b57b167bb [OMPIRBuilder] Fix shared clause for task construct
This patch fixes the shared clause for the task construct with multiple
shared variables. The shareds field in the kmp_task_t is not an inline
array in the struct, rather it is a pointer to an array. With an inline
array, the pointer dereference to the outlined function body of the task
would segmentation fault when accessed by the runtime.

Reviewed By: kiranchandramohan, jdoerfert

Differential Revision: https://reviews.llvm.org/D158462
2023-09-15 12:19:47 -04:00
Andrzej Warzyński
57cf6896cd
[mlir][vector] Fix vector.broadcast lowering for scalable vectors (#66344)
This patch makes sure that the following case is lowered correctly
("duplication"):
```
  func.func @broadcast_scalable_duplication(%arg0: vector<[32]xf32>) -> vector<1x[32]xf32> {
    %res = vector.broadcast %arg0 : vector<[32]xf32> to vector<1x[32]xf32>
    return %res : vector<1x[32]xf32>
  }
```
2023-09-15 16:35:47 +01:00
Andrzej Warzynski
cadabb58f1 [mlir][linalg][nfc] Fix typo in a file name
Follow-up of D158427
2023-09-15 15:31:36 +00:00
Andrzej Warzynski
c92124765e [mlir][Linalg] Move test
To avoid confusion with vectorization-masked.mlir, move

  test/Dialect/Linalg/masked_vectorization.mlir

to:

  test/Dialect/Linalg/transpose-compose-masked-vectorize-and-cleanups.mlir

The updated name better reflects what's being tested.

Differential Revision: https://reviews.llvm.org/D158427
2023-09-15 15:21:32 +00:00
vic
87d77d3cfb
[mlir][IR] Insert operations before SingleBlock's terminator (#65959)
Change `SingleBlock::{insert,push_back}` to avoid inserting the argument
operation after the block's terminator. This allows removing
`SingleBlockImplicitTerminator`'s functions with the same name.

Define `Block::hasTerminator` checking whether the block has a
terminator operation.

Signed-off-by: Victor Perez <victor.perez@codeplay.com>
2023-09-15 16:17:35 +02:00
Benjamin Maxwell
665995b918 [mlir][Conversion] Allow lowering to fixed arrays of scalable vectors
This allows lowering vector types like: vector<3x[4]> or vector<3x2x[4]>
to LLVM IR, i.e. vectors where the trailing dim is scalable.

This is contingent on:
https://discourse.llvm.org/t/rfc-enable-arrays-of-scalable-vector-types/72935

More tests will be added in later patches, however, some MLIR fixes are
needed first.

Depends on: D158517

Reviewed By: awarzynski

Differential Revision: https://reviews.llvm.org/D158752
2023-09-15 09:33:18 +00:00
Martin Erhart
3d51010a33 Revert "[mlir][bufferization] Switch tests to new deallocation pass pipeline (#66471)"
This reverts commit ea42b49f1069ec647cbc67e6360026bc4e5d9a60.

Some GPU integration tests are failing that I didn't observe locally.
Reverting until I have a fix.
2023-09-15 09:19:54 +00:00
Martin Erhart
ea42b49f10
[mlir][bufferization] Switch tests to new deallocation pass pipeline (#66471)
Use the new ownership based deallocation pass pipeline in the regression
and integration tests. Some one-shot bufferization tests tested one-shot
bufferize and deallocation at the same time. I removed the deallocation
pass there because the deallocation pass is already thoroughly tested by
itself.
2023-09-15 11:08:53 +02:00