[Mlir-commits] [mlir] [mlir][vector] Relax the requirements on broadcast dims (PR #99341)
Andrzej WarzyĆski
llvmlistbot at llvm.org
Tue Jul 23 12:13:02 PDT 2024
banach-space wrote:
> Could you please elaborate on this? I'm not sure I follow
I "spoke" too soon :)
Looking at this example (output from a vectorizer test), we can infer that all broadcast dims are "in bounds" as all other dims **are in bounds**:
```mlir
#map = affine_map<(d0, d1) -> (d0, 0, 0, d1)>
#map1 = affine_map<(d0) -> (d0, 0, 0, 0)>
#map2 = affine_map<(d0) -> (0, 0, d0, 0)>
#map3 = affine_map<(d0, d1) -> (d1, 0, d0, 0)>
module {
func.func @generic_vectorize_broadcast_transpose(%arg0: memref<4xf32>, %arg1: memref<4x4xf32>, %arg2: memref<4x4x4x4xf32>) {
%c0 = arith.constant 0 : index
%cst = arith.constant 0.000000e+00 : f32
%0 = vector.transfer_read %arg1[%c0, %c0], %cst {in_bounds = [true, false, false, true], permutation_map = #map} : memref<4x4xf32>, vector<4x4x4x4xf32>
%1 = vector.transfer_read %arg0[%c0], %cst {in_bounds = [true, false, false, false], permutation_map = #map1} : memref<4xf32>, vector<4x4x4x4xf32>
%2 = vector.transfer_read %arg0[%c0], %cst {in_bounds = [false, false, true, false], permutation_map = #map2} : memref<4xf32>, vector<4x4x4x4xf32>
%3 = vector.transfer_read %arg1[%c0, %c0], %cst {in_bounds = [true, false, true, false], permutation_map = #map3} : memref<4x4xf32>, vector<4x4x4x4xf32>
%4 = arith.subf %0, %1 : vector<4x4x4x4xf32>
%5 = arith.addf %2, %4 : vector<4x4x4x4xf32>
%6 = arith.addf %3, %5 : vector<4x4x4x4xf32>
vector.transfer_write %6, %arg2[%c0, %c0, %c0, %c0] {in_bounds = [true, true, true, true]} : vector<4x4x4x4xf32>, memref<4x4x4x4xf32>
return
}
```
In cases where non-broadcast dims are not "in bounds", I think that we should conservatively stick to "out of bounds". I will be sending an update for `foldTransferInBoundsAttribute` shortly.
https://github.com/llvm/llvm-project/pull/99341
More information about the Mlir-commits
mailing list