[mlir][tosa] Spec v0.23 updates

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
This commit is contained in:
Suraj Sudhir 2021-11-08 10:13:42 -08:00 committed by Rob Suderman
parent e7823608bc
commit 82568021dd
5 changed files with 46 additions and 9 deletions

View File

@ -174,8 +174,8 @@ def Tosa_UnaryOpQuantInfoBuilder : OpBuilder<
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),
@ -184,6 +184,14 @@ def Tosa_PadOpQuantInfoBuilder : OpBuilder<
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.
//===----------------------------------------------------------------------===//

View File

@ -321,9 +321,11 @@ def Tosa_ClampOp : Tosa_Op<"clamp", [
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
@ -1394,15 +1396,16 @@ def Tosa_PadOp : Tosa_Op<"pad", [
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
);
@ -1410,7 +1413,8 @@ def Tosa_PadOp : Tosa_Op<"pad", [
Tosa_RankedTensor:$output
);
let builders = [Tosa_PadOpQuantInfoBuilder];
let builders = [Tosa_PadOpQuantInfoBuilder,
Tosa_ExplicitValuePadOpQuantInfoBuilder];
}
//===----------------------------------------------------------------------===//

View File

@ -117,6 +117,9 @@ class Tosa_TensorOfOrNone<list<Type> allowedTypes, string description = ""> :
// 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

View File

@ -609,7 +609,7 @@ static void buildUnaryOpWithQuantInfo(OpBuilder &builder,
/// 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) {
@ -620,6 +620,20 @@ static void buildPadOpWithQuantInfo(OpBuilder &builder, OperationState &result,
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.
//===----------------------------------------------------------------------===//

View File

@ -395,6 +395,14 @@ func @test_pad(%arg0: tensor<13x21x3xf32>, %arg1: tensor<3x2xi32>) -> tensor<13x
return %0 : tensor<13x21x3xf32>
}
// -----
// 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> {