Add pad_const field to tosa.pad.
Add builders to enable optional construction of pad_const in pad op.
Update documentation of tosa.clamp to match spec wording.
Signed-off-by: Suraj Sudhir <suraj.sudhir@arm.com>
Reviewed By: rsuderman
Differential Revision: https://reviews.llvm.org/D113322
buildUnaryOpWithQuantInfo($_builder, $_state, outputType, input);
}]>;
-// This builder is called on the TOSA pad operator that needs to create its own
-// OptionalAttr quantization_attr parameter to scale the padding values
+// These builders are called on the TOSA pad operator that needs to create its
+// own OptionalAttr quantization_attr parameter to scale the padding values
// correctly.
def Tosa_PadOpQuantInfoBuilder : OpBuilder<
(ins "Type":$outputType, "Value":$input, "Value":$paddings),
input, paddings);
}]>;
+def Tosa_ExplicitValuePadOpQuantInfoBuilder : OpBuilder<
+ (ins "Type":$outputType, "Value":$input, "Value":$paddings,
+ "Value":$pad_value),
+ [{
+ buildExplicitValuePadOpWithQuantInfo($_builder, $_state, outputType,
+ input, paddings, pad_value);
+ }]>;
+
//===----------------------------------------------------------------------===//
// TOSA Operator.
//===----------------------------------------------------------------------===//
let summary = "Computes clamp(features, min, max).";
let description = [{
- Clamp to an arbitrary minimum and maximum value. Note that the maximum and
- minimum values are specified as signed quantized values, no scaling happens
- before or after this operation.
+ Clamp to an arbitrary minimum and maximum value.
+ Maximum and minimum values are specified as values in the range of the
+ input type.
+ No zero point subtraction is done to the values, thus to clamp to the zero
+ point value, the zero point itself should be supplied as the minimum value.
}];
let arguments = (ins
DeclareOpInterfaceMethods<InferShapedTypeOpInterface,
["inferReturnTypeComponents"]>,
NoSideEffect]> {
- let summary = "Pads a tensor with zeros.";
+ let summary = "Pads a tensor with value specified.";
let description = [{
- Zero-pads a tensor along borders of each dimension.
+ Pads a tensor along borders of each dimension with pad_value.
}];
let arguments = (ins
Tosa_RankedTensor:$input1,
Tosa_Int32Or64Tensor:$padding,
+ Optional<Tosa_ScalarTensor>:$pad_const,
OptionalAttr<Tosa_PadOpQuantizationAttr>:$quantization_info
);
Tosa_RankedTensor:$output
);
- let builders = [Tosa_PadOpQuantInfoBuilder];
+ let builders = [Tosa_PadOpQuantInfoBuilder,
+ Tosa_ExplicitValuePadOpQuantInfoBuilder];
}
//===----------------------------------------------------------------------===//
// Tensor types with constrained ranks.
//===----------------------------------------------------------------------===//
+// Rank-0 (scalar) tensor
+def Tosa_ScalarTensor : TensorRankOf<[Tosa_AnyNumber], [0]>;
+
// We include unranked tensors as a supported type for all possible tosa
// Tensors as unranked does not guarantee invalid. If unranked tensors exist
// they should be shape propagate used Tosa's shape inference pass and verified
/// This builder is called on TOSA pad operator that needs to create its own
/// OptionalAttr quantization_attr parameter to scale the padding values
-/// correctly.
+/// correctly. No pad_const is interpreted as zero-padding.
static void buildPadOpWithQuantInfo(OpBuilder &builder, OperationState &result,
Type outputType, Value input,
Value paddings) {
result.types.push_back(outputType);
}
+/// This builder is called on TOSA pad operator when an explicit pad_const
+/// value is passed in. It also optionally constructs quantization_attr.
+static void buildExplicitValuePadOpWithQuantInfo(OpBuilder &builder,
+ OperationState &result,
+ Type outputType, Value input,
+ Value paddings,
+ Value pad_const) {
+ result.addOperands({input, paddings, pad_const});
+ auto quantAttr = buildPadOpQuantizationAttr(builder, input);
+ if (quantAttr)
+ result.addAttribute("quantization_info", quantAttr);
+ result.types.push_back(outputType);
+}
+
//===----------------------------------------------------------------------===//
// TOSA Operator Return Type Inference.
//===----------------------------------------------------------------------===//
}
// -----
+// CHECK-LABEL: pad_explicit_value
+func @test_pad_explicit_value(%arg0: tensor<13x21x3xf32>, %arg1: tensor<3x2xi32>) -> tensor<13x21x3xf32> {
+ %0 = "tosa.const"() {value = dense<3.14> : tensor<f32>} : () -> tensor<f32>
+ %1 = "tosa.pad"(%arg0, %arg1, %0) : (tensor<13x21x3xf32>, tensor<3x2xi32>, tensor<f32>) -> tensor<13x21x3xf32>
+ return %1 : tensor<13x21x3xf32>
+}
+
+// -----
// CHECK-LABEL: reshape
func @test_reshape(%arg0: tensor<13x21x3xf32>) -> tensor<1x819xf32> {
%0 = "tosa.reshape"(%arg0) {new_shape = [1, 819]} : (tensor<13x21x3xf32>) -> tensor<1x819xf32>