Commit Graph

7350 Commits

Author SHA1 Message Date
Jakub Kuderski
28246b7e75 [mlir][arith] Rename addui_carry to addui_extended
The goal is to make the naming of the future `_extended` ops more
consistent. With unsigned addition, the carry value/flag and overflow
bit are the same, but this is not true when it comes to signed addition.

Also rename the second result from `carry` to `overflow`.

Reviewed By: antiagainst

Differential Revision: https://reviews.llvm.org/D139569
2022-12-07 17:15:56 -05:00
Alexander Belyaev
f6fb0a4f35 [mlir] Make patterns for folding tensor.empty optional.
At the moment, they are a part of EmptyOp::getCanonicalizationPatterns. When
extract_slice(tensor.empty) is rewritten as a new tensor.empty, it could
happen that we end up with two tensor.empty ops, since the original
tensor.empty can have two users. After bufferization such cases result in two
allocations.

Differential Revision: https://reviews.llvm.org/D139308
2022-12-07 23:01:34 +01:00
Thomas Raoux
f7fda6ba4a [mlir][linalg] Add extra parameter to tiling reduction to foreach_thread
This adds a tile_size parameter, when it is used the tiles are
cyclically distributed onto the threads of the scf.foreach_thread op.

Differential Revision: https://reviews.llvm.org/D139474
2022-12-07 18:37:05 +00:00
Emilio Cota
72d76a2403 [mlir][bufferize] lower allocation alignment from 128 to 64 bytes
While it is unlikely to matter in practice, there is no reason
for this value to be larger than it should be. 64 bytes is the
size of a cache line in most machines, and we can fit a full
512-bit vector in it.

Reviewed By: springerm
Differential Revision: https://reviews.llvm.org/D139434
2022-12-07 11:12:46 -05:00
Quentin Colombet
9cbd136db4 [mlir][NFC] Add a new getStridesAndOffset function
The new function is a wrapper around the regular `getStridesAndOffset`
that offers a more compact way (as in writing less code) of getting the
relevant information.

This method is intended to be used only when it is known that the
LogicalResult of the regular `getStridesAndOffset` must be "succeeded".

This warpper will assert on that.

Differential Revision: https://reviews.llvm.org/D139529
2022-12-07 13:58:28 +00:00
Lorenzo Chelini
87ecf9d155 [MLIR][Tensor] Add custom builder for unpack op
Reviewed By: hanchung

Differential Revision: https://reviews.llvm.org/D139344
2022-12-07 12:40:45 +01:00
Jakub Kuderski
f7f4dd6743 [mlir][spirv] Define spirv.*DotAccSat integer dot product ops
This covers `SDotAccSat`, `SUDotAccSat`, and `UDotAccSat`.

Reviewed By: antiagainst

Differential Revision: https://reviews.llvm.org/D139243
2022-12-06 20:22:48 -05:00
Jakub Kuderski
03e6bf5f56 [mlir][spirv] Define spirv.*Dot integer dot product ops
This covers `SDot`, `SUDot`, and `UDot`. The `*AccSat` version will be
added in a follow-up revision.

Reviewed By: antiagainst

Differential Revision: https://reviews.llvm.org/D139242
2022-12-06 20:17:41 -05:00
Aart Bik
8e0abf8d61 [mlir][sparse] cleanup some pass documentation
Reviewed By: Peiming

Differential Revision: https://reviews.llvm.org/D139473
2022-12-06 15:37:39 -08:00
Hanhan Wang
0f297cad4d [mlir][tensor][linalg] Introduce DataLayoutPropagation pass.
It introduces a pattern that swaps `linalg.generic + tensor.pack` to
`tensor.pack + linalg.generic`. It requires all the iteration types
being parallel; the indexing map of output operand is identiy. They can
all be relaxed in the future.

The user can decide whether the propagation should be applied or not by
passing a control function.

Reviewed By: mravishankar

Differential Revision: https://reviews.llvm.org/D138882
2022-12-06 15:00:07 -08:00
Hanhan Wang
193cefd1b1 [mlir][tensor] Adapt FoldTensorCastProducerOp pattern on DPS interface.
This revision adapts the pattern in LinAlg to work on DPS interface, and
adds it to canonicalization patterns of tensor dialect. The
InsertSliceOp is skipped in the pattern because it has its own logic
about folding tensor.cast ops.

Reviewed By: pifon2a

Differential Revision: https://reviews.llvm.org/D139375
2022-12-06 12:13:37 -08:00
Kevin Gleason
279d294d26 Use consistent spacing before custom directives for op and attr/type assemblyFormat.
Currently, assemblyFormat `custom<A>($a) custom<B>($b)` has different spacing
if used for Ops vs Attrs/Types. Ops insert a space if needed before the custom directive,
while attributes and types do not.

This leads to the following two patterns in attributes / types:

```
# 1. Whitespace literal
let assemblyFormat = "... ` ` custom<A>($a)"

# 2. Custom printer code includes spacing
void printB(...) {
  printer << ' ' << b;
}
```

Moving this spacing into the generated code allows for some cleanup in mlir and
improves the consistency of custom directives.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D138235
2022-12-06 12:13:02 -08:00
Peiming Liu
191c43f60e Revert "Revert "[mlir][sparse] Refactoring: abstract sparse tensor memory scheme into a SparseTensorDescriptor class.""
This reverts commit 10033a179f. Plus, it fixed windows warnings and gcc errors

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D139384
2022-12-06 17:12:06 +00:00
bixia1
3032c07d3a [mlir][crunner] Add support for random number generation.
Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D139374
2022-12-06 08:54:00 -08:00
Kazu Hirata
e823abab48 [mlir] Use std::nullopt instead of None in comments (NFC)
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
2022-12-06 00:03:44 -08:00
Diego Caballero
77603e28ce [mlir] Add replaceAllUsesExcept to rewriter
This patch adds `replaceAllUsesExcept` to the rewriter class.
The implementation is copy-pasted from Value + calling
`updateRootInPlace` to notify the listeners about the
corresponding IR changes.

Reviewed By: Mogball

Differential Revision: https://reviews.llvm.org/D139382
2022-12-06 07:42:15 +00:00
Fangrui Song
3cfe412e4c [TableGen] llvm::Optional => std::optional 2022-12-06 07:21:02 +00:00
Jeff Niu
34535801d6 [mlir] UnsignedWhenEquivalent ignore dead code
The pass was not checking for uninitialized states due to dead code.
This patch also makes LLVMFuncOp correctly return a null body when it is
external.

Fixes #58807

Depends on D139388

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D139389
2022-12-05 20:38:44 -08:00
Jeff Niu
0f06da6412 [mlir][llvm] Mark LLVMReturnOp as ReturnLike
Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D139388
2022-12-05 20:38:37 -08:00
Jeff Niu
a8ccf0ef5b [mlir][ods] Allow ArrayOfAttr implicit conversion to ArrayRef
Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D139372
2022-12-05 19:13:11 -08:00
Stella Stamenova
10033a179f Revert "[mlir][sparse] Refactoring: abstract sparse tensor memory scheme into a SparseTensorDescriptor class."
This reverts commit 8a7e69d145.

This broke the windows mlir buildbot: https://lab.llvm.org/buildbot/#/builders/13/builds/29257
2022-12-05 17:20:01 -08:00
wren romano
86f91e45a2 [mlir][sparse] Cleaning up the dim/lvl distinction in SparseTensorConversion
This change cleans up the conversion pass re the "dim"-vs-"lvl" and "sizes"-vs-"shape" distinctions of the runtime. A quick synopsis includes:

* Adds new `SparseTensorStorageBase::getDimSize` method, with `sparseDimSize` wrapper in SparseTensorRuntime.h, and `genDimSizeCall` generator in SparseTensorConversion.cpp
* Changes `genLvlSizeCall` to perform no logic, just generate the function call.
* Adds `createOrFold{Dim,Lvl}Call` functions to handle the logic of replacing `gen{Dim,Lvl}SizeCall` with constants whenever possible. The `createOrFoldDimCall` function replaces the old `sizeFromPtrAtDim`.
* Adds `{get,fill}DimSizes` functions for iterating `createOrFoldDimCall` across the whole type. These functions replace the old `sizesFromPtr`.
* Adds `{get,fill}DimShape` functions for lowering a `ShapedType` into constants. These functions replace the old `sizesFromType`.
* Changes the `DimOp` rewrite to do the right thing.
* Changes the `ExpandOp` rewrite to compute the proper expansion size.

Depends On D138365

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D139165
2022-12-05 16:59:42 -08:00
Jakub Kuderski
2442aa3447 [mlir][spirv] Add extensions implied by SPIR-V 1.6
This adds existing extensions as implied by SPIR-V 1.6.

Also clean up the surrounding code.

Fixes: https://github.com/llvm/llvm-project/issues/59348.

Reviewed By: antiagainst

Differential Revision: https://reviews.llvm.org/D139369
2022-12-05 17:40:29 -05:00
Lei Zhang
3c278e5e27 [mlir][spirv] Fix spirv.MatrixTimesScalar for cooperative matrix
spirv.MatrixTimesScalar is allowed to use cooperative matrix.

Reviewed By: kuhar

Differential Revision: https://reviews.llvm.org/D139279
2022-12-05 22:13:23 +00:00
Peiming Liu
8a7e69d145 [mlir][sparse] Refactoring: abstract sparse tensor memory scheme into a SparseTensorDescriptor class.
This patch abstracts sparse tensor memory scheme into a SparseTensorDescriptor class. Previously, the field accesses are performed in a relatively error-prone way, this patch hides the hairy details behind a SparseTensorDescriptor class to allow users access sparse tensor fields in a more cohesive way.

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D138627
2022-12-05 22:11:53 +00:00
Hanhan Wang
0d03ba62c5 [mlir][tensor] Implement TilingInterface for tensor.pack op.
We can compute the offsets and sizes for the slice of input because the
iteration domain is defined over outer loops. If the dimension is tiled,
the i-th index is the product of offset_i and inner_tile_i.

Different from tiling a pad op, we do not have to deal with reading zero
data from input. Because the tiling sizes are indicated to packed outer
dimensions. We will read either the entire tile or partial tile for each
packed tile. The scf.if and tensor.generate ops are not needed in this
context.

Co-authored-by: Lorenzo Chelini <l.chelini@icloud.com>

Reviewed By: rengolin, mravishankar

Differential Revision: https://reviews.llvm.org/D138631
2022-12-05 14:00:10 -08:00
Jeff Niu
c48e0cf03a [mlir] Remove TypedAttr and ElementsAttr from DenseArrayAttr
This patch removes the implementation of TypedAttr and ElementsAttr
from DenseArrayAttr and, in doing so, removes the need store a shaped
type. The attribute now stores a size (number of elements), an MLIR type
as a discriminator, and a raw byte array.

The intent of DenseArrayAttr was not to be a drop-in replacement for DenseElementsAttr. It was meant to be a simple container of integers or floats that map to C++ types. The ElementsAttr implementation on DenseArrayAttr had many holes in it, and fixing those holes would require evolving DenseArrayAttr in a way that is incompatible with its original purpose.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D137606
2022-12-05 13:27:55 -08:00
River Riddle
737391bdf3 [mlir] Slightly optimize getRegions checks by inlining size check
Calculating the position of the region trailing objects isn't free,
given that it's the last trailing object, and inlining the size check
removes the need for users to explicitly add size checks for
micro-optimization.
2022-12-05 11:31:50 -08:00
Navdeep Katel
3d35546cd1 Support transpose mode for gpu.subgroup WMMA ops
Add support for loading, computing, and storing `gpu.subgroup` WMMA ops
in transpose mode as well. Update the GPU to NVVM lowerings to support
`transpose` mode and update integration tests as well.

Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D139021
2022-12-05 22:37:02 +05:30
Matthias Springer
50a2bb95ab [mlir][tensor] Fold rank-reducing extract_slice with inverse expand_shape
Differential Revision: https://reviews.llvm.org/D139220
2022-12-05 09:17:24 +01:00
Kazu Hirata
192d9dd731 [mlir] Use std::nullopt instead of None in comments (NFC)
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
2022-12-04 19:58:32 -08:00
Kazu Hirata
70c73d1b72 [mlir] Use std::nullopt instead of None in comments (NFC)
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
2022-12-04 17:23:50 -08:00
Kazu Hirata
004933e46a [mlir] Use std::nullopt instead of None (NFC)
I've verified that every single instance of std::nullopt in this patch
affects generated files and would reduce the number of warnings if
None were deprecated.

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
2022-12-04 14:40:08 -08:00
Kazu Hirata
5521097190 [mlir] Use std::nullopt instead of None (NFC)
I've verified that every change in this patch affects generated files
and would reduce the number of warnings if None were deprecated.

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
2022-12-04 13:52:46 -08:00
Kai Sasaki
1d541bd920 [mlir][affine] Support affine.parallel in the index set analysis
Support affine.parallel in the index set analysis. It allows us to do dependence analysis containing affine.parallel in addition to affine.for and affine.if. This change only supports the constant lower/upper bound in affine.parallel. Other complicated affine map bounds will be supported in further commits.

See https://github.com/llvm/llvm-project/issues/57327

Reviewed By: bondhugula

Differential Revision: https://reviews.llvm.org/D136056
2022-12-04 20:36:48 +09:00
Kazu Hirata
1a36588ec6 [mlir] Use std::nullopt instead of None (NFC)
This patch mechanically replaces None with std::nullopt where the
compiler would warn if None were deprecated.  The intent is to reduce
the amount of manual work required in migrating from Optional to
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
2022-12-03 18:50:27 -08:00
Joe Loser
5d3c972a35 [MLIR] Use if constexpr in StorageUniquer and IR/AffineExpr
Querying the type trait is something that can be done at compile time. So,
replace the runtime `if` with `if constexpr`.

Differential Revision: https://reviews.llvm.org/D139264
2022-12-03 19:07:11 -07:00
Joe Loser
4509fb9c00 [MLIR] Simplify key construction/hashing in StorageUniquer
`getKey` and `getHash` use mutually exclusive overloads based on existence of
methods to determine how to compute get the key or hash, respectively.  This is
a bit verbose with `std::enable_if_t`.  Simplify it a bit by using
`if constexpr` directly.  As an added bonus, this is slightly quicker to
compile.

Differential Revision: https://reviews.llvm.org/D139245
2022-12-03 17:19:46 -07:00
Peiming Liu
c7a9e5e5d2 [mlir][sparse][bufferization] cleanup bufferization attributes after SparsificationAndBufferizationPass
Reviewed By: aartbik, springerm

Differential Revision: https://reviews.llvm.org/D139218
2022-12-02 23:03:54 +00:00
River Riddle
b74192b7ae [mlir] Remove support for non-prefixed accessors
This finishes off a year long pursuit to LLVMify the generated
operation accessors, prefixing them with get/set. Support for
any other accessor naming is fully removed after this commit.

https://discourse.llvm.org/t/psa-raw-accessors-are-being-removed/65629

Differential Revision: https://reviews.llvm.org/D136727
2022-12-02 13:32:36 -08:00
Hanhan Wang
b1d3afc93e [mlir] Factor more common utils to IndexingUtils
Reviewed By: mravishankar

Differential Revision: https://reviews.llvm.org/D139159
2022-12-02 13:27:01 -08:00
Matthias Springer
f92c7506e3 Revert "[mlir][tensor] Fold rank-reducing extract_slice with inverse expand_shape"
This reverts commit a076f57a1a.
2022-12-02 21:22:20 +01:00
wren romano
1dfb9a64f1 [mlir][sparse] LICM for SparseTensorReader::readCOO
This commit performs two related changes.  First we adjust `readCOOValue` to take the `IsPattern` bool as a template parameter rather than a function argument.  Second we factor `readCOOLoop` out from `readCOO`, and template it on `IsPattern` and `IsSymmetric`.  Together this moves all the assertions and header-dependent conditionals out of the main for-loop of `readCOO`.  The only remaining conditional is in the `IsSymmetric=true` variant: checking whether the element is on the diagonal or not (which cannot be lifted out of the loop).

Depends On D138363

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D138365
2022-12-02 11:13:36 -08:00
wren romano
2af2e4dbb7 [mlir][sparse] Breaking up openSparseTensor to better support non-permutations
This commit updates how the `SparseTensorConversion` pass handles `NewOp`.  It breaks up the underlying `openSparseTensor` function into two parts (`SparseTensorReader::create` and `SparseTensorReader::readSparseTensor`) so that the pass can inject code for constructing `lvlSizes` between those two parts.  Migrating the construction of `lvlSizes` out of the runtime and into the pass is a necessary first step toward fully supporting non-permutations.  (The alternative would be for the pass to generate a `FuncOp` for performing the construction and then passing that to the runtime; which doesn't seem to have any benefits over the design of this commit.)  And since the pass now generates the code to call these two functions, this change also removes the `Action::kFromFile` value from the enum used by `_mlir_ciface_newSparseTensor`.

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D138363
2022-12-02 11:10:57 -08:00
Nicolas Vasilache
495acf98da [mlir][Linalg] NFC - Purge OpBuilder uses in favor of RewriterBase in places unrelated to op definitions
RewriterBase is the proper builder to use so one can listen to IR modifications (i.e. not just creation).

Differential Revision: https://reviews.llvm.org/D137922
2022-12-02 08:06:29 -08:00
Matthias Springer
c1fef4e88a [mlir][bufferization] Make TensorCopyInsertionPass a test pass
TensorCopyInsertion should not have been exposed as a pass. This was a flaw in the original design. It is a preparation step for bufferization and certain transforms (that would otherwise be legal) are illegal between TensorCopyInsertion and actual rewrite to MemRef ops. Therefore, even if broken down as two separate steps internally, they should be exposed as a single pass.

This change affects the sparse compiler, which uses `TensorCopyInsertionPass`. A new `SparsificationAndBufferizationPass` is added to replace all passes in the sparse tensor pipeline from `TensorCopyInsertionPass` until the actual bufferization (rewrite to memref/non-tensor). It is generally unsafe to run arbitrary passes in-between, in particular passes that hoist tensor ops out of loops or change SSA use-def chains along tensor ops.

Differential Revision: https://reviews.llvm.org/D138915
2022-12-02 15:38:02 +01:00
Lorenzo Chelini
7dc3bf0338 Revert "Revert "[MLIR] Introduce constraint attributes for DenseArrayAttr""
This reverts commit 4e6dab98e0.

Re-apply: D138988 after fixing error on windows. Remove test for boolean
attributes as it does not make sense to apply these constraints on
boolean array.
2022-12-02 15:00:46 +01:00
Matthias Springer
a076f57a1a [mlir][tensor] Fold rank-reducing extract_slice with inverse expand_shape
Differential Revision: https://reviews.llvm.org/D139103
2022-12-02 10:42:46 +01:00
River Riddle
ac9f88e862 [mlir][Index] Add pretty result names for ConstantOp and BoolConstantOp
ConstantOp uses `%idx<value>` and BoolConstantOp uses true/false, which
is similar to the printing for arith::ConstantOp.

Differential Revision: https://reviews.llvm.org/D139175
2022-12-02 01:34:29 -08:00
River Riddle
60b6c93ee9 [mlir] Allow access to the underlying diagnostic
This allows for more interesting manipulation of an
inflight diagnostic.
2022-12-02 00:48:34 -08:00