Skip to content

Commit 7968802

Browse files
committed
[mlir] Make tensor_to_memref op docs match reality
The previous code defined it as allocating a new memref for its result. However, this is not how it is treated by the dialect conversion framework, that does the equivalent of inserting and folding it away internally (even independent of any canonicalization patterns that we have defined). The semantics as they were previously written were also very constraining: Nontrivial analysis is needed to prove that the new allocation isn't needed for correctness (e.g. to avoid aliasing). By removing those semantics, we avoid losing that information. Differential Revision: https://reviews.llvm.org/D91382
1 parent faa66b1 commit 7968802

File tree

1 file changed

+10
-6
lines changed
  • mlir/include/mlir/Dialect/StandardOps/IR

1 file changed

+10
-6
lines changed

mlir/include/mlir/Dialect/StandardOps/IR/Ops.td

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3737,28 +3737,32 @@ def TensorToMemrefOp : Std_Op<"tensor_to_memref",
37373737
"getTensorTypeFromMemRefType($_self)">]> {
37383738
let summary = "tensor to memref operation";
37393739
let description = [{
3740-
Create a memref from a tensor. This is equivalent to allocating a new
3741-
memref of the appropriate (possibly dynamic) shape, and then copying the
3742-
elements (as if by a tensor_store op) into the newly allocated memref.
3740+
Create a memref from a tensor. This is a transient op created as a
3741+
materialization during type conversions between tensors and memrefs.
37433742

37443743
The opposite of this op is tensor_load. Together, these two ops are useful
37453744
for source/target materializations when doing type conversions involving
37463745
tensors and memrefs.
37473746

3747+
This op is defined by the fold
3748+
`tensor_to_memref(tensor_load(%memref)) -> %memref`, which is the property
3749+
that makes it a valid materialization in the type conversion framework.
3750+
This implies that one cannot assume that this op allocates a new memref for
3751+
its result.
3752+
37483753
Note: This op takes the memref type in its pretty form because the tensor
37493754
type can always be inferred from the memref type, but the reverse is not
37503755
true. For example, the memref might have a layout map or memory space which
37513756
cannot be inferred from the tensor type.
37523757

37533758
```mlir
37543759
// Result type is tensor<4x?xf32>
3755-
%12 = tensor_to_memref %10 : memref<4x?xf32, #map0, 42>
3760+
%12 = tensor_to_memref %10 : memref<4x?xf32, #map0, 42>
37563761
```
37573762
}];
37583763

37593764
let arguments = (ins AnyTensor:$tensor);
3760-
let results = (outs Res<AnyRankedOrUnrankedMemRef,
3761-
"the memref to create", [MemAlloc]>:$memref);
3765+
let results = (outs AnyRankedOrUnrankedMemRef:$memref);
37623766
// This op is fully verified by traits.
37633767
let verifier = ?;
37643768

0 commit comments

Comments
 (0)