Commit Graph

8011 Commits

Author SHA1 Message Date
Nicolas Vasilache 73bea97a33 [mlir][Linalg] Add support for CallOp bufferization (10/n)
Cross function boundary bufferization support is added.
This is enabled by cross-function boundary alias analysis, for which the bufferization process is extended: it can now modify the BufferizationAliasInfo as new ops are introduced.

A number of simplifying assumptions are made:

1. by default we bufferize to the most dynamic strided memref type, further memref::CastOp canonicalizations are expected to clean up the IR.
2. in the current implementation, the stride information is always erased at function boundaries. A subsequent pass will be required to analyze the meet of all call ops to a function and decide whether more static buffer types can be used. This will potentially clone functions when it is deemed profitable to do so (e.g. when the stride-1 dimension may vary).
3. external function always bufferize to the most dynamic strided memref version. This may require special annotations for specifying that particular operands of top-level functions have contiguous buffer layout.

An alternative to point 3. would be to support tensor layout annotations, which is currently not supported in MLIR.

Differential revision: https://reviews.llvm.org/D104873
2021-07-01 10:33:12 +00:00
Benjamin Kramer ce857d3cfd [mlir][async] Remove unused variable. NFC. 2021-07-01 12:24:55 +02:00
Tobias Gysi 226f925c3f [mlir][linalg][python] Update integration of OpDSL doc (NFC).
Move the OpDSL doc to a linalg sub folder and updated the integration in the main linalg documentation.

Differential Revision: https://reviews.llvm.org/D105188
2021-07-01 07:41:32 +00:00
Fabian Schuiki 8066f22c46
[MLIR] Add argument insertion helpers for FunctionLike
Add helpers to facilitate adding arguments and results to operations
that implement the `FunctionLike` trait. These operations already have a
convenient argument and result *erasure* mechanism, but a corresopnding
utility for insertion is missing. This introduces such a utility.
2021-07-01 09:18:57 +02:00
Matthias Springer c0a6318d96 [mlir][tensor] Add tensor.dim operation
* 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-07-01 10:00:19 +09:00
thomasraoux 627733b5f0 [mlir][vector] Extend vector distribution to all elementwise and contract
Uses elementwise interface to generalize canonicalization pattern and add a new
pattern for vector.contract case.

Differential Revision: https://reviews.llvm.org/D104343
2021-06-30 16:22:31 -07:00
Suraj Sudhir 2eb7bbbe65 [mlir][tosa] Use 3D tensors in tosa.matmul
Signed-off-by: Suraj Sudhir <suraj.sudhir@arm.com>

Reviewed By: rsuderman

Differential Revision: https://reviews.llvm.org/D105213
2021-06-30 12:22:52 -07:00
Ahmed Taei 2c4f5690ab Add linalg.batch_matvec named op
Similarly to batch_mat vec outer most dim is a batching dim
    and this op does |b| matrix-vector-products :
    C[b, i] = sum_k(A[b, i, k] * B[b, k])

Reviewed By: rsuderman

Differential Revision: https://reviews.llvm.org/D104739
2021-06-30 11:37:21 -07:00
thomasraoux 0298f2cfb1 [mlir] Fix wrong type in WmmaConstantOpToNVVMLowering
InsertElement takes a scalar integer attribute not an array of integer.

Differential Revision: https://reviews.llvm.org/D105174
2021-06-30 09:10:02 -07:00
thomasraoux 4392841949 [mlir][VectorToGPU] Support converting vetor.broadcast to MMA op
Differential Revision: https://reviews.llvm.org/D105175
2021-06-30 09:08:55 -07:00
William S. Moses ad4152d1b8 [MLIR] Update description of SCF.execute_region op
See https://reviews.llvm.org/D104865
2021-06-30 10:09:42 -04:00
William S. Moses dfb34c0df9 [MLIR][SCF] Inline ExecuteRegion if parent can contain multiple blocks
The executeregionop is used to allow multiple blocks within SCF constructs. If the container allows multiple blocks, inline the region

Differential Revision: https://reviews.llvm.org/D104960
2021-06-30 10:03:22 -04:00
William S. Moses 0cd8422e8c [MLIR] Eliminate unnecessary affine stores
Deduce circumstances where an affine load could not possibly be read by an operation (such as an affine load), and if so, eliminate the load

Differential Revision: https://reviews.llvm.org/D105041
2021-06-30 09:45:26 -04:00
Tobias Gysi 42d99bc376 [mlir][linalg][python] Update the OpDSL doc (NFC).
Update the OpDSL documentation to reflect recent changes. In particular, the updated documentation discusses:
- Attributes used to parameterize index expressions
- Shape-only tensor support
- Scalar parameters

Differential Revision: https://reviews.llvm.org/D105123
2021-06-30 12:27:17 +00:00
Tobias Gysi 4361bd9b7b [mlir][linalg][python] Explicit shape and dimension order in OpDSL.
Extend the OpDSL syntax with an optional `domain` function to specify an explicit dimension order. The extension is needed to provide more control over the dimension order instead of deducing it implicitly depending on the formulation of the tensor comprehension. Additionally, the patch also ensures the symbols are ordered according to the operand definitions of the operation.

Differential Revision: https://reviews.llvm.org/D105117
2021-06-30 08:59:39 +00:00
Stephan Herhut db2de8d7f1 [mlir][llvm] Add a test for memref.copy lowering to llvm
This was missing and also there was a bug in the lowering itself, which went unnoticed due to it.

Differential Revision: https://reviews.llvm.org/D105122
2021-06-30 10:49:29 +02:00
Uday Bondhugula 071d26f808 [MLIR] Fix generateCopyForMemRefRegion
Fix generateCopyForMemRefRegion for a missing check: in some cases, when
the thing to generate copies for itself is empty, no fast buffer/copy
loops would have been allocated/generated. Add an extra assertion there
while at this.

Differential Revision: https://reviews.llvm.org/D105170
2021-06-30 10:24:10 +05:30
Mehdi Amini 8b8f5c54d5 Fix test pass registration to use the new API / not use the deprecated one (NFC) 2021-06-30 04:09:11 +00:00
Lei Huang 1df981f43a Revert "Attempt to disable MLIR JIT tests on PowerPC to unbreak the bot"
This reverts commit 652f4b5140.

Re-enable MLLIR JIT tests.
The MLIR Bot was updated to export LD_LIBRARY_PATH=/usr/lib64, which
seem to fix this issue.
2021-06-29 18:03:23 -05:00
Stella Laurenzo 485cc55edf [mlir] Generare .cpp.inc files for dialects.
* Previously, we were only generating .h.inc files. We foresee the need to also generate implementations and this is a step towards that.
* Discussed in https://llvm.discourse.group/t/generating-cpp-inc-files-for-dialects/3732/2
* Deviates from the discussion above by generating a default constructor in the .cpp.inc file (and adding a tablegen bit that disables this in case if this is user provided).
* Generating the destructor started as a way to flush out the missing includes (produces a link error), but it is a strict improvement on its own that is worth doing (i.e. by emitting key methods in the .cpp file, we root vtables in one translation unit, which is a non-controversial improvement).

Differential Revision: https://reviews.llvm.org/D105070
2021-06-29 20:10:30 +00:00
Eugene Zhulenev c1194c2ec3 [mlir:Async] Change async-parallel-for block size/count calculation
Depends On D105037

Avoid creating too many tasks when the number of workers is large.

Reviewed By: herhut

Differential Revision: https://reviews.llvm.org/D105126
2021-06-29 12:57:11 -07:00
Eugene Zhulenev f57b2420b2 [mlir:Async] Add an async reference counting pass based on the user defined policy
Depends On D104999

Automatic reference counting based on the liveness analysis can add a lot of reference counting overhead at runtime. If the IR is known to be constrained to few particular "shapes", it's much more efficient to provide a custom reference counting policy that will specify where it is required to update the async value reference count.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D105037
2021-06-29 12:53:09 -07:00
Nicolas Vasilache a77524cd2c [mlir][Linalg] Add a ComprehensiveModuleBufferizePass and support for CallOp analysis(9/n)
This revision adds the minimal plumbing to create a simple ComprehensiveModuleBufferizePass that can behave conservatively in the presence of CallOps.

A topological sort of caller/callee is performed and, if the call-graph is cycle-free, analysis can proceed.

Differential revision: https://reviews.llvm.org/D104859
2021-06-29 19:18:22 +00:00
Eugene Zhulenev 9ccdaac8f9 [mlir:Async] Fix a bug in automatic refence counting around function calls
Depends On D104998

Function calls "transfer ownership" to the callee and it puts additional constraints on the reference counting optimization pass

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D104999
2021-06-29 09:35:43 -07:00
Eugene Zhulenev 6088f86a2e [mlir:Async] Convert AsyncParallelFor pass to ModuleOp pass
Depends On D104891

Outlining scf.parallel body as a function requires async-parallel-for pass to be a ModuleOp pass

Reviewed By: bondhugula

Differential Revision: https://reviews.llvm.org/D104998
2021-06-29 09:28:22 -07:00
Eugene Zhulenev a8f819c6d8 [mlir:Async] Remove async operations if it is statically known that the parallel operation has a single compute block
Depends On D104850

Add a test that verifies that canonicalization removes all async overheads if it is statically known that the scf.parallel operation will be computed using a single block.

Reviewed By: herhut

Differential Revision: https://reviews.llvm.org/D104891
2021-06-29 09:26:28 -07:00
Alex Zinenko bf9dcb4cd2 [mlir] silence -Wunused-variable in Linalg comprehensive bufferize 2021-06-29 16:44:16 +02:00
Nicolas Vasilache b661d9f9c3 [mlir][Linalg] NFC - Drop AliasInfo::existsNonDominatingRead
The case where a non-dominating read can be found is captured by slightly generalizing `AliasInfo::wouldCreaateReadAfterWriteInterference`.

This simplification will make it easier to implement bufferization across function call.

APIs are also simplified were possible.

Differential revision: https://reviews.llvm.org/D104845
2021-06-29 13:30:33 +00:00
Felipe de Azevedo Piovezan 8ca04b0513 [mlir] Add support for LLVM's dso_local attr
This patch brings support for setting runtime preemption specifiers of
LLVM's GlobalValues. In LLVM semantics, if the `dso_local` attribute
is not explicitly requested, then it is inferred based on linkage and
visibility. We model this same behavior with a UnitAttribute: if it is
present, then we explicitly request the GlobalValue to marked as
`dso_local`, otherwise we rely on the GlobalValue itself to make this
decision.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D104983
2021-06-29 15:00:48 +02:00
Alex Zinenko 355216380b [mlir] Remove SDBM
This data structure and algorithm collection is no longer in use.

Reviewed By: bondhugula

Differential Revision: https://reviews.llvm.org/D105102
2021-06-29 14:46:26 +02:00
Butygin 293064222a [mlir] Add MemoryEffects::Allocate to memref::CloneOp
Without it BufferDeallocationPass process only CloneOps created during pass itself and ignore all CloneOps that were already present in IR.

For our specific usecase:

```
func @dealloc_existing_clones(%arg0: memref<?x?xf64>, %arg1: memref<?x?xf64>) -> memref<?x?xf64> {
  return %arg0 : memref<?x?xf64>
}
```

Input arguments will be freed immediately after return from function and we want to prolong lifetime for the returned argument.
To achieve this we explicitly add clones to all input memrefs and expect that BufferDeallocationPass will add correct deallocs to them (unnessesary clone+dealloc pairs will be canonicalized away later).

Differential Revision: https://reviews.llvm.org/D104973
2021-06-29 13:37:32 +03:00
Chia-hung Duan 7dec20dbb6 [mlir-reduce] Add doc for usage of mlir-reduce
Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D103683
2021-06-29 18:20:23 +08:00
Tobias Gysi a2a4bc561d [mlir][linalg] All StructuredOp parameters are inputs or outputs.
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-29 07:45:50 +00:00
Alexander Belyaev d15663710c Revert "[mlir] Skip scalar operands when tiling to linalg.tiled_loop."
This reverts commit 69046b4a79. It did not
really break anything, but it was decided to allow scalars and other
non-shaped operands for tiled_loop.
2021-06-29 08:55:25 +02:00
harsh-nod 0d6e4199e3 [mlir][vector] Order parallel indices before transposing the input in multireductions
The current code does not preserve the order of the parallel
dimensions when doing multi-reductions and thus we can end
up in scenarios where the result shape does not match the
desired shape after reduction.

This patch fixes that by ensuring that the parallel indices
are in order and then concatenates them to the reduction dimensions
so that the reduction dimensions are innermost.

Differential Revision: https://reviews.llvm.org/D104884
2021-06-28 18:47:16 -07:00
River Riddle 473a21c0e9 [vscode-mlir] Add support for restarting the server on setting/server changes
This revision adds detection for changes to either the mlir-lsp-server binary or the setting, and prompts the user to restart the server. Whether the user gets prompted or not is a configurable setting in the extension, and this setting may updated based on the user response to the prompt.

Differential Revision: https://reviews.llvm.org/D104501
2021-06-29 00:08:44 +00:00
Alexander Belyaev 69046b4a79 [mlir] Skip scalar operands when tiling to linalg.tiled_loop.
We are interested only in tensors/memrefs when creating a TiledLoopOp.

Differential Revision: https://reviews.llvm.org/D105059
2021-06-28 23:01:17 +02:00
Jacques Pienaar 5bc9cc1332 [drr] Enable specifying range in NativeCodeCall replacement.
This enables creating a replacement rule where range of positional replacements
need not be spelled out, or are not known (e.g., enable having a rewrite that
forward all operands to a call generically).

Differential Revision: https://reviews.llvm.org/D104955
2021-06-28 13:42:16 -07:00
Eugene Zhulenev fe3c425ae0 [mlir] Destroy MLIRContext thread pool when disable multi threading
Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D105057
2021-06-28 13:26:56 -07:00
William S. Moses 2ab27758d5 Revert "[MLIR][SCF] Inline ExecuteRegion if parent can contain multiple blocks"
This reverts commit 5d6240b77e.

The commit was mistakenly landed without a PR approval, this will be
reverted now and resubmitted.
2021-06-28 13:52:30 -04:00
Rob Suderman c7676d9993 [mlir][tosa] Update Tosa conv verifier to handle IntegerType input
Input/output types can be integers, which represent a quantized convolution.
Update verifier to expect this behavior.

Reviewed By: sjarus

Differential Revision: https://reviews.llvm.org/D104949
2021-06-28 10:18:45 -07:00
William S. Moses 5d6240b77e [MLIR][SCF] Inline ExecuteRegion if parent can contain multiple blocks
The executeregionop is used to allow multiple blocks within SCF constructs. If the container allows multiple blocks, inline the region

Differential Revision: https://reviews.llvm.org/D104960
2021-06-28 13:09:22 -04:00
Stephan Herhut 88d5eba139 Revert "Revert "[mlir][memref] Implement lowering of memref.copy to llvm""
This reverts commit 7d6e589fc8.

Windows build was unbroken.
2021-06-28 18:48:00 +02:00
William S. Moses 44826ecd92 [MLIR] Correct memrefdataflow behavior in the presence of cast and other operations
MemRefDataFlow performs mem2reg style operations for affine load/stores. Unfortunately, it is not presently correct in the presence of external operations such as memref.cast, or function calls. This diff extends the functionality of the pass to remain correct in the presence of such ops.

Differential Revision: https://reviews.llvm.org/D104053
2021-06-28 12:23:29 -04:00
Stephan Herhut e6450d88e2 [mlir][llvm] Fix windows build
Gate the include of alloca.h behind _WIN32 guard.

Differential Revision: https://reviews.llvm.org/D105036
2021-06-28 18:22:21 +02:00
William S. Moses cccc7e5aa8 [MLIR] Don't remove memref allocation if stored into another allocation
A canonicalization accidentally will remove a memref allocation if it is only stored into. However, this is incorrect if the allocation is the value being stored, not the allocation being stored into.

Differential Revision: https://reviews.llvm.org/D104947
2021-06-28 12:05:59 -04:00
William S. Moses 35c0ab72fc [MLIR] Simplify select to a not
Given a select that returns the logical negation of the condition, replace it with a not of the condition.

Differential Revision: https://reviews.llvm.org/D104966
2021-06-28 11:00:02 -04:00
Jacques Pienaar 7d6e589fc8 Revert "[mlir][memref] Implement lowering of memref.copy to llvm"
This reverts commit e939644977.

Breaks Windows build.
2021-06-28 07:50:11 -07:00
Stephan Herhut e939644977 [mlir][memref] Implement lowering of memref.copy to llvm
This lowering uses a library call to implement copying in the general case, i.e.,
supporting arbitrary rank and strided layouts.
2021-06-28 14:52:07 +02:00
Tobias Gysi bbf4436a82 [mlir][linalg] Remove the StructuredOp capture mechanism.
After https://reviews.llvm.org/D104109, structured ops support scalar inputs. As a result, the capture mechanism meant to pass non-shaped parameters got redundant. The patch removes the capture semantics after the FillOp migrated to use scalar operands https://reviews.llvm.org/D104121.

Differential Revision: https://reviews.llvm.org/D104785
2021-06-28 07:57:40 +00:00