Commit Graph

8599 Commits

Author SHA1 Message Date
Mehdi Amini 5edd79fc97 Revert "[MLIR][SCF] Add for-to-while loop transformation pass"
This reverts commit 644b55d57e.

The added test is failing the bots.
2021-09-20 17:21:59 +00:00
Mehdi Amini f18f1ab4fd Temporarily XFAIL MLIR test that fails the LLVM verifier after 8700f2bd3 2021-09-20 17:20:11 +00:00
Tobias Gysi 7be28d82b4 [mlir][linalg] Add IndexOp support to fusion on tensors.
This revision depends on https://reviews.llvm.org/D109761 and https://reviews.llvm.org/D109766.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D109774
2021-09-20 15:59:35 +00:00
Morten Borup Petersen 644b55d57e [MLIR][SCF] Add for-to-while loop transformation pass
This pass transforms SCF.ForOp operations to SCF.WhileOp. The For loop condition is placed in the 'before' region of the while operation, and indctuion variable incrementation + the loop body in the 'after' region. The loop carried values of the while op are the induction variable (IV) of the for-loop + any iter_args specified for the for-loop.
Any 'yield' ops in the for-loop are rewritten to additionally yield the (incremented) induction variable.

This transformation is useful for passes where we want to consider structured control flow solely on the basis of a loop body and the computation of a loop condition. As an example, when doing high-level synthesis in CIRCT, the incrementation of an IV in a for-loop is "just another part" of a circuit datapath, and what we really care about is the distinction between our datapath and our control logic (the condition variable).

Differential Revision: https://reviews.llvm.org/D108454
2021-09-20 16:57:50 +01:00
Tobias Gysi 09100c75b5 [mlir][linalg] Fix typo (NFC). 2021-09-20 15:46:16 +00:00
Tobias Gysi 6db928b8f3 [mlir][linalg] Fusion on tensors.
Add a new version of fusion on tensors that supports the following scenarios:
- support input and output operand fusion
- fuse a producer result passed in via tile loop iteration arguments (update the tile loop iteration arguments)
- supports only linalg operations on tensors
- supports only scf::for
- cannot add an output to the tile loop nest

The LinalgTileAndFuseOnTensors pass tiles the root operation and fuses its producers.

Reviewed By: nicolasvasilache, mravishankar

Differential Revision: https://reviews.llvm.org/D109766
2021-09-20 14:45:34 +00:00
Valentin Clement d6929aaa67
[mlir][openacc] Make use of the second counter extension in DataOp translation
Make use of runtime extension for the second reference counter used in
structured data region. This extension is implemented in D106510 and D106509.

Differential Revision: https://reviews.llvm.org/D106517
2021-09-20 13:43:50 +02:00
Vladislav Vinogradov 798e4bfbed [mlir] Fix integration tests failures introduced in D108505 2021-09-20 11:48:24 +03:00
KareemErgawy-TomTom bdcf4b9b96 [MLIR][Linalg] Make detensoring cost-model more flexible.
So far, the CF cost-model for detensoring was limited to discovering
pure CF structures. This means, if while discovering the CF component,
the cost-model found any op that is not detensorable, it gives up on
detensoring altogether. This patch makes it a bit more flexible by
cleaning-up the detensorable component from non-detensorable ops without
giving up entirely.

Reviewed By: silvas

Differential Revision: https://reviews.llvm.org/D109965
2021-09-20 10:21:31 +02:00
Arjun P 76cb876563 [MLIR] Simplex::appendVariable: early return if count == 0 2021-09-20 13:16:56 +05:30
Vladislav Vinogradov ec03bbe8a7 [mlir] Fix bug in partial dialect conversion
The discussion on forum:
https://llvm.discourse.group/t/bug-in-partial-dialect-conversion/4115

The `applyPartialConversion` didn't handle the operations, that were
marked as illegal inside dynamic legality callback.
Instead of reporting error, if such operation was not converted to legal set,
the method just added it to `unconvertedSet` in the same way as unknown operations.

This patch fixes that and handle dynamically illegal operations as well.

The patch includes 2 fixes for existing passes:

* `tensor-bufferize` - explicitly mark `std.return` as legal.
* `convert-parallel-loops-to-gpu` - ugly fix with marking visited operations
  to avoid recursive legality checks.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D108505
2021-09-20 10:39:10 +03:00
Vladislav Vinogradov 9a2255dfa0 [mlir][NFC] Add explicit "::mlir" namespace to tblgen generated code
Reviewed By: lattner, ftynse

Differential Revision: https://reviews.llvm.org/D109223
2021-09-20 10:37:50 +03:00
xndcn 9de88fc0ea [mlir][emitc] Fix indent in CondBranchOp and block label
1. Add missing indent in CondBranchOp
2. Remove indent in block label

Differential Revision: https://reviews.llvm.org/D109805
2021-09-19 20:03:42 +08:00
Arjun P 33afea5488 [MLIR] Simplex: rename num{Variables,Constraints} to getNum{Variables,Constraints}
As per the LLVM Coding Standards, function names should be verb phrases.
2021-09-18 22:39:35 +05:30
Arjun P 2b44a7325c [MLIR] Simplex: support adding new variables dynamically
Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D109962
2021-09-18 21:32:17 +05:30
Jacques Pienaar 0a1e569d37 [mlir-c] Add getting fused loc
For creating a fused loc using array of locations and metadata.

Differential Revision: https://reviews.llvm.org/D110022
2021-09-18 06:57:51 -07:00
Uday Bondhugula 57eda9becc [MLIR][GPU] Add constant propagator for gpu.launch op
Add a constant propagator for gpu.launch op in cases where the
grid/thread IDs can be trivially determined to take a single constant
value of zero.

Differential Revision: https://reviews.llvm.org/D109994
2021-09-18 12:02:46 +05:30
Geoffrey Martin-Noble 2cda4f8ed7
[mlir] Fix syntax example for tensor.from_elements
Parens are not used here
2021-09-17 17:23:11 -07:00
Aart Bik 46e77b5d10 [mlir][sparse] add a sparse quantized_matmul example to integration test
Note that this revision adds a very tiny bit of constant folding in the
sparse compiler lattice construction. Although I am generally trying to
avoid such canonicalizations (and rely on other passes to fix this instead),
the benefits of avoiding a very expensive disjunction lattice construction
justify having this special code (at least for now).

Reviewed By: bixia

Differential Revision: https://reviews.llvm.org/D109939
2021-09-17 13:04:44 -07:00
Aart Bik d4e16171e8 [mlir][sparse] add dce test for all sparse tensor ops
Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D109992
2021-09-17 13:03:42 -07:00
Krzysztof Drewniak 121aab84d1 [MLIR][Affine] Simplify nested modulo operations when able
It is the case that, for all positive a and b such that b divides a
(e mod (a * b)) mod b = e mod b. For example, ((d0 mod 35) mod 5) can
be simplified to (d0 mod 5), but ((d0 mod 35) mod 4) cannot be simplified
further (x = 36 is a counterexample).

This change enables more complex simplifications. For example,
((d0 * 72 + d1) mod 144) mod 9 can now simplify to (d0 * 72 + d1) mod 9
and thus to d1 mod 9. Expressions with chained modulus operators are
reasonably common in tensor applications, and this change _should_
improve code generation for such expressions.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D109930
2021-09-17 19:06:00 +00:00
thomasraoux 08f0cb7719 [mlir] Prevent crash in DropUnitDim pattern due to tensor with encoding
Differential Revision: https://reviews.llvm.org/D109984
2021-09-17 12:03:16 -07:00
thomasraoux 36aac53b36 [mlir][linalg] Extend drop unit dim pattern to all cases of reduction
Even with all parallel loops reading the output value is still allowed so we
don't have to handle reduction loops differently.

Differential Revision: https://reviews.llvm.org/D109851
2021-09-17 10:09:57 -07:00
thomasraoux 416679615d [mlir] Linalg hoisting should ignore uses outside the loop
Differential Revision: https://reviews.llvm.org/D109859
2021-09-17 10:06:57 -07:00
thomasraoux a123e3c48b [mlir] Fix potential crash in hoistRedundantVectorTransfers
Differential Revision: https://reviews.llvm.org/D107856
2021-09-17 10:05:20 -07:00
Tobias Gysi 90b7817e03 [mlir][linalg] Add helper to update IndexOps after tiling (NFC).
Add the addTileLoopIvsToIndexOpResults method to shift the IndexOp results after tiling.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D109761
2021-09-17 15:17:33 +00:00
Arjun P 58719f6153 [MLIR] PresbugerSet: slightly expand documentation 2021-09-17 18:04:46 +05:30
Arjun P 44db07f11f [MLIR] AffineStructures: support removing a range of constraints at once
Reviewed By: Groverkss, grosser

Differential Revision: https://reviews.llvm.org/D109892
2021-09-17 16:27:48 +05:30
Arjun P 6607bd9fd8 [MLIR] AffineStructures::removeIdRange: support specifying a range within an IdKind
Reviewed By: Groverkss, grosser

Differential Revision: https://reviews.llvm.org/D109896
2021-09-17 16:25:26 +05:30
Arjun P f263ea1571 [MLIR] Matrix: support resizing horizontally
Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D109897
2021-09-17 16:22:31 +05:30
MaheshRavishankar 04a66f8d2b Fixing vector add pattern that incorrectly returns success.
The pattern is returning success even if it does no work leading to pattern application running up to the max iteration count and failing.

Reviewed By: nicolasvasilache, mravishankar

Differential Revision: https://reviews.llvm.org/D109791
2021-09-16 14:48:09 -07:00
Aart Bik 233b42a8bb [mlir][sparse] remove unused TENSOR environment
Reviewed By: bixia

Differential Revision: https://reviews.llvm.org/D109919
2021-09-16 14:32:09 -07:00
Rob Suderman 8662a2f208 [mlir][tosa] Relax ranked constraint on quantization builder
TosaOp defintion had an artificial constraint that the input/output types
needed to be ranked to invoke the quantization builder. This is correct as an
unranked tensor could still be quantized.

Reviewed By: NatashaKnk

Differential Revision: https://reviews.llvm.org/D109863
2021-09-16 11:43:47 -07:00
Aart Bik 860cbeb159 [mlir][sparse] add more asserts to sparse support lib
We are having issues running the integration test of the sparse compiler
on AArch64 (crashing in the lib). This revision adds more assertions.

Reviewed By: jsetoain

Differential Revision: https://reviews.llvm.org/D109861
2021-09-16 10:13:29 -07:00
Nicolas Vasilache ee2e414dde [mlir][Linalg] Cleanup doc and improve logging and readability in ComprehensiveBufferize.cpp - NFC 2021-09-16 16:41:47 +00:00
Tobias Gysi 8f2db36b01 [mlir][OpDSL] Update op definitions to make shapes more concise (NFC).
Express the input shape definitions of convolution and pooling operations in terms of the output shapes, filter shapes, strides, and dilations.

Reviewed By: shabalin, rsuderman, stellaraccident

Differential Revision: https://reviews.llvm.org/D109815
2021-09-16 06:02:00 +00:00
Aart Bik b1d44e5902 [mlir][sparse] add affine subscripts to sparse compilation pass
This enables the sparsification of more kernels, such as convolutions
where there is a x(i+j) subscript. It also enables more tensor invariants
such as x(1) or other affine subscripts such as x(i+1). Currently, we
reject sparsity altogether for such tensors. Despite this restriction,
however, we can already handle a lot more kernels with compound subscripts
for dense access (viz. convolution with dense input and sparse filter).
Some unit tests and an integration test demonstrate new capability.

Reviewed By: bixia

Differential Revision: https://reviews.llvm.org/D109783
2021-09-15 20:28:04 -07:00
Mogball cb8c30d35d [DRR] Explicit Return Types in Rewrites
Adds a new rewrite directive returnType that can be added at the end of an op's
argument list to explicitly specify return types.

```
(OpX $v0, $v1, (returnType "$_builder.getI32Type()"))
```

Pass in a bound value to copy its return type, or pass a native code call to
dynamically create new types.

```
(OpX $v0, $v1, (returnType $v0, (NativeCodeCall<"..."> $v1)))
```

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D109472
2021-09-15 14:25:29 -07:00
Rob Suderman 1ac2d195ec [mlir][linalg] Add canonicalizers for depthwise conv
There are two main versions of depthwise conv depending whether the multiplier
is 1 or not. In cases where m == 1 we should use the version without the
multiplier channel as it can perform greater optimization.

Add lowering for the quantized/float versions to have a multiplier of one.

Reviewed By: antiagainst

Differential Revision: https://reviews.llvm.org/D108959
2021-09-15 14:09:15 -07:00
Simon Camphausen 1b79efdc72 [mlir] Fix printing of EmitC attrs/types with escape characters
Attributes and types were not escaped when printing.

Reviewed By: jpienaar, marbre

Differential Revision: https://reviews.llvm.org/D109143
2021-09-15 18:15:38 +00:00
Nicolas Vasilache 96ec0ff2b7 [mlir][Linalg] Revisit insertion points in comprehensive bufferization.
This revision fixes a corner case that could appear due to incorrect insertion point behavior in comprehensive bufferization.

Differential Revision: https://reviews.llvm.org/D109830
2021-09-15 18:11:38 +00:00
Mehdi Amini 13237c3b1e Add llvm_unreachable after fully covered switch (NFC)
This fixes a compiler warning for some version of GCC.
2021-09-15 17:53:05 +00:00
Uday Bondhugula f68939d3d9 [MLIR] Tighten type constraint on memref.global op def
Tighten the def of memref.global op to use the right kind of TypeAttr
(of MemRefType).

Differential Revision: https://reviews.llvm.org/D109822
2021-09-15 22:41:03 +05:30
Nicolas Vasilache 6fe77b1051 [mlir][Linalg] Fail comprehensive bufferization if a memref is returned.
Summary:

Reviewers:

Subscribers:

Differential revision: https://reviews.llvm.org/D109824
2021-09-15 15:11:17 +00:00
Nicolas Vasilache 660f281b5e [mlir][Linalg] Make codegen strategy late transformations opt-in
Summary: Making the late transformations opt-in results in less surprising behavior when composing multiple calls to the codegen strategy.

Reviewers:

Subscribers:

Differential revision: https://reviews.llvm.org/D109820
2021-09-15 11:02:14 +00:00
Nicolas Vasilache e3889b3059 [mlir][Linalg] Replace DenseSet by UnionFind in ComprehensiveBufferize - NFC
AliasInfo can now use union-find for a much more efficient implementation.
This brings no functional changes but large performance gains on more complex examples.

Differential Revision: https://reviews.llvm.org/D109819
2021-09-15 10:35:54 +00:00
Matthias Springer 934e2f695e [mlir][linalg] ComprehensiveBufferize: Do not copy InitTensorOp results
E.g.:

```
%2 = memref.alloc() {alignment = 128 : i64} : memref<256x256xf32>
%3 = memref.alloc() {alignment = 128 : i64} : memref<256x256xf32>

// ... (%3 is not written to)

linalg.copy(%3, %2) : memref<256x256xf32>, memref<256x256xf32>
vector.transfer_write %11, %2[%c0, %c0] {in_bounds = [true, true]} : vector<256x256xf32>, memref<256x256xf32>
```

Avoid copies of %3 if %3 came directly from an InitTensorOp.

Differential Revision: https://reviews.llvm.org/D109742
2021-09-15 17:28:04 +09:00
Alex Zinenko b10940edfc [mlir] Update docs on conversion and translation to LLVM
Create a new document that explain both stages of the process in a single
place, merge and deduplicate the content from the two previous documents. Also
extend the documentation to account for the recent changes in pass structure
due to standard dialect splitting and translation being more flexible.

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D109605
2021-09-15 09:50:21 +02:00
Tobias Gysi a543abc5ea [mlir][linalg] Update OpDSL doc (NFC).
Update the doc due to recent path changes an point to a helper script.
2021-09-15 07:38:15 +00:00
Mehdi Amini a32300a68f Make the --mlir-disable-threading command line option overrides the C++ API usage
This seems in-line with the intent and how we build tools around it.
Update the description for the flag accordingly.
Also use an injected thread pool in MLIROptMain, now we will create
threads up-front and reuse them across split buffers.

Differential Revision: https://reviews.llvm.org/D109802
2021-09-15 03:20:48 +00:00