Commit Graph

11935 Commits

Author SHA1 Message Date
Markus Böck 884d310d87 [mlir][LLVM] Add OpBuilder for opaque pointer GEPs without struct indices
An OpBuilder already exists for GEPs that does not have any struct indices for existing typed pointers, but no such builder exists for GEPs utilizing opaque pointers that has an explicit `basePtrType`.

Differential Revision: https://reviews.llvm.org/D129376
2022-07-16 10:55:49 +02:00
Matthias Springer afb1def876 [mli][sparse] Remove manual dense dealloc from test case
Differential Revision: https://reviews.llvm.org/D129834
2022-07-16 09:28:27 +02:00
Uday Bondhugula 9819cbda0c [MLIR] Clean up checks for alloc-like ops in analysis
Clean up checks for alloc-like ops in analysis. Use the analysis
utility to properly check for the desired kind of effects. The previous
locality utility worked for all practical purposes but wasn't sound and
was locally duplicate code. Instead, use mlir::hasSingleEffect.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D129439
2022-07-16 12:54:47 +05:30
Uday Bondhugula 9f7d80145a [MLIR] NFC. Clean up logic of hasSingleEffect
Clean up conditional logic of hasSingleEffect. NFC.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D129438
2022-07-16 12:39:32 +05:30
Kazu Hirata 5605a1eedd Use drop_begin (NFC) 2022-07-15 23:58:11 -07:00
Stella Laurenzo 1d6a90418e Example:
```
// -----// IR Dump Before LowerLinalgMicrokernels (iree-vmvx-lower-linalg-microkernels) //----- //
```

I've been meaning to suggest this for a long time, and I think the only reason we don't have it is because we didn't used to have the `getArgument()` handy when printing these comments. When debugging or putting a pipeline together based on such dumps, I often find myself grepping for the argument name of the pass (which is often related but not universally).
2022-07-15 23:27:14 -07:00
Kazu Hirata 246bf08db3 Use drop_begin (NFC) 2022-07-15 23:24:59 -07:00
bzcheeseman f382dfc06b [MLIR][Liveness] Add `currentlyLiveValues`, a way to get a set of values that are live as of a given operation.
This change allows the user of LivenessBlockInfo to specify an op within the block and get a set of all values that are live as of that op. Semantically it relies on having a dominance-based region that has ordered operations. For DFG regions, computing liveness statically this way doesn't really make sense, it likely needs to be done at runtime.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D129447
2022-07-15 22:10:53 -07:00
Kazu Hirata 1a5d007659 Use has_value/value instead of hasValue/getValue (NFC) 2022-07-15 21:48:17 -07:00
Kazu Hirata 3b0dce5b8b Use value_or (NFC) 2022-07-15 19:46:29 -07:00
Ashay Rane 179588ea39
[mlir] remove unnecessary statements in test
A previous commit (f2b94bd) added some unnecessary statements that
dereferenced operations only to get the operations back.  This patch
removes the unnecessary statements.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D129913
2022-07-15 18:57:07 -07:00
Jeff Niu 7fe2294e47 [mlir][ods] Allow specifying return types of builders
This patch allows custom attribute and type builders to return
something other than the C++ type of the attribute or type.

This is useful for attributes or types that may perform extra work during
construction (e.g. canonicalization) that could result in a different
kind of attribute or type being returned.

Reviewed By: rriddle, lattner

Differential Revision: https://reviews.llvm.org/D129792
2022-07-15 18:00:35 -07:00
Mahesh Ravishankar 3139cc766c [mlir][Linalg] Add a pattern to decompose `linalg.generic` ops.
This patch adds a pattern to decompose a `linalg.generic` operations
that
- has only parallel iterator types
- has more than 2 statements (including the yield)

into multiple `linalg.generic` operation such that each operation has
a single statement and a yield.
The pattern added here just splits the matching `linalg.generic` into
two `linalg.generic`s, one containing the first statement, and the
other containing the remaining. The same pattern can be applied
repeatedly on the second op to ultimately fully decompose the generic
op.

Differential Revision: https://reviews.llvm.org/D129704
2022-07-15 23:01:18 +00:00
Ashay Rane f2b94bd7ea
[mlir] check whether region and block visitors are interrupted
The visitor functions for `Region` and `Block` types did not always
check the value returned by recursive calls.  This caused the top-level
visitor invocation to return `WalkResult::advance()` even if one or more
recursive invocations returned `WalkResult::interrupt()`.  This patch
fixes the problem by check if any recursive call is interrupted, and if
so, return `WalkResult::interrupt()`.

Reviewed By: dcaballe

Differential Revision: https://reviews.llvm.org/D129718
2022-07-15 14:50:42 -07:00
Jim Kitchen 2b8a4d9ce1 [mlir][sparse] Introduce new reduce op
A new sparse_tensor operation allows for
custom reduction code to be injected during
linalg.generic lowering for sparse tensors.
An identity value is provided to indicate
the starting value of the reduction. A single
block region is required to contain the
custom reduce computation.

Reviewed by: aartbik

Differential Revision: https://reviews.llvm.org/D128004
2022-07-15 15:30:41 -05:00
Mahesh Ravishankar 331afccad2 [mlir][Linalg] Extend Generic op dedup canonicalization to drop redundant result values. 2022-07-15 19:47:46 +00:00
Mahesh Ravishankar b62060a8e3 [mlir][Linalg] NFC: Refactor canonicalization for deduping generic op operands.
This is a NFC change to make it easier to update this canonicalization
for more use cases. The refactoring makes things easier to
understand/adapt.

Differential Revision: https://reviews.llvm.org/D129829
2022-07-15 19:47:45 +00:00
Rajas Vanjape 1976ad70c5 [mlir][sparse] Add 3-dimensional sparse tensor multiplication integration test
This diff adds an integration test which does element wise multiplication for two sparse 3-d tensors of size 3x3x5

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D129638
2022-07-15 12:12:51 -07:00
Lei Zhang 56796ae1a8 [mlir][linalg] Fix tensor tiling together with interchange
In `linalg::tileConsumerAndFuseProducers`, there are two levels of
tiling and fusion; we partition the tile sizes and only use one
half for each of them. The partition is using the first non-parallel
dimension *after* interchange as the boundary. However, concrete
tiling happens *together with* loop interchange, so we still need
to provide the partial tile sizes *before* the interchange.
Otherwise, there will be inconsistency, which is what this patch
is to fix.

Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D129804
2022-07-15 13:54:47 -04:00
Laszlo Kindrat ac14d5a1db [mlir] Enable perfect forwarding in RewritePatternSet::add
This patch modifies the implementation of `RewritePatternSet::add` to perfectly forward its arguments to pattern constructors. Without this, code like the following compiles but, due to the limited lifetime of the temporary TypeConverter, can produce unexpected behavior:
```
RewritePatternSet patterns(context);
patterns.add<SomeOpConversion, OtherOpConversion>(TypeConverter(), context);

if (failed(applyPartialConversion(getOperation(), target, std::move(patterns))))
  return signalPassFailure();
```

The patch also changes the linalg fusion pattern implementation to correctly fill the test pattern set given the new behavior.

Author: Laszlo Kindrat <laszlokindrat@gmail.com>

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D129601
2022-07-15 19:44:18 +02:00
lorenzo chelini 12929c241a Revert "[mlir] Enable perfect forwarding in RewritePatternSet::add"
Did not preserve author information.

This reverts commit b0afda78f0.
2022-07-15 19:16:09 +02:00
lorenzo chelini b0afda78f0 [mlir] Enable perfect forwarding in RewritePatternSet::add
This patch modifies the implementation of `RewritePatternSet::add` to perfectly forward its arguments to pattern constructors. Without this, code like the following compiles but, due to the limited lifetime of the temporary TypeConverter, can produce unexpected behavior:
```
RewritePatternSet patterns(context);
patterns.add<SomeOpConversion, OtherOpConversion>(TypeConverter(), context);

if (failed(applyPartialConversion(getOperation(), target, std::move(patterns))))
  return signalPassFailure();
```

The patch also changes the linalg fusion pattern implementation to correctly fill the test pattern set given the new behavior.

Author: Laszlo Kindrat <laszlokindrat@gmail.com>

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D129601
2022-07-15 19:08:23 +02:00
Arjun P 821fe9efa4 [MLIR][Presburger] reintroduce int64_t versions of floorDiv, ceilDiv in mlir::presburger namespace
This is useful because MPInt.h defines identically-named functions that
operate on MPInts, which would otherwie become the only candidates of
overload resolution when calling e.g. ceilDiv from the mlir::presburger
namespace (iff MPInt.h is included). So to access the 64-bit overloads, an
explict call to mlir::ceilDiv would be required. This patch adds `using`
declarations allowing overload resolution to transparently call the right
function.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D129820
2022-07-15 17:29:31 +01:00
Arjun P 9390b8d34c [MLIR][Presburger] MPInt: add missing fastpath in ceilDiv
This is not a bug in functionality, just a missed optimization.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D129815
2022-07-15 17:26:37 +01:00
Slava Zakharin 451e5e2b28 [mlir][math] Added math::tan operation.
Differential Revision: https://reviews.llvm.org/D129539
2022-07-15 09:17:06 -07:00
Ingo Müller b9f5b02fd0 [mlir][mbr] Improve diagnostics on error with `raise from`.
This commit extends the `raise` statements on errors in user-provided
code with `from e` clauses that attach the original exception to the one
being raised. This allows to debug the root cause of the error more
easily.

Reviewed By: SaurabhJha

Differential Revision: https://reviews.llvm.org/D129762
2022-07-15 15:15:58 +00:00
David Kreitzer c720b6fddd Clarify the behavior of the llvm.vector.insert/extract intrinsics when the index
is out of range. Both intrinsics return a poison value.

Consequently, mark the intrinsics speculatable.
Differential Revision: https://reviews.llvm.org/D129656
2022-07-15 07:56:44 -07:00
Arjun P 86d73c11cf [MLIR][Presburger] SlowMPInt: gcd: assert that operands are non-negative 2022-07-15 15:45:53 +01:00
Arjun P ec5f18e38a [MLIR][Presburger] MPInt: gcd: assert that operands are non-negative 2022-07-15 14:13:41 +01:00
Fangrui Song 3c849d0aef Modernize Optional::{getValueOr,hasValue} 2022-07-15 01:20:39 -07:00
Ingo Müller 5da5483ffb [mlir][benchmark] Fix import in sparse benchmark.
The benchmark currently fails to run because it cannot find the `func`
symbol when using a `FuncOp`. I suppose that the breakage was introduced
by the extraction of the func dialect from the builtin dialect that
wasn't reflected in the benchmark yet.

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D129738
2022-07-15 07:15:51 +00:00
Arjun P d6fbe1394f [MLIR][Presburger] MPInt: use /// for top-level comment, not // (NFC) 2022-07-15 00:30:02 +01:00
Manish Gupta 713d3de5fb [mlir][NVGPU] Verifier for nvgpu.ldmatrix
* Adds verifiers for `nvgpu.ldmatrix` op
* Adds tests to `mlir/test/Dialect/NVGPU/invalid.mlir`

Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D129669
2022-07-14 22:46:38 +00:00
Aart Bik f30822d29c [mlir][sparse][bufferization] fix a few memory leaks
Fixed some new memory leaks after migration to new
bufferization. One is expected, the other may need
some more careful analysis.

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D129805
2022-07-14 15:05:12 -07:00
Aart Bik 67564841cb [mlir][sparse][bufferization] initialize reduction variable
After recent bufferization improvement, this test
started failing due to missed zero initialization.

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D129800
2022-07-14 13:58:23 -07:00
Krzysztof Drewniak bc61cc9a2d [mlir][AMDGPU] Add lds_barrier op
The lds_barrier op allows workgroups to wait at a barrier for
operations to/from their local data store (LDS) to complete without
incurring the performance penalties of a full memory fence.

Reviewed By: nirvedhmeshram

Differential Revision: https://reviews.llvm.org/D129522
2022-07-14 20:45:26 +00:00
Jeff Niu b7f93c2809 [mlir] (NFC) run clang-format on all files 2022-07-14 13:32:13 -07:00
Thomas Raoux f48ce52c4c [mlir][vector] Pattern to clean up vector.extract during distribution
This prevents blocking propagation when converting between scalar and
vector<1>

Differential Revision: https://reviews.llvm.org/D129782
2022-07-14 17:07:32 +00:00
Thomas Raoux ffa7384f10 [mlir][vector] Support distribution of vector.reduce with accumulator
Right now the pattern was ignoring the optional accumulator.

Differential Revision: https://reviews.llvm.org/D129719
2022-07-14 14:28:38 +00:00
Matthias Springer 74902cc96f [mlir][linalg][NFC] Cleanup: Drop linalg.inplaceable attribute
bufferization.writable is used in most cases instead. All remaining test cases are updated. Some code that is no longer needed is deleted.

Differential Revision: https://reviews.llvm.org/D129739
2022-07-14 15:50:03 +02:00
Nicolas Vasilache 5a0011360c [mlir][Linalg] Retire LinalgPromotion pattern
This revision removes the LinalgPromotion pattern and adds a `transform.structured.promotion` op.
Since the LinalgPromotion transform allows the injection of arbitrary C++ via lambdas, the current
transform op does not handle it.
It is left for future work to decide what the right transform op control is for those cases.

Note the underlying implementation remains unchanged and the mechanism is still controllable by
lambdas from the API.

During this refactoring it was also determined that the `dynamicBuffers` option does not actually
connect to a change of behavior in the algorithm.
This also exhibits that the related test is wrong (and dangerous).
Both the option and the test are therefore removed.

Lastly, a test that connects patterns using the filter-based mechanism is removed: all the independent
pieces are already tested separately.

Context: https://discourse.llvm.org/t/psa-retire-linalg-filter-based-patterns/63785

Differential Revision: https://reviews.llvm.org/D129649
2022-07-14 05:29:27 -07:00
Ingo Müller d4a7ca81fe [mlir][doc] Fix usage of PatternApplicator.
The constructor of PatternApplicator doesn't have a constructor that
accepts only a `RewritePatternSet` as currently used in the example
code in PatternRewriter.md. Instead, one has to turn it into a
`FrozenRewritePatternSet`.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D125236
2022-07-14 09:08:26 +00:00
Matthias Springer c66303c287 [mlir][sparse] Switch to One-Shot Bufferize
This change removes the partial bufferization passes from the sparse compilation pipeline and replaces them with One-Shot Bufferize. One-Shot Analysis (and TensorCopyInsertion) is used to resolve all out-of-place bufferizations, dense and sparse. Dense ops are then bufferized with BufferizableOpInterface. Sparse ops are still bufferized in the Sparsification pass.

Details:
* Dense allocations are automatically deallocated, unless they are yielded from a block. (In that case the alloc would leak.) All test cases are modified accordingly. E.g., some funcs now have an "out" tensor argument that is returned from the function. (That way, the allocation happens at the call site.)
* Sparse allocations are *not* automatically deallocated. They must be "released" manually. (No change, this will be addressed in a future change.)
* Sparse tensor copies are not supported yet. (Future change)
* Sparsification no longer has to consider inplacability. If necessary, allocations and/or copies are inserted during TensorCopyInsertion. All tensors are inplaceable by the time Sparsification is running. Instead of marking a tensor as "not inplaceable", it can be marked as "not writable", which will trigger an allocation and/or copy during TensorCopyInsertion.

Differential Revision: https://reviews.llvm.org/D129356
2022-07-14 09:52:48 +02:00
Kazu Hirata c27d815249 [mlir] Use value instead of getValue (NFC) 2022-07-14 00:19:59 -07:00
Manish Gupta f7d42d5149 [mlir][NVGPU] Verifiers for nvgpu.mma.sync Op
- Adds verification for `nvgpu.mma.sync` op
- Adds tests to `mlir/test/Dialect/NVGPU/invalid.mlir`
- `nvgpu.mma.sync` verifier caught a bug and triggered a failure in m16n8k4_tf32_f32 variant in `mlir/test/Conversion/NVGPUToNVVM/nvgpu-to-nvvm.mlir`
     - The output shape of vector holding thread-level accumulators was inconsistent  and fixed in this change

Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D129400
2022-07-13 18:57:07 +00:00
Benoit Jacob 6870a50f43 lowerParallel is also called on unit-size, one-sided reduction dims
See: https://gist.github.com/bjacob/d8be8ec7e70ed0be4b3a5794ced2a7e8

Differential Revision: https://reviews.llvm.org/D129096
2022-07-13 16:21:12 +00:00
Jacques Pienaar 69b6454fff [mlir] Plumb through default attribute populate for extensible dialect. 2022-07-13 09:05:04 -07:00
Nicolas Vasilache cd6e02eebc [mlir][Linalg] Retire TestLinalgCodegenStrategy pass.
This pass tests patterns that are already tested elsewhere by applying them in a semi-targeted
fashion using anchor function and op names.

From now on, targeted tests should use the transform dialect interpreter.

Differential Revision: https://reviews.llvm.org/D129627
2022-07-13 04:20:42 -07:00
Kazu Hirata 491d27013d [mlir] Use has_value instead of hasValue (NFC) 2022-07-13 00:57:02 -07:00
Adrian Kuegel aabfaf901b [mlir] Allow empty lists for DenseArrayAttr.
Differential Revision: https://reviews.llvm.org/D129552
2022-07-13 09:16:09 +02:00