13 Commits

Author SHA1 Message Date
Javed Absar
7c4c274643
[MLIR][NFC] Fix some comments in padding transform. (#81741) 2024-02-14 17:00:42 +00:00
Matthias Springer
0a8e3dd432
[mlir][Interfaces] DestinationStyleOpInterface: Rename hasTensor/BufferSemantics (#77574)
Rename interface functions as follows:
* `hasTensorSemantics` -> `hasPureTensorSemantics`
* `hasBufferSemantics` -> `hasPureBufferSemantics`

These two functions return "true" if the op has tensor/buffer operands
but not buffer/tensor operands.

Also drop the "ranked" part from the interface, i.e., do not distinguish
between ranked/unranked types.

The new function names describe the functions more accurately. They also
align their semantics with the notion of "tensor semantics" with the
bufferization framework. (An op is supposed to be bufferized if it has
tensor operands, and we don't care if it also has memref operands.)

This change is in preparation of #75273, which adds
`BufferizableOpInterface::hasTensorSemantics`. By renaming the functions
in the `DestinationStyleOpInterface`, we can avoid name clashes between
the two interfaces.
2024-01-12 10:02:54 +01:00
Matthias Springer
0fcaca2fea
[mlir][bufferization] MaterializeInDestinationOp: Support memref destinations (#68074)
Extend `bufferization.materialize_in_destination` to support memref
destinations. This op can now be used to indicate that a tensor
computation should materialize in a given buffer (that may have been
allocated by another component/runtime). The op still participates in
"empty tensor elimination".

Example:
```mlir
func.func @test(%out: memref<10xf32>) {
  %t = tensor.empty() : tensor<10xf32>
  %c = linalg.generic ... outs(%t: tensor<10xf32>) -> tensor<10xf32>
  bufferization.materialize_in_destination %c in restrict writable %out : (tensor<10xf32>, memref<10xf32>) -> ()
  return
}
```
After "empty tensor elimination", the above IR can bufferize without an
allocation:
```mlir
func.func @test(%out: memref<10xf32>) {
  linalg.generic ... outs(%out: memref<10xf32>)
  return
}
```

This change also clarifies the meaning of the `restrict` unit attribute
on `bufferization.to_tensor` ops.
2023-10-06 11:57:10 +02:00
Matthias Springer
0b2197b0cf
[mlir][Interfaces] Clean up DestinationStyleOpInterface (#67015)
* "init" operands are specified with `MutableOperandRange` (which gives
access to the underlying `OpOperand *`). No more magic numbers.
* Remove most interface methods and make them helper functions. Only
`getInitsMutable` should be implemented.
* Provide separate helper functions for accessing mutable/immutable
operands (`OpOperand`/`Value`, in line with #66515): `getInitsMutable`
and `getInits` (same naming convention as auto-generated op accessors).
`getInputOperands` was not renamed because this function cannot return a
`MutableOperandRange` (because the operands are not necessarily
consecutive). `OpOperandVector` is no longer needed.
* The new `getDpsInits`/`getDpsInitsMutable` is more efficient than the
old `getDpsInitOperands` because no `SmallVector` is created. The new
functions return a range of operands.
* Fix a bug in `getDpsInputOperands`: out-of-bounds operands were
potentially returned.
2023-09-21 18:04:08 +02:00
Matthias Springer
91464e1d6a
[mlir][bufferization][NFC] Rename copy_tensor op to materialize_in_destination (#65467)
The previous name was badly chosen. The op is used to ensure that a
computation materializes in the future buffer of a certain tensor.
2023-09-12 15:20:41 +02:00
Matthias Springer
977cb4fdf8 [mlir][linalg][transform] PadOp: Add option to generate linalg.copy copy_back op
Three different options can be specified:
* `bufferization.copy_tensor` (default)
* `linalg.copy`
* `none` (no copy_back)

Differential Revision: https://reviews.llvm.org/D156173
2023-08-09 17:10:16 +02:00
Robert Suderman
a5cee3e386 [mlir][linalg] Add a padding case for ComplexType
If the paddingAttr is an ArrayAttr with two values we know that
the element type is a `ComplexType` and we should pad the value
accordingly.

Reviewed By: mravishankar

Differential Revision: https://reviews.llvm.org/D154908
2023-07-17 17:20:38 -07:00
Nicolas Vasilache
1e84e91efa [mlir][Linalg] NFC - Improve some transform op builders 2023-07-11 15:35:43 +02:00
Lorenzo Chelini
2049b2adfe [MLIR] Fix compiler warnings (NFC)
In `TestTensorTransforms.cpp` `replaced` is nullptr I assumed the intent
was to emit the error for the `rootOp`.

In `TransformInterfaces.cpp` there were some uninitialized variables.

In `NVGPUTransformOps.cpp` `matmulOp` was never used.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D154439
2023-07-05 09:49:57 +02:00
Matthias Springer
0e06ec5961 [mlir][linalg] Return tensor::PadOp handle from transform op
"transform.structured.pad" now returns all `tensor::PadOp` in addition to the padded ops.

Also add a test case that shows how to force an allocation for "tensor.pad" ops with a custom memory space.

Differential Revision: https://reviews.llvm.org/D153555
2023-07-04 14:24:47 +02:00
Matthias Springer
431c49d6b6 [mlir][linalg] Padding transformation: Write back result to original destination
Copy back the padded result to the original destination of the computation. This is important for bufferization, to ensure that the result of the computation does not suddenly materialize in a different buffer due to padding.

A `bufferization.copy_tensor` is inserted for every (unpadded) result. Such ops bufferize to memcpys, but they fold away, should the padding fold away.

Differential Revision: https://reviews.llvm.org/D153554
2023-06-27 14:58:51 +02:00
Matthias Springer
369c5d6ad6 [mlir][linalg][NFC] Cleanup padding transform
* Use LinalgPaddingOptions instead of passing many parameters.
* Split function into two parts.

Differential Revision: https://reviews.llvm.org/D153853
2023-06-27 14:52:41 +02:00
Matthias Springer
02c662077c [mlir][linalg][NFC] Move padding transformation to separate file
Also remove `LinalgPaddingPattern`, which has no uses. (There is a transform dialect op that is used for testing instead.)

Differential Revision: https://reviews.llvm.org/D153512
2023-06-27 14:45:03 +02:00