@@ -1168,16 +1168,17 @@ def Tensor_PadOp : Tensor_Op<"pad", [
11681168
11691169 * source: the "base" tensor on which to pad.
11701170 * low: A list contains the padding along the start of each
1171- dimension, i.e `low`.
1171+ dimension, i.e., how many padded values are prepended
1172+ to the beginning of the tensor in each dimension.
11721173 * high: A list contains the padding along the end of each
1173- dimension, i.e. `high`.
1174+ dimension, i.e., how many padded values are appended
1175+ to the end of the tensor in each dimension.
11741176 * nofold: indicates that the operation should not be folded when source and
11751177 result types are equal.
11761178
1177- The result tensor dimensions are `low` + `dim` + `high` along that
1178- dimension. The number of elements of `low` and `high` must match
1179- the rank of the input tensor. They can be either a constant or a
1180- dynamic value.
1179+ The result tensor dimensions are `low[i]` + `dim[i]` + `high[i]` for each
1180+ dimension `i`. The number of elements of `low` and `high` must match the
1181+ rank of the input tensor. They can be either a constant or a dynamic value.
11811182
11821183 The region of the `tensor.pad` operation returns the value to use
11831184 for the padding. The arguments of the region represent the index
@@ -1189,7 +1190,21 @@ def Tensor_PadOp : Tensor_Op<"pad", [
11891190 if the source type and the padded type have the same static shape. This can
11901191 be used, e.g., for packing or promotion to faster memory.
11911192
1192- Example 1:
1193+ Example 1: add 3 zeros to the beginning and 5 zeros to the end of a 1D
1194+ tensor.
1195+
1196+ ```mlir
1197+ %arg0 = ... : tensor<10xi32>
1198+ %c0_i32 = arith.constant 0 : i32
1199+ %padded = tensor.pad %arg0 low[3] high[5] {
1200+ ^bb0(%arg1: index):
1201+ tensor.yield %c0_i32 : i32
1202+ } : tensor<10xi32> to tensor<18xi32>
1203+ ```
1204+
1205+ Example 2: add 1 value to the beginning of dimension 0, 2 values to the end
1206+ of dimension 0, 2 values to the start of dimension 1, and 3 values to the
1207+ end of dimension 1.
11931208
11941209 ```mlir
11951210 %pad_value = ... : f32
@@ -1199,7 +1214,7 @@ def Tensor_PadOp : Tensor_Op<"pad", [
11991214 } : tensor<?x?xf32> to tensor<?x?xf32>
12001215 ```
12011216
1202- Example 2 :
1217+ Example 3 :
12031218
12041219 ```mlir
12051220 %pad_value = ... : f32
@@ -1209,7 +1224,7 @@ def Tensor_PadOp : Tensor_Op<"pad", [
12091224 } : tensor<1x2x2x?xf32> to tensor<6x?x?x?xf32>
12101225 ```
12111226
1212- Example 3 :
1227+ Example 4 :
12131228
12141229 ```mlir
12151230 %pad_value = ... : f32
@@ -1219,10 +1234,11 @@ def Tensor_PadOp : Tensor_Op<"pad", [
12191234 } : tensor<2x3xf32> to tensor<?x?xf32>
12201235 ```
12211236
1222- Example 4:
1237+ Example 5: Force a padded value to be always exist with `nofold`, even
1238+ though the padding config specifies that no new elements will be added to
1239+ the tensor.
12231240
12241241 ```mlir
1225- // Force a padded value to be always exist with `nofold`.
12261242 %pad_value = ... : f32
12271243 %0 = tensor.pad %arg0 nofold low[0, 0] high[0, 0] {
12281244 ^bb0(%arg1: index, %arg2: index):
0 commit comments