Commit Graph

8360 Commits

Author SHA1 Message Date
Aart Bik 56d607006d [mlir][sparse][python] add an "exhaustive" sparse test using python
Using the python API to easily set up sparse kernels, this test
exhaustively builds, compilers, and runs SpMM for all annotations
on a sparse tensor, making sure every version generates the correct
result. This test also illustrates using the python API to set up
a sparse kernel and sparse compilation.

Reviewed By: bixia

Differential Revision: https://reviews.llvm.org/D107943
2021-08-12 11:13:04 -07:00
Florian Hahn f999312872
Recommit "[Matrix] Overload stride arg in matrix.columnwise.load/store."
This reverts the revert 28c04794df.

The failing MLIR test that caused the revert should be fixed  in this
version.

Also includes a PPC test fix previously in 1f87c7c478.
2021-08-12 18:31:57 +01:00
Tyler Augustine 3a2ff982d7 Support post-processing Ops in unrolled loop iterations
This can be useful when one needs to know which unrolled iteration an Op belongs to, for example, conveying noalias information among memory-affecting ops in parallel-access loops.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D107789
2021-08-11 23:11:10 +00:00
Benjamin Kramer 35d6e75aba [mlir] Drop LLVM dialect from TestPolynomialApproximation
No longer needed after c1ebefdf77
2021-08-12 00:58:52 +02:00
Mehdi Amini 93e084e7e8 Add missing cmake dep to fix MLIR build with BUILD_SHARED_LIBS=ON (NFC) 2021-08-11 22:51:57 +00:00
Aart Bik a5ae34afaa [mlir][linalg] fixed typo
Differential Revision: https://reviews.llvm.org/D107915
2021-08-11 11:59:15 -07:00
Rob Suderman 7de439b2be [mlir][tosa] Migrate tosa to more efficient linalg.conv
Existing linalg.conv2d is not well optimized for performance. Changed to a
version that is more aligned for optimziation. Include the corresponding
transposes to use this optimized version.

This also splits the conv and depthwise conv into separate implementations
to avoid overly complex lowerings.

Reviewed By: antiagainst

Differential Revision: https://reviews.llvm.org/D107504
2021-08-11 11:05:12 -07:00
Benjamin Kramer c1ebefdf77 [mlir] Make polynomial approximation emit std instead of LLVM ops
This is a bit cleaner and removes issues with 2d vectors. It also has a
big impact on constant folding, hence the test changes.

Differential Revision: https://reviews.llvm.org/D107896
2021-08-11 16:37:21 +02:00
Alex Zinenko a0d8a08e3e [mlir] Add std.bitcast -> llvm.bitcast conversion
The conversion is a straightforward one-to-one mapping with optional unrolling
for nD vectors, similarly to other cast operations.

Depends On D107889

Reviewed By: cota, akuegel

Differential Revision: https://reviews.llvm.org/D107891
2021-08-11 16:30:21 +02:00
Alex Zinenko 79b0576dd4 [mlir] Tighten LLVM_AnyNonAggregate ODS type constraint
The constraint was checking that the type is not an LLVM structure or array
type, but was not checking that it is an LLVM-compatible type, making it accept
incorrect types. As a result, some LLVM dialect ops could process values that
are not compatible with the LLVM dialect leading to further issues with
conversions and translations that assume all values are LLVM-compatible. Make
LLVM_AnyNonAggregate only accept LLVM-compatible types.

Reviewed By: cota, akuegel

Differential Revision: https://reviews.llvm.org/D107889
2021-08-11 16:30:19 +02:00
Alexander Belyaev 1e733a8c04 Revert "Bufferization for tiled loop."
This reverts commit edaffebcb2.
2021-08-11 10:04:12 +02:00
Alexander Belyaev 967578f0b8 Revert "[mlir] Change the pattern for TiledLoopOp bufferization."
This reverts commit 2f946eaa9d.
2021-08-11 10:01:36 +02:00
Matthias Springer 4b56e2ee1d [mlir][Analysis][NFC] Remove code duplication around getFlattenedAffineExprs
Remove code duplication in `addLowerOrUpperBound` and `composeMatchingMap`.

Differential Revision: https://reviews.llvm.org/D107814
2021-08-11 16:02:10 +09:00
Matthias Springer 9e6e08149c [mlir][Analysis][NFC] Reimplement FlatAffineConstraints::composeMap
Reimplement this function in terms of `composeMatchingMap`.

Also fix a bug in `composeMatchingMap` where local dims of `this` could be missing in `localCst`.

Differential Revision: https://reviews.llvm.org/D107813
2021-08-11 15:49:50 +09:00
Matthias Springer 98e30a9b47 [mlir][Analysis][NFC] Reimplement FlatAffineConstraints::addLowerOrUpperBound
Reimplement this function in terms of the function variant without Value semantics.

Differential Revision: https://reviews.llvm.org/D107729
2021-08-11 15:26:36 +09:00
Matthias Springer 97e41c004c [mlir][Analysis] Add FlatAffineConstraints::addLowerOrUpperBound
This function overload is similar to the existing `FlatAffineConstraints::addLowerOrUpperBound`. It constrains a dimension based on an affine map. However, in contrast to the other overloading, it does not attempt to align dimensions/symbols of the affine map with the dimensions/symbols of the constraint set. Instead, dimensions/symbols are expected to already be aligned.

Differential Revision: https://reviews.llvm.org/D107727
2021-08-11 15:13:48 +09:00
Matthias Springer 9832e1a079 [mlir][Analysis] Add alignAffineMapWithValues
This function aligns an affine map (and operands) with given dims and syms SSA values.

This is useful in conjunction with `FlatAffineConstraints::addLowerOrUpperBound`, which requires the `boundMap` to be aligned with the constraint set's dims and syms.

Differential Revision: https://reviews.llvm.org/D107728
2021-08-11 14:59:03 +09:00
Rob Suderman 2b2ebb6f98 [mlir][tosa] Add folders for trivial tosa operation cases
Some folding cases are trivial to fold away, specifically no-op cases where
an operation's input and output are the same. Canonicalizing these away
removes unneeded operations.

The current version includes tensor cast operations to resolve shape
discreprencies that occur when an operation's result type differs from the
input type. These are resolved during a tosa shape propagation pass.

Reviewed By: NatashaKnk

Differential Revision: https://reviews.llvm.org/D107321
2021-08-10 14:43:00 -07:00
Rob Suderman 86858c62ba [mlir][tosa] Add dilation to tosa.transpose_conv2d lowering
Dilation only requires increasing the padding on the left/right side of the
input, and including dilation in the convolution. This implementation still
lacks support for strided convolutions.

Reviewed By: NatashaKnk

Differential Revision: https://reviews.llvm.org/D107680
2021-08-10 14:36:11 -07:00
natashaknk a1f46569a1 [mlir][tosa] Add quantized and unquantized versions for tosa.depthwise_conv2d lowering
Reviewed By: rsuderman

Differential Revision: https://reviews.llvm.org/D107855
2021-08-10 14:29:26 -07:00
Jacques Pienaar 768a517581 [mlir][drr] Improve error message for unexpected attribute (NFC)
When using an attribute where a value is expected previously this would fail
complaining about unbound symbol. Instead make error clear and mention common
failure reason.
2021-08-10 13:03:53 -07:00
Haruki Imai b34b1c6955 [mlir] Support normalizing memrefs with MemRef_ReinterpretCastOp
This patch enables normalizing memrefs with MemRef_ReinterpretCastOp by
adding MemRefsNormalizable trait in the Op definition.

Signed-off-by: Haruki Imai <imaihal@jp.ibm.com>

Reviewed By: bondhugula

Differential Revision: https://reviews.llvm.org/D107425
2021-08-11 01:15:18 +05:30
Alexander Belyaev 2f946eaa9d [mlir] Change the pattern for TiledLoopOp bufferization.
This version is does not affect the patterns for Extract/InsertSliceOp and
LinalgOps.

Differential Revision: https://reviews.llvm.org/D107858
2021-08-10 21:27:02 +02:00
Jacques Pienaar 093493032d [mlir] Enable specifying querying function in ValueShapeRange
This enables querying shapes/values as shapes without mutating the IR
directly (e.g., towards enabling doing inference in analysis &
application steps, inferring function shape with constant from callsite,
...). Add a new ShapeAdaptor that abstracts over whether shape is from
Type or ShapedTypeComponents or DenseIntElementsAttribute. This adds new
accessors to ValueShapeRange to get Shape and value as shape, but
doesn't restrict or remove the previous way of accessing Type via the
Value for now, that does mean a less refined shape could be accidentally
queried and will be restricted in follow up.

Currently restricted Value query to what can be represented as Shape. So
only supports cases where constant subgraph evaluation's output is a
shape. I had considered making it more general, but without TBD extern
attribute concept or some such a user cannot today uniformly avoid
overhead.

Update TOSA ops and also the shape inference pass.

Differential Revision: https://reviews.llvm.org/D107768
2021-08-10 11:44:20 -07:00
bakhtiyar 391456f33c Fix a bug in algebraic simplification, and enable the tests.
Reviewed By: ezhulenev

Differential Revision: https://reviews.llvm.org/D107788
2021-08-10 04:15:56 -07:00
Tres Popp 2060155480 [mlir] NFC Replace some code snippets with equivalent method calls
Replace some code snippets With scf::ForOp methods. Additionally,
share a listener at one more point (although this pattern is still
not safe to roll back currently)

Differential Revision: https://reviews.llvm.org/D107754
2021-08-10 08:22:08 +02:00
Matthias Springer ab03a84e2c [mlir][Analysis][NFC] Disambiguate FlatAffineConstraints constructor
The following constructor call (and others) used to be ambiguous:

```
FlatAffineConstraints constraints(0, 0, 0);
```

Differential Revision: https://reviews.llvm.org/D107726
2021-08-10 10:34:30 +09:00
Matthias Springer 27c2fa4f05 [mlir][Analysis] Revert D107221
This is in preparation of a larger refactoring that makes the changes in D107221 obsolete.

Differential Revision: https://reviews.llvm.org/D107724
2021-08-10 10:17:49 +09:00
Alexander Belyaev edaffebcb2 Cloned from CL 389610703 by 'g4 patch'.
Original change by pifon@pifon:tfrt_clean:6896:citc on 2021/08/09 05:30:17.

Ad b

Differential Revision: https://reviews.llvm.org/D107762
2021-08-09 21:57:06 +02:00
Aart Bik 8cf8349eaa [mlir][sparse] add an elaborate sparse storage scheme integration test
Looks "under the hood" of the sparse stogage schemes.
Users should typically not be interested in these details
(hey, that is why we have "sparse compilers"!) but this
test makes sure the compact contents are as expected.

Reviewed By: ThomasRaoux, bixia

Differential Revision: https://reviews.llvm.org/D107683
2021-08-09 12:54:15 -07:00
Aart Bik 05c7f450df [mlir][sparse] add dense to sparse conversion implementation
Implements lowering dense to sparse conversion, for static tensor types only.
First step towards general sparse_tensor.convert support.

Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D107681
2021-08-09 12:12:39 -07:00
Alex Zinenko 8a7c657c4d [mlir] support nD vector forms of shifts in std-to-llvm conversion
These ops were not ported to the nD vector conversion when it was introduced
and nobody needed them so far.

Reviewed By: gysit

Differential Revision: https://reviews.llvm.org/D107750
2021-08-09 12:00:41 +02:00
Dimitry Andric ab4b4684a2 [mlir] Avoid including <alloca.h> on FreeBSD and NetBSD
Instead, include `<cstdlib>` which is the canonical header containing
the declaration of `alloca()`.

Reviewed By: bondhugula

Differential Revision: https://reviews.llvm.org/D107699
2021-08-08 13:32:35 +02:00
Max Kudryavtsev 0b8cb87e0d [MLIR][STD] Add safe scalar constant propagation for FPTruncOp
Perform scalar constant propagation for FPTruncOp only if the resulting value can be represented without precision loss or rounding.

Example:
%cst = constant 1.000000e+00 : f32
%0 = fptrunc %cst : f32 to bf16
-->
%cst = constant 1.000000e+00 : bf16

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D107518
2021-08-06 16:31:29 -07:00
Alexander Belyaev a552debdcf [mlir] Add patterns for vector.transfer_read/write to Linalg bufferization.
Differential Revision: https://reviews.llvm.org/D107643
2021-08-06 20:24:44 +02:00
Markus Böck 5522ec00bc [mlir][NFC] Fix typos in DataLayoutInterfaces.td 2021-08-06 18:54:25 +02:00
Geoffrey Martin-Noble ca6baf1e1d [MLIR][std] Introduce bitcast operation
This patch introduces a bitcast operation to the standard dialect.
RFC: https://llvm.discourse.group/t/rfc-introduce-a-bitcast-op/3774

Reviewed By: silvas

Differential Revision: https://reviews.llvm.org/D105376
2021-08-06 08:47:51 -07:00
Alex Zinenko c4c1030976 [mlir] support collapsed loops in OpenMP-to-LLVM translation
Reviewed By: Meinersbur

Differential Revision: https://reviews.llvm.org/D105706
2021-08-06 17:13:12 +02:00
Alexander Belyaev aa2210a830 [linalg] Expose `rewriteAsPaddedOp` function.
Differential Revision: https://reviews.llvm.org/D107629
2021-08-06 12:08:12 +02:00
Vladislav Vinogradov 59f59d1c62 [mlir] Allow to override type/attr aliases from various hooks
Use new return type for `OpAsmDialectInterface::getAlias`:

* `AliasResult::NoAlias` if an alias was not provided.
* `AliasResult::OverridableAlias` if an alias was provided, but it might be overriden by other hook.
* `AliasResult::FinalAlias` if an alias was provided and it should be used (no other hooks will be checked).

In that case `AsmPrinter` will use either the first alias with `FinalAlias` result or
the last alias with `OverridableAlias` result (it depends on dialect array order).

Used `OverridableAlias` result for `BuiltinOpAsmDialectInterface`.

Use case: provide more informative alias for built-in attributes like `AffineMapAttr`
instead of generic "map<N>".

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D107437
2021-08-06 12:05:31 +03:00
Stella Laurenzo 835cbfa8cf [mlir][python] Make a number of imports relative.
Avoiding absolute imports allows the code to be relocatable (which is used for out of tree integrations).

Differential Revision: https://reviews.llvm.org/D107617
2021-08-06 07:23:37 +00:00
Adrian Kuegel d6b4993736 [mlir][MemRef] Fix canonicalization of BufferCast(TensorLoad).
CastOp::areCastCompatible does not check whether casts are definitely compatible.
When going from dynamic to static offset or stride, the canonicalization cannot
know whether it is really cast compatible. In that case, it can only canonicalize
to an alloc plus copy.

Differential Revision: https://reviews.llvm.org/D107545
2021-08-06 08:32:35 +02:00
Jacques Pienaar 9d10be70a8 [mlir] std.call reference function return types in failure
Makes it easier to see type mismatch from failure locally.

Differential Revision: https://reviews.llvm.org/D107288
2021-08-05 19:51:48 -07:00
Matthias Springer 66b1e629d8 [mlir] Cleanup: Fix warnings in MLIR
Tested with gcc-10. Other compilers may generate additional warnings. This does not fix all warnings. There are a few extra ones in LLVMCore and MLIR.

* `OpEmitter::getAttrNameIndex`: -Wunused-function (function is private and not used anywhere)
* `PrintOpPass` copy constructor: -Wextra ("Base class should be explicitly initialized in the copy constructor")
* `LegalizeForLLVMExport.cpp`: -Woverflow (overflow is expected, silence warning by making the cast explicit)

Differential Revision: https://reviews.llvm.org/D107525
2021-08-06 10:36:37 +09:00
Matthias Springer 12b34e056c [mlir] Clean up includes in Transforms/Passes.h
Differential Revision: https://reviews.llvm.org/D107520
2021-08-05 11:52:19 +09:00
Matthias Springer ac7c7cbfda [mlir] Update comment in Region.h
The file in which `Region::viewGraph` is defined has changed. This should have been updated with D106342.

Differential Revision: https://reviews.llvm.org/D107517
2021-08-05 10:57:34 +09:00
Catherine Payne 50264ff88a Adding missing filter check to SourceMgrDiagnosticHandler::EmitDiagnostics
There is a case in EmitDiagnostics where the filter check is bypassed (when locationStack is empty).   Filter might also be bypassed when loc instead of showableLoc is added to the locationStack.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D106522
2021-08-04 23:52:00 +00:00
Gus Smith 0bd2d4c4b1 [mlir][sparse] Remove comment w/ code in it
Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D107484
2021-08-04 21:41:36 +00:00
River Riddle 0bd297fce2 [mlir-lsp-server] Only use one MLIRContext per MLIRTextFile
A text file may be comprised of many different "chunks", when
the input file contains the `// -----` split markers. We don't
need to use a unique MLIRContext per chunk, as having
separate contexts is intended to allow for easy unloading of
unused data and all chunks have the same lifetime (tied to the
input file). This commit uses one context for the entire file,
greatly reducing memory consumption in certain situations (up
to 70%).

Differential Revision: https://reviews.llvm.org/D107488
2021-08-04 20:09:07 +00:00
Alfsonso Gregory fb27e8c76e [MLIR][NFC] Get DiagnosticEngine as a reference in doc
'mlir::DiagnosticEngine::DiagnosticEngine(const mlir::DiagnosticEngine&)' is implicitly deleted because the default definition would be ill-formed.

Reviewed By: rdzhabarov

Differential Revision: https://reviews.llvm.org/D107287
2021-08-04 19:00:18 +00:00