Commit Graph

1219 Commits

Author SHA1 Message Date
Mehdi Amini
1c65897978 Apply clang-tidy fixes for readability-simplify-boolean-expr in Vectorization.cpp (NFC) 2023-01-08 12:04:52 +00:00
Alex Zinenko
c214cee772 [mlir] improve error handling in Linalg op splitting
In several cases, the splitting may be known to be a noop, i.e., produce
no second part. Thread this information through the transform utilities
to the transform dialect, and differentiate it from the error state.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D141138
2023-01-06 18:35:08 +01:00
Murali Vijayaraghavan
755e776849 [mlir][linalg] Vectorize 1D convolution
Differential Revision: https://reviews.llvm.org/D140188
2023-01-05 23:08:32 +00:00
Alex Zinenko
faac898987 [mlir] fix out-of-bounds in reduction tiling
A transformation tiling a reduction dimension of a Linalg op needs a
tile size for said dimension. When an insufficient number of dimensions
was provided, it would segfault due to out-of-bounds access to a vector.

Also fix incorrect error reporting in the structured transform op
exercising this functionality.

Reviewed By: springerm, ThomasRaoux

Differential Revision: https://reviews.llvm.org/D141046
2023-01-05 15:20:26 +00:00
Mehdi Amini
16b2604423 Apply clang-tidy fixes for performance-for-range-copy in Vectorization.cpp (NFC) 2022-12-29 20:50:25 +00:00
Andrzej Warzynski
9d6f2b5f35 [mlir] Add a newline character in the Linalg debug macro
Differential Revision: https://reviews.llvm.org/D140752
2022-12-29 10:01:30 +00:00
Matthias Springer
6b76c4eafd [mlir][linalg] Bring populateFoldUnitExtentDimsVia(Reshapes/Slices)Patterns in sync
Make sure that both functions populate patterns with the same functionality. Both should be refactored at some point so that canonicalization patterns are not populated.

Differential Revision: https://reviews.llvm.org/D140372
2022-12-20 13:10:12 +01:00
Hanhan Wang
3ebc6bee6b [mlir][tensor][linalg] Add a pattern that generalizes tensor.unpack op.
The pattern generalizes a tensor::UnPackOp into a sequence of tensor +
Linalg ops, when the outer dims are all 1s. It uses the trick of
rank-reduced tensor.extract_slice to get the tile; transpose the tile;
extract sub tile for incomplete cases if needed; use tensor.insert_slice
to insert it to the destination tensor.

Reviewed By: tyb0807, chelini

Differential Revision: https://reviews.llvm.org/D140254
2022-12-19 17:52:10 -08:00
Murali Vijayaraghavan
1a151fdc01 [mlir][linalg] Downscale 2D pooling with unit dimensions for height to 1D pooling
Differential Revision: https://reviews.llvm.org/D140187
2022-12-19 22:34:43 +00:00
Matthias Springer
a583616918 [mlir][vector] Fix error handling in VectorizationState::initState
This function used to create new ops even if the vectorization failed. Those ops were then folded away. This caused a failure of the GreedyPatternRewriter, which no longer terminated (each time the IR is modified => one more iteration).

Differential Revision: https://reviews.llvm.org/D140286
2022-12-19 10:20:05 +01:00
Fangrui Song
cbb0981388 [mlir] llvm::Optional::value => operator*/operator->
std::optional::value() has undesired exception checking semantics and is
unavailable in older Xcode (see _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS). The
call sites block std::optional migration.
2022-12-17 19:07:38 +00:00
Ramkumar Ramachandra
22426110c5 mlir/tblgen: use std::optional in generation
This is part of an effort to migrate from llvm::Optional to
std::optional. This patch changes the way mlir-tblgen generates .inc
files, and modifies tests and documentation appropriately. It is a "no
compromises" patch, and doesn't leave the user with an unpleasant mix of
llvm::Optional and std::optional.

A non-trivial change has been made to ControlFlowInterfaces to split one
constructor into two, relating to a build failure on Windows.

See also: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

Signed-off-by: Ramkumar Ramachandra <r@artagnon.com>

Differential Revision: https://reviews.llvm.org/D138934
2022-12-17 11:13:26 +01:00
Hanhan Wang
644f0f834d [mlir][tensor][linalg] Add a pattern that generalizes tensor.pack op.
The pattern generalizes a tensor::PackOp into a sequence of tensor +
Linalg ops, when the outer dims are all 1s. It uses the trick of
rank-reduced tensor.extract_slice to get the tile; transpose the tile;
use tensor.insert_slice to insert it to the destination of inner tile.

Reviewed By: pifon2a, tyb0807

Differential Revision: https://reviews.llvm.org/D140060
2022-12-15 15:27:59 -08:00
Mehdi Amini
f1321b0ab8 Apply clang-tidy fixes for llvm-qualified-auto in ElementwiseOpFusion.cpp (NFC) 2022-12-15 17:21:53 +00:00
Mehdi Amini
65954a33c3 Apply clang-tidy fixes for bugprone-argument-comment in BufferizableOpInterfaceImpl.cpp (NFC) 2022-12-15 17:21:53 +00:00
Matthias Springer
d2b070d3c9 [mlir][linalg][NFC] Split populateFoldUnitExtentDimsViaReshapesPatterns
MoveInitOperandsToInput is put into a separate populate... function because it can interfere with certain transformations.

Differential Revision: https://reviews.llvm.org/D140091
2022-12-15 12:04:40 +01:00
Matthias Springer
e07149c91f [mlir][linalg] Add option to generate rank-reducing slices in DropUnitDims
This change extends the `ReplaceUnitExtents` pattern so that users can choose between of two strategies for generating rank reductions:
* CollapseShapeOp / ExpandShapeOp (was already implemented but code was cleaned up; default strategy)
* rank-reducing ExtractSliceOp / InsertSliceOp

Also add helper functions to the memref dialect that we already have on the tensor dialect: `getMixedSizes`, `createCanonicalRankReducingSubViewOp`, `rankReduceIfNeeded`.

We are using ReassociationIndices instead of ReassoicationExprs in many other places and this makes the code easier to read. Also adding a new test case (that also passed before).

Differential Revision: https://reviews.llvm.org/D139947
2022-12-14 14:10:04 +01:00
Kazu Hirata
cadd8d3e20 [mlir] Fix a warning
This patch fixes:

  mlir/lib/Dialect/Linalg/Transforms/DataLayoutPropagation.cpp:52:42:
  error: 'None' is deprecated: Use std::nullopt
  instead. [-Werror,-Wdeprecated-declarations]
2022-12-13 15:44:30 -08:00
Hanhan Wang
d38d606558 [mlir][tensor][linalg] Enhance pack op propagation across generic ops.
Considering the case that generic + pack (with outer_dim_perms), the
truth is that it is equipvelent to generic + pack + transpose. There are
two steps to bubble up the pack op accross the generic op.

Step 1. swap generic + pack -> pack + generic.

In this step, we can bind the packing information to dimensions of
iteration domain. With the information, we can pack the operands with
corresponding data tile sizes; the packed inner dimensions will be
appended to the indexing_maps. Note that the outer dimensions of
indexing maps are not changed at all.

Step 2. Fold the transpose into generic op.

The step two is just updating the indexing map, so we do not have to
handle outer_dim_perms anymore.

There could be step 3 to extract the transpose op out (i.e., generic ->
transpose + generic), then we can fold the transpose into the pack op.
This step is not done in the revision.

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

Reviewed By: chelini

Differential Revision: https://reviews.llvm.org/D139680
2022-12-13 14:06:13 -08:00
Aliia Khasanova
ded75a282a Remove sentinel argument from dispatchIndexOpFoldResults.
Post clean-up after merger of kDynamicSize and kDynamicStrideOrOffset.

Differential Revision: https://reviews.llvm.org/D139929
2022-12-13 14:04:46 +01:00
Diego Caballero
72fd36448d [mlir][Vector] Initial masking support in Linalg vectorizer
This patch introduces the initial bits to support vector masking
using the `vector.mask` operation. Vectorization changes should be
NFC for non-masked cases. We can't test masked cases directly until
we extend the Transform dialect to support masking.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D137690
2022-12-13 01:33:06 +00:00
Andrzej Warzynski
c181f21ac7 [MLIR] Vectorize tensor.extract on n-D tensor (n >= 2)
This patch implements the vectorization of tensor.extract for arbitrary
tensors. It basically extends https://reviews.llvm.org/D133786 by adding
support for n-D tensors (n >= 2). This is implemented by essentially
flattening the indices.

When benchmarking the vectorized code, we have observed that it is
slower than the scalar code. That's most likely due to sub-optimal (and,
in general slow) gather loads. More work is needed to identify an
implementation and/or a representation that would lead to better code.
In the meantime, the vectorization of n-D tensors (where n >= 2) has to
be explicitly enabled. This can be done either via:
  * transfer dialect's `vectorize_nd_extract` attribute,
  * dedicated bool argument in the `vectorize` method from
    "Vectorization.cpp".
The second option was added to control the new functionality through
means other than the transfer dialect.

Related discussion: https://github.com/iree-org/iree/issues/9198

Differential Revision: https://reviews.llvm.org/D137660
2022-12-12 09:32:16 +00:00
Nicolas Vasilache
06ca5c81a4 [mlir][Linalg] Apply fixes to TileReductionUsingForeachThreadOp
In the process, numerous insertion point issues were found and fixed.
RAII on insertion points is now used more dilligently.

Differential Revision: https://reviews.llvm.org/D139714
2022-12-09 07:51:12 -08:00
Matthias Springer
e7328a9eb2 [mlir][linalg] Fold duplicate and unused inputs in linalg.generic
If an input bbArg is not used, its corresponding input operand is removed. If there are duplicate input operands or input operands that are also used as output operands, the duplicate input operands are removed. Output operands are never modified.

Differential Revision: https://reviews.llvm.org/D139709
2022-12-09 15:18:26 +01: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
Javier Setoain
da291bab81 [mlir] Add hoisting of transfer ops in affine loops
The only way to do this with the current hoisting strategy is by
lowering Affine to Scf first, but that prevents further passes on
Affine.

Differential Revision: https://reviews.llvm.org/D137600
2022-12-07 20:08:07 +00: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
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
Mitch Phillips
969f0cba7e Revert "[mlir] Add hoisting of transfer ops in affine loops"
This reverts commit 825da072a8.

Reason: Broke the sanitizer buildbots. See original review for more
details: https://reviews.llvm.org/D137600
2022-12-06 09:44:59 -08:00
Javier Setoain
825da072a8 [mlir] Add hoisting of transfer ops in affine loops
The only way to do this with the current hoisting strategy is by
lowering Affine to Scf first, but that prevents further passes on
Affine.

Differential Revision: https://reviews.llvm.org/D137600
2022-12-06 10:07:21 +00:00
Guray Ozen
12cc8e7310 [mlir] Fix infinite loop in collapse
Incrementing `counter` variable is inside the if statement. If the code does not enter there, the while loop will iterate infinitely. This revision moves the codes outside of if statement.

Reviewed By: mravishankar

Differential Revision: https://reviews.llvm.org/D139005
2022-12-05 12:57:20 +01:00
Adrian Kuegel
215666d983 [mlir][Linalg] Apply ClangTidy fixes (NFC) 2022-12-05 08:18:00 +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
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
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
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
Nicolas Vasilache
3a6ae0f8f5 [mlir][Linalg][NFC] Improve debugging during vectorization
Make more systematic use of `notifyMatchFailure`.
2022-12-01 02:49:52 -08:00
Christian Sigg
be065c41d8 [mlir] Change scf::LoopNest to store 'results'.
This fixes the case where scf::LoopNest::loops is empty.

Change LoopVector and ValueVector to SmallVector.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D136926
2022-12-01 06:51:45 +01:00
Murali Vijayaraghavan
2d2cdf4176 [mlir][linalg] Changing the positions of introduced parallel loop in SplitReduction to be consistent with IREE's downstream passes
IREE's passes depend on the behavior of SplitReduction's introduced
parallel loop being the same as the introduced dimension in the
intermediate tensor (the order of loops was changed in
https://reviews.llvm.org/D137478).

Differential Revision: https://reviews.llvm.org/D138972
2022-11-30 04:01:07 +00:00
Ivan Butygin
e3f75c1cb7 [mlir][linalg] Allow some fusion on mixed generics
Relax linalg elementwise fusion check to allow mixed consumers. Producer is still required to be fully tensor to avoid potential memref aliasing.

Differential Revision: https://reviews.llvm.org/D138759
2022-11-29 15:35:02 +01:00
Hanhan Wang
9b16d9d271 [mlir][linalg] Add a new pattern to handle folding unit reduction dims.
The output operands will be added to input operands if the generic op (on tensors)
becomes an elementwise operation. The outputs of the generic op is still the same.
They will be cleaned up by ReplaceWithEmptyTensorIfUnused pattern.

This is https://reviews.llvm.org/D138251, plus a cmake dep fix.

Reviewed By: mravishankar

Differential Revision: https://reviews.llvm.org/D138843
2022-11-28 14:14:43 -08:00
Guray Ozen
135977c92a [mlir] Export collapseGenericOpIterationDims (NFC)
This revision exports `collapseGenericOpIterationDims` to a header so it can be used outside of the pattern.  We have use-case where we want to call this function directly.

Reviewed By: springerm

Differential Revision: https://reviews.llvm.org/D138697
2022-11-28 13:54:26 +01:00
Ramkumar Ramachandra
537137ece1 mlir/linalg: use std::optional
This is part of an effort to migrate from llvm::Optional to std::optional:

See also: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

Signed-off-by: Ramkumar Ramachandra <r@artagnon.com>
2022-11-27 13:32:20 -08:00
Lorenzo Chelini
a9733b8a5e [MLIR] Adopt DenseI64ArrayAttr in tensor, memref and linalg transform
This commit is a first step toward removing inconsistencies between dynamic
and static attributes (i64 v. index) by dropping `I64ArrayAttr` and
using `DenseI64ArrayAttr` in Tensor, Memref and Linalg Transform ops.
In Linalg Transform ops only `TileToScfForOp` and `TileOp` have been updated.

See related discussion: https://discourse.llvm.org/t/rfc-inconsistency-between-dynamic-and-static-attributes-i64-v-index/66612/1

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D138567
2022-11-25 09:43:30 +01:00
Hanhan Wang
a827c5c7ab Revert "[mlir][linalg] Add a new pattern to handle folding unit reduction dims."
This reverts commit 6eee66d12a.

It breaks builds, see https://lab.llvm.org/buildbot/#/builders/61/builds/35742

Differential Revision: https://reviews.llvm.org/D138633
2022-11-23 19:07:01 -08:00
Hanhan Wang
6eee66d12a [mlir][linalg] Add a new pattern to handle folding unit reduction dims.
The output operands will be added to input operands if the generic op (on tensors)
becomes an elementwise operation. The outputs of the generic op is still the same.
They will be cleaned up by ReplaceWithEmptyTensorIfUnused pattern.

Reviewed By: mravishankar

Differential Revision: https://reviews.llvm.org/D138251
2022-11-23 10:47:10 -08:00
Alexander Belyaev
f286af29d8 [mlir] Remove clone methods from DPS interface.
Differential Revision: https://reviews.llvm.org/D138586
2022-11-23 19:25:26 +01:00
Mahesh Ravishankar
2d4b998697 [mlir][Linalg] Avoid unnecessary propagating producer result to fused op result.
Elementwise op fusion conserves the result of the producer in the
fused op, relying on later clean up patterns to drop unused results of
the fused op. Instead, if the producer result has no other use apart
from the consumer op, avoid making the producer result available in
the fused node. This saves some unnecessary IR manipulations.

Differential Revision: https://reviews.llvm.org/D138096
2022-11-22 07:08:17 +00:00
Aliia Khasanova
399638f98c Merge kDynamicSize and kDynamicSentinel into one constant.
resolve conflicts

Differential Revision: https://reviews.llvm.org/D138282
2022-11-21 13:01:26 +00:00