[Mlir-commits] [mlir] [mlir][vector] Determine vector sizes from the result shape for tensor.pad operation (PR #97248)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu Jul 4 00:09:43 PDT 2024


================
@@ -1055,3 +1055,35 @@ func.func @test_vectorize_unpack_no_vector_sizes_permute(%source: tensor<4x7x4xf
     transform.yield
   } 
  }
+
+   // -----
+
+// CHECK-LABEL: test_vectorize_pad_no_vector_sizes
+func.func @test_vectorize_pad_no_vector_sizes(%arg0: tensor<63x63xf32>) -> tensor<64x64xf32> {
+  %f0 = arith.constant 0.0 : f32
+  %pad = tensor.pad %arg0 low[0, 0] high[1, 1] {
+  ^bb0(%arg1: index, %arg2: index):
+    tensor.yield %f0 : f32
+  } : tensor<63x63xf32> to tensor<64x64xf32>
+  return %pad : tensor<64x64xf32>
+}
+//  CHECK-DAG: %[[cst:.*]] = arith.constant 0.000000e+00 : f32
+//  CHECK-DAG: %[[c0:.*]] = arith.constant 0 : index
+//  CHECK-DAG: %[[c63:.*]] = arith.constant 63 : index
+//  CHECK-DAG: %[[c63_0:.*]] = arith.constant 63 : index
+//  CHECK: %[[mask:.*]] = vector.create_mask %[[c63]], %[[c63_0]] : vector<64x64xi1>
+//  CHECK: %[[read:.*]] = vector.mask %0 { vector.transfer_read {{.*}}, %cst {in_bounds = [true, true]}
----------------
BRUCE11111 wrote:

Hi~ Thanks for the advice~. In order to get better code implementation, I have a question here.
 First I don't see any essential difference between inferring the vectorize size from the result shape and setting the vectorize size directly. They both provide vector size finally. 
Second, I try to figure out why we prefer to use `in_bounds` other than `mask`, I may find some reasons here. 
For `transfer_read` or `transfer_write` operations, when we lower them to llvm ([code link](https://github.com/llvm/llvm-project/blob/843117050d63db6de983d4840ab3786f91c118b3/mlir/lib/Dialect/Vector/Transforms/LowerVectorTransfer.cpp#L448)), we can find that we can't support mask operation perfectly now. Sometimes we need a lowering pattern can lowering `mask read` to just `read` like [code](https://github.com/llvm/llvm-project/blob/c67653fbc3dd4ea9ab2a32c481a9ac4411020c7b/mlir/lib/Dialect/Vector/Transforms/LowerVectorMask.cpp#L224).
But when the input vector sizes are provided why we can use mask operation?
A more precise question is, under what conditions can we safely use mask to mask operation when writing code?
Thanks~

https://github.com/llvm/llvm-project/pull/97248


More information about the Mlir-commits mailing list