pub struct PadOperation<'c> { /* private fields */ }
Expand description
A pad
operation. Tensor pad operation.
tensor.pad
is an operation that pads the source
tensor
with given low
and high
padding config.
The PadOp operation supports the following arguments:
- source: the “base” tensor on which to pad.
- low: A list contains the padding along the start of each
dimension, i.e
low
. - high: A list contains the padding along the end of each
dimension, i.e.
high
. - nofold: indicates that the operation should not be folded when source and result types are equal.
The result tensor dimensions are low
+ dim
+ high
along that
dimension. The number of elements of low
and high
must match
the rank of the input tensor. They can be either a constant or a
dynamic value.
The region of the tensor.pad
operation returns the value to use
for the padding. The arguments of the region represent the index
of the source being accessed. There should be as many arguments as
the rank of the source
tensor. The value yield
-ed by the
region is used as the value of the view at the given position.
If nofold
is set, the padding operation will not be folded away even
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:
%pad_value = ... : f32
%0 = tensor.pad %0 low[1, 2] high[2, 3] {
^bb0(%arg0 : index, %arg1 : index):
tensor.yield %pad_value : f32
} : tensor<?x?xf32> to tensor<?x?xf32>
Example 2:
%pad_value = ... : f32
%0 = tensor.pad %arg0 low[2, %arg1, 3, 3] high[3, 3, %arg1, 2] {
^bb0(%arg2: index, %arg3: index, %arg4: index, %arg5: index):
tensor.yield %pad_value : f32
} : tensor<1x2x2x?xf32> to tensor<6x?x?x?xf32>
Example 3:
%pad_value = ... : f32
%0 = tensor.pad %arg0 low[0, 0] high[%ub0, %ub1] {
^bb0(%arg1: index, %arg2: index):
tensor.yield %pad_value : f32
} : tensor<2x3xf32> to tensor<?x?xf32>
Example 4:
// 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):
tensor.yield %pad_value : f32
} : tensor<2x3xf32> to tensor<2x3xf32>
Implementations§
source§impl<'c> PadOperation<'c>
impl<'c> PadOperation<'c>
sourcepub fn as_operation(&self) -> &Operation<'c>
pub fn as_operation(&self) -> &Operation<'c>
Returns a generic operation.
sourcepub fn builder(
context: &'c Context,
location: Location<'c>
) -> PadOperationBuilder<'c, Unset, Unset, Unset, Unset, Unset, Unset, Unset>
pub fn builder( context: &'c Context, location: Location<'c> ) -> PadOperationBuilder<'c, Unset, Unset, Unset, Unset, Unset, Unset, Unset>
Creates a builder.