Commit Graph

7206 Commits

Author SHA1 Message Date
Jacques Pienaar e74e6afcf1 [shape] Add min and max ops
These are element-wise operations that operates on shapes with equal ranks.
Also add missing printer/parser for join operator.

Differential Revision: https://reviews.llvm.org/D99986
2021-04-06 17:58:12 -07:00
John Demme 0126e90648 [MLIR] [Python] Add capsule methods for pybind11 to PyOperation
Add the `getCapsule()` and `createFromCapsule()` methods to the PyOperation class.

Reviewed By: stellaraccident

Differential Revision: https://reviews.llvm.org/D99927
2021-04-06 14:29:03 -07:00
Rob Suderman 0312b25df0 [mlir][tosa] Add tosa.table lowering to linalg.generic
Table op lowering to linalg.generic for both i8 (behaves like a gather) and a
pair of gathers with a quantized interpolation.

Differential Revision: https://reviews.llvm.org/D99756
2021-04-06 13:57:18 -07:00
Jacques Pienaar 96caf3817f [mlir] Hoist out getRequestedOpDefinitions helper
Enables performing the same filtering in the op doc definition as in the op definition generator.

Differential Revision: https://reviews.llvm.org/D99793
2021-04-06 12:53:28 -07:00
Christian Sigg fcc5755878 [mlir] Remove no-op array assignment in dictionaryAttrSort().
Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D99954
2021-04-06 21:30:37 +02:00
Thomas Preud'homme 1d9d7f6a2c [MLIR, test] Fix use of undef FileCheck var
MLIR test Dialect/Linalg/transform-patterns.mlir tries to check for the
absence of a sequence of instructions with several CHECK-NOT with one of
those directives using a variable defined in another. However CHECK-NOT
are checked independently so that is using a variable defined in a
pattern that should not occur in the input.

This commit removes the dependency between those CHECK-NOT by replacing
occurences of variables by the regex that were used to define them.

Note to reviewers: please pay attention to whether the remaining
reference to l0 is correct. There was a l0 defined in those CHECK-NOT
and one defined before. I'm not sure what was the intent there.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D99957
2021-04-06 20:08:23 +01:00
Nicolas Vasilache 48268aa0a9 [mlir][python] Add missing affine map compression test 2021-04-06 16:54:57 +00:00
Alexander Belyaev 5571cc7dee [mlir][linalg] Add helpers for linalg.tiled_loop [nfc].
Differential Revision: https://reviews.llvm.org/D99968
2021-04-06 18:17:37 +02:00
Thomas Preud'homme 17f4f23eea [MLIR, test] Fix use of undef FileCheck var
MLIR test Transforms/canonicalize.mlir tries to check for the absence of
a sequence of instructions with several CHECK-NOT with one of those
directives using a variable defined in another. However CHECK-NOT are
checked independently so that is using a variable defined in a pattern
that should not occur in the input.

This commit removes the dependency between those CHECK-NOT by replacing
occurences of variables by the regex that were used to define them.

Reviewed By: pifon2a

Differential Revision: https://reviews.llvm.org/D99958
2021-04-06 16:58:09 +01:00
Nicolas Vasilache 518e6f341d [mlir][Linalg] Fix fusion on tensors operands / bbArg mismatch
Linalg fusion on tensors has mismatching assumptions on the operand side than on the region bbArg side.
Relax the behavior on the operand/indexing map side so that we better support output operands that may also be read from.

Differential revision: https://reviews.llvm.org/D99499
2021-04-06 15:39:40 +00:00
Thomas Preud'homme b36ef9f47d [MLIR, test] Fix use of undef FileCheck var
MLIR test Dialect/Linalg/tile-indexed-generic.mlir has a CHECK-NOT
directive referring to a variable only defined in a CHECK directive with
a different prefix, and thus undefined in the CHECK-NOT.

This commit removes the variable reference altogether to error on any
content it might have.

Reviewed By: pifon2a

Differential Revision: https://reviews.llvm.org/D99956
2021-04-06 16:27:25 +01:00
Alex Zinenko 7dc7790ec5 [mlir] Fix support for lowering non-32-bit affine reductions.
The existing implementation was always creating 32-bit constants for
floating-point and integer reductions regardless of the actual type, which
resulted in invalid IR being generated for any types other than f32 and i32
when lowering affine.parallel to SCF. Use the actual type instead.

Reviewed By: chelini

Differential Revision: https://reviews.llvm.org/D99942
2021-04-06 14:00:15 +02:00
Geoffrey Martin-Noble 22411d8072 [MLIR][docs] Fixes to operation syntax in Lang Ref
Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D99922
2021-04-05 22:29:21 -07:00
MaheshRavishankar 944a2fe763 [mlir][Linalg] Add callbacks to fusion of elementwise operations to control fusion.
Right now Elementwise operations fusion in Linalg fuses everything it
can. This can run up against resource limits of the target hardware
without some checks. This patch adds a callback function that clients
can use to implement a cost function. When two elementwise operations
are deemed structurally fusable, the callback can be used to control
if the fusion applies.

Differential Revision: https://reviews.llvm.org/D99820
2021-04-05 16:08:47 -07:00
Aart Bik a46f59a747 [mlir][sparse] move new test to right directory structure
Differential Revision: https://reviews.llvm.org/D99899
2021-04-05 14:41:18 -07:00
MaheshRavishankar ea069aebcc [mlir][Linalg] NFC: Move populatePatterns* method into linalg namespace.
The moved `populate` methods are only relevant to Linalg
operations. So they are better of in `linalg` namespace.  Also rename
`populateLinalgTensorOpsFusionPatterns` to
`populateElementwiseOpsFusionPatterns`. This makes the scope of these
patterns explicit and disambiguates it with fusion on tensors using
tile + fuse.

Differential Revision: https://reviews.llvm.org/D99819
2021-04-05 11:16:02 -07:00
Butygin 6e96de8abf [mlir][NFC] Fully spell mlir types names in LoopLikeOpInterface, so it can be used in ops defined outside mlir namespace
Differential Revision: https://reviews.llvm.org/D99844
2021-04-04 12:25:15 +03:00
David Blaikie 9f6649dd12 Add void cast to suppress -Wunused-member-variable on assert-only member 2021-04-03 14:03:43 -07:00
David Blaikie 499571ea83 Add workaround for false positive in -Wfree-nonheap-object 2021-04-03 14:03:43 -07:00
Christian Sigg 3bcb6a389f Silence `-Wunused-private-field` warning on isIsolatedFromAbove.
NDEBUG builds currently warn because it's only used inside an assert.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D99721
2021-04-03 15:45:21 +02:00
Rob Suderman eb1b55c652 [mlir][tosa] Add tosa.reduce_any and tosa.reduce_all linalg lowering
Added lowerings for Tosa's reduce boolean operations. This includes a fix to
maintain the output rank of reduce operations.

Reviewed By: silvas

Differential Revision: https://reviews.llvm.org/D99228
2021-04-02 14:32:18 -07:00
Sean Silva 223dcdcfbe [mlir] Add optional TypeConverter for materializations.
`ConversionPatternRewriter::applySignatureConversion` did not have a way
to apply a signature conversion that involved materializations.

Differential Revision: https://reviews.llvm.org/D99782
2021-04-02 13:39:06 -07:00
River Riddle 109305e104 [mlir] Emit errors when creating unregistered attributes/types when not allowed
This was missed when verification for creating unregistered operations was added.

Differential Revision: https://reviews.llvm.org/D99684
2021-04-02 12:45:35 -07:00
Rob Suderman 12c3bca193 [mlir] Rename linalg.pooling operations to have a FOp postfix for floating point
Linalg pooling operations only support floating point currently but integer
variants will soon be needed. Renaming to uncluse a FOp postfix to clarify.

Differential Revision: https://reviews.llvm.org/D99779
2021-04-02 11:54:20 -07:00
Lei Zhang 6dd07fa513 [mlir][spirv] Add utilities for push constant value
This commit add utility functions for creating push constant
storage variable and loading values from it.

Along the way, performs some clean up:

* Deleted `setABIAttrs`, which is just a 4-liner function
  with one user.
* Moved `SPIRVConverstionTarget` into `mlir` namespace,
  to be consistent with `SPIRVTypeConverter` and
  `LLVMConversionTarget`.

Reviewed By: mravishankar

Differential Revision: https://reviews.llvm.org/D99725
2021-04-02 07:51:07 -04:00
Alex Zinenko 5d7c832e8c [mlir] add memref dialect as dependent of lower-affine pass
The lower-affine pass also processes affine load and store operations
that get converted to load and store operations now available in the
memref dialect. Since it produces operations from the memref dialect,
this dialect should be registered as dependent for this pass. It is rare
but possible to have code that doesn't have memref operations in the
input and calls this pass.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D99720
2021-04-02 09:17:10 +02:00
Aart Bik a0c5b7e3b5 [mlir][sparse] support for very narrow index and pointer types
Rationale:
Small indices and values, when allowed by the required range of the
input tensors, can reduce the memory footprint of sparse tensors
even more. Note, however, that we must be careful zero extending
the values (since sparse tensors never use negatives for indexing),
but LLVM treats the index type as signed in most memory operations
(like the scatter and gather). This CL dots all the i's in this regard.

Reviewed By: bixia

Differential Revision: https://reviews.llvm.org/D99777
2021-04-01 18:21:27 -07:00
Mehdi Amini 51a07182b3 Setup OpBuilder to support detached block in loopUnrollByFactor (NFC)
Setting the builder from a block is looking up for a parent operation
to get a context, instead by setting up the builder with an explicit
context we can support invoking this helper in absence of a parent
operation.
2021-04-01 23:34:03 +00:00
Aden Grue 3ba1b1cd20 Add a pattern to combine composed subview ops
Differential Revision: https://reviews.llvm.org/D99229
2021-04-01 10:56:57 -07:00
Vinayaka Bandishti dc537158d5 [MLIR][Affine] Add utility to check if the slice is valid
Fixes a bug in affine fusion pipeline where an incorrect slice is computed.
After the slice computation is done, original domain of the the source is
compared with the new domain that will result if the fusion succeeds. If the
new domain must be a subset of the original domain for the slice to be
valid. If the slice computed is incorrect, fusion based on such a slice is
avoided.

Relevant test cases are added/edited.

Fixes https://bugs.llvm.org/show_bug.cgi?id=49203

Differential Revision: https://reviews.llvm.org/D98239
2021-04-01 14:52:22 +05:30
Nicolas Vasilache 335d2df533 [mlir][Python][Linalg] Add missing attributes to linalg ops
This revision tightens up the handling of attributes for both named
and generic linalg ops.
To demonstrate the IR validity, a working e2e Linalg example is added.

Differential Revision: https://reviews.llvm.org/D99430
2021-04-01 08:16:50 +00:00
natashaknk a879a1b034 [mlir][tosa] Add tosa.reciprocal and tosa.sigmoid lowerings
Lowering reciprocal and sigmoid elementwise operations to linalg dialect.

Reviewed By: rsuderman

Differential Revision: https://reviews.llvm.org/D99676
2021-03-31 14:21:03 -07:00
Andrew Young 9c61c76b12
[mlir][cse] do not replace operands in previously simplified operations
If an operation has been inserted as a key in to the known values
hashtable, then it can not be modified in a way which changes its hash.
This change avoids modifying the operands of any previously recorded
operation, which prevents their hash from changing.

In an SSACFG region, it is impossible to visit an operation before
visiting its operands, so this is not a problem. This situation can only
happen in regions without strict dominance, such as graph regions.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D99486
2021-03-31 12:20:34 -07:00
Suraj Sudhir 888c5067b4 Move non-spec TOSA operators into TosaUtilOps.td
Reviewed By: stellaraccident

Differential Revision: https://reviews.llvm.org/D99628
2021-03-31 11:01:01 -07:00
Matthias Springer 95f8135043 [mlir] Change vector.transfer_read/write "masked" attribute to "in_bounds".
This is in preparation for adding a new "mask" operand. The existing "masked" attribute was used to specify dimensions that may be out-of-bounds. Such transfers can be lowered to masked load/stores. The new "in_bounds" attribute is used to specify dimensions that are guaranteed to be within bounds. (Semantics is inverted.)

Differential Revision: https://reviews.llvm.org/D99639
2021-03-31 18:04:22 +09:00
Nicolas Vasilache 43b9fa3ce0 [mlir][Linalg][Python] Create the body of builtin named Linalg ops
This revision adds support to properly add the body of registered
builtin named linalg ops.
At this time, indexing_map and iterator_type support is still
missing so the op is not executable yet.

Differential Revision: https://reviews.llvm.org/D99578
2021-03-31 07:58:32 +00:00
Alexander Belyaev 465b9a4a33 Revert "Revert "[mlir] Introduce CloneOp and adapt test cases in BufferDeallocation.""
This reverts commit 883912abe6.
2021-03-31 09:49:09 +02:00
Stella Laurenzo 9a9214fa25 [mlir] Add C and python API for is_registered_operation.
* Suggested to be broken out of D99578

Differential Revision: https://reviews.llvm.org/D99638
2021-03-30 22:56:02 -07:00
Mehdi Amini a360a9786f Fix deletion of operations through the rewriter in a pattern matching a consumer operation
This allows for the conversion to match `A(B()) -> C()` with a pattern matching
`A` and marking `B` for deletion.

Also add better assertions when an operation is erased while still having uses.

Differential Revision: https://reviews.llvm.org/D99442
2021-03-30 22:02:14 +00:00
Eugene Zhulenev 6c9fbcf5b1 [mlir] Linalg: add tile interchange flag to test-linalg-codegen-strategy pass
Interchange options was missing in the pass flags.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D99397
2021-03-30 10:48:34 -07:00
Mehdi Amini 7a4d630764 Add a "register_runtime" method to the mlir.execution_engine and show calling back from MLIR into Python
This exposes the ability to register Python functions with the JIT and
exposes them to the MLIR jitted code. The provided test case illustrates
the mechanism.

Differential Revision: https://reviews.llvm.org/D99562
2021-03-30 17:04:38 +00:00
Inho Seo f584633454 Added static verification for Linalg Ops.
This verification is to check if the indices for static shaped operands
on linalgOps access out of bound memory or not. For dynamic shaped
operands, we would be able to check it on runtime stage.

Found several invalid Linalg ops testcases, and fixed them.

Reviewed By: hanchung

Differential Revision: https://reviews.llvm.org/D98390
2021-03-30 07:10:17 -07:00
MaheshRavishankar c4d5b95617 Fix broken build for commit 9b0517035f
Differential Revision: https://reviews.llvm.org/D99533
2021-03-29 12:48:45 -07:00
MaheshRavishankar 9b0517035f [mlir] Enhance InferShapedTypeOpInterface and move LinalgOps to use them.
A new `InterfaceMethod` is added to `InferShapedTypeOpInterface` that
allows an operation to return the `Value`s for each dim of its
results. It is intended for the case where the `Value` returned for
each dim is computed using the operands and operation attributes. This
interface method is for cases where the result dim of an operation can
be computed independently, and it avoids the need to aggregate all
dims of a result into a single shape value. This also implies that
this is not suitable for cases where the result type is unranked (for
which the existing interface methods is to be used).

Also added is a canonicalization pattern that uses this interface and
resolves the shapes of the output in terms of the shapes of the
inputs. Moving Linalg ops to use this interface, so that many
canonicalization patterns implemented for individual linalg ops to
achieve the same result can be removed in favor of the added
canonicalization pattern.

Differential Revision: https://reviews.llvm.org/D97887
2021-03-29 11:39:48 -07:00
Stella Laurenzo 4ca39dad52 NFC: Update MLIR python bindings docs to install deps via requirements.txt.
* Also adds some verbiage about upgrading `pip` itself, since this is a
  common source of issues.

Differential Revision: https://reviews.llvm.org/D99522
2021-03-29 18:32:51 +00:00
MaheshRavishankar f0a2fe7f79 [mlir][Linalg] Rewrite SubTensors that take a slice out of a unit-extend dimension.
Subtensor operations that are taking a slice out of a tensor that is
unit-extent along a dimension can be rewritten to drop that dimension.

Differential Revision: https://reviews.llvm.org/D99226
2021-03-29 09:19:36 -07:00
MaheshRavishankar 7d8b478ce1 [mlir][Linalg] Drop spurious error message
Drop usage of `emitRemark` and use `notifyMatchFailure` instead to
avoid unnecessary spew during compilation.

Differential Revision: https://reviews.llvm.org/D99485
2021-03-29 09:17:25 -07:00
thomasraoux 5288c25c70 [mlir][vector] Add lowering of Transfer_read with broadcast and permutation map
Convert transfer_read ops with permutation maps into simpler
transfer_read with minority map + vector.braodcast and vector.transpose.
And transfer_read with leading dimensions broacast into transfer_read of
lower rank.

Differential Revision: https://reviews.llvm.org/D99019
2021-03-29 08:38:43 -07:00
Nicolas Vasilache 2f367f34fd [mlir][Linalg] Allow calling named ops when available and make it the default.
Differential Revision: https://reviews.llvm.org/D99419
2021-03-29 13:23:11 +00:00
Frederik Gossen 630afc61a8 [MLIR][Shape] Canonicalize casted dynamic extent tensor
Differential Revision: https://reviews.llvm.org/D99161
2021-03-29 13:59:19 +02:00