Commit Graph

414 Commits

Author SHA1 Message Date
Aliia Khasanova
ef545ef62a [mlir][linalg] Reuploading: Apply shortened printing/parsing form to linalg.reduce.
Differential Revision: https://reviews.llvm.org/D141259
2023-01-09 13:32:29 +01:00
Matthias Springer
bcfd32adc4 [mlir][linalg] Swap extract_slice(fill(x)) ops
This pattern is similar to `FoldFillWithTensorReshape`, which performs the same swapping with reshapes.

Fill the smaller extracted tensor slice instead of `x`. This allows for additional simplifications in case `x` is the result of another extract_slice.

Differential Revision: https://reviews.llvm.org/D141117
2023-01-06 12:28:29 +01:00
Stella Stamenova
5759d9467c Revert "Apply shortened printing/parsing form to linalg.reduce."
This reverts commit 281c2d49c9.

This broke the windows mlir buildbot:
https://lab.llvm.org/buildbot/#/builders/13/builds/30167
2022-12-23 17:31:08 -08:00
Aliia Khasanova
281c2d49c9 Apply shortened printing/parsing form to linalg.reduce.
Differential Revision: https://reviews.llvm.org/D140622
2022-12-23 14:40:19 +01:00
Aliia Khasanova
aee2c23066 [mlir][linalg] Reuploading: add a shortened printing/parsing form for linalg.map and linalg.reduce.
Differential Revision: https://reviews.llvm.org/D140535
2022-12-22 16:03:35 +01:00
Ramkumar Ramachandra
9c58d10c7d mlir/LinalgOps: fix name of generated .yamlgen in comments
Signed-off-by: Ramkumar Ramachandra <r@artagnon.com>

Differential Revision: https://reviews.llvm.org/D139946
2022-12-21 18:43:03 +01:00
Mitch Phillips
c0b775a5b5 Revert "BEGIN_PUBLIC"
This reverts commit a6d6d40d8b.

Reason: Broke the ASan/MSan bots. More information in phabricator:
https://reviews.llvm.org/D140406
2022-12-21 09:32:54 -08:00
Aliia Khasanova
a6d6d40d8b BEGIN_PUBLIC
Add a shortened printing/parsing form for linalg.map and linalg.reduce.
END_PUBLIC

Differential Revision: https://reviews.llvm.org/D140406
2022-12-21 14:39:30 +01:00
Alexander Belyaev
11175b5507 [mlir][linalg] Print broadcast, map, reduce, transpose ins/outs on one line.
Differential Revision: https://reviews.llvm.org/D139650
2022-12-08 19:16:36 +01:00
Hanhan Wang
193cefd1b1 [mlir][tensor] Adapt FoldTensorCastProducerOp pattern on DPS interface.
This revision adapts the pattern in LinAlg to work on DPS interface, and
adds it to canonicalization patterns of tensor dialect. The
InsertSliceOp is skipped in the pattern because it has its own logic
about folding tensor.cast ops.

Reviewed By: pifon2a

Differential Revision: https://reviews.llvm.org/D139375
2022-12-06 12:13:37 -08:00
Hanhan Wang
b1d3afc93e [mlir] Factor more common utils to IndexingUtils
Reviewed By: mravishankar

Differential Revision: https://reviews.llvm.org/D139159
2022-12-02 13:27:01 -08:00
Alexander Belyaev
f286af29d8 [mlir] Remove clone methods from DPS interface.
Differential Revision: https://reviews.llvm.org/D138586
2022-11-23 19:25:26 +01:00
Oleg Shyshkov
3598c24983 [mlir][linalg] Change linalg.broadcast dimensions attribute to represent added dimensions.
Original [RFC](discourse.llvm.org/t/rfc-primitive-ops-add-broadcastop-to-linalg/66313) defined `dimensions` as a map from input to init, but a discussion in reviews.llvm.org/D138291 concluded that it's more natural for `dimensions` to represent added dims. Also this way is more consistent with `linalg.reduce`.

Differential Revision: https://reviews.llvm.org/D138408
2022-11-21 13:16:41 +01:00
Oleg Shyshkov
244105f791 [mlir][linalg] Do not check if added dimension are static in linalg.broadcast.
Added dimensions can be both static and dinamic. Mapped dimension should be the same in the input and the init.

Differential Revision: https://reviews.llvm.org/D138291
2022-11-18 15:51:13 +01:00
Ivan Butygin
06e972ed91 [mlir][linalg] Fix FoldTensorCastProducerOp for generic with memref output
Type should only be added to results if it is tensor.

Differential Revision: https://reviews.llvm.org/D137801
2022-11-16 22:59:54 +01:00
Mahesh Ravishankar
da8a8e9280 [mlir][Linalg] Move patterns to remove dead arguments and results out of canonicalization.
The patterns to remove dead arguments and results of `linalg.generic`
operations are not necessarily canonicalizations. Instead a new entry
point `populateEraseUnusedOperandsAndResults` is added to allow using
these patterns when needed. The transformations that rely on this
pattern for cleanup now include these patterns explicitly.

Differential Revision: https://reviews.llvm.org/D138085
2022-11-16 16:00:43 +00:00
Vladislav Vinogradov
2ada5cbea4 [mlir][linalg] Fix bug in InferStaticShapeOfOperands pattern
The pattern tries to deduce static shape from `tensor.cast` producer of linalg operation operands.
The original code unconditionally casts type of the `tensor.cast` source to `RankedTensorType`.
But the `tensor.cast` can also operate on `UnrankedTensorType`, so this cast either fail on assertion
in debug build or introduce UB in release build.

The patch replaces unconditional cast with `dyn_cast` and check for the cast result.

Reviewed By: mravishankar

Differential Revision: https://reviews.llvm.org/D137775
2022-11-16 12:19:16 +03:00
Mahesh Ravishankar
cb40d5291e [mlir][Linalg] Avoid using tensor.cast by default while folding fill with pad.
This is unnecessary if the generated operation type already matches
the type of the replaced value.  Also use `OpFoldResult` to reduce the
number of cases the casts are needed.

Reviewed By: springerm, hanchung, antiagainst

Differential Revision: https://reviews.llvm.org/D137479
2022-11-11 23:17:07 +00:00
Oleg Shyshkov
e6598b053d Revert "Revert "[mlir][linalg] Replace "string" iterator_types attr with enums in LinalgInterface.""
With python code fixed.

This reverts commit 41280908e4.
2022-11-11 10:54:08 +01:00
Prashant Kumar
04b449e147 The fillOp's value needs to casted
During elementwise fusion the fillOp's value was directly
referred without casting which can create mismatching dtypes.

Reviewed By: mravishankar, ThomasRaoux

Differential Revision: https://reviews.llvm.org/D137447
2022-11-10 03:43:22 +00:00
Oleg Shyshkov
41280908e4 Revert "[mlir][linalg] Replace "string" iterator_types attr with enums in LinalgInterface."
Breaks linalg python tests. Would need to also update python/mlir/dialects/linalg/opdsl.

This reverts commit b809d73973.
2022-11-09 15:59:54 +01:00
Oleg Shyshkov
b809d73973 [mlir][linalg] Replace "string" iterator_types attr with enums in LinalgInterface.
[RFC: EnumAttr for iterator types in Linalg](https://discourse.llvm.org/t/rfc-enumattr-for-iterator-types-in-linalg/64535)

This affect touches and probably breaks most of the code that creates `linalg.generic`. A fix would be to replace calls to `getParallelIteratorTypeName/getReductionIteratorTypeName` with `mlir::utils::IteratorType::parallel/reduction` and types from `StringRef` to `mlir::utils::IteratorType`.

Due to limitations of tablegen, shared C++ definition of IteratorType enum lives in StructuredOpsUtils.td, but each dialect should have it's own EnumAttr wrapper. To avoid conflict, all enums in a dialect are put into a separate file with a separate tablegen rule.

Test dialect td files are refactored a bit.

Printed format of `linalg.generic` temporarily remains unchanged to avoid breaking code and tests in the same change.

Differential Revision: https://reviews.llvm.org/D137658
2022-11-09 15:47:29 +01:00
Mehdi Amini
93cb2b0933 Apply clang-tidy fixes for performance-unnecessary-value-param in LinalgOps.cpp (NFC) 2022-11-07 21:22:56 +00:00
Kazu Hirata
a8d93783f3 [mlir] Fix a warning
This patch fixes:

  llvm-project/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp:1855:17:
  error: comparison of integers of different signs: 'int64_t' (aka
  'long') and 'size_t' (aka 'unsigned long') [-Werror,-Wsign-compare]
2022-11-06 00:52:42 -07:00
Oleg Shyshkov
fd64de3212 [mlir][linalg] Add BroadcastOp to Linalg structured ops.
[[RFC] Primitive Ops: add BroadcastOp to Linalg](https://discourse.llvm.org/t/rfc-primitive-ops-add-broadcastop-to-linalg/66313?u=olegshyshkov)

Differential Revision: https://reviews.llvm.org/D137331
2022-11-04 12:07:18 +01:00
Matthias Springer
534638eae3 [mlir][linalg] Fix crash in canonicalization pattern
This crash was due to incorrect usage of `hasTensorSemantics`, which has changed recently with DestinationStyleOpInterface. An op has tensor semantics if all of its inits and inputs are tensors. Previously, only inits needed to be tensors.

Differential Revision: https://reviews.llvm.org/D137243
2022-11-02 14:05:48 +01:00
Benjamin Kramer
2a37ec927e [mlir][linalg] Add missing region when building TransposeOp
This fixes a regression from ad89eb5b1f
2022-10-28 21:17:42 +02:00
Alexander Belyaev
b4db15a949 [mlir] Rename getInputs->getDpsInputs and getOutputs->getDpsInits in DPS interface.
https://discourse.llvm.org/t/rfc-interface-for-destination-style-ops/64056

Differential Revision: https://reviews.llvm.org/D136943
2022-10-28 15:41:12 +02:00
Oleg Shyshkov
ad89eb5b1f Revert "Revert "[mlir][linalg] Add nicer builders for map and reduce.""
This reverts commit 7eef3ea5f4.
2022-10-28 11:31:58 +02:00
Oleg Shyshkov
acdd576d05 [mlir][linalg] Fix linalg.transpose region builder.
The region should yield the first argument (input) not the last argument
(output). Also fix a few tests that were affected by this bug.

Differential Revision: https://reviews.llvm.org/D136924
2022-10-28 11:19:02 +02:00
Oleg Shyshkov
7eef3ea5f4 Revert "[mlir][linalg] Add nicer builders for map and reduce."
This reverts commit aebde28047.
2022-10-28 09:56:59 +02:00
Oleg Shyshkov
aebde28047 [mlir][linalg] Add nicer builders for map and reduce.
The new builders get a list of additional attrs, a lambda to build the region
body and infer return types from `init`.

Differential Revision: https://reviews.llvm.org/D136838
2022-10-28 08:51:09 +02:00
Alexander Belyaev
30ceb749c5 [mlir] Fix printing when linalg.map has no inputs.
Differential Revision: https://reviews.llvm.org/D136836
2022-10-27 13:55:16 +02:00
Alexander Belyaev
350d686444 [mlir] Print bbArgs of linalg.map/reduce/tranpose on the next line.
```
%mapped = linalg.map
  ins(%arg0 : tensor<64xf32>)
  outs(%arg1 : tensor<64xf32>)
  (%in: f32) {
    %0 = math.absf %in : f32
    linalg.yield %0 : f32
  }
%reduced = linalg.reduce
  ins(%arg0 : tensor<16x32x64xf32>)
  outs(%arg1 : tensor<16x64xf32>)
  dimensions = [1]
  (%in: f32, %init: f32) {
    %0 = arith.addf %in, %init : f32
    linalg.yield %0 : f32
  }
%transposed = linalg.transpose
  ins(%arg0 : tensor<16x32x64xf32>)
  outs(%arg1 : tensor<32x64x16xf32>)
  permutation = [1, 2, 0]
```

Differential Revision: https://reviews.llvm.org/D136818
2022-10-27 10:19:04 +02:00
Hanhan Wang
00767cb452 [mlir] Delete dup code and use unified methods.
The foldMemRefCast method is defined in memref namespace; the
foldTensorCast method is defined in tensor namespace. This revision
deletes the dup code and use the unified methods.

Reviewed By: dcaballe

Differential Revision: https://reviews.llvm.org/D136379
2022-10-21 16:51:44 -07:00
Oleg Shyshkov
d261aa88f8 [mlir] Add TransposeOp to Linalg structured ops.
RFC: https://discourse.llvm.org/t/rfc-primitive-ops-add-mapop-reductionop-transposeop-broadcastop-to-linalg/64184

Differential Revision: https://reviews.llvm.org/D135854
2022-10-19 12:27:52 +02:00
Ivan Butygin
04ac8cb8e1 [mlir][linalg] Fix canonicalizer crash for linalg.generic with mixed semantics
`EraseIdentityGenericOp` for `!hasBufferSemantics()` assumed fully tensor semantics and tried to access non-existent return values.

Differential Revision: https://reviews.llvm.org/D135725
2022-10-17 15:20:42 +02:00
Alexander Belyaev
a7cccb9cbb [mlir] Simplify DestinationStyleOpInterface.
Differential Revision: https://reviews.llvm.org/D135348
2022-10-17 12:43:41 +02:00
Oleg Shyshkov
c38d9cf20e [mlir] Remove iterator_types() method from LinalgStructuredInterface.
`getIteratorTypesArray` should be used instead. It's a better substitute for all the current usages of the interface.

The current `ArrayAttr iterator_types()` has a few problems:
* It creates an assumption operation has iterators types as an attribute, but it's not always the case. Sometime iterator types can be inferred from other attribute, or they're just static.
* ArrayAttr is an obscure contained and required extracting values in the client code.
* Makes it hard to migrate iterator types from strings to enums ([RFC](https://discourse.llvm.org/t/rfc-enumattr-for-iterator-types-in-linalg/64535/9)).

Concrete ops, like `linalg.generic` will still have iterator types as an attribute if needed.

As a side effect, this change helps a bit with migration to prefixed accessors.

Differential Revision: https://reviews.llvm.org/D135765
2022-10-13 07:52:43 +00:00
Adrian Kuegel
95630b93b0 [mlir][Linalg] Add MapOp to Linalg structured ops.
This will allow to model elementwise ops with this special op instead of using
GenericOp.
Also allow MapOp and ReduceOp to have no result if the output type is not a tensor.
This is needed for buffer semantics.

Differential Revision: https://reviews.llvm.org/D135754
2022-10-12 13:56:21 +02:00
Stanley Winata
fa58926d7c [mlir][linalg] Remove redundant check on linalgOps to fix windows builder
One of the assertion is causing signed/unsigned mismatch. However this
assertion seems redundant and is no longer used.

Reviewed By: mravishankar, ThomasRaoux

Differential Revision: https://reviews.llvm.org/D135612
2022-10-10 13:19:18 -07:00
Kazu Hirata
d208baee65 [mlir] Fix a warning
This patch fixes:

  mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp:1051:40: error: comparison
  of integers of different signs: 'int64_t' (aka 'long') and
  'std::size_t' (aka 'unsigned long') [-Werror,-Wsign-compare]
2022-10-10 12:57:25 -07:00
Stanley Winata
ac0fe5dd14 [mlir][linalg] Remove unused payload related OutOpOperand
Some higher level operations such as torch.max generates linalg generic
that returns both the index and the value of the max operation. However
sometimes not all information is being used. This however blocks
vectorization for certain cases which causes performance degradation.
This patch aims to fix this issue.

Reviewed By: mravishankar

Differential Revision: https://reviews.llvm.org/D135388
2022-10-10 11:45:46 -07:00
Adrian Kuegel
2ae27dc948 [mlir][Linalg] Use ConfinedAttr for dimensions of ReduceOp.
We can use the new DenseArrayStrictlySorted constraint.

Differential Revision: https://reviews.llvm.org/D135246
2022-10-10 09:37:59 +02:00
Nicolas Vasilache
5fc28ebbaf [mlir][Linalg] NFC - Add bbarg pretty printing to linalg::generic
Differential Revision: https://reviews.llvm.org/D135151
2022-10-05 00:59:42 -07:00
Nicolas Vasilache
e3f439ea20 [mlir][Linalg] NFC - Add result and bbArg pretty printing to linalg.reduce
Differential Revision: https://reviews.llvm.org/D135152
2022-10-04 09:27:18 -07:00
Matthias Springer
81ca5aa452 [mlir][tensor][NFC] Rename linalg.init_tensor to tensor.empty
tensor.empty/linalg.init_tensor produces an uninititalized tensor that can be used as a destination operand for destination-style ops (ops that implement `DestinationStyleOpInterface`).

This change makes it possible to implement `TilingInterface` for non-destination-style ops without depending on the Linalg dialect.

RFC: https://discourse.llvm.org/t/rfc-add-tensor-from-shape-operation/65101

Differential Revision: https://reviews.llvm.org/D135129
2022-10-04 17:25:35 +09:00
Kazu Hirata
e898be2f6e [mlir] Fix warnings
This patch fixes:

  mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp:1348:31: error: comparison
  of integers of different signs: 'size_t' (aka 'unsigned long') and
  'int64_t' (aka 'long') [-Werror,-Wsign-compare]

  mlir/lib/ExecutionEngine/SparseTensor/File.cpp:110:3: error: default
  label in switch which covers all enumeration values
  [-Werror,-Wcovered-switch-default]
2022-09-30 15:00:56 -07:00
Oleg Shyshkov
1227b8ab54 [mlir] Rename getTied* methods to getMatching* in LinalgInterface.
Summary:
As mentioned in the comment to https://reviews.llvm.org/D134444, the term `tied`
is a misnomer in this context and `matching` sounds much better.

Differential Revision: https://reviews.llvm.org/D134534
2022-09-30 10:05:45 +00:00
Adrian Kuegel
fa79dff8bc [mlir][Linalg] Reland Add ReduceOp to Linalg structured ops.
This op will allow to model (variadic) reductions with this special op
instead of using GenericOp.

This reverts commit 535fd753ef.
Additional fix: implement a getLibraryName method.
2022-09-30 08:42:34 +02:00