aboutsummaryrefslogtreecommitdiff
path: root/mlir/lib/Dialect/Linalg/Transforms/Fusion.cpp
AgeCommit message (Collapse)Author
2022-07-27[mlir] more aggressive folding in tiling/fusion transformationsAlex Zinenko
Combine the recently added utilities for folded-by-construction affine operations with the attribute-based Range to enable more folding. This decreases the amount of emitted code but has little effect on test precisely because the tests are not checking for the spurious constants. The difference in the shape of affine maps comes from the internals of affine folding. Depends on D129633 Reviewed By: nicolasvasilache Differential Revision: https://reviews.llvm.org/D130167
2022-07-27[mlir] Make ViewLikeInterface Range work with attributesAlex Zinenko
While most of methods in ViewLikeInterface accept an `OpFoldResult` for the offset/size/stride that may be static, represented as `Attribute`, or dynamic, represented as `Value`, the `Range` abstraction only accepted `Values`. This can often lead to known-constant offset/size/strides being materialized into constant operations and hinder further constant propagation without explicitly running the constant folding pass. This often leads to a more complicated than necessary addressing code being emitted. Switch `Range` to use `OpFoldResult`. Code that uses `Range` currently keeps materializing the constants to minimize the effect of this change on the IR. Further commits will make use of this. Reviewed By: nicolasvasilache, mravishankar Differential Revision: https://reviews.llvm.org/D129633
2022-07-21[mlir][Linalg] Deprecate `tileAndFuseLinalgOps` method and associated patterns.Mahesh Ravishankar
The `tileAndFuseLinalgOps` is a legacy approach for tiling + fusion of Linalg operations. Since it was also intended to work on operations with buffer operands, this method had fairly complex logic to make sure tile and fuse was correct even with side-effecting linalg ops. While complex, it still wasnt robust enough. This patch deprecates this method and thereby deprecating the tiling + fusion method for ops with buffer semantics. Note that the core transformation to do fusion of a producer with a tiled consumer still exists. The deprecation here only removes methods that auto-magically tried to tile and fuse correctly in presence of side-effects. The `tileAndFuseLinalgOps` also works with operations with tensor semantics. There are at least two other ways the same functionality exists. 1) The `tileConsumerAndFuseProducers` method. This does a similar transformation, but using a slightly different logic to automatically figure out the legal tile + fuse code. Note that this is also to be deprecated soon. 2) The prefered way uses the `TilingInterface` for tile + fuse, and relies on the caller to set the tiling options correctly to ensure that the generated code is correct. As proof that (2) is equivalent to the functionality provided by `tileAndFuseLinalgOps`, relevant tests have been moved to use the interface, where the test driver sets the tile sizes appropriately to generate the expected code. Differential Revision: https://reviews.llvm.org/D129901
2022-07-14[mlir] Use value instead of getValue (NFC)Kazu Hirata
2022-07-12[mlir] Handle linalg.index correctly in TilingInterfaceAlex Zinenko
The existing implementation of the TilingInterface for Linalg ops was not modifying the `linalg.index` ops contained within other Linalg ops (they need to be summed up with the values of respective tile loop induction variables), which led to the interface-based tiling being incorrect for any Linalg op with index semantics. In the process, fix the function performing the index offsetting to use the pattern rewriter API instead of RAUW as it is being called from patterns and may mess up the internal state of the rewriter. Also rename the function to clearly catch all uses. Depends On D129365 Reviewed By: mravishankar Differential Revision: https://reviews.llvm.org/D129366
2022-06-28[mlir] Update flipped accessors (NFC)Jacques Pienaar
Follow up with memref flipped and flipping any intermediate changes made.
2022-06-25Revert "Don't use Optional::hasValue (NFC)"Kazu Hirata
This reverts commit aa8feeefd3ac6c78ee8f67bf033976fc7d68bc6d.
2022-06-25Don't use Optional::hasValue (NFC)Kazu Hirata
2022-06-20[mlir] Don't use Optional::getValue (NFC)Kazu Hirata
2022-04-29[mlir][linalg][transform] Add TileOp to transform dialectMatthias Springer
This commit adds a tiling op to the transform dialect as an external op. Differential Revision: https://reviews.llvm.org/D124661
2022-03-31[mlir] Bubble up tensor.extract_slice above linalg operationOkwan Kwon
Bubble up extract_slice above Linalg operation. A sequence of operations %0 = linalg.<op> ... arg0, arg1, ... %1 = tensor.extract_slice %0 ... can be replaced with %0 = tensor.extract_slice %arg0 %1 = tensor.extract_slice %arg1 %2 = linalg.<op> ... %0, %1, ... This results in the reduce computation of the linalg operation. The implementation uses the tiling utility functions. One difference from the tiling process is that we don't need to insert the checking code for the out-of-bound accesses. The use of the slice itself represents that the code writer is sure about the boundary condition. To avoid adding the boundary condtion check code, `omitPartialTileCheck` is introduced for the tiling utility functions. Differential Revision: https://reviews.llvm.org/D122437
2022-02-28[mlir] Purge linalg.tiled_loop.Alexander Belyaev
Differential Revision: https://reviews.llvm.org/D119415
2022-02-07[mlir] Use SmallBitVector instead of SmallDenseSet for ↵Benjamin Kramer
AffineMap::compressSymbols This is both more efficient and more ergonomic to use, as inverting a bit vector is trivial while inverting a set is annoying. Sadly this leaks into a bunch of APIs downstream, so adapt them as well. This would be NFC, but there is an ordering dependency in MemRefOps's computeMemRefRankReductionMask. This is now deterministic, previously it was dependent on SmallDenseSet's unspecified iteration order. Differential Revision: https://reviews.llvm.org/D119076
2022-02-01Revert "Revert "[mlir] Purge `linalg.copy` and use `memref.copy` instead.""Alexander Belyaev
This reverts commit 25bf6a2a9bc6ecb3792199490c70c4ce50a94aea.
2022-01-31Revert "[mlir] Purge `linalg.copy` and use `memref.copy` instead."Alexander Belyaev
This reverts commit 016956b68081705ffee511c334e31e414fa1ddbf. Reverting it to fix NVidia build without being in a hurry.
2022-01-31[mlir] Purge `linalg.copy` and use `memref.copy` instead.Alexander Belyaev
Differential Revision: https://reviews.llvm.org/D118028
2022-01-06[mlir][Linalg] NFC - Modernize APIs and get rid of unnecessary tiling paterns.Nicolas Vasilache
Tiling patterns can be reduced to a single pattern by using interface-based patterns. Differential Revision: https://reviews.llvm.org/D116733
2022-01-02Apply clang-tidy fixes for performance-for-range-copy to MLIR (NFC)Mehdi Amini
2022-01-01[mlir] Remove unused "using" (NFC)Kazu Hirata
Identified by misc-unused-using-decls.
2021-12-15[mlir][linalg] Replace LinalgOps.h and LinalgTypes.h by a single header.gysit
After removing the range type, Linalg does not define any type. The revision thus consolidates the LinalgOps.h and LinalgTypes.h into a single Linalg.h header. Additionally, LinalgTypes.cpp is renamed to LinalgDialect.cpp to follow the convention adopted by other dialects such as the tensor dialect. Depends On D115727 Reviewed By: nicolasvasilache Differential Revision: https://reviews.llvm.org/D115728
2021-10-22[mlir][Linalg] NFC - Drop Optional in favor of FailureOrNicolas Vasilache
Differential revision: https://reviews.llvm.org/D112332
2021-10-13[MLIR] Replace std ops with arith dialect opsMogball
Precursor: https://reviews.llvm.org/D110200 Removed redundant ops from the standard dialect that were moved to the `arith` or `math` dialects. Renamed all instances of operations in the codebase and in tests. Reviewed By: rriddle, jpienaar Differential Revision: https://reviews.llvm.org/D110797
2021-10-08[mlir][linalg] Retire Linalg ConvOp.Tobias Gysi
The convolution op is one of the remaining hard coded Linalg operations that have no region attached. It got obsolete due to the OpDSL convolution operations. Removing it allows us to delete specialized code and tests that are not needed for the OpDSL counterparts that rely on the standard code paths. Test needed due to specialized implementations are removed. Tiling and fusion tests are replaced by variants using linalg.conv_2d. Reviewed By: nicolasvasilache Differential Revision: https://reviews.llvm.org/D111233
2021-09-17[mlir][linalg] Add helper to update IndexOps after tiling (NFC).Tobias Gysi
Add the addTileLoopIvsToIndexOpResults method to shift the IndexOp results after tiling. Reviewed By: nicolasvasilache Differential Revision: https://reviews.llvm.org/D109761
2021-09-09[mlir][linalg] Tiling: Use loop ub in extract_slice size computation if possibleMatthias Springer
When tiling a LinalgOp, extract_slice/insert_slice pairs are inserted. To avoid going out-of-bounds when the tile size does not divide the shape size evenly (at the boundary), AffineMin ops are inserted. Some ops have assumptions regarding the dimensions of inputs/outputs. E.g., in a `A * B` matmul, `dim(A, 1) == dim(B, 0)`. However, loop bounds use either `dim(A, 1)` or `dim(B, 0)`. With this change, AffineMin ops are expressed in terms of loop bounds instead of tensor sizes. (Both have the same runtime value.) This simplifies canonicalizations. Differential Revision: https://reviews.llvm.org/D109267
2021-07-01[mlir][tensor] Add tensor.dim operationMatthias Springer
* Split memref.dim into two operations: memref.dim and tensor.dim. Both ops have the same builder interface and op argument names, so that they can be used with templates in patterns that apply to both tensors and memrefs (e.g., some patterns in Linalg). * Add constant materializer to TensorDialect (needed for folding in affine.apply etc.). * Remove some MemRefDialect dependencies, make some explicit. Differential Revision: https://reviews.llvm.org/D105165
2021-06-29[mlir][linalg] All StructuredOp parameters are inputs or outputs.Tobias Gysi
Adapt the StructuredOp verifier to ensure all operands are either in the input or the output group. The change is possible after adding support for scalar input operands (https://reviews.llvm.org/D104220). Differential Revision: https://reviews.llvm.org/D104783
2021-06-23[mlir][linalg] Change the pretty printed FillOp operand order.Tobias Gysi
The patch changes the pretty printed FillOp operand order from output, value to value, output. The change is a follow up to https://reviews.llvm.org/D104121 that passes the fill value using a scalar input instead of the former capture semantics. Differential Revision: https://reviews.llvm.org/D104356
2021-06-22[mlir][NFC] Move SubTensorOp and SubTensorInsertOp to TensorDialectMatthias Springer
The main goal of this commit is to remove the dependency of Standard dialect on the Tensor dialect. * Rename SubTensorOp -> tensor.extract_slice, SubTensorInsertOp -> tensor.insert_slice. * Some helper functions are (already) duplicated between the Tensor dialect and the MemRef dialect. To keep this commit smaller, this will be cleaned up in a separate commit. * Additional dialect dependencies: Shape --> Tensor, Tensor --> Standard * Remove dialect dependencies: Standard --> Tensor * Move canonicalization test cases to correct dialect (Tensor/MemRef). Note: This is a fixed version of https://reviews.llvm.org/D104499, which was reverted due to a missing update to two CMakeFile.txt. Differential Revision: https://reviews.llvm.org/D104676
2021-06-21Revert "[mlir][NFC] Move SubTensorOp and SubTensorInsertOp to TensorDialect"Mehdi Amini
This reverts commit 83bf801f5f266c788f025a3efbb0c83817137c3b. This breaks the build with -DBUILD_SHARED_LIBS=ON
2021-06-22[mlir][NFC] Move SubTensorOp and SubTensorInsertOp to TensorDialectMatthias Springer
The main goal of this commit is to remove the dependency of Standard dialect on the Tensor dialect. * Rename ops: SubTensorOp --> ExtractTensorOp, SubTensorInsertOp --> InsertTensorOp * Some helper functions are (already) duplicated between the Tensor dialect and the MemRef dialect. To keep this commit smaller, this will be cleaned up in a separate commit. * Additional dialect dependencies: Shape --> Tensor, Tensor --> Standard * Remove dialect dependencies: Standard --> Tensor * Move canonicalization test cases to correct dialect (Tensor/MemRef). Differential Revision: https://reviews.llvm.org/D104499
2021-06-17[mlir][linalg] Purge linalg.indexed_generic.Alexander Belyaev
Differential Revision: https://reviews.llvm.org/D104449
2021-06-14[mlir][linalg] Add support for scalar input operands.Tobias Gysi
Up to now all structured op operands are assumed to be shaped. The patch relaxes this assumption and allows scalar input operands. In contrast to shaped operands scalar operands are not indexed and directly forwarded to the body of the operation. As all other operands, scalar operands are associated to an indexing map that in case of a scalar or a 0D-operand has an empty range. We will use scalar operands as a replacement for the capture mechanism. In contrast to captures, the approach ensures we can generate the function signature from the operand list and it prevents outdated capture values in case a transformation updates only the capture operand but not the hidden body of a named operation. Removing captures and updating existing operations such as linalg.fill is left for a later patch. The patch depends on https://reviews.llvm.org/D103891 and https://reviews.llvm.org/D103890. Differential Revision: https://reviews.llvm.org/D104109
2021-06-01[mlir][linalg] Cleanup LinalgOp usage in fusion (NFC).Tobias Gysi
Replace the uses of deprecated Structured Op Interface methods in Fusion.cpp. This patch is based on https://reviews.llvm.org/D103394. Differential Revision: https://reviews.llvm.org/D103437
2021-05-21[mlir] Add support for fusion into TiledLoopOp.Alexander Belyaev
Differential Revision: https://reviews.llvm.org/D102722
2021-05-21[mlir][Standard] NFC - Drop remaining EDSC usageNicolas Vasilache
Drop the remaining EDSC subdirectories and update all uses. Differential Revision: https://reviews.llvm.org/D102911
2021-05-20[mlir][MemRef] NFC - Drop MemRef EDSC usageNicolas Vasilache
Drop the MemRef dialect EDSC subdirectory and update all uses. Differential Revision: https://reviews.llvm.org/D102868
2021-05-13[mlir][NFC] Add helper for common pattern of replaceAllUsesExceptSean Silva
This covers the extremely common case of replacing all uses of a Value with a new op that is itself a user of the original Value. This should also be a little bit more efficient than the `SmallPtrSet<Operation *, 1>{op}` idiom that was being used before. Differential Revision: https://reviews.llvm.org/D102373
2021-05-11[mlir][linalg] Remove IndexedGenericOp support from Fusion...Tobias Gysi
after introducing the IndexedGenericOp to GenericOp canonicalization (https://reviews.llvm.org/D101612). Differential Revision: https://reviews.llvm.org/D102174
2021-04-16[mlir][linalg] Add support for WAW fusion on tensors.Nicolas Vasilache
Differential Revision: https://reviews.llvm.org/D100603
2021-04-14[mlir][linalg] update fusion to support linalg index operations.Tobias Gysi
The patch updates the linalg fusion pass to add the tile offsets to the indices. Differential Revision: https://reviews.llvm.org/D100456
2021-03-24[mlir][linalg] Fuse producers with non-permutation indexing mapsLei Zhang
Until now Linalg fusion only allow fusing producers whose operands are all permutation indexing maps. It's easier to deduce the subtensor/subview but it is an unnecessary constraint, as in tiling we have more advanced logic to deduce the subranges even when the operand is not of permutation indexing maps, e.g., the input operand for convolution ops. This patch uses the logic on tiling side to deduce subranges for fusion. This enables fusing convolution with its consumer ops when possible. Along the way, we are now generating proper affine.min ops to guard against size boundaries, if we cannot be certain they won't be out of bounds. Differential Revision: https://reviews.llvm.org/D99014
2021-03-15[MLIR] Create memref dialect and move dialect-specific ops from std.Julian Gross
Create the memref dialect and move dialect-specific ops from std dialect to this dialect. Moved ops: AllocOp -> MemRef_AllocOp AllocaOp -> MemRef_AllocaOp AssumeAlignmentOp -> MemRef_AssumeAlignmentOp DeallocOp -> MemRef_DeallocOp DimOp -> MemRef_DimOp MemRefCastOp -> MemRef_CastOp MemRefReinterpretCastOp -> MemRef_ReinterpretCastOp GetGlobalMemRefOp -> MemRef_GetGlobalOp GlobalMemRefOp -> MemRef_GlobalOp LoadOp -> MemRef_LoadOp PrefetchOp -> MemRef_PrefetchOp ReshapeOp -> MemRef_ReshapeOp StoreOp -> MemRef_StoreOp SubViewOp -> MemRef_SubViewOp TransposeOp -> MemRef_TransposeOp TensorLoadOp -> MemRef_TensorLoadOp TensorStoreOp -> MemRef_TensorStoreOp TensorToMemRefOp -> MemRef_BufferCastOp ViewOp -> MemRef_ViewOp The roadmap to split the memref dialect from std is discussed here: https://llvm.discourse.group/t/rfc-split-the-memref-dialect-from-std/2667 Differential Revision: https://reviews.llvm.org/D98041
2021-02-11s[mlir] Tighten computation of inferred SubView result type.Nicolas Vasilache
The AffineMap in the MemRef inferred by SubViewOp may have uncompressed symbols which result in type mismatch on otherwise unused symbols. Make the computation of the AffineMap compress those unused symbols which results in better canonical types. Additionally, improve the error message to report which inferred type was expected. Differential Revision: https://reviews.llvm.org/D96551
2021-02-04[mlir][Linalg] Drop SliceOpNicolas Vasilache
This op is subsumed by rank-reducing SubViewOp and has become useless. Differential revision: https://reviews.llvm.org/D95317
2021-01-28[mlir][Linalg] Enable TileAndFusePattern to work with tensors.MaheshRavishankar
Differential Revision: https://reviews.llvm.org/D94531
2021-01-25[mlir] Generalize OpFoldResult usage in ops with offsets, sizes and operands.Nicolas Vasilache
This revision starts evolving the APIs to manipulate ops with offsets, sizes and operands towards a ValueOrAttr abstraction that is already used in folding under the name OpFoldResult. The objective, in the future, is to allow such manipulations all the way to the level of ODS to avoid all the genuflexions involved in distinguishing between values and attributes for generic constant foldings. Once this evolution is accepted, the next step will be a mechanical OpFoldResult -> ValueOrAttr. Differential Revision: https://reviews.llvm.org/D95310
2021-01-22[mlir][Linalg] Extend tile+fuse to work on Linalg operation on tensors.MaheshRavishankar
Differential Revision: https://reviews.llvm.org/D93086
2021-01-22[mlir][Linalg] NFC: Refactor LinalgDependenceGraphElem to allowMaheshRavishankar
representing dependence from producer result to consumer. With Linalg on tensors the dependence between operations can be from the result of the producer to the consumer. This change just does a NFC refactoring of the LinalgDependenceGraphElem to allow representing both OpResult and OpOperand*. Differential Revision: https://reviews.llvm.org/D95208
2021-01-12Delete unused function (was breaking the -Werror build)David Blaikie