Commit Graph

8778 Commits

Author SHA1 Message Date
Stella Laurenzo a201829a20 Fix parsing of hex-format index dense tensor attributes.
TensorLiteralParser::getHexAttr does a isIntOrIndexOrFloat check and properly handles index elements, but TensorLiteralParser::getAttr that calls into it has a mismatched check. This just makes the checks match so that index element attrs can parse when of type tensor.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D111374
2021-10-08 15:44:02 +00:00
Matthias Springer f8453ea75f [mlir][linalg][bufferize] Rewrite "write into non-writable memory" detection
The purpose of this revision is to make "write into non-writable memory" conflict detection easier to understand.

The main idea is that there is a conflict in the case of inplace bufferization if:

1. Someone writes to (an alias of) opOperand, opResult or the to-be-bufferized op writes itself.
2. And, opOperand or opResult aliases a non-writable buffer.

Differential Revision: https://reviews.llvm.org/D111379
2021-10-08 21:27:49 +09:00
Lei Zhang 4cd7ff6728 [mlir][linalg] Constant fold linalg.generic that are transposes
This commit adds a pattern to perform constant folding on linalg
generic ops which are essentially transposes. We see real cases
where model importers may generate such patterns.

Reviewed By: mravishankar

Differential Revision: https://reviews.llvm.org/D110597
2021-10-08 08:09:13 -04:00
Eugene Zhulenev e2a37bb540 [mlir] Add alignment option to constant tensor bufferization pass
Reviewed By: bkramer

Differential Revision: https://reviews.llvm.org/D111364
2021-10-08 03:17:20 -07:00
Alex Zinenko b164f23c29 [mlir][python] support taking ops instead of values in op constructors
Introduce support for accepting ops instead of values when constructing ops. A
single-result op can be used instead of a value, including in lists of values,
and any op can be used instead of a list of values. This is similar to, but
more powerful, than the C++ API that allows for implicitly casting an OpType to
Value if it is statically known to have a single result - the cast in Python is
based on the op dynamically having a single result, and also handles the
multi-result case. This allows to build IR in a more concise way:

    op = dialect.produce_multiple_results()
    other = dialect.produce_single_result()
    dialect.consume_multiple_results(other, op)

instead of having to access the results manually

    op = dialect.produce.multiple_results()
    other = dialect.produce_single_result()
    dialect.consume_multiple_results(other.result, op.operation.results)

The dispatch is implemented directly in Python and is triggered automatically
for autogenerated OpView subclasses. Extension OpView classes should use the
functions provided in ods_common.py if they want to implement this behavior.
An alternative could be to implement the dispatch in the C++ bindings code, but
it would require to forward opaque types through all Python functions down to a
binding call, which makes it hard to inspect them in Python, e.g., to obtain
the types of values.

Reviewed By: gysit

Differential Revision: https://reviews.llvm.org/D111306
2021-10-08 09:49:48 +02:00
Tobias Gysi 8ed2e8e04f [mlir][linalg] Retire Linalg ConvOp.
The convolution op is one of the remaining hard coded Linalg operations that have no region attached. It got obsolete due to the OpDSL convolution operations. Removing it allows us to delete specialized code and tests that are not needed for the OpDSL counterparts that rely on the standard code paths.

Test needed due to specialized implementations are removed. Tiling and fusion tests are replaced by variants using linalg.conv_2d.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D111233
2021-10-08 06:56:37 +00:00
Tobias Gysi 23800b05be [mlir][linalg] Add loop interchange to CodegenStrategy.
Add a loop interchange pass and integrate it with CodegenStrategy.

This patch depends on https://reviews.llvm.org/D110728 and https://reviews.llvm.org/D110746.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D110748
2021-10-08 06:39:22 +00:00
Tobias Gysi 1ebd197bc5 [mlir][linalg] Add generalization to CodegenStrategy.
Add a generalization pass and integrate it with CodegenStrategy.

This patch depends on https://reviews.llvm.org/D110728.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D110746
2021-10-08 06:31:19 +00:00
Matthias Springer 7dfd3bb034 [mlir][linalg][bufferize][NFC] API change of aliasesNonWritableBuffer
The function now takes a Value instead of an OpOperand.

Differential Revision: https://reviews.llvm.org/D111378
2021-10-08 14:47:29 +09:00
Matthias Springer 89b2f29d62 [mlir][linalg][bufferize] Fix/add missing case to getAliasingOpOperand
Differential Revision: https://reviews.llvm.org/D111377
2021-10-08 14:38:47 +09:00
Matthias Springer a046154057 [mlir][linalg][bufferize] Add bufferRelation to op interface
Currently supported are: BufferRelation::None, BufferRelation::Equivalent.

Differential Revision: https://reviews.llvm.org/D111376
2021-10-08 14:28:24 +09:00
Mehdi Amini 70a8d61ca1 evert "[mlir] Limit Python dependency to Development.Module when possible."
This reverts commit 7aebdfc4fc.

The build is broken with errors like:

GPUPasses.cpp:(.text.pybind11_object_init[pybind11_object_init]+0x118): undefined reference to `PyExc_TypeError'
2021-10-08 05:18:52 +00:00
Mike Urbach 7aebdfc4fc [mlir] Limit Python dependency to Development.Module when possible.
After CMake 3.18, we are able to limit the scope of the
find_package(Python3 ...) search to just Development.Module. Searching
for Development will fail in manylinux builds, and isn't necessary
since we are not embedding the Python interpreter. For more information, see:
https://pybind11.readthedocs.io/en/stable/compiling.html#findpython-mode

Reviewed By: stellaraccident

Differential Revision: https://reviews.llvm.org/D111383
2021-10-07 23:05:43 -06:00
Mehdi Amini 82cd8b81aa Fix test-rsqrt.mlir to accept AMD's approximation of rsqrt as well
These kind of function can behave differently on these X86 chips, there
isn't really "one true answer" so we'll accept both.

Also remove spurious passes and use mattr="avx" to match the instruction
used here.

Differential Revision: https://reviews.llvm.org/D111373
2021-10-08 04:24:24 +00:00
MaheshRavishankar 4281946390 [mlir][Tensor] Add ReifyRankedShapedTypeOpInterface to tensor.extract_slice.
Differential Revision: https://reviews.llvm.org/D111263
2021-10-07 17:10:35 -07:00
Amy Zhuang 5d001f58f2 [mlir] Fix a bug in Affine LICM.
Currently Affine LICM checks iterOperands and does not hoist out any
instruction containing iterOperands. We should check iterArgs instead.

Reviewed By: bondhugula

Differential Revision: https://reviews.llvm.org/D111090
2021-10-07 15:46:43 -07:00
Kiran Chandramohan 3b01cf9286
[mlir][openmp] Add an interface for Outlineable OpenMP ops
Add an interface for outlineable OpenMP operations.
This patch was initially done in fir-dev and is now needed
for the upstreaming.

Reviewed By: schweitz

Differential Revision: https://reviews.llvm.org/D111310
2021-10-07 20:53:48 +02:00
Stella Laurenzo c5f445d143 [mlir][python] Temporarily disable test for converting unsupported DenseElementsAttr types to a buffer.
* Need to investigate the proper solution to https://github.com/pybind/pybind11/issues/3336 or engineer something different.
* The attempt to produce an empty buffer_info as a workaround triggers asan/ubsan.
* Usage of this API does not arise naturally in practice yet, and it is more important to be asan/crash clean than have a solution right now.
* Switching back to raising an exception, even though that triggers terminate().
2021-10-07 11:50:57 -07:00
Stella Laurenzo 5d6d30edf8 [mlir] Extend C and Python API to support bulk loading of DenseElementsAttr.
* This already half existed in terms of reading the raw buffer backing a DenseElementsAttr.
* Documented the precise expectations of the buffer layout.
* Extended the Python API to support construction from bitcasted buffers, allowing construction of all primitive element types (even those that lack a compatible representation in Python).
* Specifically, the Python API can now load all integer types at all bit widths and all floating point types (f16, f32, f64, bf16).

Differential Revision: https://reviews.llvm.org/D111284
2021-10-07 08:42:12 -07:00
Kazu Hirata 80e39366ee [lldb, mlir] Migrate from getNumArgOperands and arg_operands (NFC)
Note that getNumArgOperands and arg_operands are considered legacy
names.  See llvm/include/llvm/IR/InstrTypes.h for details.
2021-10-07 08:29:42 -07:00
Matthias Springer 56bf688a09 [mlir][linalg][bufferize][NFC] Simplify getAliasingOpResult()
The signature of this function was confusing. Check for hasKnownBufferizationAliasingBehavior separately when needed.

Differential Revision: https://reviews.llvm.org/D110916
2021-10-07 22:41:21 +09:00
Lei Zhang 3964c1db91 [mlir][vector] Split populateVectorContractLoweringPatterns
It was bundling quite a lot of patterns that convert high-D
vector ops into low-D elementary ops. It might not be good
for all of the patterns to happen for a particular downstream
user. For example, `ShapeCastOpRewritePattern` rewrites
`vector.shape_cast` into data movement extract/insert ops.

Instead, split the entry point into multiple ones so users
can pull in patterns on demand.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D111225
2021-10-07 09:39:26 -04:00
Matthias Springer 1d24b8c603 [mlir][linalg][bufferize][NFC] Change bufferizableInPlaceAnalysis signature
Move getInplaceableOpResult() call into bufferizableInPlaceAnalysis.

Note: The only goal of this change is to make the signature of bufferizableInPlaceAnalysis smaller. (Fewer arguments.)

Differential Revision: https://reviews.llvm.org/D110915
2021-10-07 22:35:40 +09:00
Matthias Springer 6b1f653c94 [mlir][linalg][bufferize] tensor.cast may require a copy
Differential Revision: https://reviews.llvm.org/D110806
2021-10-07 22:24:05 +09:00
Eugene Zhulenev 8276ac13e9 [mlir] Add alignment attribute to memref.global
Revived https://reviews.llvm.org/D102435

Add alignment attribute to `memref.global` and propagate it to llvm global in memref->llvm lowering

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D111309
2021-10-07 06:21:57 -07:00
Adrian Kuegel 2bb208ddfd [mlir] Don't allow dynamic extent tensor types for ConstShapeOp.
ConstShapeOp has a constant shape, so its type can always be static.
We still allow it to have ShapeType though.

Differential Revision: https://reviews.llvm.org/D111139
2021-10-07 10:56:16 +02:00
Tobias Gysi 3fe7fe4424 [mlir][linalg] Add unsigned min/max/cast function to OpDSL.
Update OpDSL to support unsigned integers by adding unsigned min/max/cast signatures. Add tests in OpDSL and on the C++ side to verify the proper signed and unsigned operations are emitted.

The patch addresses an issue brought up in https://reviews.llvm.org/D111170.

Reviewed By: rsuderman

Differential Revision: https://reviews.llvm.org/D111230
2021-10-07 06:27:20 +00:00
Uday Bondhugula 1e39d32c5a [MLIR] Add OrOp folding rule for constant one operand
Add folding rule for std.or op when an operand has all bits set.

or(x, <all bits set>) -> <all bits set>

Differential Revision: https://reviews.llvm.org/D111206
2021-10-07 08:05:39 +05:30
Mogball 8f0c673d20 [MLIR] fix arith dialect build failure
Missing function defs causes errors on some build configs.
2021-10-06 23:39:10 +00:00
Stella Laurenzo 56272257f3 Return failure on failure in convertBlockSignature.
This was causing a subsequent assert/crash when a type converter failed to convert a block argument.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D110985
2021-10-06 15:35:31 -07:00
Mogball 8c08f21b60 [MLIR] Split arith dialect from the std dialect
Create the Arithmetic dialect that contains basic integer and floating
point arithmetic operations. Ops that did not meet this criterion were
moved to the Math dialect.

First of two atomic patches to remove integer and floating point
operations from the standard dialect. Ops will be removed from the
standard dialect in a subsequent patch.

Reviewed By: ftynse, silvas

Differential Revision: https://reviews.llvm.org/D110200
2021-10-06 19:25:51 +00:00
rdzhabarov fb3d83acaf [mlir] Fix redundant return in the void method.
clang-tidy, fix redundant return statement at the end of the void method.

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D111251
2021-10-06 18:45:30 +00:00
natashaknk 4c48f7e29b [mlir][tosa] Create basic dynamic shape support for several ops.
Transpose, Matmul and Fully-connected dynamic shape support

Reviewed By: rsuderman

Differential Revision: https://reviews.llvm.org/D111167
2021-10-06 10:36:04 -07:00
Mogball 0210a3de7b [MLIR] Update DRR doc with returnType directive
Add missing documentation.

Reviewed By: Chia-hungDuan, jpienaar

Differential Revision: https://reviews.llvm.org/D110964
2021-10-06 17:32:40 +00:00
Geoffrey Martin-Noble b096ac9092 [MLIR] Improve debug messages in BuiltinTypes
It's nice for users to have more information when debugging failures and
these are only triggered in a failure path.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D107676
2021-10-06 09:42:13 -07:00
Alexandre Rames fd9613324d [MLIR] Rename Shape dialect's `join` to `meet`.
For the type lattice, we (now) use the "less specialized or equal" partial
order, leading to the bottom representing the empty set, and the top
representing any type.

This naming is more in line with the generally used conventions, where the top
of the lattice is the full set, and the bottom of the lattice is the empty set.
A typical example is the powerset of a finite set: generally, meet would be the
intersection, and join would be the union.

```
top:  {a,b,c}
     /   |   \
 {a,b} {a,c} {b,c}
   |  X     X  |
   {a} { b } {c}
      \  |  /
bottom: { }
```

This is in line with the examined lattice representations in LLVM:
* lattice for `BitTracker::BitValue` in `Hexagon/BitTracker.h`
* lattice for constant propagation in `HexagonConstPropagation.cpp`
* lattice in `VarLocBasedImpl.cpp`
* lattice for address space inference code in `InferAddressSpaces.cpp`

Reviewed By: silvas, jpienaar

Differential Revision: https://reviews.llvm.org/D110766
2021-10-06 09:41:33 -07:00
Simon Pilgrim e244a6fec7 [mlir] Replace report_fatal_error(std::string) uses with report_fatal_error(Twine)
As described on D111049, we're trying to remove the <string> dependency from error handling and replace uses of report_fatal_error(const std::string&) with the Twine() variant which can be forward declared.
2021-10-06 12:57:20 +01:00
Nicolas Vasilache 26b3e92981 [mlir][Linalg] Don't return early from inPlaceAnalysis
Instead just emit a warning that analysis failed and the result will be treated conservatively.

Differential Revision: https://reviews.llvm.org/D111217
2021-10-06 10:03:25 +00:00
Tobias Gysi a744c7e962 [mlir][linalg] Update OpDSL to use the newly introduced min and max ops.
Implement min and max using the newly introduced std operations instead of relying on compare and select.

Reviewed By: dcaballe

Differential Revision: https://reviews.llvm.org/D111170
2021-10-06 06:45:53 +00:00
Mehdi Amini 00b7d95182 Stop stripping the `std.` prefix when printing operations in a region with a defined default dialect
This fixes round-trip / ambiguity when an operation in the standard dialect would
have the same name as an operation in the default dialect.

Differential Revision: https://reviews.llvm.org/D111204
2021-10-06 02:36:14 +00:00
Diego Caballero eaf2588a51 [mlir][Linalg] Add support for min/max reduction vectorization in linalg.generic
This patch extends Linalg core vectorization with support for min/max reductions
in linalg.generic ops. It enables the reduction detection for min/max combiner ops.
It also renames MIN/MAX combining kinds to MINS/MAXS to make the sign explicit for
floating point and signed integer types. MINU/MAXU should be introduce din the future
for unsigned integer types.

Reviewed By: pifon2a, ThomasRaoux

Differential Revision: https://reviews.llvm.org/D110854
2021-10-05 22:47:20 +00:00
Lei Zhang 7a89444cd9 [mlir][spirv] Add ops and patterns for lowering standard max/min ops
Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D111143
2021-10-05 14:27:32 -04:00
River Riddle b8ffcb12e2 [mlir:Pass] Generate a reproducer as early as possible
This avoids keeping references to passes that may be freed by
the time that the pass manager has finished executing (in the
non-crash case).

Fixes PR#52069

Differential Revision: https://reviews.llvm.org/D111106
2021-10-05 18:11:26 +00:00
Rob Suderman d5a4c86d14 [mlir][tosa] tosa.cast support for unsigned integers
Unsigned integers need to be handled for cast to floating point.

Reviewed By: NatashaKnk

Differential Revision: https://reviews.llvm.org/D111102
2021-10-05 10:57:16 -07:00
Geoffrey Martin-Noble b983783d2e [MLIR][linalg] Preserve location during elementwise fusion
This otherwise loses a lot of debugging info and results in a painful
debugging experience.

Reviewed By: mravishankar, stellaraccident

Differential Revision: https://reviews.llvm.org/D111107
2021-10-05 09:43:53 -07:00
Aart Bik 16b8f4ddae [mlir][sparse] add a "release" operation to sparse tensor dialect
We have several ways to materialize sparse tensors (new and convert) but no explicit operation to release the underlying sparse storage scheme at runtime (other than making an explicit delSparseTensor() library call). To simplify memory management, a sparse_tensor.release operation has been introduced that lowers to the runtime library call while keeping tensors, opague pointers, and memrefs transparent in the initial IR.

*Note* There is obviously some tension between the concept of immutable tensors and memory management methods. This tension is addressed by simply stating that after the "release" call, no further memref related operations are allowed on the tensor value. We expect the design to evolve over time, however, and arrive at a more satisfactory view of tensors and buffers eventually.

Bug:
http://llvm.org/pr52046

Reviewed By: bixia

Differential Revision: https://reviews.llvm.org/D111099
2021-10-05 09:35:59 -07:00
Lei Zhang 83e074a0c6 [mlir] Add an 'cppNamespace' field to availability
This allows us to generate interfaces in a namespace,
following other TableGen'erated code.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D108311
2021-10-05 09:38:09 -04:00
Lei Zhang 070b0af9b8 [mlir][spirv] Fix path in define_enum.sh script
Reviewed By: mravishankar

Differential Revision: https://reviews.llvm.org/D108310
2021-10-05 09:32:01 -04:00
Tobias Gysi e826db6240 [mlir][linalg] Move generalization pattern to Transforms (NFC).
Move the generalization pattern to the other Linalg transforms to make it available to the codegen strategy.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D110728
2021-10-05 12:49:42 +00:00
Nicolas Vasilache af9dce18bf [mlir][Linalg] Allow operand-less scf::ExecuteRegionOp to encapsulate scf::YieldOp
These are considered noops.
Buferization will still fail on scf.execute_region which yield values.
This is used to make comprehensive bufferization interoperate better with external clients.

Differential Revision: https://reviews.llvm.org/D111130
2021-10-05 11:34:53 +00:00