Hey, one of the linalg::genericOp
canonicalizations patterns is EraseIdentityGenericOp
which is removing the linalg generic op if it meets the two conditions:
- all of the iterator types are parallel.
- the body has only one
linalg.yield
.
When running the linalg.generic canonicalization’s patterns on an Identity linalg.generic
which one of its output operand is a result of bufferization.alloc_tensor()
It’s still erasing my generic op. Although, the alloc_tensor() op indicates a new bufferization/materialized tensor.
would attach an example for my code
func.func @slice_kernel(%arg0: tensor<4x4x4x4xf32>) -> (tensor<1x4x4x4xf32>){
%extracted_slice = tensor.extract_slice %arg0[0, 0, 0, 0] [1, 4, 4, 4] [1, 1, 1, 1] : tensor<4x4x4x4xf32> to tensor<4x4x4xf32>
%0 = bufferization.alloc_tensor() : tensor<1x4x4x4xf32>
%1 = linalg.generic {indexing_maps = [affine_map<(d0,d1,d2,d3) -> (d0,d1,d2,d3)>, affine_map<(d0,d1,d2,d3) -> (d0,d1,d2,d3)>], iterator_types = ["parallel","parallel","parallel","parallel"]} ins(%extracted_slice : tensor<1x4x4x4xf32>) outs(%0 : tensor<1x4x4x4xf32>) {
^bb0(%in: f32, %out: f32):
linalg.yield %in : f32
} -> tensor<1x4x4x4xf32>
return %1 : tensor<1x4x4x4xf32>
}
I expect not removing this linalg.generic since it’s not a default/redundant
copy, shouldn’t the RewritePattern checks this case and fail in this case?
Thanks,