diff options
author | Tai Ly <tai.ly@arm.com> | 2023-07-03 22:46:25 +0000 |
---|---|---|
committer | Tai Ly <tai.ly@arm.com> | 2023-07-18 23:02:10 +0000 |
commit | f65ce51e3344313b744429c3763d1c85bf77a857 (patch) | |
tree | cc07319a88e04e6a5ea2e933fb436448a9276966 /src/TosaSerialize.cpp | |
parent | 1acb3672107eeb94c7c23d13c24df3d7671dbcc6 (diff) | |
download | tosa_mlir_translator-f65ce51e3344313b744429c3763d1c85bf77a857.tar.gz |
Add deserialization of AccumType
Added deserialize accum_type attribute for AvgPool2D Op
also fixed serialization of accum_type attribute for AvgPool2D Op
also updated third_party/serialization_lib hash
LLVM_REFSPEC: refs/changes/23/532123/2
TF_REFSPEC: refs/changes/34/699334/5
Signed-off-by: Tai Ly <tai.ly@arm.com>
Change-Id: I2084f33e60d1bf8f76958b320a96fc1f3a94d95c
Diffstat (limited to 'src/TosaSerialize.cpp')
-rw-r--r-- | src/TosaSerialize.cpp | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/TosaSerialize.cpp b/src/TosaSerialize.cpp index 66d0a31..33d87d0 100644 --- a/src/TosaSerialize.cpp +++ b/src/TosaSerialize.cpp @@ -107,10 +107,12 @@ static DType Type2AccumDType(mlir::Type element_type) { } static DType Type2PoolAccumDType(mlir::Type element_type) { - if (element_type.isF64() || element_type.isF32() || element_type.isF16() || - element_type.isBF16()) { + // def Tosa_AccType : AnyTypeOf<[I<32>, SI<32>, F16, F32]>; + if (element_type.isF32()) { return DType_FP32; - } else if (element_type.isInteger(8) || element_type.isInteger(16)) { + } else if (element_type.isF16()) { + return DType_FP16; + } else if (element_type.isInteger(32) || element_type.isSignedInteger(32)) { return DType_INT32; } return DType_UNKNOWN; @@ -289,6 +291,13 @@ TosaSerializationOperatorBuilder::BuildPoolOpFromMlirOp(mlir::Operation &op, auto kernel = getDenseI64ArrayAttr<int>(op.getAttr("kernel")); ASSERT_VECTOR_LENGTH(kernel, 2); + DType accum_dtype = DType_FP32; + // AvgPool has accum_dtype, MaxPool does not + if (op.hasAttr("acc_type")) { + auto acc_type = op.getAttr("acc_type").cast<mlir::TypeAttr>().getValue(); + accum_dtype = Type2PoolAccumDType(acc_type); + } + std::string input_name = GetTensorName(op.getOperand(0)); std::string output_name = GetTensorName(op.getResult(0)); @@ -300,8 +309,8 @@ TosaSerializationOperatorBuilder::BuildPoolOpFromMlirOp(mlir::Operation &op, mlir::RankedTensorType tensor = op.getOperand(0).getType().cast<mlir::RankedTensorType>(); - DType type = Type2PoolAccumDType(tensor.getElementType()); - TosaPoolAttribute attribute(pad, kernel, stride, input_zp, output_zp, type); + TosaPoolAttribute attribute(pad, kernel, stride, input_zp, output_zp, + accum_dtype); TosaSerializationOperator *tyop = new TosaSerializationOperator(opcode, Attribute_PoolAttribute, &attribute, |