[Mlir-commits] [mlir] [mlir]: clarify tensor.pad docs for low/high config (PR #69641)
Jeremy Kun
llvmlistbot at llvm.org
Thu Oct 19 14:13:45 PDT 2023
https://github.com/j2kun created https://github.com/llvm/llvm-project/pull/69641
Thanks @makslevental for educating me ^_^
>From 05f40ef948c05e646e95ed929898ee1a19d89148 Mon Sep 17 00:00:00 2001
From: Jeremy Kun <jkun at google.com>
Date: Thu, 19 Oct 2023 14:12:26 -0700
Subject: [PATCH] [mlir]: clarify tensor.pad docs for low/high config
---
.../mlir/Dialect/Tensor/IR/TensorOps.td | 31 ++++++++++++++-----
1 file changed, 24 insertions(+), 7 deletions(-)
diff --git a/mlir/include/mlir/Dialect/Tensor/IR/TensorOps.td b/mlir/include/mlir/Dialect/Tensor/IR/TensorOps.td
index 86a250b77dcc8ee..6f3e932ace3e48e 100644
--- a/mlir/include/mlir/Dialect/Tensor/IR/TensorOps.td
+++ b/mlir/include/mlir/Dialect/Tensor/IR/TensorOps.td
@@ -1168,9 +1168,11 @@ def Tensor_PadOp : Tensor_Op<"pad", [
* source: the "base" tensor on which to pad.
* low: A list contains the padding along the start of each
- dimension, i.e `low`.
+ dimension, i.e., how many padded values are prepended
+ to the beginning of the tensor in each dimension.
* high: A list contains the padding along the end of each
- dimension, i.e. `high`.
+ dimension, i.e., how many padded values are appended
+ to the end of the tensor in each dimension.
* nofold: indicates that the operation should not be folded when source and
result types are equal.
@@ -1189,7 +1191,21 @@ def Tensor_PadOp : Tensor_Op<"pad", [
if the source type and the padded type have the same static shape. This can
be used, e.g., for packing or promotion to faster memory.
- Example 1:
+ Example 1: add 3 zeros to the beginning and 5 zeros to the end of a 1D
+ tensor.
+
+ ```mlir
+ %arg0 = ... : tensor<10xi32>
+ %c0_i32 = arith.constant 0 : i32
+ %padded = tensor.pad %arg0 low[3] high[5] {
+ ^bb0(%arg1: index):
+ tensor.yield %c0_i32 : i32
+ } : tensor<10xi32> to tensor<18xi32>
+ ```
+
+ Example 2: add 1 value to the beginning of dimension 0, 2 values to the end
+ of dimension 0, 2 values to the start of dimension 1, and 3 values to the
+ end of dimension 1.
```mlir
%pad_value = ... : f32
@@ -1199,7 +1215,7 @@ def Tensor_PadOp : Tensor_Op<"pad", [
} : tensor<?x?xf32> to tensor<?x?xf32>
```
- Example 2:
+ Example 3:
```mlir
%pad_value = ... : f32
@@ -1209,7 +1225,7 @@ def Tensor_PadOp : Tensor_Op<"pad", [
} : tensor<1x2x2x?xf32> to tensor<6x?x?x?xf32>
```
- Example 3:
+ Example 4:
```mlir
%pad_value = ... : f32
@@ -1219,10 +1235,11 @@ def Tensor_PadOp : Tensor_Op<"pad", [
} : tensor<2x3xf32> to tensor<?x?xf32>
```
- Example 4:
+ Example 5: Force a padded value to be always exist with `nofold`, even
+ though the padding config asserts no new elements will be added to the
+ tensor.
```mlir
- // Force a padded value to be always exist with `nofold`.
%pad_value = ... : f32
%0 = tensor.pad %arg0 nofold low[0, 0] high[0, 0] {
^bb0(%arg1: index, %arg2: index):
More information about the Mlir-commits
mailing list