@@ -1168,16 +1168,17 @@ def Tensor_PadOp : Tensor_Op<"pad", [
1168
1168
1169
1169
* source: the "base" tensor on which to pad.
1170
1170
* 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.
1172
1173
* 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.
1174
1176
* nofold: indicates that the operation should not be folded when source and
1175
1177
result types are equal.
1176
1178
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.
1181
1182
1182
1183
The region of the `tensor.pad` operation returns the value to use
1183
1184
for the padding. The arguments of the region represent the index
@@ -1189,7 +1190,21 @@ def Tensor_PadOp : Tensor_Op<"pad", [
1189
1190
if the source type and the padded type have the same static shape. This can
1190
1191
be used, e.g., for packing or promotion to faster memory.
1191
1192
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.
1193
1208
1194
1209
```mlir
1195
1210
%pad_value = ... : f32
@@ -1199,7 +1214,7 @@ def Tensor_PadOp : Tensor_Op<"pad", [
1199
1214
} : tensor<?x?xf32> to tensor<?x?xf32>
1200
1215
```
1201
1216
1202
- Example 2 :
1217
+ Example 3 :
1203
1218
1204
1219
```mlir
1205
1220
%pad_value = ... : f32
@@ -1209,7 +1224,7 @@ def Tensor_PadOp : Tensor_Op<"pad", [
1209
1224
} : tensor<1x2x2x?xf32> to tensor<6x?x?x?xf32>
1210
1225
```
1211
1226
1212
- Example 3 :
1227
+ Example 4 :
1213
1228
1214
1229
```mlir
1215
1230
%pad_value = ... : f32
@@ -1219,10 +1234,11 @@ def Tensor_PadOp : Tensor_Op<"pad", [
1219
1234
} : tensor<2x3xf32> to tensor<?x?xf32>
1220
1235
```
1221
1236
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.
1223
1240
1224
1241
```mlir
1225
- // Force a padded value to be always exist with `nofold`.
1226
1242
%pad_value = ... : f32
1227
1243
%0 = tensor.pad %arg0 nofold low[0, 0] high[0, 0] {
1228
1244
^bb0(%arg1: index, %arg2: index):
0 commit comments