[all-commits] [llvm/llvm-project] 6d9ce6: [mlir][bufferization] implement BufferizableOpInte...
Jeremy Kun via All-commits
all-commits at lists.llvm.org
Fri May 16 20:14:04 PDT 2025
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 6d9ce6767d259a5231ae312a19459f8fea3bd0ca
https://github.com/llvm/llvm-project/commit/6d9ce6767d259a5231ae312a19459f8fea3bd0ca
Author: Jeremy Kun <jkun at google.com>
Date: 2025-05-16 (Fri, 16 May 2025)
Changed paths:
M mlir/lib/Dialect/Tensor/IR/TensorDialect.cpp
M mlir/lib/Dialect/Tensor/Transforms/BufferizableOpInterfaceImpl.cpp
M mlir/test/Dialect/Tensor/bufferize.mlir
Log Message:
-----------
[mlir][bufferization] implement BufferizableOpInterface for concat op (#140171)
Lowers `tensor.concat` to an alloc with a series of `memref.copy` ops to
copy the operands to the alloc.
Example:
```mlir
func.func @tensor.concat(%f: tensor<8xf32>) -> tensor<16xf32> {
%t = tensor.concat dim(0) %f, %f : (tensor<8xf32>, tensor<8xf32>) -> tensor<16xf32>
return %t : tensor<16xf32>
}
```
Produces
```mlir
module {
func.func @tensor.concat(%arg0: tensor<8xf32>) -> tensor<16xf32> {
// initialization
%0 = bufferization.to_memref %arg0 : tensor<8xf32> to memref<8xf32>
%alloc = memref.alloc() {alignment = 64 : i64} : memref<8xf32>
memref.copy %0, %alloc : memref<8xf32> to memref<8xf32>
%alloc_0 = memref.alloc() {alignment = 64 : i64} : memref<8xf32>
memref.copy %0, %alloc_0 : memref<8xf32> to memref<8xf32>
%alloc_1 = memref.alloc() {alignment = 64 : i64} : memref<16xf32>
// one copy for each operand
%subview = memref.subview %alloc_1[0] [8] [1] : memref<16xf32> to memref<8xf32, strided<[1]>>
memref.copy %alloc, %subview : memref<8xf32> to memref<8xf32, strided<[1]>>
%subview_2 = memref.subview %alloc_1[8] [8] [1] : memref<16xf32> to memref<8xf32, strided<[1], offset: 8>>
memref.copy %alloc_0, %subview_2 : memref<8xf32> to memref<8xf32, strided<[1], offset: 8>>
%1 = bufferization.to_tensor %alloc_1 : memref<16xf32> to tensor<16xf32>
return %1 : tensor<16xf32>
}
}
```
This is my first time implementing BufferizableOpInterface, so I'm
looking for some advice on how I can:
1. Clean up my implementation.
2. Avoid duplicate `memref.copy` ops in the `// initialization` section
above when handling duplicate `tensor.concat` operands.
---------
Co-authored-by: Jeremy Kun <j2kun at users.noreply.github.com>
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list