Commit Graph

2129 Commits

Author SHA1 Message Date
gysit a3655de2c8 [mlir][OpDSL] Add support for basic rank polymorphism.
Previously, OpDSL did not support rank polymorphism, which required a separate implementation of linalg.fill. This revision extends OpDSL to support rank polymorphism for a limited class of operations that access only scalars and tensors of rank zero. At operation instantiation time, it scales these scalar computations to multi-dimensional pointwise computations by replacing the empty indexing maps with identity index maps. The revision does not change the DSL itself, instead it adapts the Python emitter and the YAML generator to generate different indexing maps and and iterators depending on the rank of the first output.

Additionally, the revision introduces a `linalg.fill_tensor` operation that in a future revision shall replace the current handwritten `linalg.fill` operation. `linalg.fill_tensor` is thus only temporarily available and will be renamed to `linalg.fill`.

Reviewed By: nicolasvasilache, stellaraccident

Differential Revision: https://reviews.llvm.org/D119003
2022-02-11 08:27:49 +00:00
Thomas Raoux 5ab04bc068 [mlir][gpu] Add device side async copy operations
Add new operations to the gpu dialect to represent device side
asynchronous copies. This also add the lowering of those operations to
nvvm dialect.
Those ops are meant to be low level and map directly to llvm dialects
like nvvm or rocdl.

We can further add higher level of abstraction by building on top of
those operations.
This has been discuss here:
https://discourse.llvm.org/t/modeling-gpu-async-copy-ampere-feature/4924

Differential Revision: https://reviews.llvm.org/D119191
2022-02-10 17:25:59 -08:00
Nirvedh ad9b5a4b8e [mlir][vector] Add pattern to drop lead unit dim for Contraction Op
If the result operand has a unit leading dim it is removed from all operands.

Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D119206
2022-02-10 09:51:07 -08:00
Lei Zhang 06a0385142 [mlir][linalg] Fold tensor.pad(linalg.fill) with the same value
Reviewed By: mravishankar

Differential Revision: https://reviews.llvm.org/D119160
2022-02-10 08:39:35 -05:00
Matthias Springer fe0bf7d469 [mlir][vector][NFC] Use CombiningKindAttr instead of StringAttr
This makes the op consistent with other ops in vector dialect.

Differential Revision: https://reviews.llvm.org/D119343
2022-02-10 19:13:29 +09:00
Tres Popp 34ff99a0b7 Revert "[MLIR] Fix fold-memref-subview-ops for affine.load/store"
This reverts commit ac6cb41303.

This code has a stack-use-after-scope error that can be seen with asan.
2022-02-10 10:46:59 +01:00
Uday Bondhugula ac6cb41303 [MLIR] Fix fold-memref-subview-ops for affine.load/store
Fix fold-memref-subview-ops for affine.load/store. We need to expand out
the affine apply on its operands.

Differential Revision: https://reviews.llvm.org/D119402
2022-02-10 13:55:38 +05:30
Matthias Springer 22a1973dbe [mlir][linalg][bufferize] Print results of FuncOp read/write analysis
Print more information with test-analysis-only.

Differential Revision: https://reviews.llvm.org/D119118
2022-02-09 20:52:38 +09:00
Jacques Pienaar bbddd19ec7 [mlir][math] Expand coverage of atan2 expansion
Reuse the higher precision F32 approximation for the F16 one (by expanding and
truncating). This is partly RFC as I'm not sure what the expectations are here
(e.g., these are only for F32 and should not be expanded, that reusing
higher-precision ones for lower precision is undesirable due to increased
compute cost and only approximations per exact type is preferred, or this is
appropriate [at least as fallback] but we need to see how to make it more
generic across all the patterns here).

Differential Revision: https://reviews.llvm.org/D118968
2022-02-08 15:00:39 -08:00
harsh 4a876b13fb Add case to handle 0-D vectors in FlattenContiguousRowMajorTransferWritePattern and FlattenContiguousRowMajorTransferReadPattern.
For 0-D as well as 1-D vectors, both these patterns should
return a failure as there is no need to collapse the shape
of the source. Currently, only 1-D vectors were handled. This
patch handles the 0-D case as well.

Reviewed By: Benoit, ThomasRaoux

Differential Revision: https://reviews.llvm.org/D119202
2022-02-08 20:00:12 +00:00
Mahesh Ravishankar 2abd7f13bc [mlir][Linalg] NFC: Combine elementwise fusion test passes.
There are a few different test passes that check elementwise fusion in
Linalg. Consolidate them to a single pass controlled by different pass
options (in keeping with how `TestLinalgTransforms` exists).
2022-02-08 18:08:37 +00:00
Tres Popp 64b918852c Remove restriction on static dimensions in Shape method
mlir::shape::ToExtentTensorOp::areCastCompatible didn't allow the input
to have a static dimension, but that is allowed.
2022-02-08 11:20:01 +01:00
River Riddle 2418cd92c0 [mlir] Update uses of `parser`/`printer` ODS op field to `hasCustomAssemblyFormat`
The parser/printer fields are deprecated and in the process of being removed.
2022-02-07 19:03:58 -08:00
Mahesh Ravishankar 7568f7101f Revert "[mlir][Linalg] NFC: Combine elementwise fusion test passes."
This reverts commit d730336411.
2022-02-07 22:51:29 +00:00
Mahesh Ravishankar d730336411 [mlir][Linalg] NFC: Combine elementwise fusion test passes.
There are a few different test passes that check elementwise fusion in
Linalg. Consolidate them to a single pass controlled by different pass
options (in keeping with how `TestLinalgTransforms` exists).
2022-02-07 22:46:57 +00:00
Sergei Grechanik bb39ad43ce [mlir][spirv] Fix verification of nested array constants
Fix the verification function of spirv::ConstantOp to allow nesting
array attributes.

Reviewed By: antiagainst

Differential Revision: https://reviews.llvm.org/D118939
2022-02-07 13:48:53 -08:00
Matthias Springer 9aa74347d5 [mlir][SCF] Further simplify affine maps during `for-loop-canonicalization`
* Implement `FlatAffineConstraints::getConstantBound(EQ)`.
* Inject a simpler constraint for loops that have at most 1 iteration.
* Taking into account constant EQ bounds of FlatAffineConstraint dims/symbols during canonicalization of the resulting affine map in `canonicalizeMinMaxOp`.

Differential Revision: https://reviews.llvm.org/D119153
2022-02-08 02:40:08 +09:00
Benjamin Kramer 6635c12ada [mlir] Use SmallBitVector instead of SmallDenseSet for 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-07 00:21:44 +01:00
River Riddle ace01605e0 [mlir] Split out a new ControlFlow dialect from Standard
This dialect is intended to model lower level/branch based control-flow constructs. The initial set
of operations are: AssertOp, BranchOp, CondBranchOp, SwitchOp; all split out from the current
standard dialect.

See https://discourse.llvm.org/t/standard-dialect-the-final-chapter/6061

Differential Revision: https://reviews.llvm.org/D118966
2022-02-06 14:51:16 -08:00
Eugene Zhulenev edca177cbe [mlir] Add canonicalizer to remove redundant shape.cstr_broadcastable ops
Depends On D119025

Reviewed By: frgossen

Differential Revision: https://reviews.llvm.org/D119043
2022-02-06 14:46:42 -08:00
Eugene Zhulenev 981f0a14f1 [mlir] Add canonicalizer to merge shape.assuming_all ops
Depends On D119021

Reviewed By: frgossen

Differential Revision: https://reviews.llvm.org/D119025
2022-02-04 15:27:37 -08:00
Lei Zhang 9dd4c2dcb6 [mlir][vector] Add constant folder for vector.shuffle ops
Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D119032
2022-02-04 16:59:32 -05:00
gysit b5ea288d13 [mlir][linalg] Let tile and fuse fail for tile sizes zero.
Adapt `tileConsumerAndFuseProducers` to return failure if the generated tile loop nest is empty since all tile sizes are zero. Additionally, fix `LinalgTileAndFuseTensorOpsPattern` to return success if the pattern applied successfully.

Reviewed By: mravishankar

Differential Revision: https://reviews.llvm.org/D118878
2022-02-04 19:19:21 +00:00
Thomas Raoux c3c1c5c695 [mlir][scf] Fix bug in pipelining prologue emission
Induction variable calculation was ignoring scf.for step value. Fix it to get
the correct induction variable value in the prologue.

Differential Revision: https://reviews.llvm.org/D118932
2022-02-03 13:12:50 -08:00
Abhishek Varma 59b23c4aec [MLIR][SCF] Remove loop invariant arguments of scf.while
-- This commit adds a canonicalization pattern on scf.while to remove
   the loop invariant arguments.
-- An argument is considered loop invariant if the iteration argument value is
   the same as the corresponding one being yielded (at the same position) in both
   the before/after block of scf.while.
-- For the arguments removed, their use within scf.while and their corresponding
   scf.while's result are replaced with their corresponding initial value.

Signed-off-by: Abhishek Varma <abhishek.varma@polymagelabs.com>

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D116923
2022-02-03 17:13:25 +01:00
River Riddle 8e123ca65f [mlir:Standard] Remove support for creating a `unit` ConstantOp
This is completely unused upstream, and does not really have well defined semantics
on what this is supposed to do/how this fits into the ecosystem. Given that, as part of
splitting up the standard dialect it's best to just remove this behavior, instead of try
to awkwardly fit it somewhere upstream. Downstream users are encouraged to
define their own operations that clearly can define the semantics of this.

This also uncovered several lingering uses of ConstantOp that weren't
updated to use arith::ConstantOp, and worked during conversions because
the constant was removed/converted into something else before
verification.

See https://llvm.discourse.group/t/standard-dialect-the-final-chapter/ for more discussion.

Differential Revision: https://reviews.llvm.org/D118654
2022-02-02 14:45:12 -08:00
River Riddle dec8af701f [mlir] Move SelectOp from Standard to Arithmetic
This is part of splitting up the standard dialect. See https://llvm.discourse.group/t/standard-dialect-the-final-chapter/ for discussion.

Differential Revision: https://reviews.llvm.org/D118648
2022-02-02 14:45:12 -08:00
River Riddle 6a8ba3186e [mlir] Split std.splat into tensor.splat and vector.splat
This is part of the larger effort to split the standard dialect. This will also allow for pruning some
additional dependencies on Standard (done in a followup).

Differential Revision: https://reviews.llvm.org/D118202
2022-02-02 14:45:12 -08:00
River Riddle ef72cf4413 [mlir][NFC] Update OpenACC/OpenMP operations to use `hasVerifier` instead of `verifier`
The verifier field is deprecated, and slated for removal.

Differential Revision: https://reviews.llvm.org/D118825
2022-02-02 13:34:30 -08:00
Nicolas Vasilache 3c3810e72e [mlir][vector] Avoid hoisting alloca'ed temporary buffers across AutomaticAllocationScope
This revision avoids incorrect hoisting of alloca'd buffers across an AutomaticAllocationScope boundary.
In the more general case, we will probably need a ParallelScope-like interface.

Differential Revision: https://reviews.llvm.org/D118768
2022-02-02 06:00:42 -05:00
gysit dc82547b17 [mlir][vector] Make write permutation lowering work with tensors.
Use type inference when building the TransferWriteOp in the TransferWritePermutationLowering. Previously, the result type has been set to Type() which triggers an assertion if the pattern is used with tensors instead of memrefs.

Reviewed By: springerm

Differential Revision: https://reviews.llvm.org/D118758
2022-02-02 09:21:10 +00:00
Mahesh Ravishankar a2361eb281 Avoid doing tile + fuse if tile sizes are zero.
Reviewed By: gysit

Differential Revision: https://reviews.llvm.org/D118576
2022-02-01 18:34:06 +00:00
Alexander Belyaev ebc8153786 Revert "Revert "[mlir] Purge `linalg.copy` and use `memref.copy` instead.""
This reverts commit 25bf6a2a9b.
2022-02-01 18:21:21 +01:00
Christian Sigg 9b078f8fd2 [MLIR][arith] Mark addf/mulf as commutative
Following the discussion in D118318, mark `arith.addf/mulf` commutative.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D118600
2022-02-01 08:33:48 +01:00
bakhtiyar 149311b405 [async] Get the number of worker threads from the runtime.
Reviewed By: ezhulenev

Differential Revision: https://reviews.llvm.org/D117751
2022-01-31 12:06:01 -08:00
Christian Sigg f278cf9cbc [MLIR][arith] More float op folders
Fold `arith.fadd %x, -0.0 -> %x` and similarly for `fsub`, `fmul`, `fdiv`.

Fold `arith.fmin %x, %x -> %x`, `arith.fmin %x, +inf -> %x` and similarly for `fmax`.

Reviewed By: pifon2a, mehdi_amini, bondhugula

Differential Revision: https://reviews.llvm.org/D118244
2022-01-31 19:31:48 +01:00
Alexander Belyaev 25bf6a2a9b Revert "[mlir] Purge `linalg.copy` and use `memref.copy` instead."
This reverts commit 016956b680.
Reverting it to fix NVidia build without being in a hurry.
2022-01-31 18:51:39 +01:00
Alexander Belyaev 016956b680 [mlir] Purge `linalg.copy` and use `memref.copy` instead.
Differential Revision: https://reviews.llvm.org/D118028
2022-01-31 18:25:56 +01:00
Uday Bondhugula f8a2cd67b9 Support affine.load/store ops in fold-memref-subview-ops pass
Support affine.load/store ops in fold-memref-subview ops pass. The
existing pass just "inlines" the subview operation on load/stores by
inserting affine.apply ops in front of the memref load/store ops: this
is by design always consistent with the semantics on affine.load/store
ops and the same would work even more naturally/intuitively with the
latter.

Differential Revision: https://reviews.llvm.org/D118565
2022-01-31 10:10:49 +05:30
Uday Bondhugula 92ccb8cc50 [MLIR][NFC] Update SCF pass cmd line names to prefix scf
Update SCF pass cmd line names to prefix `scf`. This is consistent with
guidelines/convention on how to name dialect passes. This also avoids
ambiguity on the context given the multiple `for` operations in the
tree.

NFC.

Differential Revision: https://reviews.llvm.org/D118564
2022-01-31 07:09:30 +05:30
Matthias Springer 6700a26d5f [mlir][linalg][bufferize] Fix insertion point InitTensorElimination
There was a bug where some of the OpOperands needed in the replacement op were not in scope.

It does not matter where the replacement op is inserted. Any insertion point is OK as long as there are no dominance errors. In the worst case, the newly inserted op will bufferize out-of-place. This is no worse than not eliminating the InitTensorOp at all.

Differential Revision: https://reviews.llvm.org/D117685
2022-01-30 22:25:39 +09:00
Matthias Springer ab47418df6 [mlir][bufferize] Merge tensor-constant-bufferize into arith-bufferize
The bufferization of arith.constant ops is also switched over to BufferizableOpInterface-based bufferization. The old implementation is deleted. Both implementations utilize GlobalCreator, now renamed to just `getGlobalFor`.

GlobalCreator no longer maintains a set of all created allocations to avoid duplicate allocations of the same constant. Instead, `getGlobalFor` scans the module to see if there is already a global allocation with the same constant value.

For compatibility reasons, it is still possible to create a pass that bufferizes only `arith.constant`. This pass (createConstantBufferizePass) could be deleted once all users were switched over to One-Shot bufferization.

Differential Revision: https://reviews.llvm.org/D118483
2022-01-30 21:37:48 +09:00
harsh 80e0bf1af1 Add vector.scan op
This patch adds the vector.scan op which computes the
scan for a given n-d vector. It requires specifying the operator,
the identity element and whether the scan is inclusive or
exclusive.

TEST: Added test in ops.mlir

Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D117171
2022-01-28 20:07:57 +00:00
Frederik Gossen 2c7b0685e1 Fix tensor.extract for complex elements 2022-01-28 04:33:15 +01:00
Mogball 1e3a02162d [mlir][scf] Update IfOp to have getInvocationBounds
This allows `scf.if` to be used by Control-Flow sink.

Depends on D115088

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D115089
2022-01-27 23:15:53 +00:00
Matthias Springer 075e3fdda1 [mlir][bufferize] Move arith BufferizableOpInterface impl to arith dialect
Also switch the implementation of `-arith-bufferize` to BufferizableOpInterface.

Differential Revision: https://reviews.llvm.org/D118325
2022-01-28 01:40:22 +09:00
Matthias Springer b2f5004259 Revert "[mlir][bufferize] Insert memref.cast ops during finalizing pass"
This reverts commit 1043107ce5.

This commit caused a breakage in `finalizing-bufferize.mlir`.
2022-01-27 20:48:58 +09:00
Matthias Springer dbd1bbced9 [mlir][linalg][bufferize] Support arith.index_cast bufferization
This is in preparation of switching `-tensor-constant-bufferize` and `-arith-bufferize` to BufferizableOpInterface-based implementations.

Differential Revision: https://reviews.llvm.org/D118324
2022-01-27 19:50:31 +09:00
Matthias Springer daf18108ec [mlir][tensor] Replace tensor-bufferize with BufferizableOpInterface impl
This commit switches the `tensor-bufferize` pass over to BufferizableOpInterface-based bufferization.

Differential Revision: https://reviews.llvm.org/D118246
2022-01-27 19:30:45 +09:00
Matthias Springer 1043107ce5 [mlir][bufferize] Insert memref.cast ops during finalizing pass
The pass can currently not handle to_memref(to_tensor(x)) folding where a cast is necessary. This is required with the new unified bufferization. There is already a canonicalization pattern that handles such foldings and it should be used during this pass.

Differential Revision: https://reviews.llvm.org/D117988
2022-01-27 19:06:53 +09:00