As described in issue llvm/llvm-project#91518, a previous PR llvm/llvm-project#78484 introduced the `defaultMemorySpaceFn` into bufferization options, allowing one to inform OneShotBufferize that it should use a specified function to derive the memory space attribute from the encoding attribute attached to tensor types. However, introducing this feature exposed unhandled edge cases, examples of which are introduced by this change in the new test under `test/Dialect/Bufferization/Transforms/one-shot-bufferize-encodings.mlir`. Fixing the inconsistencies introduced by `defaultMemorySpaceFn` is pretty simple. This change: - Updates the `bufferization.to_memref` and `bufferization.to_tensor` operations to explicitly include operand and destination types, whereas previously they relied on type inference to deduce the tensor types. Since the type inference cannot recover the correct tensor encoding/memory space, the operand and result types must be explicitly included. This is a small assembly format change, but it touches a large number of test files. - Makes minor updates to other bufferization functions to handle the changes in building the above ops. - Updates bufferization of `tensor.from_elements` to handle memory space. Integration/upgrade guide: In downstream projects, if you have tests or MLIR files that explicitly use `bufferization.to_tensor` or `bufferization.to_memref`, then update them to the new assembly format as follows: ``` %1 = bufferization.to_memref %0 : memref<10xf32> %2 = bufferization.to_tensor %1 : memref<10xf32> ``` becomes ``` %1 = bufferization.to_memref %0 : tensor<10xf32> to memref<10xf32> %2 = bufferization.to_tensor %0 : memref<10xf32> to tensor<10xf32> ```
50 lines
1.8 KiB
MLIR
50 lines
1.8 KiB
MLIR
// RUN: mlir-opt -verify-diagnostics -ownership-based-buffer-deallocation \
|
|
// RUN: --buffer-deallocation-simplification -canonicalize -split-input-file %s | FileCheck %s
|
|
|
|
// No ownership is assumed for ops that do not implement any interface and have
|
|
// no memref operands.
|
|
|
|
// CHECK-LABEL: func private @no_interface_no_operands(
|
|
// CHECK-NEXT: %[[m:.*]] = bufferization.to_memref
|
|
// CHECK-NEXT: %[[clone:.*]] = bufferization.clone %[[m]]
|
|
// CHECK-NEXT: return %[[clone]]
|
|
func.func private @no_interface_no_operands(%t : tensor<?x?x?xf16>) -> memref<?x?x?xf16> {
|
|
%0 = bufferization.to_memref %t : tensor<?x?x?xf16> to memref<?x?x?xf16>
|
|
return %0 : memref<?x?x?xf16>
|
|
}
|
|
|
|
// -----
|
|
|
|
// If an op does not implement any interface but has memref operands, the
|
|
// ownership of the memref results is computed from the operands.
|
|
|
|
// CHECK-LABEL: func private @no_interface(
|
|
// CHECK: %[[true:.*]] = arith.constant true
|
|
// CHECK: %[[alloc:.*]] = memref.alloc
|
|
// CHECK: %[[foo:.*]] = "test.forward_buffer"(%[[alloc]])
|
|
// CHECK: %[[r:.*]] = bufferization.dealloc (%[[alloc]] : {{.*}}) if (%[[true]]) retain (%[[foo]] : {{.*}})
|
|
// CHECK: return %[[foo]]
|
|
func.func private @no_interface() -> memref<5xf32> {
|
|
%0 = memref.alloc() : memref<5xf32>
|
|
%1 = "test.forward_buffer"(%0) : (memref<5xf32>) -> (memref<5xf32>)
|
|
return %1 : memref<5xf32>
|
|
}
|
|
|
|
// -----
|
|
|
|
func.func @no_side_effects() {
|
|
%0 = memref.alloc() : memref<5xf32>
|
|
// expected-error @below{{ops with unknown memory side effects are not supported}}
|
|
"test.unregistered_op_foo"(%0) : (memref<5xf32>) -> ()
|
|
return
|
|
}
|
|
|
|
// -----
|
|
|
|
// Buffer deallocation should not emit any error here as the operation does not
|
|
// operate on buffers and has known memory effect (write).
|
|
func.func @no_buffer_semantics_with_write_effect(%v0: vector<9x6xf32>) {
|
|
vector.print %v0 : vector<9x6xf32>
|
|
return
|
|
}
|