ArmNN
 20.08
Serializer.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 #include "Serializer.hpp"
6 
7 #include <armnn/Descriptors.hpp>
8 #include <armnn/LstmParams.hpp>
11 
12 #include <iostream>
13 
14 #include <boost/numeric/conversion/cast.hpp>
15 #include <flatbuffers/util.h>
16 
17 #include "SerializerUtils.hpp"
18 
19 using namespace armnn;
20 namespace fb = flatbuffers;
21 namespace serializer = armnnSerializer;
22 
23 namespace armnnSerializer
24 {
25 
27 {
28  switch (function)
29  {
31  return serializer::ActivationFunction::ActivationFunction_Sigmoid;
33  return serializer::ActivationFunction::ActivationFunction_TanH;
35  return serializer::ActivationFunction::ActivationFunction_Linear;
37  return serializer::ActivationFunction::ActivationFunction_ReLu;
39  return serializer::ActivationFunction::ActivationFunction_BoundedReLu;
41  return serializer::ActivationFunction::ActivationFunction_LeakyReLu;
43  return serializer::ActivationFunction::ActivationFunction_Abs;
45  return serializer::ActivationFunction::ActivationFunction_Sqrt;
47  return serializer::ActivationFunction::ActivationFunction_Square;
49  return serializer::ActivationFunction::ActivationFunction_Elu;
51  return serializer::ActivationFunction::ActivationFunction_HardSwish;
52  default:
53  return serializer::ActivationFunction::ActivationFunction_Sigmoid;
54  }
55 }
56 
58 {
59  switch (function)
60  {
62  return serializer::ArgMinMaxFunction::ArgMinMaxFunction_Max;
64  default:
65  return serializer::ArgMinMaxFunction::ArgMinMaxFunction_Min;
66  }
67 }
68 
69 uint32_t SerializerVisitor::GetSerializedId(armnn::LayerGuid guid)
70 {
71  if (m_guidMap.empty())
72  {
73  m_guidMap.insert(std::make_pair(guid, m_layerId));
74  }
75  else if (m_guidMap.find(guid) == m_guidMap.end())
76  {
77  ++m_layerId;
78  m_guidMap.insert(std::make_pair(guid, m_layerId));
79 
80  return m_layerId;
81  }
82  return m_guidMap[guid];
83 }
84 
85 // Build FlatBuffer for Input Layer
86 void SerializerVisitor::VisitInputLayer(const armnn::IConnectableLayer* layer, LayerBindingId id, const char* name)
87 {
88  IgnoreUnused(name);
89 
90  // Create FlatBuffer BaseLayer
91  auto flatBufferInputBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Input);
92 
93  // Create FlatBuffer BindableBaseLayer
94  auto flatBufferInputBindableBaseLayer = serializer::CreateBindableLayerBase(m_flatBufferBuilder,
95  flatBufferInputBaseLayer,
96  id);
97  // Push layer binding id to outputIds.
98  m_inputIds.push_back(id);
99 
100  // Create the FlatBuffer InputLayer
101  auto flatBufferInputLayer = serializer::CreateInputLayer(m_flatBufferBuilder, flatBufferInputBindableBaseLayer);
102 
103  // Add the AnyLayer to the FlatBufferLayers
104  CreateAnyLayer(flatBufferInputLayer.o, serializer::Layer::Layer_InputLayer);
105 }
106 
107 // Build FlatBuffer for Output Layer
108 void SerializerVisitor::VisitOutputLayer(const armnn::IConnectableLayer* layer, LayerBindingId id, const char* name)
109 {
110  IgnoreUnused(name);
111 
112  // Create FlatBuffer BaseLayer
113  auto flatBufferOutputBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Output);
114 
115  // Create FlatBuffer BindableBaseLayer
116  auto flatBufferOutputBindableBaseLayer = serializer::CreateBindableLayerBase(m_flatBufferBuilder,
117  flatBufferOutputBaseLayer,
118  id);
119  // Push layer binding id to outputIds.
120  m_outputIds.push_back(id);
121 
122  // Create the FlatBuffer OutputLayer
123  auto flatBufferOutputLayer = serializer::CreateOutputLayer(m_flatBufferBuilder, flatBufferOutputBindableBaseLayer);
124  // Add the AnyLayer to the FlatBufferLayers
125  CreateAnyLayer(flatBufferOutputLayer.o, serializer::Layer::Layer_OutputLayer);
126 }
127 
128 void SerializerVisitor::VisitAbsLayer(const armnn::IConnectableLayer* layer, const char* name)
129 {
130  IgnoreUnused(name);
131  auto flatBufferBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Abs);
132  auto flatBufferAbsLayer = serializer::CreateAbsLayer(m_flatBufferBuilder, flatBufferBaseLayer);
133 
134  CreateAnyLayer(flatBufferAbsLayer.o, serializer::Layer::Layer_AbsLayer);
135 }
136 
137 // Build FlatBuffer for Activation Layer
138 void SerializerVisitor::VisitActivationLayer(const armnn::IConnectableLayer* layer,
139  const armnn::ActivationDescriptor& descriptor,
140  const char* name)
141 {
142  IgnoreUnused(name);
143 
144  // Create FlatBuffer BaseLayer
145  auto flatBufferBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Activation);
146 
147  // Create the FlatBuffer ActivationDescriptor
148  auto flatBufferDescriptor = CreateActivationDescriptor(m_flatBufferBuilder,
150  descriptor.m_A,
151  descriptor.m_B);
152 
153  // Create the FlatBuffer ActivationLayer
154  auto flatBufferAdditionLayer = CreateActivationLayer(m_flatBufferBuilder,
155  flatBufferBaseLayer,
156  flatBufferDescriptor);
157 
158  // Add the AnyLayer to the FlatBufferLayers
159  CreateAnyLayer(flatBufferAdditionLayer.o, serializer::Layer::Layer_ActivationLayer);
160 }
161 
162 // Build FlatBuffer for Addition Layer
163 void SerializerVisitor::VisitAdditionLayer(const armnn::IConnectableLayer* layer, const char* name)
164 {
165  IgnoreUnused(name);
166 
167  // Create FlatBuffer BaseLayer
168  auto flatBufferAdditionBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Addition);
169 
170  // Create the FlatBuffer AdditionLayer
171  auto flatBufferAdditionLayer = serializer::CreateAdditionLayer(m_flatBufferBuilder, flatBufferAdditionBaseLayer);
172 
173  // Add the AnyLayer to the FlatBufferLayers
174  CreateAnyLayer(flatBufferAdditionLayer.o, serializer::Layer::Layer_AdditionLayer);
175 }
176 
177 // Build FlatBuffer for ArgMinMax Layer
178 void SerializerVisitor::VisitArgMinMaxLayer(const armnn::IConnectableLayer *layer,
179  const armnn::ArgMinMaxDescriptor& descriptor,
180  const char *name)
181 {
182  IgnoreUnused(name);
183 
184  // Create FlatBuffer BaseLayer
185  auto flatBufferBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_ArgMinMax);
186 
187  // Create FlatBuffer Descriptor
188  auto flatBufferDescriptor = CreateArgMinMaxDescriptor(m_flatBufferBuilder,
190  descriptor.m_Axis);
191 
192  // Create FlatBuffer ArgMinMaxLayer
193  auto flatBufferLayer = CreateArgMinMaxLayer(m_flatBufferBuilder,
194  flatBufferBaseLayer,
195  flatBufferDescriptor);
196 
197  CreateAnyLayer(flatBufferLayer.o, serializer::Layer::Layer_ArgMinMaxLayer);
198 }
199 
200 // Build FlatBuffer for BatchToSpaceNd Layer
201 void SerializerVisitor::VisitBatchToSpaceNdLayer(const armnn::IConnectableLayer* layer,
202  const armnn::BatchToSpaceNdDescriptor& descriptor,
203  const char* name)
204 {
205  IgnoreUnused(name);
206 
207  // Create FlatBuffer BaseLayer
208  auto flatBufferBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_BatchToSpaceNd);
209 
210  std::vector<unsigned int> crops;
211  crops.reserve(descriptor.m_Crops.size() * 2);
212  for (auto& crop : descriptor.m_Crops)
213  {
214  crops.push_back(crop.first);
215  crops.push_back(crop.second);
216  }
217 
218  auto flatBufferDescriptor =
219  CreateBatchToSpaceNdDescriptor(m_flatBufferBuilder,
220  m_flatBufferBuilder.CreateVector(descriptor.m_BlockShape),
221  m_flatBufferBuilder.CreateVector(crops),
223 
224  auto flatBufferLayer = serializer::CreateBatchToSpaceNdLayer(m_flatBufferBuilder,
225  flatBufferBaseLayer,
226  flatBufferDescriptor);
227 
228  CreateAnyLayer(flatBufferLayer.o, serializer::Layer::Layer_BatchToSpaceNdLayer);
229 }
230 
231 void SerializerVisitor::VisitBatchNormalizationLayer(const armnn::IConnectableLayer* layer,
232  const armnn::BatchNormalizationDescriptor& batchNormDescriptor,
233  const armnn::ConstTensor& mean,
234  const armnn::ConstTensor& variance,
235  const armnn::ConstTensor& beta,
236  const armnn::ConstTensor& gamma,
237  const char* name)
238 {
239  IgnoreUnused(name);
240 
241  auto fbBatchNormalizationBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_BatchNormalization);
242  auto fbBatchNormalizationDescriptor = serializer::CreateBatchNormalizationDescriptor(
243  m_flatBufferBuilder,
244  batchNormDescriptor.m_Eps,
245  GetFlatBufferDataLayout(batchNormDescriptor.m_DataLayout));
246 
247  auto fbMeanConstTensorInfo = CreateConstTensorInfo(mean);
248  auto fbVarianceConstTensorInfo = CreateConstTensorInfo(variance);
249  auto fbBetaConstTensorInfo = CreateConstTensorInfo(beta);
250  auto fbGammaConstTensorInfo = CreateConstTensorInfo(gamma);
251  auto fbBatchNormalizationLayer = serializer::CreateBatchNormalizationLayer(m_flatBufferBuilder,
252  fbBatchNormalizationBaseLayer,
253  fbBatchNormalizationDescriptor,
254  fbMeanConstTensorInfo,
255  fbVarianceConstTensorInfo,
256  fbBetaConstTensorInfo,
257  fbGammaConstTensorInfo);
258 
259  CreateAnyLayer(fbBatchNormalizationLayer.o, serializer::Layer::Layer_BatchNormalizationLayer);
260 }
261 
262 void SerializerVisitor::VisitComparisonLayer(const armnn::IConnectableLayer* layer,
263  const armnn::ComparisonDescriptor& descriptor,
264  const char* name)
265 {
266  IgnoreUnused(name);
267 
268  auto fbBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Comparison);
269  auto fbDescriptor = serializer::CreateComparisonDescriptor(
270  m_flatBufferBuilder,
272 
273  auto fbLayer = serializer::CreateComparisonLayer(m_flatBufferBuilder, fbBaseLayer, fbDescriptor);
274  CreateAnyLayer(fbLayer.o, serializer::Layer::Layer_ComparisonLayer);
275 }
276 
277 // Build FlatBuffer for Constant Layer
278 void SerializerVisitor::VisitConstantLayer(const armnn::IConnectableLayer* layer,
279  const armnn::ConstTensor& input,
280  const char* name)
281 {
282  IgnoreUnused(name);
283 
284  // Create FlatBuffer BaseLayer
285  auto flatBufferConstantBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Constant);
286 
287  auto flatBufferConstTensorInfo = CreateConstTensorInfo(input);
288 
289  // Create the FlatBuffer ConstantLayer
290  auto flatBufferLayer = CreateConstantLayer(m_flatBufferBuilder,
291  flatBufferConstantBaseLayer,
292  flatBufferConstTensorInfo);
293 
294  // Add the AnyLayer to the FlatBufferLayers
295  CreateAnyLayer(flatBufferLayer.o, serializer::Layer::Layer_ConstantLayer);
296 }
297 
298 // Build FlatBuffer for Convolution2dLayer
299 void SerializerVisitor::VisitConvolution2dLayer(const armnn::IConnectableLayer* layer,
300  const armnn::Convolution2dDescriptor& descriptor,
301  const armnn::ConstTensor& weights,
303  const char* name)
304 {
305  IgnoreUnused(name);
306 
307  // Create FlatBuffer BaseLayer
308  auto flatBufferBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Convolution2d);
309 
310  auto flatBufferDescriptor = CreateConvolution2dDescriptor(m_flatBufferBuilder,
311  descriptor.m_PadLeft,
312  descriptor.m_PadRight,
313  descriptor.m_PadTop,
314  descriptor.m_PadBottom,
315  descriptor.m_StrideX,
316  descriptor.m_StrideY,
317  descriptor.m_DilationX,
318  descriptor.m_DilationY,
319  descriptor.m_BiasEnabled,
321  auto flatBufferWeightsConstTensorInfo = CreateConstTensorInfo(weights);
322  flatbuffers::Offset<serializer::ConstTensor> flatBufferBiasesConstTensorInfo;
323 
324  if (biases.has_value())
325  {
326  flatBufferBiasesConstTensorInfo = CreateConstTensorInfo(biases.value());
327  }
328 
329  // Create the FlatBuffer Convolution2dLayer
330  auto flatBufferLayer = CreateConvolution2dLayer(m_flatBufferBuilder,
331  flatBufferBaseLayer,
332  flatBufferDescriptor,
333  flatBufferWeightsConstTensorInfo,
334  flatBufferBiasesConstTensorInfo);
335 
336  // Add the AnyLayer to the FlatBufferLayers
337  CreateAnyLayer(flatBufferLayer.o, serializer::Layer::Layer_Convolution2dLayer);
338 }
339 
340 void SerializerVisitor::VisitDepthToSpaceLayer(const armnn::IConnectableLayer* layer,
341  const armnn::DepthToSpaceDescriptor& descriptor,
342  const char* name)
343 {
344  IgnoreUnused(name);
345 
346  auto fbBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_DepthToSpace);
347  auto fbDescriptor = CreateDepthToSpaceDescriptor(m_flatBufferBuilder,
348  descriptor.m_BlockSize,
350 
351  auto fbLayer = serializer::CreateDepthToSpaceLayer(m_flatBufferBuilder, fbBaseLayer, fbDescriptor);
352 
353  CreateAnyLayer(fbLayer.o, serializer::Layer::Layer_DepthToSpaceLayer);
354 }
355 
356 void SerializerVisitor::VisitDepthwiseConvolution2dLayer(const armnn::IConnectableLayer* layer,
357  const armnn::DepthwiseConvolution2dDescriptor& descriptor,
358  const armnn::ConstTensor& weights,
360  const char* name)
361 {
362  IgnoreUnused(name);
363 
364  auto fbBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_DepthwiseConvolution2d);
365  auto fbDescriptor = CreateDepthwiseConvolution2dDescriptor(m_flatBufferBuilder,
366  descriptor.m_PadLeft,
367  descriptor.m_PadRight,
368  descriptor.m_PadTop,
369  descriptor.m_PadBottom,
370  descriptor.m_StrideX,
371  descriptor.m_StrideY,
372  descriptor.m_DilationX,
373  descriptor.m_DilationY,
374  descriptor.m_BiasEnabled,
376 
377  flatbuffers::Offset<serializer::ConstTensor> fbWeightsConstTensorInfo = CreateConstTensorInfo(weights);
378  flatbuffers::Offset<serializer::ConstTensor> fbBiasesConstTensorInfo;
379  if (biases.has_value())
380  {
381  fbBiasesConstTensorInfo = CreateConstTensorInfo(biases.value());
382  }
383 
384  auto flatBufferLayer = CreateDepthwiseConvolution2dLayer(m_flatBufferBuilder,
385  fbBaseLayer,
386  fbDescriptor,
387  fbWeightsConstTensorInfo,
388  fbBiasesConstTensorInfo);
389 
390  CreateAnyLayer(flatBufferLayer.o, serializer::Layer::Layer_DepthwiseConvolution2dLayer);
391 }
392 
393 void SerializerVisitor::VisitDequantizeLayer(const armnn::IConnectableLayer* layer,
394  const char* name)
395 {
396  IgnoreUnused(name);
397 
398  auto fbDequantizeBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Dequantize);
399  auto fbDequantizeLayer = serializer::CreateDequantizeLayer(m_flatBufferBuilder, fbDequantizeBaseLayer);
400 
401  CreateAnyLayer(fbDequantizeLayer.o, serializer::Layer::Layer_DequantizeLayer);
402 }
403 
404 void SerializerVisitor::VisitDetectionPostProcessLayer(const armnn::IConnectableLayer* layer,
405  const armnn::DetectionPostProcessDescriptor& descriptor,
407  const char* name)
408 {
409  IgnoreUnused(name);
410 
411  auto fbBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_DetectionPostProcess);
412  auto fbDescriptor = CreateDetectionPostProcessDescriptor(m_flatBufferBuilder,
413  descriptor.m_MaxDetections,
414  descriptor.m_MaxClassesPerDetection,
415  descriptor.m_DetectionsPerClass,
416  descriptor.m_NmsScoreThreshold,
417  descriptor.m_NmsIouThreshold,
418  descriptor.m_NumClasses,
419  descriptor.m_UseRegularNms,
420  descriptor.m_ScaleX,
421  descriptor.m_ScaleY,
422  descriptor.m_ScaleW,
423  descriptor.m_ScaleH);
424 
425  flatbuffers::Offset<serializer::ConstTensor> fbAnchorsConstTensorInfo = CreateConstTensorInfo(anchors);
426 
427  auto flatBufferLayer = CreateDetectionPostProcessLayer(m_flatBufferBuilder,
428  fbBaseLayer,
429  fbDescriptor,
430  fbAnchorsConstTensorInfo);
431 
432  CreateAnyLayer(flatBufferLayer.o, serializer::Layer::Layer_DetectionPostProcessLayer);
433 }
434 
435 void SerializerVisitor::VisitDivisionLayer(const armnn::IConnectableLayer* layer, const char* name)
436 {
437  IgnoreUnused(name);
438 
439  auto fbDivisionBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Division);
440  auto fbDivisionLayer = serializer::CreateDivisionLayer(m_flatBufferBuilder, fbDivisionBaseLayer);
441 
442  CreateAnyLayer(fbDivisionLayer.o, serializer::Layer::Layer_DivisionLayer);
443 }
444 
445 void SerializerVisitor::VisitElementwiseUnaryLayer(const armnn::IConnectableLayer* layer,
446  const armnn::ElementwiseUnaryDescriptor& descriptor,
447  const char* name)
448 {
449  IgnoreUnused(name);
450 
451  auto fbBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_ElementwiseUnary);
452  auto fbDescriptor = serializer::CreateElementwiseUnaryDescriptor(
453  m_flatBufferBuilder,
455 
456  auto fbLayer = serializer::CreateElementwiseUnaryLayer(m_flatBufferBuilder, fbBaseLayer, fbDescriptor);
457  CreateAnyLayer(fbLayer.o, serializer::Layer::Layer_ElementwiseUnaryLayer);
458 }
459 
460 void SerializerVisitor::VisitEqualLayer(const armnn::IConnectableLayer* layer, const char* name)
461 {
462  IgnoreUnused(name);
463 
464  auto fbBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Equal);
465  auto fbEqualLayer = serializer::CreateEqualLayer(m_flatBufferBuilder, fbBaseLayer);
466 
467  CreateAnyLayer(fbEqualLayer.o, serializer::Layer::Layer_EqualLayer);
468 }
469 
470 void SerializerVisitor::VisitFillLayer(const armnn::IConnectableLayer* layer,
471  const armnn::FillDescriptor& fillDescriptor,
472  const char* name)
473 {
474  IgnoreUnused(name);
475 
476  auto fbFillBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Fill);
477 
478  auto fbDescriptor = serializer::CreateFillDescriptor(m_flatBufferBuilder, fillDescriptor.m_Value);
479 
480  auto fbFillLayer = serializer::CreateFillLayer(m_flatBufferBuilder, fbFillBaseLayer, fbDescriptor);
481 
482  CreateAnyLayer(fbFillLayer.o, serializer::Layer::Layer_FillLayer);
483 }
484 
485 void SerializerVisitor::VisitFloorLayer(const armnn::IConnectableLayer *layer, const char *name)
486 {
487  IgnoreUnused(name);
488 
489  auto flatBufferFloorBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Floor);
490  auto flatBufferFloorLayer = serializer::CreateFloorLayer(m_flatBufferBuilder, flatBufferFloorBaseLayer);
491 
492  CreateAnyLayer(flatBufferFloorLayer.o, serializer::Layer::Layer_FloorLayer);
493 }
494 
495 void SerializerVisitor::VisitGatherLayer(const armnn::IConnectableLayer* layer,
496  const char* name)
497 {
498  armnn::GatherDescriptor gatherDescriptor{};
499  VisitGatherLayer(layer, gatherDescriptor, name);
500 }
501 
502 void SerializerVisitor::VisitGatherLayer(const armnn::IConnectableLayer* layer,
503  const armnn::GatherDescriptor& gatherDescriptor,
504  const char* name)
505 {
506  IgnoreUnused(name);
507 
508  auto fbGatherDescriptor = CreateGatherDescriptor(m_flatBufferBuilder,
509  gatherDescriptor.m_Axis);
510  auto fbGatherBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Gather);
511  auto flatBufferLayer = serializer::CreateGatherLayer(m_flatBufferBuilder, fbGatherBaseLayer, fbGatherDescriptor);
512 
513  CreateAnyLayer(flatBufferLayer.o, serializer::Layer::Layer_GatherLayer);
514 }
515 
516 void SerializerVisitor::VisitGreaterLayer(const armnn::IConnectableLayer* layer, const char* name)
517 {
518  IgnoreUnused(name);
519 
520  auto fbGreaterBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Greater);
521  auto fbGreaterLayer = serializer::CreateGreaterLayer(m_flatBufferBuilder, fbGreaterBaseLayer);
522 
523  CreateAnyLayer(fbGreaterLayer.o, serializer::Layer::Layer_GreaterLayer);
524 }
525 
526 void SerializerVisitor::VisitInstanceNormalizationLayer(
527  const armnn::IConnectableLayer* layer,
528  const armnn::InstanceNormalizationDescriptor& instanceNormalizationDescriptor,
529  const char* name)
530 {
531  IgnoreUnused(name);
532 
533  auto fbDescriptor = serializer::CreateInstanceNormalizationDescriptor(
534  m_flatBufferBuilder,
535  instanceNormalizationDescriptor.m_Gamma,
536  instanceNormalizationDescriptor.m_Beta,
537  instanceNormalizationDescriptor.m_Eps,
538  GetFlatBufferDataLayout(instanceNormalizationDescriptor.m_DataLayout));
539 
540  auto fbBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_InstanceNormalization);
541  auto fbLayer = serializer::CreateInstanceNormalizationLayer(m_flatBufferBuilder, fbBaseLayer, fbDescriptor);
542 
543  CreateAnyLayer(fbLayer.o, serializer::Layer::Layer_InstanceNormalizationLayer);
544 }
545 
546 void SerializerVisitor::VisitL2NormalizationLayer(const armnn::IConnectableLayer* layer,
547  const armnn::L2NormalizationDescriptor& l2NormalizationDescriptor,
548  const char* name)
549 {
550  IgnoreUnused(name);
551 
552  // Create FlatBuffer BaseLayer
553  auto fbBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_L2Normalization);
554 
555  // Create the FlatBuffer L2Normalization Descriptor
556  auto fbDescriptor = serializer::CreateL2NormalizationDescriptor(
557  m_flatBufferBuilder,
558  GetFlatBufferDataLayout(l2NormalizationDescriptor.m_DataLayout),
559  l2NormalizationDescriptor.m_Eps);
560 
561  // Create FlatBuffer layer
562  auto fbLayer = serializer::CreateL2NormalizationLayer(m_flatBufferBuilder, fbBaseLayer, fbDescriptor);
563 
564  CreateAnyLayer(fbLayer.o, serializer::Layer::Layer_L2NormalizationLayer);
565 }
566 
567 void SerializerVisitor::VisitLogSoftmaxLayer(const armnn::IConnectableLayer* layer,
568  const armnn::LogSoftmaxDescriptor& logSoftmaxDescriptor,
569  const char* name)
570 {
571  IgnoreUnused(name);
572 
573  // Create FlatBuffer BaseLayer
574  auto flatBufferLogSoftmaxBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_LogSoftmax);
575 
576  // Create the FlatBuffer LogSoftmaxDescriptor
577  auto flatBufferLogSoftmaxDesc =
578  serializer::CreateLogSoftmaxDescriptor(m_flatBufferBuilder,
579  logSoftmaxDescriptor.m_Beta,
580  logSoftmaxDescriptor.m_Axis);
581 
582  // Create the FlatBuffer LogSoftmaxLayer
583  auto flatBufferLogSoftmaxLayer =
584  serializer::CreateLogSoftmaxLayer(m_flatBufferBuilder,
585  flatBufferLogSoftmaxBaseLayer,
586  flatBufferLogSoftmaxDesc);
587 
588  CreateAnyLayer(flatBufferLogSoftmaxLayer.o, serializer::Layer::Layer_LogSoftmaxLayer);
589 }
590 
591 void SerializerVisitor::VisitLstmLayer(const armnn::IConnectableLayer* layer,
592  const armnn::LstmDescriptor& descriptor,
593  const armnn::LstmInputParams& params,
594  const char* name)
595 {
596  IgnoreUnused(name);
597 
598  auto fbLstmBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Lstm);
599 
600  auto fbLstmDescriptor = serializer::CreateLstmDescriptor(
601  m_flatBufferBuilder,
602  descriptor.m_ActivationFunc,
603  descriptor.m_ClippingThresCell,
604  descriptor.m_ClippingThresProj,
605  descriptor.m_CifgEnabled,
606  descriptor.m_PeepholeEnabled,
607  descriptor.m_ProjectionEnabled,
608  descriptor.m_LayerNormEnabled);
609 
610  // Get mandatory input parameters
611  auto inputToForgetWeights = CreateConstTensorInfo(*params.m_InputToForgetWeights);
612  auto inputToCellWeights = CreateConstTensorInfo(*params.m_InputToCellWeights);
613  auto inputToOutputWeights = CreateConstTensorInfo(*params.m_InputToOutputWeights);
614  auto recurrentToForgetWeights = CreateConstTensorInfo(*params.m_RecurrentToForgetWeights);
615  auto recurrentToCellWeights = CreateConstTensorInfo(*params.m_RecurrentToCellWeights);
616  auto recurrentToOutputWeights = CreateConstTensorInfo(*params.m_RecurrentToOutputWeights);
617  auto forgetGateBias = CreateConstTensorInfo(*params.m_ForgetGateBias);
618  auto cellBias = CreateConstTensorInfo(*params.m_CellBias);
619  auto outputGateBias = CreateConstTensorInfo(*params.m_OutputGateBias);
620 
621  //Define optional parameters, these will be set depending on configuration in Lstm descriptor
622  flatbuffers::Offset<serializer::ConstTensor> inputToInputWeights;
623  flatbuffers::Offset<serializer::ConstTensor> recurrentToInputWeights;
624  flatbuffers::Offset<serializer::ConstTensor> cellToInputWeights;
625  flatbuffers::Offset<serializer::ConstTensor> inputGateBias;
626  flatbuffers::Offset<serializer::ConstTensor> projectionWeights;
627  flatbuffers::Offset<serializer::ConstTensor> projectionBias;
628  flatbuffers::Offset<serializer::ConstTensor> cellToForgetWeights;
629  flatbuffers::Offset<serializer::ConstTensor> cellToOutputWeights;
630  flatbuffers::Offset<serializer::ConstTensor> inputLayerNormWeights;
631  flatbuffers::Offset<serializer::ConstTensor> forgetLayerNormWeights;
632  flatbuffers::Offset<serializer::ConstTensor> cellLayerNormWeights;
633  flatbuffers::Offset<serializer::ConstTensor> outputLayerNormWeights;
634 
635  if (!descriptor.m_CifgEnabled)
636  {
637  inputToInputWeights = CreateConstTensorInfo(*params.m_InputToInputWeights);
638  recurrentToInputWeights = CreateConstTensorInfo(*params.m_RecurrentToInputWeights);
639  cellToInputWeights = CreateConstTensorInfo(*params.m_CellToInputWeights);
640  inputGateBias = CreateConstTensorInfo(*params.m_InputGateBias);
641  }
642 
643  if (descriptor.m_ProjectionEnabled)
644  {
645  projectionWeights = CreateConstTensorInfo(*params.m_ProjectionWeights);
646  projectionBias = CreateConstTensorInfo(*params.m_ProjectionBias);
647  }
648 
649  if (descriptor.m_PeepholeEnabled)
650  {
651  cellToForgetWeights = CreateConstTensorInfo(*params.m_CellToForgetWeights);
652  cellToOutputWeights = CreateConstTensorInfo(*params.m_CellToOutputWeights);
653  }
654 
655  if (descriptor.m_LayerNormEnabled)
656  {
657  if (!descriptor.m_CifgEnabled)
658  {
659  inputLayerNormWeights = CreateConstTensorInfo((*params.m_InputLayerNormWeights));
660  }
661  forgetLayerNormWeights = CreateConstTensorInfo(*params.m_ForgetLayerNormWeights);
662  cellLayerNormWeights = CreateConstTensorInfo(*params.m_CellLayerNormWeights);
663  outputLayerNormWeights = CreateConstTensorInfo(*params.m_OutputLayerNormWeights);
664  }
665 
666  auto fbLstmParams = serializer::CreateLstmInputParams(
667  m_flatBufferBuilder,
668  inputToForgetWeights,
669  inputToCellWeights,
670  inputToOutputWeights,
671  recurrentToForgetWeights,
672  recurrentToCellWeights,
673  recurrentToOutputWeights,
674  forgetGateBias,
675  cellBias,
676  outputGateBias,
677  inputToInputWeights,
678  recurrentToInputWeights,
679  cellToInputWeights,
680  inputGateBias,
681  projectionWeights,
682  projectionBias,
683  cellToForgetWeights,
684  cellToOutputWeights,
685  inputLayerNormWeights,
686  forgetLayerNormWeights,
687  cellLayerNormWeights,
688  outputLayerNormWeights);
689 
690  auto fbLstmLayer = serializer::CreateLstmLayer(
691  m_flatBufferBuilder,
692  fbLstmBaseLayer,
693  fbLstmDescriptor,
694  fbLstmParams);
695 
696  CreateAnyLayer(fbLstmLayer.o, serializer::Layer::Layer_LstmLayer);
697 }
698 
699 void SerializerVisitor::VisitMaximumLayer(const armnn::IConnectableLayer* layer, const char* name)
700 {
701  IgnoreUnused(name);
702 
703  auto fbMaximumBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Maximum);
704  auto fbMaximumLayer = serializer::CreateMaximumLayer(m_flatBufferBuilder, fbMaximumBaseLayer);
705 
706  CreateAnyLayer(fbMaximumLayer.o, serializer::Layer::Layer_MaximumLayer);
707 }
708 
709 void SerializerVisitor::VisitMeanLayer(const armnn::IConnectableLayer* layer,
710  const armnn::MeanDescriptor& descriptor,
711  const char* name)
712 {
713  IgnoreUnused(name);
714 
715  auto fbMeanBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Mean);
716  auto fbMeanDescriptor = serializer::CreateMeanDescriptor(m_flatBufferBuilder,
717  m_flatBufferBuilder.CreateVector(descriptor.m_Axis),
718  descriptor.m_KeepDims);
719 
720  auto fbMeanLayer = serializer::CreateMeanLayer(m_flatBufferBuilder,
721  fbMeanBaseLayer,
722  fbMeanDescriptor);
723 
724  CreateAnyLayer(fbMeanLayer.o, serializer::Layer::Layer_MeanLayer);
725 }
726 
727 void SerializerVisitor::VisitMinimumLayer(const armnn::IConnectableLayer* layer, const char* name)
728 {
729  IgnoreUnused(name);
730 
731  auto fbMinimumBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Minimum);
732  auto fbMinimumLayer = serializer::CreateMinimumLayer(m_flatBufferBuilder, fbMinimumBaseLayer);
733 
734  CreateAnyLayer(fbMinimumLayer.o, serializer::Layer::Layer_MinimumLayer);
735 }
736 
737 void SerializerVisitor::VisitMergeLayer(const armnn::IConnectableLayer* layer, const char* name)
738 {
739  IgnoreUnused(name);
740 
741  auto fbMergeBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Merge);
742  auto fbMergeLayer = serializer::CreateMergeLayer(m_flatBufferBuilder, fbMergeBaseLayer);
743 
744  CreateAnyLayer(fbMergeLayer.o, serializer::Layer::Layer_MergeLayer);
745 }
746 
747 void SerializerVisitor::VisitMergerLayer(const armnn::IConnectableLayer* layer,
748  const armnn::MergerDescriptor& mergerDescriptor,
749  const char* name)
750 {
751  VisitConcatLayer(layer, mergerDescriptor, name);
752 }
753 
754 void SerializerVisitor::VisitConcatLayer(const armnn::IConnectableLayer* layer,
755  const armnn::ConcatDescriptor& concatDescriptor,
756  const char* name)
757 {
758  IgnoreUnused(name);
759 
760  auto flatBufferConcatBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Concat);
761 
762  std::vector<flatbuffers::Offset<UintVector>> views;
763  for (unsigned int v = 0; v < concatDescriptor.GetNumViews(); ++v)
764  {
765  const uint32_t* origin = concatDescriptor.GetViewOrigin(v);
766  std::vector<uint32_t> origins;
767  for (unsigned int d = 0; d < concatDescriptor.GetNumDimensions(); ++d)
768  {
769  origins.push_back(origin[d]);
770  }
771  auto view = m_flatBufferBuilder.CreateVector(origins);
772  auto uintVector = CreateUintVector(m_flatBufferBuilder, view);
773  views.push_back(uintVector);
774  }
775 
776  auto flatBufferConcatDescriptor = CreateOriginsDescriptor(m_flatBufferBuilder,
777  concatDescriptor.GetConcatAxis(),
778  concatDescriptor.GetNumViews(),
779  concatDescriptor.GetNumDimensions(),
780  m_flatBufferBuilder.CreateVector(views));
781 
782  auto flatBufferLayer = CreateConcatLayer(m_flatBufferBuilder,
783  flatBufferConcatBaseLayer,
784  flatBufferConcatDescriptor);
785 
786  CreateAnyLayer(flatBufferLayer.o, serializer::Layer::Layer_ConcatLayer);
787 }
788 
789 void SerializerVisitor::VisitMultiplicationLayer(const armnn::IConnectableLayer* layer, const char* name)
790 {
791  IgnoreUnused(name);
792 
793  auto fbMultiplicationBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Multiplication);
794  auto fbMultiplicationLayer = serializer::CreateMultiplicationLayer(m_flatBufferBuilder,
795  fbMultiplicationBaseLayer);
796 
797  CreateAnyLayer(fbMultiplicationLayer.o, serializer::Layer::Layer_MultiplicationLayer);
798 }
799 
800 void SerializerVisitor::VisitPadLayer(const armnn::IConnectableLayer* layer,
801  const armnn::PadDescriptor& padDescriptor,
802  const char* name)
803 {
804  IgnoreUnused(name);
805 
806  auto flatBufferBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Pad);
807 
808  std::vector<unsigned int> padList;
809  for (auto& p: padDescriptor.m_PadList)
810  {
811  padList.push_back(p.first);
812  padList.push_back(p.second);
813  }
814 
815  auto flatBufferPadDesc = serializer::CreatePadDescriptor(m_flatBufferBuilder,
816  m_flatBufferBuilder.CreateVector(padList),
817  padDescriptor.m_PadValue);
818 
819  auto flatBufferPadLayer = serializer::CreatePadLayer(m_flatBufferBuilder,
820  flatBufferBaseLayer,
821  flatBufferPadDesc);
822 
823  CreateAnyLayer(flatBufferPadLayer.o, serializer::Layer::Layer_PadLayer);
824 }
825 
826 void SerializerVisitor::VisitPermuteLayer(const armnn::IConnectableLayer* layer,
827  const armnn::PermuteDescriptor& permuteDescriptor,
828  const char* name)
829 {
830  IgnoreUnused(name);
831 
832  // Create FlatBuffer BaseLayer
833  auto flatBufferPermuteBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Permute);
834 
835  std::vector<unsigned int> dimMappings;
836  for (unsigned int i=0; i<permuteDescriptor.m_DimMappings.GetSize(); ++i)
837  {
838  dimMappings.push_back(permuteDescriptor.m_DimMappings[i]);
839  }
840 
841  auto flatBufferPermuteDesc = serializer::CreatePermuteDescriptor(m_flatBufferBuilder,
842  m_flatBufferBuilder.CreateVector(dimMappings));
843 
844  // Create the FlatBuffer PermuteLayer
845  auto flatBufferPermuteLayer = serializer::CreatePermuteLayer(m_flatBufferBuilder,
846  flatBufferPermuteBaseLayer,
847  flatBufferPermuteDesc);
848 
849  // Add the AnyLayer to the FlatBufferLayers
850  CreateAnyLayer(flatBufferPermuteLayer.o, serializer::Layer::Layer_PermuteLayer);
851 }
852 
853 // Build FlatBuffer for Rank Layer
854 void SerializerVisitor::VisitRankLayer(const armnn::IConnectableLayer* layer,
855  const char* name)
856 {
857  IgnoreUnused(name);
858  auto flatBufferBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Rank);
859  auto flatBufferRankLayer = serializer::CreateRankLayer(m_flatBufferBuilder, flatBufferBaseLayer);
860 
861  CreateAnyLayer(flatBufferRankLayer.o, serializer::Layer::Layer_RankLayer);
862 }
863 // Build FlatBuffer for Reshape Layer
864 void SerializerVisitor::VisitReshapeLayer(const armnn::IConnectableLayer* layer,
865  const armnn::ReshapeDescriptor& reshapeDescriptor,
866  const char* name)
867 {
868  IgnoreUnused(name);
869 
870  // Create FlatBuffer BaseLayer
871  auto flatBufferReshapeBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Reshape);
872 
873  std::vector<unsigned int> targetShape;
874  for (unsigned int i =0; i < reshapeDescriptor.m_TargetShape.GetNumDimensions(); i++)
875  {
876  targetShape.push_back(reshapeDescriptor.m_TargetShape[i]);
877  }
878 
879  auto flatBufferReshapeDesc = serializer::CreateReshapeDescriptor(m_flatBufferBuilder,
880  m_flatBufferBuilder.CreateVector(targetShape));
881 
882  // Create the FlatBuffer ReshapeLayer
883  auto flatBufferReshapeLayer = serializer::CreateReshapeLayer(m_flatBufferBuilder, flatBufferReshapeBaseLayer,
884  flatBufferReshapeDesc);
885 
886  // Add the AnyLayer to the FlatBufferLayers
887  CreateAnyLayer(flatBufferReshapeLayer.o, serializer::Layer::Layer_ReshapeLayer);
888 }
889 
890 void SerializerVisitor::VisitResizeBilinearLayer(const armnn::IConnectableLayer* layer,
891  const armnn::ResizeBilinearDescriptor& resizeDescriptor,
892  const char* name)
893 {
894  IgnoreUnused(name);
895 
896  auto flatBufferBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_ResizeBilinear);
897 
898  auto flatBufferDescriptor =
899  CreateResizeBilinearDescriptor(m_flatBufferBuilder,
900  resizeDescriptor.m_TargetWidth,
901  resizeDescriptor.m_TargetHeight,
902  GetFlatBufferDataLayout(resizeDescriptor.m_DataLayout),
903  resizeDescriptor.m_AlignCorners,
904  resizeDescriptor.m_HalfPixelCenters);
905 
906  auto flatBufferLayer = serializer::CreateResizeBilinearLayer(m_flatBufferBuilder,
907  flatBufferBaseLayer,
908  flatBufferDescriptor);
909 
910  CreateAnyLayer(flatBufferLayer.o, serializer::Layer::Layer_ResizeBilinearLayer);
911 }
912 
913 void SerializerVisitor::VisitResizeLayer(const armnn::IConnectableLayer* layer,
914  const armnn::ResizeDescriptor& resizeDescriptor,
915  const char* name)
916 {
917  IgnoreUnused(name);
918 
919  auto flatBufferBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Resize);
920 
921  auto flatBufferDescriptor =
922  CreateResizeDescriptor(m_flatBufferBuilder,
923  resizeDescriptor.m_TargetHeight,
924  resizeDescriptor.m_TargetWidth,
925  GetFlatBufferResizeMethod(resizeDescriptor.m_Method),
926  GetFlatBufferDataLayout(resizeDescriptor.m_DataLayout),
927  resizeDescriptor.m_AlignCorners,
928  resizeDescriptor.m_HalfPixelCenters);
929 
930  auto flatBufferLayer = serializer::CreateResizeLayer(m_flatBufferBuilder,
931  flatBufferBaseLayer,
932  flatBufferDescriptor);
933 
934  CreateAnyLayer(flatBufferLayer.o, serializer::Layer::Layer_ResizeLayer);
935 }
936 
937 void SerializerVisitor::VisitRsqrtLayer(const armnn::IConnectableLayer* layer, const char* name)
938 {
939  IgnoreUnused(name);
940 
941  auto fbRsqrtBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Rsqrt);
942  auto fbRsqrtLayer = serializer::CreateRsqrtLayer(m_flatBufferBuilder, fbRsqrtBaseLayer);
943 
944  CreateAnyLayer(fbRsqrtLayer.o, serializer::Layer::Layer_RsqrtLayer);
945 }
946 
947 void SerializerVisitor::VisitSliceLayer(const armnn::IConnectableLayer* layer,
948  const armnn::SliceDescriptor& sliceDescriptor,
949  const char* name)
950 {
951  IgnoreUnused(name);
952 
953  auto fbSliceBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Slice);
954  auto fbSliceDescriptor = CreateSliceDescriptor(m_flatBufferBuilder,
955  m_flatBufferBuilder.CreateVector(sliceDescriptor.m_Begin),
956  m_flatBufferBuilder.CreateVector(sliceDescriptor.m_Size));
957 
958  auto fbSliceLayer = serializer::CreateSliceLayer(m_flatBufferBuilder, fbSliceBaseLayer, fbSliceDescriptor);
959 
960  CreateAnyLayer(fbSliceLayer.o, serializer::Layer::Layer_SliceLayer);
961 }
962 
963 // Build FlatBuffer for Softmax Layer
964 void SerializerVisitor::VisitSoftmaxLayer(const armnn::IConnectableLayer* layer,
965  const armnn::SoftmaxDescriptor& softmaxDescriptor,
966  const char* name)
967 {
968  IgnoreUnused(name);
969 
970  // Create FlatBuffer BaseLayer
971  auto flatBufferSoftmaxBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Softmax);
972 
973  // Create the FlatBuffer SoftmaxDescriptor
974  auto flatBufferSoftmaxDesc =
975  serializer::CreateSoftmaxDescriptor(m_flatBufferBuilder, softmaxDescriptor.m_Beta);
976 
977  // Create the FlatBuffer SoftmaxLayer
978  auto flatBufferSoftmaxLayer =
979  serializer::CreateSoftmaxLayer(m_flatBufferBuilder,
980  flatBufferSoftmaxBaseLayer,
981  flatBufferSoftmaxDesc);
982 
983  CreateAnyLayer(flatBufferSoftmaxLayer.o, serializer::Layer::Layer_SoftmaxLayer);
984 }
985 
986 void SerializerVisitor::VisitPooling2dLayer(const armnn::IConnectableLayer* layer,
987  const armnn::Pooling2dDescriptor& pooling2dDescriptor,
988  const char* name)
989 {
990  IgnoreUnused(name);
991 
992  auto fbPooling2dBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Pooling2d);
993  auto fbPooling2dDescriptor = serializer::CreatePooling2dDescriptor(
994  m_flatBufferBuilder,
995  GetFlatBufferPoolingAlgorithm(pooling2dDescriptor.m_PoolType),
996  pooling2dDescriptor.m_PadLeft,
997  pooling2dDescriptor.m_PadRight,
998  pooling2dDescriptor.m_PadTop,
999  pooling2dDescriptor.m_PadBottom,
1000  pooling2dDescriptor.m_PoolWidth,
1001  pooling2dDescriptor.m_PoolHeight,
1002  pooling2dDescriptor.m_StrideX,
1003  pooling2dDescriptor.m_StrideY,
1005  GetFlatBufferPaddingMethod(pooling2dDescriptor.m_PaddingMethod),
1006  GetFlatBufferDataLayout(pooling2dDescriptor.m_DataLayout));
1007 
1008  auto fbPooling2dLayer = serializer::CreatePooling2dLayer(m_flatBufferBuilder,
1009  fbPooling2dBaseLayer,
1010  fbPooling2dDescriptor);
1011 
1012  CreateAnyLayer(fbPooling2dLayer.o, serializer::Layer::Layer_Pooling2dLayer);
1013 }
1014 
1015 void SerializerVisitor::VisitPreluLayer(const armnn::IConnectableLayer* layer,
1016  const char* name)
1017 {
1018  IgnoreUnused(name);
1019 
1020  // Create FlatBuffer BaseLayer
1021  auto flatBufferPreluBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Prelu);
1022 
1023  // Create the FlatBuffer AdditionLayer
1024  auto flatBufferPreluLayer = serializer::CreatePreluLayer(m_flatBufferBuilder, flatBufferPreluBaseLayer);
1025 
1026  // Add the AnyLayer to the FlatBufferLayers
1027  CreateAnyLayer(flatBufferPreluLayer.o, serializer::Layer::Layer_PreluLayer);
1028 }
1029 
1030 void SerializerVisitor::VisitQuantizeLayer(const armnn::IConnectableLayer *layer, const char *name)
1031 {
1032  IgnoreUnused(name);
1033 
1034  auto fbQuantizeBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Quantize);
1035  auto fbQuantizeLayer = serializer::CreateQuantizeLayer(m_flatBufferBuilder,
1036  fbQuantizeBaseLayer);
1037  CreateAnyLayer(fbQuantizeLayer.o, serializer::Layer::Layer_QuantizeLayer);
1038 }
1039 
1040 // Build FlatBuffer for FullyConnected Layer
1041 void SerializerVisitor::VisitFullyConnectedLayer(const armnn::IConnectableLayer* layer,
1042  const armnn::FullyConnectedDescriptor& fullyConnectedDescriptor,
1043  const armnn::ConstTensor& weights,
1045  const char* name)
1046 {
1047  IgnoreUnused(name);
1048 
1049  // Create FlatBuffer BaseLayer
1050  auto flatBufferBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_FullyConnected);
1051 
1052  // Create FlatBuffer FullyConnectedDescriptor
1053  auto flatBufferDescriptor =
1054  serializer::CreateFullyConnectedDescriptor(m_flatBufferBuilder,
1055  fullyConnectedDescriptor.m_BiasEnabled,
1056  fullyConnectedDescriptor.m_TransposeWeightMatrix);
1057 
1058  // Create FlatBuffer weights data
1059  auto flatBufferWeights = CreateConstTensorInfo(weights);
1060 
1061  // Create FlatBuffer bias data
1062  flatbuffers::Offset<serializer::ConstTensor> flatBufferBiases;
1063  if (fullyConnectedDescriptor.m_BiasEnabled)
1064  {
1065  flatBufferBiases = CreateConstTensorInfo(biases.value());
1066  }
1067 
1068  // Create FlatBuffer FullyConnectedLayer
1069  auto flatBufferLayer = serializer::CreateFullyConnectedLayer(m_flatBufferBuilder,
1070  flatBufferBaseLayer,
1071  flatBufferDescriptor,
1072  flatBufferWeights,
1073  flatBufferBiases);
1074 
1075  // Add created FullyConnectedLayer to the FlatBufferLayers
1076  CreateAnyLayer(flatBufferLayer.o, serializer::Layer::Layer_FullyConnectedLayer);
1077 }
1078 
1079 // Build FlatBuffer for SpaceToBatchNd Layer
1080 void SerializerVisitor::VisitSpaceToBatchNdLayer(const armnn::IConnectableLayer* layer,
1081  const armnn::SpaceToBatchNdDescriptor& spaceToBatchNdDescriptor,
1082  const char* name)
1083 {
1084  IgnoreUnused(name);
1085 
1086  // Create FlatBuffer BaseLayer
1087  auto flatBufferBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_SpaceToBatchNd);
1088 
1089  std::vector<unsigned int> padList;
1090  padList.reserve(spaceToBatchNdDescriptor.m_PadList.size()*2);
1091  for (auto& pad : spaceToBatchNdDescriptor.m_PadList)
1092  {
1093  padList.push_back(pad.first);
1094  padList.push_back(pad.second);
1095  }
1096 
1097  auto flatBufferDescriptor =
1098  CreateSpaceToBatchNdDescriptor(m_flatBufferBuilder,
1099  m_flatBufferBuilder.CreateVector(spaceToBatchNdDescriptor.m_BlockShape),
1100  m_flatBufferBuilder.CreateVector(padList),
1101  GetFlatBufferDataLayout(spaceToBatchNdDescriptor.m_DataLayout));
1102 
1103  auto flatBufferLayer = serializer::CreateSpaceToBatchNdLayer(m_flatBufferBuilder,
1104  flatBufferBaseLayer,
1105  flatBufferDescriptor);
1106 
1107  CreateAnyLayer(flatBufferLayer.o, serializer::Layer::Layer_SpaceToBatchNdLayer);
1108 }
1109 
1110 // Build FlatBuffer for SpaceToDepthLayer
1111 void SerializerVisitor::VisitSpaceToDepthLayer(const armnn::IConnectableLayer* layer,
1112  const armnn::SpaceToDepthDescriptor& spaceToDepthDescriptor,
1113  const char* name)
1114 {
1115  IgnoreUnused(name);
1116 
1117  auto flatBufferBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_SpaceToDepth);
1118  auto flatBufferDescriptor =
1119  CreateSpaceToDepthDescriptor(m_flatBufferBuilder,
1120  spaceToDepthDescriptor.m_BlockSize,
1121  GetFlatBufferDataLayout(spaceToDepthDescriptor.m_DataLayout));
1122 
1123  auto flatBufferLayer = serializer::CreateSpaceToDepthLayer(m_flatBufferBuilder,
1124  flatBufferBaseLayer,
1125  flatBufferDescriptor);
1126 
1127  CreateAnyLayer(flatBufferLayer.o, serializer::Layer::Layer_SpaceToDepthLayer);
1128 }
1129 
1130 // Build FlatBuffer for Splitter Layer
1131 void SerializerVisitor::VisitSplitterLayer(const armnn::IConnectableLayer* layer,
1132  const armnn::ViewsDescriptor& viewsDescriptor,
1133  const char* name)
1134 {
1135  IgnoreUnused(name);
1136 
1137  // Create FlatBuffer ViewOrigins
1138  std::vector<flatbuffers::Offset<UintVector>> flatBufferViewOrigins;
1139  flatBufferViewOrigins.reserve(viewsDescriptor.GetNumViews());
1140 
1141  for(unsigned int vIdx = 0; vIdx < viewsDescriptor.GetNumViews(); ++vIdx)
1142  {
1143  std::vector<uint32_t> viewOrigin;
1144  viewOrigin.reserve(viewsDescriptor.GetNumDimensions());
1145 
1146  // Copy vector
1147  for(unsigned int dIdx = 0; dIdx < viewsDescriptor.GetNumDimensions(); ++dIdx)
1148  {
1149  viewOrigin.push_back(viewsDescriptor.GetViewOrigin(vIdx)[dIdx]);
1150  }
1151 
1152  flatBufferViewOrigins.push_back(CreateUintVector(m_flatBufferBuilder,
1153  m_flatBufferBuilder.CreateVector(viewOrigin)));
1154  }
1155 
1156  // Create FlatBuffer OriginsDescriptor
1157  auto flatBufferOriginDescriptor = CreateOriginsDescriptor(m_flatBufferBuilder,
1158  viewsDescriptor.GetOrigins().GetConcatAxis(),
1159  viewsDescriptor.GetOrigins().GetNumViews(),
1160  viewsDescriptor.GetOrigins().GetNumDimensions(),
1161  m_flatBufferBuilder.CreateVector(flatBufferViewOrigins));
1162 
1163  // Create FlatBuffer ViewOrigins
1164  std::vector<flatbuffers::Offset<UintVector>> flatBufferViewSizes;
1165  flatBufferViewSizes.reserve(viewsDescriptor.GetNumViews());
1166 
1167  for(unsigned int vIdx = 0; vIdx < viewsDescriptor.GetNumViews(); ++vIdx)
1168  {
1169  std::vector<uint32_t> viewSize;
1170  viewSize.reserve(viewsDescriptor.GetNumDimensions());
1171 
1172  // Copy vector
1173  for(unsigned int dIdx = 0; dIdx < viewsDescriptor.GetNumDimensions(); ++dIdx)
1174  {
1175  viewSize.push_back(viewsDescriptor.GetViewSizes(vIdx)[dIdx]);
1176  }
1177 
1178  flatBufferViewSizes.push_back(CreateUintVector(m_flatBufferBuilder,
1179  m_flatBufferBuilder.CreateVector(viewSize)));
1180  }
1181 
1182  // Create FlatBuffer ViewsDescriptor
1183  auto flatBufferViewsDescriptor = CreateViewsDescriptor(m_flatBufferBuilder,
1184  flatBufferOriginDescriptor,
1185  m_flatBufferBuilder.CreateVector(flatBufferViewSizes));
1186 
1187  // Create FlatBuffer BaseLayer
1188  auto flatBufferBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Splitter);
1189 
1190  auto flatBufferSplitterLayer = serializer::CreateSplitterLayer(m_flatBufferBuilder,
1191  flatBufferBaseLayer,
1192  flatBufferViewsDescriptor);
1193 
1194  CreateAnyLayer(flatBufferSplitterLayer.o, serializer::Layer::Layer_SplitterLayer);
1195 }
1196 
1197 void SerializerVisitor::VisitNormalizationLayer(const armnn::IConnectableLayer* layer,
1198  const armnn::NormalizationDescriptor& descriptor,
1199  const char* name)
1200 {
1201  IgnoreUnused(name);
1202 
1203  auto fbNormalizationBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Normalization);
1204 
1205  auto fbNormalizationDescriptor = serializer::CreateNormalizationDescriptor(
1206  m_flatBufferBuilder,
1209  descriptor.m_NormSize,
1210  descriptor.m_Alpha,
1211  descriptor.m_Beta,
1212  descriptor.m_K,
1214 
1215  auto flatBufferLayer = serializer::CreateNormalizationLayer(m_flatBufferBuilder,
1216  fbNormalizationBaseLayer,
1217  fbNormalizationDescriptor);
1218 
1219  CreateAnyLayer(flatBufferLayer.o, serializer::Layer::Layer_NormalizationLayer);
1220 }
1221 
1222 void SerializerVisitor::VisitStackLayer(const armnn::IConnectableLayer* layer,
1223  const armnn::StackDescriptor& stackDescriptor,
1224  const char* name)
1225 {
1226  IgnoreUnused(name);
1227 
1228  auto stackBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Stack);
1229 
1230  std::vector<unsigned int> inputShape;
1231  for (unsigned int i =0; i < stackDescriptor.m_InputShape.GetNumDimensions(); i++)
1232  {
1233  inputShape.push_back(stackDescriptor.m_InputShape[i]);
1234  }
1235 
1236  auto flatBufferStackDescriptor = CreateStackDescriptor(m_flatBufferBuilder,
1237  stackDescriptor.m_Axis,
1238  stackDescriptor.m_NumInputs,
1239  m_flatBufferBuilder.CreateVector(inputShape));
1240 
1241  auto stackLayer = serializer::CreateStackLayer(m_flatBufferBuilder, stackBaseLayer, flatBufferStackDescriptor);
1242  CreateAnyLayer(stackLayer.o, serializer::Layer::Layer_StackLayer);
1243 }
1244 
1245 void SerializerVisitor::VisitStandInLayer(const armnn::IConnectableLayer *layer,
1246  const armnn::StandInDescriptor& standInDescriptor,
1247  const char *name)
1248 {
1249  IgnoreUnused(name);
1250 
1251  auto fbDescriptor = serializer::CreateStandInDescriptor(m_flatBufferBuilder,
1252  standInDescriptor.m_NumInputs,
1253  standInDescriptor.m_NumOutputs);
1254 
1255  auto fbBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_StandIn);
1256  auto fbLayer = serializer::CreateStandInLayer(m_flatBufferBuilder, fbBaseLayer, fbDescriptor);
1257 
1258  CreateAnyLayer(fbLayer.o, serializer::Layer::Layer_StandInLayer);
1259 }
1260 
1261 void SerializerVisitor::VisitStridedSliceLayer(const armnn::IConnectableLayer* layer,
1262  const armnn::StridedSliceDescriptor& stridedSliceDescriptor,
1263  const char* name)
1264 {
1265  IgnoreUnused(name);
1266 
1267  auto flatBufferBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_StridedSlice);
1268 
1269  auto flatBufferDescriptor =
1270  CreateStridedSliceDescriptor(m_flatBufferBuilder,
1271  m_flatBufferBuilder.CreateVector(stridedSliceDescriptor.m_Begin),
1272  m_flatBufferBuilder.CreateVector(stridedSliceDescriptor.m_End),
1273  m_flatBufferBuilder.CreateVector(stridedSliceDescriptor.m_Stride),
1274  stridedSliceDescriptor.m_BeginMask,
1275  stridedSliceDescriptor.m_EndMask,
1276  stridedSliceDescriptor.m_ShrinkAxisMask,
1277  stridedSliceDescriptor.m_EllipsisMask,
1278  stridedSliceDescriptor.m_NewAxisMask,
1279  GetFlatBufferDataLayout(stridedSliceDescriptor.m_DataLayout));
1280 
1281  auto flatBufferLayer = serializer::CreateStridedSliceLayer(m_flatBufferBuilder,
1282  flatBufferBaseLayer,
1283  flatBufferDescriptor);
1284 
1285  CreateAnyLayer(flatBufferLayer.o, serializer::Layer::Layer_StridedSliceLayer);
1286 }
1287 
1288 void SerializerVisitor::VisitSubtractionLayer(const armnn::IConnectableLayer* layer, const char* name)
1289 {
1290  IgnoreUnused(name);
1291 
1292  auto fbSubtractionBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Subtraction);
1293  auto fbSubtractionLayer = serializer::CreateSubtractionLayer(m_flatBufferBuilder, fbSubtractionBaseLayer);
1294 
1295  CreateAnyLayer(fbSubtractionLayer.o, serializer::Layer::Layer_SubtractionLayer);
1296 }
1297 
1298 void SerializerVisitor::VisitSwitchLayer(const armnn::IConnectableLayer* layer, const char* name)
1299 {
1300  IgnoreUnused(name);
1301 
1302  auto fbSwitchBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Switch);
1303  auto fbSwitchLayer = serializer::CreateSwitchLayer(m_flatBufferBuilder, fbSwitchBaseLayer);
1304 
1305  CreateAnyLayer(fbSwitchLayer.o, serializer::Layer::Layer_SwitchLayer);
1306 }
1307 
1308 void SerializerVisitor::VisitTransposeConvolution2dLayer(
1309  const armnn::IConnectableLayer* layer,
1310  const armnn::TransposeConvolution2dDescriptor& descriptor,
1311  const armnn::ConstTensor& weights,
1313  const char* name)
1314 {
1315  IgnoreUnused(name);
1316 
1317  auto fbBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Convolution2d);
1318  auto fbDescriptor = CreateTransposeConvolution2dDescriptor(m_flatBufferBuilder,
1319  descriptor.m_PadLeft,
1320  descriptor.m_PadRight,
1321  descriptor.m_PadTop,
1322  descriptor.m_PadBottom,
1323  descriptor.m_StrideX,
1324  descriptor.m_StrideY,
1325  descriptor.m_BiasEnabled,
1327 
1328  // weights & biases
1329  auto fbWeightsConstTensorInfo = CreateConstTensorInfo(weights);
1330  flatbuffers::Offset<serializer::ConstTensor> fbBiasesConstTensorInfo;
1331  if (biases.has_value())
1332  {
1333  fbBiasesConstTensorInfo = CreateConstTensorInfo(biases.value());
1334  }
1335 
1336  auto fbLayer = CreateTransposeConvolution2dLayer(m_flatBufferBuilder,
1337  fbBaseLayer,
1338  fbDescriptor,
1339  fbWeightsConstTensorInfo,
1340  fbBiasesConstTensorInfo);
1341 
1342  CreateAnyLayer(fbLayer.o, serializer::Layer::Layer_TransposeConvolution2dLayer);
1343 }
1344 
1345 void SerializerVisitor::VisitTransposeLayer(const armnn::IConnectableLayer* layer,
1346  const armnn::TransposeDescriptor& descriptor,
1347  const char* name)
1348 {
1349  IgnoreUnused(name);
1350 
1351  // Create FlatBuffer BaseLayer
1352  auto flatBufferBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Transpose);
1353 
1354  std::vector<unsigned int> dimMappings;
1355  for (unsigned int i=0; i<descriptor.m_DimMappings.GetSize(); ++i)
1356  {
1357  dimMappings.push_back(descriptor.m_DimMappings[i]);
1358  }
1359 
1360  auto flatBufferDesc = serializer::CreateTransposeDescriptor(m_flatBufferBuilder,
1361  m_flatBufferBuilder.CreateVector(dimMappings));
1362 
1363  // Create the FlatBuffer TransposeLayer
1364  auto flatBufferLayer = serializer::CreateTransposeLayer(m_flatBufferBuilder,
1365  flatBufferBaseLayer,
1366  flatBufferDesc);
1367 
1368  // Add the AnyLayer to the FlatBufferLayers
1369  CreateAnyLayer(flatBufferLayer.o, serializer::Layer::Layer_TransposeLayer);
1370 }
1371 
1372 void SerializerVisitor::VisitQLstmLayer(const armnn::IConnectableLayer* layer,
1373  const armnn::QLstmDescriptor& descriptor,
1374  const armnn::LstmInputParams& params,
1375  const char* name)
1376 {
1377  IgnoreUnused(name);
1378 
1379  auto fbQLstmBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_QLstm);
1380 
1381  auto fbQLstmDescriptor = serializer::CreateQLstmDescriptor(
1382  m_flatBufferBuilder,
1383  descriptor.m_CifgEnabled,
1384  descriptor.m_PeepholeEnabled,
1385  descriptor.m_ProjectionEnabled,
1386  descriptor.m_LayerNormEnabled,
1387  descriptor.m_CellClip,
1388  descriptor.m_ProjectionClip,
1389  descriptor.m_InputIntermediateScale,
1390  descriptor.m_ForgetIntermediateScale,
1391  descriptor.m_CellIntermediateScale,
1392  descriptor.m_OutputIntermediateScale,
1393  descriptor.m_HiddenStateZeroPoint,
1394  descriptor.m_HiddenStateScale
1395  );
1396 
1397  // Mandatory params
1398  auto inputToForgetWeights = CreateConstTensorInfo(*params.m_InputToForgetWeights);
1399  auto inputToCellWeights = CreateConstTensorInfo(*params.m_InputToCellWeights);
1400  auto inputToOutputWeights = CreateConstTensorInfo(*params.m_InputToOutputWeights);
1401  auto recurrentToForgetWeights = CreateConstTensorInfo(*params.m_RecurrentToForgetWeights);
1402  auto recurrentToCellWeights = CreateConstTensorInfo(*params.m_RecurrentToCellWeights);
1403  auto recurrentToOutputWeights = CreateConstTensorInfo(*params.m_RecurrentToOutputWeights);
1404  auto forgetGateBias = CreateConstTensorInfo(*params.m_ForgetGateBias);
1405  auto cellBias = CreateConstTensorInfo(*params.m_CellBias);
1406  auto outputGateBias = CreateConstTensorInfo(*params.m_OutputGateBias);
1407 
1408  // CIFG
1409  flatbuffers::Offset<serializer::ConstTensor> inputToInputWeights;
1410  flatbuffers::Offset<serializer::ConstTensor> recurrentToInputWeights;
1411  flatbuffers::Offset<serializer::ConstTensor> inputGateBias;
1412 
1413  if (!descriptor.m_CifgEnabled)
1414  {
1415  inputToInputWeights = CreateConstTensorInfo(*params.m_InputToInputWeights);
1416  recurrentToInputWeights = CreateConstTensorInfo(*params.m_RecurrentToInputWeights);
1417  inputGateBias = CreateConstTensorInfo(*params.m_InputGateBias);
1418  }
1419 
1420  // Projectiom
1421  flatbuffers::Offset<serializer::ConstTensor> projectionWeights;
1422  flatbuffers::Offset<serializer::ConstTensor> projectionBias;
1423 
1424  if (descriptor.m_ProjectionEnabled)
1425  {
1426  projectionWeights = CreateConstTensorInfo(*params.m_ProjectionWeights);
1427  projectionBias = CreateConstTensorInfo(*params.m_ProjectionBias);
1428  }
1429 
1430  // Peephole
1431  flatbuffers::Offset<serializer::ConstTensor> cellToInputWeights;
1432  flatbuffers::Offset<serializer::ConstTensor> cellToForgetWeights;
1433  flatbuffers::Offset<serializer::ConstTensor> cellToOutputWeights;
1434 
1435  if (descriptor.m_PeepholeEnabled)
1436  {
1437  if (!descriptor.m_CifgEnabled)
1438  {
1439  cellToInputWeights = CreateConstTensorInfo(*params.m_CellToInputWeights);
1440  }
1441 
1442  cellToForgetWeights = CreateConstTensorInfo(*params.m_CellToForgetWeights);
1443  cellToOutputWeights = CreateConstTensorInfo(*params.m_CellToOutputWeights);
1444  }
1445 
1446  // Layer norm
1447  flatbuffers::Offset<serializer::ConstTensor> inputLayerNormWeights;
1448  flatbuffers::Offset<serializer::ConstTensor> forgetLayerNormWeights;
1449  flatbuffers::Offset<serializer::ConstTensor> cellLayerNormWeights;
1450  flatbuffers::Offset<serializer::ConstTensor> outputLayerNormWeights;
1451 
1452  if (descriptor.m_LayerNormEnabled)
1453  {
1454  if (!descriptor.m_CifgEnabled)
1455  {
1456  inputLayerNormWeights = CreateConstTensorInfo((*params.m_InputLayerNormWeights));
1457  }
1458 
1459  forgetLayerNormWeights = CreateConstTensorInfo(*params.m_ForgetLayerNormWeights);
1460  cellLayerNormWeights = CreateConstTensorInfo(*params.m_CellLayerNormWeights);
1461  outputLayerNormWeights = CreateConstTensorInfo(*params.m_OutputLayerNormWeights);
1462  }
1463 
1464  auto fbQLstmParams = serializer::CreateQLstmInputParams(
1465  m_flatBufferBuilder,
1466  inputToForgetWeights,
1467  inputToCellWeights,
1468  inputToOutputWeights,
1469  recurrentToForgetWeights,
1470  recurrentToCellWeights,
1471  recurrentToOutputWeights,
1472  forgetGateBias,
1473  cellBias,
1474  outputGateBias,
1475  inputToInputWeights,
1476  recurrentToInputWeights,
1477  inputGateBias,
1478  projectionWeights,
1479  projectionBias,
1480  cellToInputWeights,
1481  cellToForgetWeights,
1482  cellToOutputWeights,
1483  inputLayerNormWeights,
1484  forgetLayerNormWeights,
1485  cellLayerNormWeights,
1486  outputLayerNormWeights);
1487 
1488  auto fbQLstmLayer = serializer::CreateQLstmLayer(
1489  m_flatBufferBuilder,
1490  fbQLstmBaseLayer,
1491  fbQLstmDescriptor,
1492  fbQLstmParams);
1493 
1494  CreateAnyLayer(fbQLstmLayer.o, serializer::Layer::Layer_QLstmLayer);
1495 }
1496 
1497 void SerializerVisitor::VisitQuantizedLstmLayer(const armnn::IConnectableLayer* layer,
1498  const armnn::QuantizedLstmInputParams& params,
1499  const char* name)
1500 {
1501  IgnoreUnused(name);
1502 
1503  auto fbQuantizedLstmBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_QuantizedLstm);
1504 
1505  // Get input parameters
1506  auto inputToInputWeights = CreateConstTensorInfo(params.GetInputToInputWeights());
1507  auto inputToForgetWeights = CreateConstTensorInfo(params.GetInputToForgetWeights());
1508  auto inputToCellWeights = CreateConstTensorInfo(params.GetInputToCellWeights());
1509  auto inputToOutputWeights = CreateConstTensorInfo(params.GetInputToOutputWeights());
1510 
1511  auto recurrentToInputWeights = CreateConstTensorInfo(params.GetRecurrentToInputWeights());
1512  auto recurrentToForgetWeights = CreateConstTensorInfo(params.GetRecurrentToForgetWeights());
1513  auto recurrentToCellWeights = CreateConstTensorInfo(params.GetRecurrentToCellWeights());
1514  auto recurrentToOutputWeights = CreateConstTensorInfo(params.GetRecurrentToOutputWeights());
1515 
1516  auto inputGateBias = CreateConstTensorInfo(params.GetInputGateBias());
1517  auto forgetGateBias = CreateConstTensorInfo(params.GetForgetGateBias());
1518  auto cellBias = CreateConstTensorInfo(params.GetCellBias());
1519  auto outputGateBias = CreateConstTensorInfo(params.GetOutputGateBias());
1520 
1521  auto fbQuantizedLstmParams = serializer::CreateQuantizedLstmInputParams(
1522  m_flatBufferBuilder,
1523  inputToInputWeights,
1524  inputToForgetWeights,
1525  inputToCellWeights,
1526  inputToOutputWeights,
1527  recurrentToInputWeights,
1528  recurrentToForgetWeights,
1529  recurrentToCellWeights,
1530  recurrentToOutputWeights,
1531  inputGateBias,
1532  forgetGateBias,
1533  cellBias,
1534  outputGateBias);
1535 
1536  auto fbQuantizedLstmLayer = serializer::CreateQuantizedLstmLayer(
1537  m_flatBufferBuilder,
1538  fbQuantizedLstmBaseLayer,
1539  fbQuantizedLstmParams);
1540 
1541  CreateAnyLayer(fbQuantizedLstmLayer.o, serializer::Layer::Layer_QuantizedLstmLayer);
1542 }
1543 
1544 fb::Offset<serializer::LayerBase> SerializerVisitor::CreateLayerBase(const IConnectableLayer* layer,
1545  const serializer::LayerType layerType)
1546 {
1547 
1548  uint32_t fbIndex = GetSerializedId(layer->GetGuid());
1549 
1550  std::vector<fb::Offset<serializer::InputSlot>> inputSlots = CreateInputSlots(layer);
1551  std::vector<fb::Offset<serializer::OutputSlot>> outputSlots = CreateOutputSlots(layer);
1552 
1553  return serializer::CreateLayerBase(m_flatBufferBuilder,
1554  fbIndex,
1555  m_flatBufferBuilder.CreateString(layer->GetName()),
1556  layerType,
1557  m_flatBufferBuilder.CreateVector(inputSlots),
1558  m_flatBufferBuilder.CreateVector(outputSlots));
1559 }
1560 
1561 void SerializerVisitor::CreateAnyLayer(const flatbuffers::Offset<void>& layer, const serializer::Layer serializerLayer)
1562 {
1563 
1564  auto anyLayer = armnnSerializer::CreateAnyLayer(m_flatBufferBuilder, serializerLayer, layer);
1565  m_serializedLayers.push_back(anyLayer);
1566 }
1567 
1568 template <typename T>
1569 flatbuffers::Offset<flatbuffers::Vector<T>> SerializerVisitor::CreateDataVector(const void* memory, unsigned int size)
1570 {
1571  const T* buffer = reinterpret_cast<const T*>(memory);
1572  std::vector<T> vector(buffer, buffer + (size / sizeof(T)));
1573  auto fbVector = m_flatBufferBuilder.CreateVector(vector);
1574  return fbVector;
1575 }
1576 
1577 flatbuffers::Offset<TensorInfo> SerializerVisitor::CreateTensorInfo(const armnn::TensorInfo& tensorInfo)
1578 {
1579  // Get the dimensions
1580  std::vector<unsigned int> shape;
1581  for(unsigned int dim = 0; dim < tensorInfo.GetShape().GetNumDimensions(); ++dim)
1582  {
1583  shape.push_back(tensorInfo.GetShape()[dim]);
1584  }
1585 
1586  if (tensorInfo.HasPerAxisQuantization())
1587  {
1588  // Create FlatBuffer TensorInfo
1589  auto flatBufferTensorInfo =
1590  serializer::CreateTensorInfo(m_flatBufferBuilder,
1591  m_flatBufferBuilder.CreateVector(shape),
1592  GetFlatBufferDataType(tensorInfo.GetDataType()),
1593  tensorInfo.GetQuantizationScales()[0],
1594  tensorInfo.GetQuantizationOffset(),
1595  m_flatBufferBuilder.CreateVector(tensorInfo.GetQuantizationScales()),
1596  tensorInfo.GetQuantizationDim().value(),
1597  static_cast<unsigned int>
1598  (tensorInfo.GetShape().GetDimensionality()));
1599  return flatBufferTensorInfo;
1600  }
1601 
1602  // Create FlatBuffer TensorInfo
1603  auto flatBufferTensorInfo = serializer::CreateTensorInfo(m_flatBufferBuilder,
1604  m_flatBufferBuilder.CreateVector(shape),
1605  GetFlatBufferDataType(tensorInfo.GetDataType()),
1606  tensorInfo.GetQuantizationScale(),
1607  tensorInfo.GetQuantizationOffset(),
1608  0,
1609  0,
1610  static_cast<unsigned int>
1611  (tensorInfo.GetShape().GetDimensionality()));
1612  return flatBufferTensorInfo;
1613 }
1614 
1615 flatbuffers::Offset<serializer::ConstTensor>
1616  SerializerVisitor::CreateConstTensorInfo(const armnn::ConstTensor& constTensor)
1617 {
1618  armnn::TensorInfo tensorInfo = constTensor.GetInfo();
1619 
1620  flatbuffers::Offset<void> fbPayload;
1621 
1622  switch (tensorInfo.GetDataType())
1623  {
1626  {
1627  auto fbVector = CreateDataVector<int32_t>(constTensor.GetMemoryArea(), constTensor.GetNumBytes());
1628  flatbuffers::Offset<serializer::IntData> flatBuffersData = serializer::CreateIntData(
1629  m_flatBufferBuilder,
1630  fbVector);
1631  fbPayload = flatBuffersData.o;
1632  break;
1633  }
1637  {
1638  auto fbVector = CreateDataVector<int16_t>(constTensor.GetMemoryArea(), constTensor.GetNumBytes());
1639  flatbuffers::Offset<serializer::ShortData> flatBuffersData = serializer::CreateShortData(
1640  m_flatBufferBuilder,
1641  fbVector);
1642  fbPayload = flatBuffersData.o;
1643  break;
1644  }
1649  default:
1650  {
1651  auto fbVector = CreateDataVector<int8_t>(constTensor.GetMemoryArea(), constTensor.GetNumBytes());
1652  flatbuffers::Offset<serializer::ByteData> flatBuffersData = serializer::CreateByteData(
1653  m_flatBufferBuilder,
1654  fbVector);
1655  fbPayload = flatBuffersData.o;
1656  }
1657  }
1658  flatbuffers::Offset<serializer::ConstTensor> flatBufferConstTensor = serializer::CreateConstTensor(
1659  m_flatBufferBuilder,
1660  CreateTensorInfo(tensorInfo),
1662  fbPayload);
1663  return flatBufferConstTensor;
1664 }
1665 
1666 flatbuffers::Offset<armnnSerializer::FeatureCompatibilityVersions> SerializerVisitor::GetVersionTable()
1667 {
1668  flatbuffers::Offset<armnnSerializer::FeatureCompatibilityVersions> versionsTable =
1669  serializer::CreateFeatureCompatibilityVersions(
1670  m_flatBufferBuilder,
1671  1 // Binding ids scheme version
1672  );
1673  return versionsTable;
1674 }
1675 
1676 std::vector<fb::Offset<serializer::InputSlot>>
1677  SerializerVisitor::CreateInputSlots(const armnn::IConnectableLayer* layer)
1678 {
1679  std::vector<fb::Offset<serializer::InputSlot>> inputSlots;
1680 
1681  // Get the InputSlots
1682  for (unsigned int slotIndex = 0; slotIndex<layer->GetNumInputSlots(); ++slotIndex)
1683  {
1684  const IInputSlot& inputSlot = layer->GetInputSlot(slotIndex);
1685 
1686  // Get the Connection for the InputSlot
1687  const IOutputSlot* connection = inputSlot.GetConnection();
1688 
1689  // Create FlatBuffer Connection
1690  serializer::Connection conn(GetSerializedId(inputSlot.GetConnection()->GetOwningLayerGuid()),
1691  connection->CalculateIndexOnOwner());
1692  // Create FlatBuffer InputSlot
1693  inputSlots.push_back(serializer::CreateInputSlot(m_flatBufferBuilder, slotIndex, &conn));
1694  }
1695  return inputSlots;
1696 }
1697 
1698 std::vector<fb::Offset<serializer::OutputSlot>>
1699  SerializerVisitor::CreateOutputSlots(const armnn::IConnectableLayer* layer)
1700 {
1701  std::vector<fb::Offset<serializer::OutputSlot>> outputSlots;
1702 
1703  // Get the OutputSlots
1704  for (unsigned int slotIndex = 0; slotIndex < layer->GetNumOutputSlots(); ++slotIndex)
1705  {
1706  const IOutputSlot& outputSlot = layer->GetOutputSlot(slotIndex);
1707  const armnn::TensorInfo& tensorInfo = outputSlot.GetTensorInfo();
1708 
1709  // Create FlatBuffer Outputslot
1710  outputSlots.push_back(serializer::CreateOutputSlot(m_flatBufferBuilder,
1711  slotIndex,
1712  CreateTensorInfo(tensorInfo)));
1713  }
1714  return outputSlots;
1715 }
1716 
1717 
1718 ISerializer* ISerializer::CreateRaw()
1719 {
1720  return new Serializer();
1721 }
1722 
1723 ISerializerPtr ISerializer::Create()
1724 {
1725  return ISerializerPtr(CreateRaw(), &ISerializer::Destroy);
1726 }
1727 
1728 void ISerializer::Destroy(ISerializer* serializer)
1729 {
1730  delete serializer;
1731 }
1732 
1733 void Serializer::Serialize(const INetwork& inNetwork)
1734 {
1735  // Iterate through to network
1736  inNetwork.Accept(m_SerializerVisitor);
1737  flatbuffers::FlatBufferBuilder& fbBuilder = m_SerializerVisitor.GetFlatBufferBuilder();
1738 
1739  // Create FlatBuffer SerializedGraph
1740  auto serializedGraph = serializer::CreateSerializedGraph(
1741  fbBuilder,
1742  fbBuilder.CreateVector(m_SerializerVisitor.GetSerializedLayers()),
1743  fbBuilder.CreateVector(m_SerializerVisitor.GetInputIds()),
1744  fbBuilder.CreateVector(m_SerializerVisitor.GetOutputIds()),
1745  m_SerializerVisitor.GetVersionTable());
1746 
1747  // Serialize the graph
1748  fbBuilder.Finish(serializedGraph);
1749 }
1750 
1751 bool Serializer::SaveSerializedToStream(std::ostream& stream)
1752 {
1753  flatbuffers::FlatBufferBuilder& fbBuilder = m_SerializerVisitor.GetFlatBufferBuilder();
1754 
1755  auto bytesToWrite = boost::numeric_cast<std::streamsize>(fbBuilder.GetSize());
1756  stream.write(reinterpret_cast<const char*>(fbBuilder.GetBufferPointer()), bytesToWrite);
1757  return !stream.bad();
1758 }
1759 
1760 } // namespace armnnSerializer
uint32_t m_PadBottom
Padding bottom value in the height dimension.
bool m_BiasEnabled
Enable/disable bias.
float m_Eps
Used to avoid dividing by zero.
virtual unsigned int GetNumOutputSlots() const =0
Returns the number of connectable output slots.
bool m_HalfPixelCenters
Half Pixel Centers.
armnnSerializer::UnaryOperation GetFlatBufferUnaryOperation(armnn::UnaryOperation comparisonOperation)
bool m_ProjectionEnabled
Enable/disable the projection layer.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
bool m_AlignCorners
Aligned corners.
const ConstTensor * m_ProjectionWeights
Definition: LstmParams.hpp:55
UnaryOperation m_Operation
Specifies the elementwiseUnary operation to execute.
const ConstTensor & GetRecurrentToOutputWeights() const
uint32_t m_Axis
0-based axis along which to stack the input tensors.
A ViewsDescriptor for the SplitterLayer.
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
Definition: INetwork.hpp:61
float m_ScaleW
Center size encoding scale weight.
const ConstTensor * m_CellBias
Definition: LstmParams.hpp:53
uint32_t m_PadBottom
Padding bottom value in the height dimension.
bool m_BiasEnabled
Enable/disable bias.
virtual unsigned int GetNumInputSlots() const =0
Returns the number of connectable input slots.
float m_K
Kappa value used for the across channel normalization equation.
int m_Axis
Scalar, defaulted to the last index (-1), specifying the dimension the activation will be performed o...
A TransposeConvolution2dDescriptor for the TransposeConvolution2dLayer.
const TensorShape & GetShape() const
Definition: Tensor.hpp:187
uint32_t m_PadBottom
Padding bottom value in the height dimension.
uint32_t m_PadLeft
Padding left value in the width dimension.
float m_ClippingThresProj
Clipping threshold value for the projection.
int32_t m_ShrinkAxisMask
Shrink axis mask value. If set, the nth specification shrinks the dimensionality by 1...
A ReshapeDescriptor for the ReshapeLayer.
const ConstTensor & GetRecurrentToForgetWeights() const
std::vector< int > m_Begin
Begin values for the input that will be sliced.
const ConstTensor * m_CellToOutputWeights
Definition: LstmParams.hpp:50
float m_PadValue
Optional value to use for padding, defaults to 0.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
uint32_t GetNumDimensions() const
Get the number of dimensions.
A ComparisonDescriptor for the ComparisonLayer.
Definition: Descriptors.hpp:70
float m_ScaleX
Center size encoding scale x.
TensorShape m_InputShape
Required shape of all input tensors.
uint32_t m_TargetWidth
Target width value.
bool m_TransposeWeightMatrix
Enable/disable transpose weight matrix.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
Dimensionality GetDimensionality() const
Function that returns the tensor type.
Definition: Tensor.hpp:92
bool HasPerAxisQuantization() const
Definition: Tensor.cpp:438
uint32_t m_PoolWidth
Pooling width value.
const ConstTensor & GetCellBias() const
bool m_PeepholeEnabled
Enable/disable peephole.
armnnSerializer::OutputShapeRounding GetFlatBufferOutputShapeRounding(armnn::OutputShapeRounding outputShapeRounding)
A Convolution2dDescriptor for the Convolution2dLayer.
float m_Alpha
Alpha value for the normalization equation.
uint32_t m_PadLeft
Padding left value in the width dimension.
float m_HiddenStateScale
Hidden State quantization scale.
bool m_BiasEnabled
Enable/disable bias.
const ConstTensor * m_CellToInputWeights
Definition: LstmParams.hpp:48
Optional< unsigned int > GetQuantizationDim() const
Definition: Tensor.cpp:486
float m_OutputIntermediateScale
Output intermediate quantization scale.
ResizeMethod m_Method
The Interpolation method to use (Bilinear, NearestNeighbor).
float m_Gamma
Gamma, the scale scalar value applied for the normalized tensor. Defaults to 1.0. ...
float m_Beta
Exponentiation value.
std::vector< unsigned int > m_Size
Size of the slice in each dimension.
float m_Eps
Value to add to the variance. Used to avoid dividing by zero.
const ConstTensor * m_InputGateBias
Definition: LstmParams.hpp:51
PaddingMethod m_PaddingMethod
The padding method to be used. (Exclude, IgnoreValue).
ArgMinMaxFunction m_Function
Specify if the function is to find Min or Max.
Definition: Descriptors.hpp:64
uint32_t m_DetectionsPerClass
Detections per classes, used in Regular NMS.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
serializer::ActivationFunction GetFlatBufferActivationFunction(armnn::ActivationFunction function)
Definition: Serializer.cpp:26
Main network class which provides the interface for building up a neural network. ...
Definition: INetwork.hpp:105
armnnSerializer::NormalizationAlgorithmMethod GetFlatBufferNormalizationAlgorithmMethod(armnn::NormalizationAlgorithmMethod normalizationAlgorithmMethod)
uint32_t m_PadTop
Padding top value in the height dimension.
const ConstTensor * m_RecurrentToCellWeights
Definition: LstmParams.hpp:46
uint32_t m_PadRight
Padding right value in the width dimension.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
MemoryType GetMemoryArea() const
Definition: Tensor.hpp:276
std::vector< std::pair< unsigned int, unsigned int > > m_PadList
Specifies the padding for input dimension.
const ConstTensor * m_ForgetLayerNormWeights
Definition: LstmParams.hpp:58
uint32_t GetNumViews() const
Get the number of views.
const ConstTensor * m_CellToForgetWeights
Definition: LstmParams.hpp:49
Copyright (c) 2020 ARM Limited.
void IgnoreUnused(Ts &&...)
uint32_t m_PadBottom
Padding bottom value in the height dimension.
int32_t m_BeginMask
Begin mask value.
SizeType GetSize() const
Definition: Types.hpp:225
uint32_t m_DilationY
Dilation along y axis.
int32_t m_EndMask
End mask value.
A SpaceToDepthDescriptor for the SpaceToDepthLayer.
const ConstTensor & GetInputToOutputWeights() const
std::vector< std::pair< unsigned int, unsigned int > > m_PadList
Specifies the padding values for the input dimension: heightPad{top, bottom} widthPad{left, right}.
std::vector< float > GetQuantizationScales() const
Definition: Tensor.cpp:443
uint32_t m_DilationY
Dilation factor value for height dimension.
armnnSerializer::ConstTensorData GetFlatBufferConstTensorData(armnn::DataType dataType)
A BatchToSpaceNdDescriptor for the BatchToSpaceNdLayer.
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.
PermutationVector m_DimMappings
Indicates how to translate tensor elements from a given source into the target destination, when source and target potentially have different memory layouts e.g.
int LayerBindingId
Type of identifiers for bindable layers (inputs, outputs).
Definition: Types.hpp:194
const ConstTensor * m_OutputGateBias
Definition: LstmParams.hpp:54
armnnSerializer::DataType GetFlatBufferDataType(armnn::DataType dataType)
uint32_t m_NumOutputs
Number of output tensors.
NormalizationAlgorithmMethod m_NormMethodType
Normalization method algorithm to use (LocalBrightness, LocalContrast).
A ResizeDescriptor for the ResizeLayer.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
uint32_t m_MaxClassesPerDetection
Maximum numbers of classes per detection, used in Fast NMS.
std::vector< unsigned int > m_Axis
Values for the dimensions to reduce.
A StackDescriptor for the StackLayer.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
serializer::ArgMinMaxFunction GetFlatBufferArgMinMaxFunction(armnn::ArgMinMaxFunction function)
Definition: Serializer.cpp:57
TensorShape m_TargetShape
Target shape value.
uint32_t m_PoolHeight
Pooling height value.
uint32_t m_PadTop
Padding top value in the height dimension.
uint32_t m_MaxDetections
Maximum numbers of detections.
A PadDescriptor for the PadLayer.
const uint32_t * GetViewOrigin(uint32_t idx) const
Return the view origin at the int value idx.
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.
const ConstTensor * m_InputLayerNormWeights
Definition: LstmParams.hpp:57
const ConstTensor & GetInputToCellWeights() const
armnnSerializer::NormalizationAlgorithmChannel GetFlatBufferNormalizationAlgorithmChannel(armnn::NormalizationAlgorithmChannel normalizationAlgorithmChannel)
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.
bool m_LayerNormEnabled
Enable/disable layer normalization.
float m_NmsIouThreshold
Intersection over union threshold.
const ConstTensor * m_RecurrentToOutputWeights
Definition: LstmParams.hpp:47
An LstmDescriptor for the LstmLayer.
uint32_t m_PadRight
Padding right value in the width dimension.
uint32_t m_DilationX
Dilation factor value for width dimension.
uint32_t m_PadTop
Padding top value in the height dimension.
std::vector< unsigned int > m_Begin
Beginning indices of the slice in each dimension.
int32_t m_NewAxisMask
New axis mask value.
bool m_KeepDims
Enable/disable keep dimensions. If true, then the reduced dimensions that are of length 1 are kept...
std::vector< unsigned int > m_BlockShape
Block shape values.
float m_Eps
Epsilon, small scalar value added to variance to avoid dividing by zero. Defaults to 1e-12f...
An output connection slot for a layer.
Definition: INetwork.hpp:37
A L2NormalizationDescriptor for the L2NormalizationLayer.
const ConstTensor * m_ProjectionBias
Definition: LstmParams.hpp:56
int32_t GetQuantizationOffset() const
Definition: Tensor.cpp:470
An ArgMinMaxDescriptor for ArgMinMaxLayer.
Definition: Descriptors.hpp:51
float GetQuantizationScale() const
Definition: Tensor.cpp:453
DataType GetDataType() const
Definition: Tensor.hpp:194
An OriginsDescriptor for the ConcatLayer.
float m_ProjectionClip
Clipping threshold value for the projection.
bool has_value() const noexcept
Definition: Optional.hpp:53
A FullyConnectedDescriptor for the FullyConnectedLayer.
int32_t m_EllipsisMask
Ellipsis mask value.
virtual LayerGuid GetGuid() const =0
Returns the unique id of the layer.
bool m_BiasEnabled
Enable/disable bias.
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
Definition: Tensor.hpp:298
float m_InputIntermediateScale
Input intermediate quantization scale.
uint32_t m_TargetWidth
Target width value.
A GatherDescriptor for the GatherLayer.
const ConstTensor & GetInputToInputWeights() const
bool m_PeepholeEnabled
Enable/disable peephole.
uint32_t m_NumClasses
Number of classes.
bool m_HalfPixelCenters
Half Pixel Centers.
uint32_t m_PadTop
Padding top value in the height dimension.
A StandInDescriptor for the StandIn layer.
A QLstmDescriptor for the QLstmLayer.
virtual unsigned int CalculateIndexOnOwner() const =0
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
Definition: NumericCast.hpp:33
bool m_UseRegularNms
Use Regular NMS.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
std::vector< unsigned int > m_BlockShape
Block shape value.
std::vector< int > m_Stride
Stride values for the input that will be sliced.
An ActivationDescriptor for the ActivationLayer.
Definition: Descriptors.hpp:20
const TensorInfo & GetInfo() const
Definition: Tensor.hpp:266
min(a, max(b, input)) ReLu1 & ReLu6.
uint32_t m_TargetHeight
Target height value.
uint32_t m_NumInputs
Number of input tensors.
uint32_t m_TargetHeight
Target height value.
uint32_t m_ActivationFunc
The activation function to use.
A SliceDescriptor for the SliceLayer.
uint32_t m_StrideY
Stride value when proceeding through input for the height dimension.
const ConstTensor & GetForgetGateBias() const
float m_ClippingThresCell
Clipping threshold value for the cell state.
unsigned int m_BlockSize
Scalar specifying the input block size. It must be >= 1.
const uint32_t * GetViewOrigin(uint32_t idx) const
Get the view origin at the int value idx.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
float m_ForgetIntermediateScale
Forget intermediate quantization scale.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
float m_Beta
Beta, the offset scalar value applied for the normalized tensor. Defaults to 1.0. ...
armnnSerializer::DataLayout GetFlatBufferDataLayout(armnn::DataLayout dataLayout)
float m_ScaleH
Center size encoding scale height.
ComparisonOperation m_Operation
Specifies the comparison operation to execute.
Definition: Descriptors.hpp:86
std::vector< int > m_End
End values for the input that will be sliced.
const ConstTensor * m_CellLayerNormWeights
Definition: LstmParams.hpp:59
const ConstTensor * m_ForgetGateBias
Definition: LstmParams.hpp:52
A SpaceToBatchNdDescriptor for the SpaceToBatchNdLayer.
const ConstTensor * m_InputToCellWeights
Definition: LstmParams.hpp:42
const ConstTensor * m_InputToOutputWeights
Definition: LstmParams.hpp:43
NormalizationAlgorithmChannel m_NormChannelType
Normalization channel algorithm to use (Across, Within).
const uint32_t * GetViewSizes(uint32_t idx) const
Get the view sizes at the int value idx.
float m_CellClip
Clipping threshold value for the cell state.
float m_A
Alpha upper bound value used by the activation functions. (BoundedReLu, Linear, TanH, Elu).
Definition: Descriptors.hpp:45
uint32_t m_DilationX
Dilation along x axis.
const ConstTensor & GetInputGateBias() const
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
bool m_CifgEnabled
Enable/disable cifg (coupled input & forget gate).
std::unique_ptr< ISerializer, void(*)(ISerializer *serializer)> ISerializerPtr
Definition: ISerializer.hpp:15
uint32_t m_PadLeft
Padding left value in the width dimension.
armnnSerializer::ComparisonOperation GetFlatBufferComparisonOperation(armnn::ComparisonOperation comparisonOperation)
bool m_AlignCorners
Aligned corners.
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.
int32_t m_Axis
The axis in params to gather indices from.
virtual void Accept(ILayerVisitor &visitor) const =0
A ElementwiseUnaryDescriptor for the ElementwiseUnaryLayer.
Definition: Descriptors.hpp:90
PoolingAlgorithm m_PoolType
The pooling algorithm to use (Max. Average, L2).
const ConstTensor * m_RecurrentToForgetWeights
Definition: LstmParams.hpp:45
uint32_t m_StrideY
Stride value when proceeding through input for the height dimension.
uint32_t m_StrideY
Stride value when proceeding through input for the height dimension.
std::vector< std::pair< unsigned int, unsigned int > > m_Crops
The values to crop from the input dimension.
unsigned int GetNumDimensions() const
Function that returns the tensor rank.
Definition: Tensor.cpp:175
bool m_ProjectionEnabled
Enable/disable the projection layer.
ArgMinMaxFunction
Definition: Types.hpp:71
OutputShapeRounding m_OutputShapeRounding
The rounding method for the output shape. (Floor, Ceiling).
armnnSerializer::ResizeMethod GetFlatBufferResizeMethod(armnn::ResizeMethod method)
uint32_t m_NumInputs
Number of input tensors.
const ConstTensor & GetRecurrentToCellWeights() const
const ConstTensor & GetInputToForgetWeights() const
uint32_t GetNumDimensions() const
Get the number of dimensions.
virtual const IInputSlot & GetInputSlot(unsigned int index) const =0
Get a const input slot handle by slot index.
A MeanDescriptor for the MeanLayer.
const ConstTensor * m_RecurrentToInputWeights
Definition: LstmParams.hpp:44
virtual const IOutputSlot * GetConnection() const =0
armnnSerializer::PaddingMethod GetFlatBufferPaddingMethod(armnn::PaddingMethod paddingMethod)
bool m_LayerNormEnabled
Enable/disable layer normalization.
uint32_t m_PadRight
Padding right value in the width dimension.
const ConstTensor & GetRecurrentToInputWeights() const
A TransposeDescriptor for the TransposeLayer.
A StridedSliceDescriptor for the StridedSliceLayer.
virtual const TensorInfo & GetTensorInfo() const =0
virtual const IOutputSlot & GetOutputSlot(unsigned int index) const =0
Get the const output slot handle by slot index.
int m_Axis
Axis to reduce across the input tensor.
Definition: Descriptors.hpp:66
virtual const char * GetName() const =0
Returns the name of the layer.
float m_ScaleY
Center size encoding scale y.
uint32_t GetNumViews() const
Get the number of views.
float m_NmsScoreThreshold
NMS score threshold.
virtual LayerGuid GetOwningLayerGuid() const =0
A Pooling2dDescriptor for the Pooling2dLayer.
const ConstTensor * m_OutputLayerNormWeights
Definition: LstmParams.hpp:60
A NormalizationDescriptor for the NormalizationLayer.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
An InstanceNormalizationDescriptor for InstanceNormalizationLayer.
unsigned int GetConcatAxis() const
Get the concatenation axis value.
A ResizeBilinearDescriptor for the ResizeBilinearLayer.
float m_CellIntermediateScale
Cell intermediate quantization scale.
float m_B
Beta lower bound value used by the activation functions. (BoundedReLu, Linear, TanH).
Definition: Descriptors.hpp:47
A SoftmaxDescriptor for the SoftmaxLayer.
float m_Beta
Beta value for the normalization equation.
const OriginsDescriptor & GetOrigins() const
Get the View Origins.
bool m_CifgEnabled
Enable/disable CIFG (coupled input & forget gate).
PermutationVector m_DimMappings
Indicates how to translate tensor elements from a given source into the target destination, when source and target potentially have different memory layouts e.g.
uint32_t m_NormSize
Depth radius value.
const ConstTensor & GetOutputGateBias() const
ActivationFunction m_Function
The activation function to use (Sigmoid, TanH, Linear, ReLu, BoundedReLu, SoftReLu, LeakyReLu, Abs, Sqrt, Square, Elu).
Definition: Descriptors.hpp:43
An input connection slot for a layer.
Definition: INetwork.hpp:24
armnnSerializer::PoolingAlgorithm GetFlatBufferPoolingAlgorithm(armnn::PoolingAlgorithm poolingAlgorithm)
uint32_t m_StrideY
Stride value when proceeding through input for the height dimension.
A DepthwiseConvolution2dDescriptor for the DepthwiseConvolution2dLayer.
A FillDescriptor for the FillLayer.
A BatchNormalizationDescriptor for the BatchNormalizationLayer.
uint32_t m_PadLeft
Padding left value in the width dimension.
unsigned int GetNumBytes() const
Definition: Tensor.hpp:273
const ConstTensor * m_InputToForgetWeights
Definition: LstmParams.hpp:41
ActivationFunction
Definition: Types.hpp:55
A PermuteDescriptor for the PermuteLayer.
uint32_t m_PadRight
Padding right value in the width dimension.
int32_t m_HiddenStateZeroPoint
Hidden State zero point.
const ConstTensor * m_InputToInputWeights
Definition: LstmParams.hpp:40
std::vector< float > anchors({ 0.5f, 0.5f, 1.0f, 1.0f, 0.5f, 0.5f, 1.0f, 1.0f, 0.5f, 0.5f, 1.0f, 1.0f, 0.5f, 10.5f, 1.0f, 1.0f, 0.5f, 10.5f, 1.0f, 1.0f, 0.5f, 100.5f, 1.0f, 1.0f })