ArmNN
 24.02
SerializerUtils.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017,2019-2021,2023 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include "SerializerUtils.hpp"
7 
8 namespace armnnSerializer
9 {
10 
12 {
13  switch (comparisonOperation)
14  {
16  return armnnSerializer::ComparisonOperation::ComparisonOperation_Equal;
18  return armnnSerializer::ComparisonOperation::ComparisonOperation_Greater;
20  return armnnSerializer::ComparisonOperation::ComparisonOperation_GreaterOrEqual;
22  return armnnSerializer::ComparisonOperation::ComparisonOperation_Less;
24  return armnnSerializer::ComparisonOperation::ComparisonOperation_LessOrEqual;
26  default:
27  return armnnSerializer::ComparisonOperation::ComparisonOperation_NotEqual;
28  }
29 }
30 
32  armnn::LogicalBinaryOperation logicalBinaryOperation)
33 {
34  switch (logicalBinaryOperation)
35  {
37  return armnnSerializer::LogicalBinaryOperation::LogicalBinaryOperation_LogicalAnd;
39  return armnnSerializer::LogicalBinaryOperation::LogicalBinaryOperation_LogicalOr;
40  default:
41  throw armnn::InvalidArgumentException("Logical Binary operation unknown");
42  }
43 }
44 
45 armnnSerializer::ConstTensorData GetFlatBufferConstTensorData(armnn::DataType dataType)
46 {
47  switch (dataType)
48  {
51  return armnnSerializer::ConstTensorData::ConstTensorData_IntData;
54  return armnnSerializer::ConstTensorData::ConstTensorData_ShortData;
59  return armnnSerializer::ConstTensorData::ConstTensorData_ByteData;
61  return armnnSerializer::ConstTensorData::ConstTensorData_LongData;
62  default:
63  return armnnSerializer::ConstTensorData::ConstTensorData_NONE;
64  }
65 }
66 
68 {
69  switch (dataType)
70  {
72  return armnnSerializer::DataType::DataType_Float32;
74  return armnnSerializer::DataType::DataType_Float16;
76  return armnnSerializer::DataType::DataType_Signed32;
78  return armnnSerializer::DataType::DataType_Signed64;
80  return armnnSerializer::DataType::DataType_QSymmS16;
82  return armnnSerializer::DataType::DataType_QAsymmS8;
84  return armnnSerializer::DataType::DataType_QAsymmU8;
86  return armnnSerializer::DataType::DataType_QSymmS8;
88  return armnnSerializer::DataType::DataType_Boolean;
89  default:
90  return armnnSerializer::DataType::DataType_Float16;
91  }
92 }
93 
95 {
96  switch (dataLayout)
97  {
99  return armnnSerializer::DataLayout::DataLayout_NHWC;
101  return armnnSerializer::DataLayout::DataLayout_NDHWC;
103  return armnnSerializer::DataLayout::DataLayout_NCDHW;
105  default:
106  return armnnSerializer::DataLayout::DataLayout_NCHW;
107  }
108 }
109 
111 {
112  switch (binaryOperation)
113  {
115  return armnnSerializer::BinaryOperation::BinaryOperation_Add;
117  return armnnSerializer::BinaryOperation::BinaryOperation_Div;
119  return armnnSerializer::BinaryOperation::BinaryOperation_Maximum;
121  return armnnSerializer::BinaryOperation::BinaryOperation_Minimum;
123  return armnnSerializer::BinaryOperation::BinaryOperation_Mul;
125  return armnnSerializer::BinaryOperation::BinaryOperation_Sub;
127  return armnnSerializer::BinaryOperation::BinaryOperation_SqDiff;
129  return armnnSerializer::BinaryOperation::BinaryOperation_Power;
130  default:
131  throw armnn::InvalidArgumentException("Elementwise Binary operation unknown");
132  }
133 }
134 
136 {
137  switch (unaryOperation)
138  {
140  return armnnSerializer::UnaryOperation::UnaryOperation_Abs;
142  return armnnSerializer::UnaryOperation::UnaryOperation_Ceil;
144  return armnnSerializer::UnaryOperation::UnaryOperation_Rsqrt;
146  return armnnSerializer::UnaryOperation::UnaryOperation_Sqrt;
148  return armnnSerializer::UnaryOperation::UnaryOperation_Exp;
150  return armnnSerializer::UnaryOperation::UnaryOperation_Neg;
152  return armnnSerializer::UnaryOperation::UnaryOperation_LogicalNot;
154  return armnnSerializer::UnaryOperation::UnaryOperation_Log;
156  return armnnSerializer::UnaryOperation::UnaryOperation_Sin;
157  default:
158  throw armnn::InvalidArgumentException("Elementwise Unary operation unknown");
159  }
160 }
161 
163 {
164  switch (poolingAlgorithm)
165  {
167  return armnnSerializer::PoolingAlgorithm::PoolingAlgorithm_Average;
169  return armnnSerializer::PoolingAlgorithm::PoolingAlgorithm_L2;
171  default:
172  return armnnSerializer::PoolingAlgorithm::PoolingAlgorithm_Max;
173  }
174 }
175 
177 {
178  switch (outputShapeRounding)
179  {
181  return armnnSerializer::OutputShapeRounding::OutputShapeRounding_Ceiling;
183  default:
184  return armnnSerializer::OutputShapeRounding::OutputShapeRounding_Floor;
185  }
186 }
187 
189 {
190  switch (paddingMethod)
191  {
193  return armnnSerializer::PaddingMethod::PaddingMethod_IgnoreValue;
195  default:
196  return armnnSerializer::PaddingMethod::PaddingMethod_Exclude;
197  }
198 }
199 
201 {
202  switch (paddingMode)
203  {
205  return armnnSerializer::PaddingMode::PaddingMode_Reflect;
207  return armnnSerializer::PaddingMode::PaddingMode_Symmetric;
208  default:
209  return armnnSerializer::PaddingMode::PaddingMode_Constant;
210  }
211 }
212 
214  armnn::NormalizationAlgorithmChannel normalizationAlgorithmChannel)
215 {
216  switch (normalizationAlgorithmChannel)
217  {
219  return armnnSerializer::NormalizationAlgorithmChannel::NormalizationAlgorithmChannel_Across;
221  return armnnSerializer::NormalizationAlgorithmChannel::NormalizationAlgorithmChannel_Within;
222  default:
223  return armnnSerializer::NormalizationAlgorithmChannel::NormalizationAlgorithmChannel_Across;
224  }
225 }
226 
228  armnn::NormalizationAlgorithmMethod normalizationAlgorithmMethod)
229 {
230  switch (normalizationAlgorithmMethod)
231  {
233  return armnnSerializer::NormalizationAlgorithmMethod::NormalizationAlgorithmMethod_LocalBrightness;
235  return armnnSerializer::NormalizationAlgorithmMethod::NormalizationAlgorithmMethod_LocalContrast;
236  default:
237  return armnnSerializer::NormalizationAlgorithmMethod::NormalizationAlgorithmMethod_LocalBrightness;
238  }
239 }
240 
242 {
243  switch (method)
244  {
246  return armnnSerializer::ResizeMethod_NearestNeighbor;
248  return armnnSerializer::ResizeMethod_Bilinear;
249  default:
250  return armnnSerializer::ResizeMethod_NearestNeighbor;
251  }
252 }
253 
255 {
256  switch (reduceOperation)
257  {
259  return armnnSerializer::ReduceOperation::ReduceOperation_Sum;
261  return armnnSerializer::ReduceOperation::ReduceOperation_Max;
263  return armnnSerializer::ReduceOperation::ReduceOperation_Mean;
265  return armnnSerializer::ReduceOperation::ReduceOperation_Min;
267  return armnnSerializer::ReduceOperation::ReduceOperation_Prod;
268  default:
269  return armnnSerializer::ReduceOperation::ReduceOperation_Sum;
270  }
271 }
272 
273 } // namespace armnnSerializer
armnn::PaddingMode::Symmetric
@ Symmetric
armnn::BinaryOperation::Mul
@ Mul
armnn::DataType::Boolean
@ Boolean
armnn::NormalizationAlgorithmChannel::Within
@ Within
armnn::BinaryOperation::Add
@ Add
armnn::ComparisonOperation::LessOrEqual
@ LessOrEqual
armnn::DataLayout::NCDHW
@ NCDHW
armnnSerializer::GetFlatBufferNormalizationAlgorithmChannel
armnnSerializer::NormalizationAlgorithmChannel GetFlatBufferNormalizationAlgorithmChannel(armnn::NormalizationAlgorithmChannel normalizationAlgorithmChannel)
Definition: SerializerUtils.cpp:213
armnn::ResizeMethod
ResizeMethod
Definition: Types.hpp:166
armnn::DataLayout
DataLayout
Definition: Types.hpp:62
armnn::DataLayout::NHWC
@ NHWC
armnn::OutputShapeRounding
OutputShapeRounding
Definition: Types.hpp:221
armnnSerializer::GetFlatBufferComparisonOperation
armnnSerializer::ComparisonOperation GetFlatBufferComparisonOperation(armnn::ComparisonOperation comparisonOperation)
Definition: SerializerUtils.cpp:11
armnn::NormalizationAlgorithmMethod::LocalBrightness
@ LocalBrightness
Krichevsky 2012: Local Brightness Normalization.
armnn::NormalizationAlgorithmMethod
NormalizationAlgorithmMethod
Definition: Types.hpp:213
armnn::BinaryOperation::Sub
@ Sub
armnn::OutputShapeRounding::Floor
@ Floor
armnn::DataType::Float32
@ Float32
armnnSerializer::GetFlatBufferDataType
armnnSerializer::DataType GetFlatBufferDataType(armnn::DataType dataType)
Definition: SerializerUtils.cpp:67
armnn::LogicalBinaryOperation::LogicalOr
@ LogicalOr
armnnSerializer
Definition: ISerializer.hpp:11
armnn::PoolingAlgorithm::L2
@ L2
armnn::PaddingMode
PaddingMode
The padding mode controls whether the padding should be filled with constant values (Constant),...
Definition: Types.hpp:200
armnn::DataType::QAsymmU8
@ QAsymmU8
armnn::DataType::QSymmS8
@ QSymmS8
armnn::UnaryOperation::Neg
@ Neg
armnn::LogicalBinaryOperation
LogicalBinaryOperation
Definition: Types.hpp:119
armnnSerializer::GetFlatBufferResizeMethod
armnnSerializer::ResizeMethod GetFlatBufferResizeMethod(armnn::ResizeMethod method)
Definition: SerializerUtils.cpp:241
armnn::ReduceOperation::Mean
@ Mean
armnn::DataType::QSymmS16
@ QSymmS16
armnn::NormalizationAlgorithmChannel::Across
@ Across
armnn::ComparisonOperation::NotEqual
@ NotEqual
armnn::ComparisonOperation::GreaterOrEqual
@ GreaterOrEqual
armnnSerializer::GetFlatBufferConstTensorData
armnnSerializer::ConstTensorData GetFlatBufferConstTensorData(armnn::DataType dataType)
Definition: SerializerUtils.cpp:45
armnn::DataLayout::NDHWC
@ NDHWC
armnnSerializer::GetFlatBufferBinaryOperation
armnnSerializer::BinaryOperation GetFlatBufferBinaryOperation(armnn::BinaryOperation binaryOperation)
Definition: SerializerUtils.cpp:110
armnn::BinaryOperation::Maximum
@ Maximum
armnnSerializer::GetFlatBufferDataLayout
armnnSerializer::DataLayout GetFlatBufferDataLayout(armnn::DataLayout dataLayout)
Definition: SerializerUtils.cpp:94
armnn::DataType::Float16
@ Float16
armnn::BinaryOperation::SqDiff
@ SqDiff
armnn::UnaryOperation::Rsqrt
@ Rsqrt
armnn::ComparisonOperation::Less
@ Less
armnn::UnaryOperation::Sqrt
@ Sqrt
armnn::UnaryOperation::LogicalNot
@ LogicalNot
armnn::UnaryOperation::Exp
@ Exp
armnn::PaddingMethod::Exclude
@ Exclude
The padding fields don't count and are ignored.
armnn::DataType
DataType
Definition: Types.hpp:48
armnnSerializer::GetFlatBufferUnaryOperation
armnnSerializer::UnaryOperation GetFlatBufferUnaryOperation(armnn::UnaryOperation unaryOperation)
Definition: SerializerUtils.cpp:135
armnn::PaddingMethod::IgnoreValue
@ IgnoreValue
The padding fields count, but are ignored.
armnnSerializer::GetFlatBufferNormalizationAlgorithmMethod
armnnSerializer::NormalizationAlgorithmMethod GetFlatBufferNormalizationAlgorithmMethod(armnn::NormalizationAlgorithmMethod normalizationAlgorithmMethod)
Definition: SerializerUtils.cpp:227
armnn::InvalidArgumentException
Definition: Exceptions.hpp:80
armnn::UnaryOperation::Sin
@ Sin
armnn::ReduceOperation::Sum
@ Sum
armnnSerializer::GetFlatBufferPaddingMethod
armnnSerializer::PaddingMethod GetFlatBufferPaddingMethod(armnn::PaddingMethod paddingMethod)
Definition: SerializerUtils.cpp:188
armnn::ResizeMethod::NearestNeighbor
@ NearestNeighbor
armnn::BinaryOperation::Power
@ Power
SerializerUtils.hpp
armnn::UnaryOperation
UnaryOperation
Definition: Types.hpp:125
armnnSerializer::GetFlatBufferReduceOperation
armnnSerializer::ReduceOperation GetFlatBufferReduceOperation(armnn::ReduceOperation reduceOperation)
Definition: SerializerUtils.cpp:254
armnn::PoolingAlgorithm::Average
@ Average
armnn::DataType::Signed32
@ Signed32
armnn::UnaryOperation::Ceil
@ Ceil
armnn::ReduceOperation::Prod
@ Prod
armnn::DataType::QAsymmS8
@ QAsymmS8
armnn::ResizeMethod::Bilinear
@ Bilinear
armnn::UnaryOperation::Log
@ Log
armnn::LogicalBinaryOperation::LogicalAnd
@ LogicalAnd
armnn::ComparisonOperation
ComparisonOperation
Definition: Types.hpp:109
armnnSerializer::GetFlatBufferPoolingAlgorithm
armnnSerializer::PoolingAlgorithm GetFlatBufferPoolingAlgorithm(armnn::PoolingAlgorithm poolingAlgorithm)
Definition: SerializerUtils.cpp:162
armnn::BinaryOperation
BinaryOperation
Definition: Types.hpp:138
armnnSerializer::GetFlatBufferOutputShapeRounding
armnnSerializer::OutputShapeRounding GetFlatBufferOutputShapeRounding(armnn::OutputShapeRounding outputShapeRounding)
Definition: SerializerUtils.cpp:176
armnn::BinaryOperation::Minimum
@ Minimum
armnn::PoolingAlgorithm::Max
@ Max
armnn::ReduceOperation
ReduceOperation
Definition: Types.hpp:157
armnn::UnaryOperation::Abs
@ Abs
armnn::ReduceOperation::Min
@ Min
armnn::PoolingAlgorithm
PoolingAlgorithm
Definition: Types.hpp:150
armnn::BinaryOperation::Div
@ Div
armnn::OutputShapeRounding::Ceiling
@ Ceiling
armnn::DataType::Signed64
@ Signed64
armnn::NormalizationAlgorithmChannel
NormalizationAlgorithmChannel
Definition: Types.hpp:207
armnn::ComparisonOperation::Equal
@ Equal
armnnSerializer::GetFlatBufferPaddingMode
armnnSerializer::PaddingMode GetFlatBufferPaddingMode(armnn::PaddingMode paddingMode)
Definition: SerializerUtils.cpp:200
armnn::NormalizationAlgorithmMethod::LocalContrast
@ LocalContrast
Jarret 2009: Local Contrast Normalization.
armnn::PaddingMethod
PaddingMethod
The padding method modifies the output of pooling layers.
Definition: Types.hpp:188
armnn::PaddingMode::Reflect
@ Reflect
armnnSerializer::GetFlatBufferLogicalBinaryOperation
armnnSerializer::LogicalBinaryOperation GetFlatBufferLogicalBinaryOperation(armnn::LogicalBinaryOperation logicalBinaryOperation)
Definition: SerializerUtils.cpp:31
armnn::ReduceOperation::Max
@ Max
armnn::DataLayout::NCHW
@ NCHW
armnn::ComparisonOperation::Greater
@ Greater