14 #include <fmt/format.h>
17 using namespace armnn;
18 namespace fb = flatbuffers;
24 ISerializer::ISerializer() : pSerializerImpl(new SerializerImpl())
28 ISerializer::~ISerializer() =
default;
47 pSerializerImpl->Serialize(inNetwork);
50 bool ISerializer::SaveSerializedToStream(std::ostream& stream)
52 return pSerializerImpl->SaveSerializedToStream(stream);
60 return serializer::ActivationFunction::ActivationFunction_Sigmoid;
62 return serializer::ActivationFunction::ActivationFunction_TanH;
64 return serializer::ActivationFunction::ActivationFunction_Linear;
66 return serializer::ActivationFunction::ActivationFunction_ReLu;
68 return serializer::ActivationFunction::ActivationFunction_BoundedReLu;
70 return serializer::ActivationFunction::ActivationFunction_LeakyReLu;
72 return serializer::ActivationFunction::ActivationFunction_Abs;
74 return serializer::ActivationFunction::ActivationFunction_Sqrt;
76 return serializer::ActivationFunction::ActivationFunction_Square;
78 return serializer::ActivationFunction::ActivationFunction_Elu;
80 return serializer::ActivationFunction::ActivationFunction_HardSwish;
82 return serializer::ActivationFunction::ActivationFunction_Gelu;
84 return serializer::ActivationFunction::ActivationFunction_Sigmoid;
93 return serializer::ArgMinMaxFunction::ArgMinMaxFunction_Max;
96 return serializer::ArgMinMaxFunction::ArgMinMaxFunction_Min;
100 uint32_t SerializerStrategy::GetSerializedId(
LayerGuid guid)
102 if (m_guidMap.empty())
104 m_guidMap.insert(std::make_pair(guid, m_layerId));
106 else if (m_guidMap.find(guid) == m_guidMap.end())
109 m_guidMap.insert(std::make_pair(guid, m_layerId));
113 return m_guidMap[guid];
122 auto flatBufferInputBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Input);
125 auto flatBufferInputBindableBaseLayer = serializer::CreateBindableLayerBase(m_flatBufferBuilder,
126 flatBufferInputBaseLayer,
129 m_inputIds.push_back(
id);
132 auto flatBufferInputLayer = serializer::CreateInputLayer(m_flatBufferBuilder, flatBufferInputBindableBaseLayer);
135 CreateAnyLayer(flatBufferInputLayer.o, serializer::Layer::Layer_InputLayer);
145 auto flatBufferOutputBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Output);
148 auto flatBufferOutputBindableBaseLayer = serializer::CreateBindableLayerBase(m_flatBufferBuilder,
149 flatBufferOutputBaseLayer,
152 m_outputIds.push_back(
id);
155 auto flatBufferOutputLayer = serializer::CreateOutputLayer(m_flatBufferBuilder, flatBufferOutputBindableBaseLayer);
157 CreateAnyLayer(flatBufferOutputLayer.o, serializer::Layer::Layer_OutputLayer);
168 auto flatBufferBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Activation);
171 auto flatBufferDescriptor = CreateActivationDescriptor(m_flatBufferBuilder,
177 auto flatBufferAdditionLayer = CreateActivationLayer(m_flatBufferBuilder,
179 flatBufferDescriptor);
182 CreateAnyLayer(flatBufferAdditionLayer.o, serializer::Layer::Layer_ActivationLayer);
191 auto flatBufferAdditionBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Addition);
194 auto flatBufferAdditionLayer = serializer::CreateAdditionLayer(m_flatBufferBuilder, flatBufferAdditionBaseLayer);
197 CreateAnyLayer(flatBufferAdditionLayer.o, serializer::Layer::Layer_AdditionLayer);
208 auto flatBufferBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_ArgMinMax);
211 auto flatBufferDescriptor = CreateArgMinMaxDescriptor(m_flatBufferBuilder,
216 auto flatBufferLayer = CreateArgMinMaxLayer(m_flatBufferBuilder,
218 flatBufferDescriptor);
220 CreateAnyLayer(flatBufferLayer.o, serializer::Layer::Layer_ArgMinMaxLayer);
230 auto flatBufferBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_BatchMatMul);
233 auto flatBufferDescriptor = CreateBatchMatMulDescriptor(m_flatBufferBuilder,
242 auto flatBufferBatchMatMulLayer = CreateBatchMatMulLayer(m_flatBufferBuilder,
244 flatBufferDescriptor);
247 CreateAnyLayer(flatBufferBatchMatMulLayer.o, serializer::Layer::Layer_BatchMatMulLayer);
258 auto flatBufferBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_BatchToSpaceNd);
260 std::vector<unsigned int> crops;
261 crops.reserve(descriptor.
m_Crops.size() * 2);
262 for (
auto& crop : descriptor.
m_Crops)
264 crops.push_back(crop.first);
265 crops.push_back(crop.second);
268 auto flatBufferDescriptor =
269 CreateBatchToSpaceNdDescriptor(m_flatBufferBuilder,
270 m_flatBufferBuilder.CreateVector(descriptor.
m_BlockShape),
271 m_flatBufferBuilder.CreateVector(crops),
274 auto flatBufferLayer = serializer::CreateBatchToSpaceNdLayer(m_flatBufferBuilder,
276 flatBufferDescriptor);
278 CreateAnyLayer(flatBufferLayer.o, serializer::Layer::Layer_BatchToSpaceNdLayer);
281 void SerializerStrategy::SerializeBatchNormalizationLayer(
284 const std::vector<armnn::ConstTensor>& constants,
294 auto fbBatchNormalizationBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_BatchNormalization);
295 auto fbBatchNormalizationDescriptor = serializer::CreateBatchNormalizationDescriptor(
297 batchNormDescriptor.
m_Eps,
300 auto fbMeanConstTensorInfo = CreateConstTensorInfo(mean);
301 auto fbVarianceConstTensorInfo = CreateConstTensorInfo(variance);
302 auto fbBetaConstTensorInfo = CreateConstTensorInfo(beta);
303 auto fbGammaConstTensorInfo = CreateConstTensorInfo(gamma);
304 auto fbBatchNormalizationLayer = serializer::CreateBatchNormalizationLayer(m_flatBufferBuilder,
305 fbBatchNormalizationBaseLayer,
306 fbBatchNormalizationDescriptor,
307 fbMeanConstTensorInfo,
308 fbVarianceConstTensorInfo,
309 fbBetaConstTensorInfo,
310 fbGammaConstTensorInfo);
312 CreateAnyLayer(fbBatchNormalizationLayer.o, serializer::Layer::Layer_BatchNormalizationLayer);
320 auto fbBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Cast);
321 auto fbCastLayer = serializer::CreateCastLayer(m_flatBufferBuilder, fbBaseLayer);
322 CreateAnyLayer(fbCastLayer.o, serializer::Layer::Layer_CastLayer);
330 auto fbDescriptor = CreateChannelShuffleDescriptor(m_flatBufferBuilder,
333 auto fbBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_ChannelShuffle);
334 auto fbChannelShuffleLayer = serializer::CreateChannelShuffleLayer(m_flatBufferBuilder, fbBaseLayer, fbDescriptor);
335 CreateAnyLayer(fbChannelShuffleLayer.o, serializer::Layer::Layer_ChannelShuffleLayer);
344 auto fbBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Comparison);
345 auto fbDescriptor = serializer::CreateComparisonDescriptor(
349 auto fbLayer = serializer::CreateComparisonLayer(m_flatBufferBuilder, fbBaseLayer, fbDescriptor);
350 CreateAnyLayer(fbLayer.o, serializer::Layer::Layer_ComparisonLayer);
355 const std::vector<armnn::ConstTensor>& constants,
363 auto flatBufferConstantBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Constant);
365 auto flatBufferConstTensorInfo = CreateConstTensorInfo(input);
368 auto flatBufferLayer = CreateConstantLayer(m_flatBufferBuilder,
369 flatBufferConstantBaseLayer,
370 flatBufferConstTensorInfo);
373 CreateAnyLayer(flatBufferLayer.o, serializer::Layer::Layer_ConstantLayer);
384 auto flatBufferBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Convolution2d);
386 auto flatBufferDescriptor = CreateConvolution2dDescriptor(m_flatBufferBuilder,
399 auto flatBufferLayer = CreateConvolution2dLayer(m_flatBufferBuilder,
401 flatBufferDescriptor);
404 CreateAnyLayer(flatBufferLayer.o, serializer::Layer::Layer_Convolution2dLayer);
415 auto flatBufferBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Convolution3d);
417 auto flatBufferDescriptor = CreateConvolution3dDescriptor(m_flatBufferBuilder,
434 auto flatBufferLayer = CreateConvolution3dLayer(m_flatBufferBuilder,
436 flatBufferDescriptor);
439 CreateAnyLayer(flatBufferLayer.o, serializer::Layer::Layer_Convolution3dLayer);
448 auto fbBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_DepthToSpace);
449 auto fbDescriptor = CreateDepthToSpaceDescriptor(m_flatBufferBuilder,
453 auto fbLayer = serializer::CreateDepthToSpaceLayer(m_flatBufferBuilder, fbBaseLayer, fbDescriptor);
455 CreateAnyLayer(fbLayer.o, serializer::Layer::Layer_DepthToSpaceLayer);
464 auto fbBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_DepthwiseConvolution2d);
465 auto fbDescriptor = CreateDepthwiseConvolution2dDescriptor(m_flatBufferBuilder,
477 auto flatBufferLayer = CreateDepthwiseConvolution2dLayer(m_flatBufferBuilder,
481 CreateAnyLayer(flatBufferLayer.o, serializer::Layer::Layer_DepthwiseConvolution2dLayer);
489 auto fbDequantizeBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Dequantize);
490 auto fbDequantizeLayer = serializer::CreateDequantizeLayer(m_flatBufferBuilder, fbDequantizeBaseLayer);
492 CreateAnyLayer(fbDequantizeLayer.o, serializer::Layer::Layer_DequantizeLayer);
497 const std::vector<armnn::ConstTensor>& constants,
504 auto fbBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_DetectionPostProcess);
505 auto fbDescriptor = CreateDetectionPostProcessDescriptor(m_flatBufferBuilder,
518 flatbuffers::Offset<serializer::ConstTensor> fbAnchorsConstTensorInfo = CreateConstTensorInfo(anchors);
520 auto flatBufferLayer = CreateDetectionPostProcessLayer(m_flatBufferBuilder,
523 fbAnchorsConstTensorInfo);
525 CreateAnyLayer(flatBufferLayer.o, serializer::Layer::Layer_DetectionPostProcessLayer);
532 auto fbDivisionBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Division);
533 auto fbDivisionLayer = serializer::CreateDivisionLayer(m_flatBufferBuilder, fbDivisionBaseLayer);
535 CreateAnyLayer(fbDivisionLayer.o, serializer::Layer::Layer_DivisionLayer);
544 auto fbBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_ElementwiseBinary);
545 auto fbDescriptor = serializer::CreateElementwiseBinaryDescriptor(
549 auto fbLayer = serializer::CreateElementwiseBinaryLayer(m_flatBufferBuilder, fbBaseLayer, fbDescriptor);
550 CreateAnyLayer(fbLayer.o, serializer::Layer::Layer_ElementwiseBinaryLayer);
559 auto fbBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_ElementwiseUnary);
560 auto fbDescriptor = serializer::CreateElementwiseUnaryDescriptor(
564 auto fbLayer = serializer::CreateElementwiseUnaryLayer(m_flatBufferBuilder, fbBaseLayer, fbDescriptor);
565 CreateAnyLayer(fbLayer.o, serializer::Layer::Layer_ElementwiseUnaryLayer);
574 auto fbFillBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Fill);
576 auto fbDescriptor = serializer::CreateFillDescriptor(m_flatBufferBuilder, fillDescriptor.
m_Value);
578 auto fbFillLayer = serializer::CreateFillLayer(m_flatBufferBuilder, fbFillBaseLayer, fbDescriptor);
580 CreateAnyLayer(fbFillLayer.o, serializer::Layer::Layer_FillLayer);
587 auto flatBufferFloorBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Floor);
588 auto flatBufferFloorLayer = serializer::CreateFloorLayer(m_flatBufferBuilder, flatBufferFloorBaseLayer);
590 CreateAnyLayer(flatBufferFloorLayer.o, serializer::Layer::Layer_FloorLayer);
599 auto fbGatherDescriptor = CreateGatherDescriptor(m_flatBufferBuilder,
601 auto fbGatherBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Gather);
602 auto flatBufferLayer = serializer::CreateGatherLayer(m_flatBufferBuilder, fbGatherBaseLayer, fbGatherDescriptor);
604 CreateAnyLayer(flatBufferLayer.o, serializer::Layer::Layer_GatherLayer);
612 auto fbGatherNdBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_GatherNd);
613 auto flatBufferLayer = serializer::CreateGatherNdLayer(m_flatBufferBuilder, fbGatherNdBaseLayer);
615 CreateAnyLayer(flatBufferLayer.o, serializer::Layer::Layer_GatherNdLayer);
618 void SerializerStrategy::SerializeInstanceNormalizationLayer(
625 auto fbDescriptor = serializer::CreateInstanceNormalizationDescriptor(
627 instanceNormalizationDescriptor.
m_Gamma,
628 instanceNormalizationDescriptor.
m_Beta,
629 instanceNormalizationDescriptor.
m_Eps,
632 auto fbBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_InstanceNormalization);
633 auto fbLayer = serializer::CreateInstanceNormalizationLayer(m_flatBufferBuilder, fbBaseLayer, fbDescriptor);
635 CreateAnyLayer(fbLayer.o, serializer::Layer::Layer_InstanceNormalizationLayer);
645 auto fbBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_L2Normalization);
648 auto fbDescriptor = serializer::CreateL2NormalizationDescriptor(
651 l2NormalizationDescriptor.
m_Eps);
654 auto fbLayer = serializer::CreateL2NormalizationLayer(m_flatBufferBuilder, fbBaseLayer, fbDescriptor);
656 CreateAnyLayer(fbLayer.o, serializer::Layer::Layer_L2NormalizationLayer);
665 auto fbBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_LogicalBinary);
666 auto fbDescriptor = serializer::CreateLogicalBinaryDescriptor(
670 auto fbLayer = serializer::CreateLogicalBinaryLayer(m_flatBufferBuilder, fbBaseLayer, fbDescriptor);
671 CreateAnyLayer(fbLayer.o, serializer::Layer::Layer_LogicalBinaryLayer);
681 auto flatBufferLogSoftmaxBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_LogSoftmax);
684 auto flatBufferLogSoftmaxDesc =
685 serializer::CreateLogSoftmaxDescriptor(m_flatBufferBuilder,
686 logSoftmaxDescriptor.
m_Beta,
687 logSoftmaxDescriptor.
m_Axis);
690 auto flatBufferLogSoftmaxLayer =
691 serializer::CreateLogSoftmaxLayer(m_flatBufferBuilder,
692 flatBufferLogSoftmaxBaseLayer,
693 flatBufferLogSoftmaxDesc);
695 CreateAnyLayer(flatBufferLogSoftmaxLayer.o, serializer::Layer::Layer_LogSoftmaxLayer);
700 const std::vector<armnn::ConstTensor>& constants,
705 auto fbLstmBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Lstm);
707 auto fbLstmDescriptor = serializer::CreateLstmDescriptor(
721 auto inputToForgetWeights = CreateConstTensorInfo(constants[i++]);
722 auto inputToCellWeights = CreateConstTensorInfo(constants[i++]);
723 auto inputToOutputWeights = CreateConstTensorInfo(constants[i++]);
724 auto recurrentToForgetWeights = CreateConstTensorInfo(constants[i++]);
725 auto recurrentToCellWeights = CreateConstTensorInfo(constants[i++]);
726 auto recurrentToOutputWeights = CreateConstTensorInfo(constants[i++]);
727 auto forgetGateBias = CreateConstTensorInfo(constants[i++]);
728 auto cellBias = CreateConstTensorInfo(constants[i++]);
729 auto outputGateBias = CreateConstTensorInfo(constants[i++]);
734 flatbuffers::Offset<serializer::ConstTensor> inputToInputWeights;
735 flatbuffers::Offset<serializer::ConstTensor> recurrentToInputWeights;
736 flatbuffers::Offset<serializer::ConstTensor> cellToInputWeights;
737 flatbuffers::Offset<serializer::ConstTensor> inputGateBias;
738 flatbuffers::Offset<serializer::ConstTensor> projectionWeights;
739 flatbuffers::Offset<serializer::ConstTensor> projectionBias;
740 flatbuffers::Offset<serializer::ConstTensor> cellToForgetWeights;
741 flatbuffers::Offset<serializer::ConstTensor> cellToOutputWeights;
742 flatbuffers::Offset<serializer::ConstTensor> inputLayerNormWeights;
743 flatbuffers::Offset<serializer::ConstTensor> forgetLayerNormWeights;
744 flatbuffers::Offset<serializer::ConstTensor> cellLayerNormWeights;
745 flatbuffers::Offset<serializer::ConstTensor> outputLayerNormWeights;
749 inputToInputWeights = CreateConstTensorInfo(constants[i++]);
750 recurrentToInputWeights = CreateConstTensorInfo(constants[i++]);
751 inputGateBias = CreateConstTensorInfo(constants[i++]);
758 cellToInputWeights = CreateConstTensorInfo(constants[i++]);
760 cellToForgetWeights = CreateConstTensorInfo(constants[i++]);
761 cellToOutputWeights = CreateConstTensorInfo(constants[i++]);
766 projectionWeights = CreateConstTensorInfo(constants[i++]);
767 projectionBias = CreateConstTensorInfo(constants[i++]);
774 inputLayerNormWeights = CreateConstTensorInfo(constants[i++]);
776 forgetLayerNormWeights = CreateConstTensorInfo(constants[i++]);
777 cellLayerNormWeights = CreateConstTensorInfo(constants[i++]);
778 outputLayerNormWeights = CreateConstTensorInfo(constants[i++]);
781 auto fbLstmParams = serializer::CreateLstmInputParams(
783 inputToForgetWeights,
785 inputToOutputWeights,
786 recurrentToForgetWeights,
787 recurrentToCellWeights,
788 recurrentToOutputWeights,
793 recurrentToInputWeights,
800 inputLayerNormWeights,
801 forgetLayerNormWeights,
802 cellLayerNormWeights,
803 outputLayerNormWeights);
805 auto fbLstmLayer = serializer::CreateLstmLayer(
811 CreateAnyLayer(fbLstmLayer.o, serializer::Layer::Layer_LstmLayer);
818 auto fbMaximumBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Maximum);
819 auto fbMaximumLayer = serializer::CreateMaximumLayer(m_flatBufferBuilder, fbMaximumBaseLayer);
821 CreateAnyLayer(fbMaximumLayer.o, serializer::Layer::Layer_MaximumLayer);
830 auto fbMeanBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Mean);
831 auto fbMeanDescriptor = serializer::CreateMeanDescriptor(m_flatBufferBuilder,
832 m_flatBufferBuilder.CreateVector(descriptor.
m_Axis),
835 auto fbMeanLayer = serializer::CreateMeanLayer(m_flatBufferBuilder,
839 CreateAnyLayer(fbMeanLayer.o, serializer::Layer::Layer_MeanLayer);
846 auto fbMinimumBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Minimum);
847 auto fbMinimumLayer = serializer::CreateMinimumLayer(m_flatBufferBuilder, fbMinimumBaseLayer);
849 CreateAnyLayer(fbMinimumLayer.o, serializer::Layer::Layer_MinimumLayer);
856 auto fbMergeBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Merge);
857 auto fbMergeLayer = serializer::CreateMergeLayer(m_flatBufferBuilder, fbMergeBaseLayer);
859 CreateAnyLayer(fbMergeLayer.o, serializer::Layer::Layer_MergeLayer);
868 auto flatBufferConcatBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Concat);
870 std::vector<flatbuffers::Offset<UintVector>> views;
871 for (
unsigned int v = 0; v < concatDescriptor.
GetNumViews(); ++v)
874 std::vector<uint32_t> origins;
877 origins.push_back(origin[d]);
879 auto view = m_flatBufferBuilder.CreateVector(origins);
880 auto uintVector = CreateUintVector(m_flatBufferBuilder, view);
881 views.push_back(uintVector);
884 auto flatBufferConcatDescriptor = CreateOriginsDescriptor(m_flatBufferBuilder,
888 m_flatBufferBuilder.CreateVector(views));
890 auto flatBufferLayer = CreateConcatLayer(m_flatBufferBuilder,
891 flatBufferConcatBaseLayer,
892 flatBufferConcatDescriptor);
894 CreateAnyLayer(flatBufferLayer.o, serializer::Layer::Layer_ConcatLayer);
901 auto fbMultiplicationBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Multiplication);
902 auto fbMultiplicationLayer = serializer::CreateMultiplicationLayer(m_flatBufferBuilder,
903 fbMultiplicationBaseLayer);
905 CreateAnyLayer(fbMultiplicationLayer.o, serializer::Layer::Layer_MultiplicationLayer);
914 auto flatBufferBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Pad);
916 std::vector<unsigned int> padList;
919 padList.push_back(p.first);
920 padList.push_back(p.second);
923 auto flatBufferPadDesc = serializer::CreatePadDescriptor(m_flatBufferBuilder,
924 m_flatBufferBuilder.CreateVector(padList),
928 auto flatBufferPadLayer = serializer::CreatePadLayer(m_flatBufferBuilder,
932 CreateAnyLayer(flatBufferPadLayer.o, serializer::Layer::Layer_PadLayer);
942 auto flatBufferPermuteBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Permute);
944 std::vector<unsigned int> dimMappings;
950 auto flatBufferPermuteDesc = serializer::CreatePermuteDescriptor(m_flatBufferBuilder,
951 m_flatBufferBuilder.CreateVector(dimMappings));
954 auto flatBufferPermuteLayer = serializer::CreatePermuteLayer(m_flatBufferBuilder,
955 flatBufferPermuteBaseLayer,
956 flatBufferPermuteDesc);
959 CreateAnyLayer(flatBufferPermuteLayer.o, serializer::Layer::Layer_PermuteLayer);
967 auto flatBufferBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Rank);
968 auto flatBufferRankLayer = serializer::CreateRankLayer(m_flatBufferBuilder, flatBufferBaseLayer);
970 CreateAnyLayer(flatBufferRankLayer.o, serializer::Layer::Layer_RankLayer);
977 auto fbReduceBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Reduce);
978 auto fbDescriptor = CreateReduceDescriptor(m_flatBufferBuilder,
980 m_flatBufferBuilder.CreateVector(reduceDescriptor.
m_vAxis),
982 auto fbReduceLayer = serializer::CreateReduceLayer(m_flatBufferBuilder,
986 CreateAnyLayer(fbReduceLayer.o, serializer::Layer::Layer_ReduceLayer);
997 auto flatBufferReshapeBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Reshape);
999 std::vector<unsigned int> targetShape;
1005 auto flatBufferReshapeDesc = serializer::CreateReshapeDescriptor(m_flatBufferBuilder,
1006 m_flatBufferBuilder.CreateVector(targetShape));
1009 auto flatBufferReshapeLayer = serializer::CreateReshapeLayer(m_flatBufferBuilder, flatBufferReshapeBaseLayer,
1010 flatBufferReshapeDesc);
1013 CreateAnyLayer(flatBufferReshapeLayer.o, serializer::Layer::Layer_ReshapeLayer);
1022 auto flatBufferBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Resize);
1024 auto flatBufferDescriptor =
1025 CreateResizeDescriptor(m_flatBufferBuilder,
1033 auto flatBufferLayer = serializer::CreateResizeLayer(m_flatBufferBuilder,
1034 flatBufferBaseLayer,
1035 flatBufferDescriptor);
1037 CreateAnyLayer(flatBufferLayer.o, serializer::Layer::Layer_ResizeLayer);
1045 auto flatBufferBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_ReverseV2);
1047 auto flatBufferLayer = serializer::CreateReverseV2Layer(m_flatBufferBuilder,
1048 flatBufferBaseLayer);
1050 CreateAnyLayer(flatBufferLayer.o, serializer::Layer::Layer_ReverseV2Layer);
1059 auto fbSliceBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Slice);
1060 auto fbSliceDescriptor = CreateSliceDescriptor(m_flatBufferBuilder,
1061 m_flatBufferBuilder.CreateVector(sliceDescriptor.
m_Begin),
1062 m_flatBufferBuilder.CreateVector(sliceDescriptor.
m_Size));
1064 auto fbSliceLayer = serializer::CreateSliceLayer(m_flatBufferBuilder, fbSliceBaseLayer, fbSliceDescriptor);
1066 CreateAnyLayer(fbSliceLayer.o, serializer::Layer::Layer_SliceLayer);
1077 auto flatBufferSoftmaxBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Softmax);
1080 auto flatBufferSoftmaxDesc =
1081 serializer::CreateSoftmaxDescriptor(m_flatBufferBuilder,
1082 softmaxDescriptor.
m_Beta,
1083 softmaxDescriptor.
m_Axis);
1086 auto flatBufferSoftmaxLayer =
1087 serializer::CreateSoftmaxLayer(m_flatBufferBuilder,
1088 flatBufferSoftmaxBaseLayer,
1089 flatBufferSoftmaxDesc);
1091 CreateAnyLayer(flatBufferSoftmaxLayer.o, serializer::Layer::Layer_SoftmaxLayer);
1100 auto fbPooling2dBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Pooling2d);
1101 auto fbPooling2dDescriptor = serializer::CreatePooling2dDescriptor(
1102 m_flatBufferBuilder,
1116 auto fbPooling2dLayer = serializer::CreatePooling2dLayer(m_flatBufferBuilder,
1117 fbPooling2dBaseLayer,
1118 fbPooling2dDescriptor);
1120 CreateAnyLayer(fbPooling2dLayer.o, serializer::Layer::Layer_Pooling2dLayer);
1129 auto fbPooling3dBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Pooling3d);
1130 auto fbPooling3dDescriptor = serializer::CreatePooling3dDescriptor(
1131 m_flatBufferBuilder,
1149 auto fbPooling3dLayer = serializer::CreatePooling3dLayer(m_flatBufferBuilder,
1150 fbPooling3dBaseLayer,
1151 fbPooling3dDescriptor);
1153 CreateAnyLayer(fbPooling3dLayer.o, serializer::Layer::Layer_Pooling3dLayer);
1162 auto flatBufferPreluBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Prelu);
1165 auto flatBufferPreluLayer = serializer::CreatePreluLayer(m_flatBufferBuilder, flatBufferPreluBaseLayer);
1168 CreateAnyLayer(flatBufferPreluLayer.o, serializer::Layer::Layer_PreluLayer);
1175 auto fbQuantizeBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Quantize);
1176 auto fbQuantizeLayer = serializer::CreateQuantizeLayer(m_flatBufferBuilder,
1177 fbQuantizeBaseLayer);
1178 CreateAnyLayer(fbQuantizeLayer.o, serializer::Layer::Layer_QuantizeLayer);
1187 auto flatBufferBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_FullyConnected);
1190 auto flatBufferDescriptor =
1191 serializer::CreateFullyConnectedDescriptor(m_flatBufferBuilder,
1197 auto flatBufferLayer = serializer::CreateFullyConnectedLayer(m_flatBufferBuilder,
1198 flatBufferBaseLayer,
1199 flatBufferDescriptor);
1202 CreateAnyLayer(flatBufferLayer.o, serializer::Layer::Layer_FullyConnectedLayer);
1213 auto flatBufferBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_SpaceToBatchNd);
1215 std::vector<unsigned int> padList;
1216 padList.reserve(spaceToBatchNdDescriptor.
m_PadList.size()*2);
1217 for (
auto& pad : spaceToBatchNdDescriptor.
m_PadList)
1219 padList.push_back(pad.first);
1220 padList.push_back(pad.second);
1223 auto flatBufferDescriptor =
1224 CreateSpaceToBatchNdDescriptor(m_flatBufferBuilder,
1225 m_flatBufferBuilder.CreateVector(spaceToBatchNdDescriptor.
m_BlockShape),
1226 m_flatBufferBuilder.CreateVector(padList),
1229 auto flatBufferLayer = serializer::CreateSpaceToBatchNdLayer(m_flatBufferBuilder,
1230 flatBufferBaseLayer,
1231 flatBufferDescriptor);
1233 CreateAnyLayer(flatBufferLayer.o, serializer::Layer::Layer_SpaceToBatchNdLayer);
1243 auto flatBufferBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_SpaceToDepth);
1244 auto flatBufferDescriptor =
1245 CreateSpaceToDepthDescriptor(m_flatBufferBuilder,
1249 auto flatBufferLayer = serializer::CreateSpaceToDepthLayer(m_flatBufferBuilder,
1250 flatBufferBaseLayer,
1251 flatBufferDescriptor);
1253 CreateAnyLayer(flatBufferLayer.o, serializer::Layer::Layer_SpaceToDepthLayer);
1264 std::vector<flatbuffers::Offset<UintVector>> flatBufferViewOrigins;
1265 flatBufferViewOrigins.reserve(viewsDescriptor.
GetNumViews());
1267 for(
unsigned int vIdx = 0; vIdx < viewsDescriptor.
GetNumViews(); ++vIdx)
1269 std::vector<uint32_t> viewOrigin;
1273 for(
unsigned int dIdx = 0; dIdx < viewsDescriptor.
GetNumDimensions(); ++dIdx)
1275 viewOrigin.push_back(viewsDescriptor.
GetViewOrigin(vIdx)[dIdx]);
1278 flatBufferViewOrigins.push_back(CreateUintVector(m_flatBufferBuilder,
1279 m_flatBufferBuilder.CreateVector(viewOrigin)));
1283 auto flatBufferOriginDescriptor = CreateOriginsDescriptor(m_flatBufferBuilder,
1287 m_flatBufferBuilder.CreateVector(flatBufferViewOrigins));
1290 std::vector<flatbuffers::Offset<UintVector>> flatBufferViewSizes;
1291 flatBufferViewSizes.reserve(viewsDescriptor.
GetNumViews());
1293 for(
unsigned int vIdx = 0; vIdx < viewsDescriptor.
GetNumViews(); ++vIdx)
1295 std::vector<uint32_t> viewSize;
1299 for(
unsigned int dIdx = 0; dIdx < viewsDescriptor.
GetNumDimensions(); ++dIdx)
1301 viewSize.push_back(viewsDescriptor.
GetViewSizes(vIdx)[dIdx]);
1304 flatBufferViewSizes.push_back(CreateUintVector(m_flatBufferBuilder,
1305 m_flatBufferBuilder.CreateVector(viewSize)));
1309 auto flatBufferViewsDescriptor = CreateViewsDescriptor(m_flatBufferBuilder,
1310 flatBufferOriginDescriptor,
1311 m_flatBufferBuilder.CreateVector(flatBufferViewSizes),
1316 auto flatBufferBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Splitter);
1318 auto flatBufferSplitterLayer = serializer::CreateSplitterLayer(m_flatBufferBuilder,
1319 flatBufferBaseLayer,
1320 flatBufferViewsDescriptor);
1322 CreateAnyLayer(flatBufferSplitterLayer.o, serializer::Layer::Layer_SplitterLayer);
1331 auto fbNormalizationBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Normalization);
1333 auto fbNormalizationDescriptor = serializer::CreateNormalizationDescriptor(
1334 m_flatBufferBuilder,
1343 auto flatBufferLayer = serializer::CreateNormalizationLayer(m_flatBufferBuilder,
1344 fbNormalizationBaseLayer,
1345 fbNormalizationDescriptor);
1347 CreateAnyLayer(flatBufferLayer.o, serializer::Layer::Layer_NormalizationLayer);
1355 auto shapeBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Shape);
1356 auto shapeLayer = serializer::CreateShapeLayer(m_flatBufferBuilder, shapeBaseLayer);
1358 CreateAnyLayer(shapeLayer.o, serializer::Layer::Layer_ShapeLayer);
1367 auto stackBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Stack);
1369 std::vector<unsigned int> inputShape;
1375 auto flatBufferStackDescriptor = CreateStackDescriptor(m_flatBufferBuilder,
1378 m_flatBufferBuilder.CreateVector(inputShape));
1380 auto stackLayer = serializer::CreateStackLayer(m_flatBufferBuilder, stackBaseLayer, flatBufferStackDescriptor);
1381 CreateAnyLayer(stackLayer.o, serializer::Layer::Layer_StackLayer);
1390 auto fbDescriptor = serializer::CreateStandInDescriptor(m_flatBufferBuilder,
1394 auto fbBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_StandIn);
1395 auto fbLayer = serializer::CreateStandInLayer(m_flatBufferBuilder, fbBaseLayer, fbDescriptor);
1397 CreateAnyLayer(fbLayer.o, serializer::Layer::Layer_StandInLayer);
1406 auto flatBufferBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_StridedSlice);
1408 auto flatBufferDescriptor =
1409 CreateStridedSliceDescriptor(m_flatBufferBuilder,
1410 m_flatBufferBuilder.CreateVector(stridedSliceDescriptor.
m_Begin),
1411 m_flatBufferBuilder.CreateVector(stridedSliceDescriptor.
m_End),
1412 m_flatBufferBuilder.CreateVector(stridedSliceDescriptor.
m_Stride),
1420 auto flatBufferLayer = serializer::CreateStridedSliceLayer(m_flatBufferBuilder,
1421 flatBufferBaseLayer,
1422 flatBufferDescriptor);
1424 CreateAnyLayer(flatBufferLayer.o, serializer::Layer::Layer_StridedSliceLayer);
1431 auto fbSubtractionBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Subtraction);
1432 auto fbSubtractionLayer = serializer::CreateSubtractionLayer(m_flatBufferBuilder, fbSubtractionBaseLayer);
1434 CreateAnyLayer(fbSubtractionLayer.o, serializer::Layer::Layer_SubtractionLayer);
1441 auto fbSwitchBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Switch);
1442 auto fbSwitchLayer = serializer::CreateSwitchLayer(m_flatBufferBuilder, fbSwitchBaseLayer);
1444 CreateAnyLayer(fbSwitchLayer.o, serializer::Layer::Layer_SwitchLayer);
1454 auto flatBufferBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Tile);
1456 auto flatBufferDesc = serializer::CreateTileDescriptor(m_flatBufferBuilder,
1457 m_flatBufferBuilder.CreateVector(descriptor.
m_Multiples));
1460 auto flatBufferLayer = serializer::CreateTileLayer(m_flatBufferBuilder,
1461 flatBufferBaseLayer,
1465 CreateAnyLayer(flatBufferLayer.o, serializer::Layer::Layer_TileLayer);
1468 void SerializerStrategy::SerializeTransposeConvolution2dLayer(
1471 const std::vector<armnn::ConstTensor>& constants,
1478 auto fbBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Convolution2d);
1479 auto fbDescriptor = CreateTransposeConvolution2dDescriptor(m_flatBufferBuilder,
1490 auto fbWeightsConstTensorInfo = CreateConstTensorInfo(weights);
1491 flatbuffers::Offset<serializer::ConstTensor> fbBiasesConstTensorInfo;
1492 if (constants.size() > 1)
1495 fbBiasesConstTensorInfo = CreateConstTensorInfo(biases);
1498 auto fbLayer = CreateTransposeConvolution2dLayer(m_flatBufferBuilder,
1501 fbWeightsConstTensorInfo,
1502 fbBiasesConstTensorInfo);
1504 CreateAnyLayer(fbLayer.o, serializer::Layer::Layer_TransposeConvolution2dLayer);
1514 auto flatBufferBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Transpose);
1516 std::vector<unsigned int> dimMappings;
1522 auto flatBufferDesc = serializer::CreateTransposeDescriptor(m_flatBufferBuilder,
1523 m_flatBufferBuilder.CreateVector(dimMappings));
1526 auto flatBufferLayer = serializer::CreateTransposeLayer(m_flatBufferBuilder,
1527 flatBufferBaseLayer,
1531 CreateAnyLayer(flatBufferLayer.o, serializer::Layer::Layer_TransposeLayer);
1536 const std::vector<armnn::ConstTensor>& constants,
1541 auto fbQLstmBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_QLstm);
1543 auto fbQLstmDescriptor = serializer::CreateQLstmDescriptor(
1544 m_flatBufferBuilder,
1563 auto inputToForgetWeights = CreateConstTensorInfo(constants[i++]);
1564 auto inputToCellWeights = CreateConstTensorInfo(constants[i++]);
1565 auto inputToOutputWeights = CreateConstTensorInfo(constants[i++]);
1566 auto recurrentToForgetWeights = CreateConstTensorInfo(constants[i++]);
1567 auto recurrentToCellWeights = CreateConstTensorInfo(constants[i++]);
1568 auto recurrentToOutputWeights = CreateConstTensorInfo(constants[i++]);
1569 auto forgetGateBias = CreateConstTensorInfo(constants[i++]);
1570 auto cellBias = CreateConstTensorInfo(constants[i++]);
1571 auto outputGateBias = CreateConstTensorInfo(constants[i++]);
1574 flatbuffers::Offset<serializer::ConstTensor> inputToInputWeights;
1575 flatbuffers::Offset<serializer::ConstTensor> recurrentToInputWeights;
1576 flatbuffers::Offset<serializer::ConstTensor> inputGateBias;
1580 inputToInputWeights = CreateConstTensorInfo(constants[i++]);
1581 recurrentToInputWeights = CreateConstTensorInfo(constants[i++]);
1582 inputGateBias = CreateConstTensorInfo(constants[i++]);
1586 flatbuffers::Offset<serializer::ConstTensor> cellToInputWeights;
1587 flatbuffers::Offset<serializer::ConstTensor> cellToForgetWeights;
1588 flatbuffers::Offset<serializer::ConstTensor> cellToOutputWeights;
1594 cellToInputWeights = CreateConstTensorInfo(constants[i++]);
1596 cellToForgetWeights = CreateConstTensorInfo(constants[i++]);
1597 cellToOutputWeights = CreateConstTensorInfo(constants[i++]);
1601 flatbuffers::Offset<serializer::ConstTensor> projectionWeights;
1602 flatbuffers::Offset<serializer::ConstTensor> projectionBias;
1606 projectionWeights = CreateConstTensorInfo(constants[i++]);
1607 projectionBias = CreateConstTensorInfo(constants[i++]);
1611 flatbuffers::Offset<serializer::ConstTensor> inputLayerNormWeights;
1612 flatbuffers::Offset<serializer::ConstTensor> forgetLayerNormWeights;
1613 flatbuffers::Offset<serializer::ConstTensor> cellLayerNormWeights;
1614 flatbuffers::Offset<serializer::ConstTensor> outputLayerNormWeights;
1620 inputLayerNormWeights = CreateConstTensorInfo(constants[i++]);
1622 forgetLayerNormWeights = CreateConstTensorInfo(constants[i++]);
1623 cellLayerNormWeights = CreateConstTensorInfo(constants[i++]);
1624 outputLayerNormWeights = CreateConstTensorInfo(constants[i++]);
1627 auto fbQLstmParams = serializer::CreateQLstmInputParams(
1628 m_flatBufferBuilder,
1629 inputToForgetWeights,
1631 inputToOutputWeights,
1632 recurrentToForgetWeights,
1633 recurrentToCellWeights,
1634 recurrentToOutputWeights,
1638 inputToInputWeights,
1639 recurrentToInputWeights,
1644 cellToForgetWeights,
1645 cellToOutputWeights,
1646 inputLayerNormWeights,
1647 forgetLayerNormWeights,
1648 cellLayerNormWeights,
1649 outputLayerNormWeights);
1651 auto fbQLstmLayer = serializer::CreateQLstmLayer(
1652 m_flatBufferBuilder,
1657 CreateAnyLayer(fbQLstmLayer.o, serializer::Layer::Layer_QLstmLayer);
1661 const std::vector<armnn::ConstTensor>& constants,
1666 auto fbQuantizedLstmBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_QuantizedLstm);
1672 auto inputToInputWeights = CreateConstTensorInfo(constants[i++]);
1673 auto inputToForgetWeights = CreateConstTensorInfo(constants[i++]);
1674 auto inputToCellWeights = CreateConstTensorInfo(constants[i++]);
1675 auto inputToOutputWeights = CreateConstTensorInfo(constants[i++]);
1677 auto recurrentToInputWeights = CreateConstTensorInfo(constants[i++]);
1678 auto recurrentToForgetWeights = CreateConstTensorInfo(constants[i++]);
1679 auto recurrentToCellWeights = CreateConstTensorInfo(constants[i++]);
1680 auto recurrentToOutputWeights = CreateConstTensorInfo(constants[i++]);
1682 auto inputGateBias = CreateConstTensorInfo(constants[i++]);
1683 auto forgetGateBias = CreateConstTensorInfo(constants[i++]);
1684 auto cellBias = CreateConstTensorInfo(constants[i++]);
1685 auto outputGateBias = CreateConstTensorInfo(constants[i++]);
1687 auto fbQuantizedLstmParams = serializer::CreateQuantizedLstmInputParams(
1688 m_flatBufferBuilder,
1689 inputToInputWeights,
1690 inputToForgetWeights,
1692 inputToOutputWeights,
1693 recurrentToInputWeights,
1694 recurrentToForgetWeights,
1695 recurrentToCellWeights,
1696 recurrentToOutputWeights,
1702 auto fbQuantizedLstmLayer = serializer::CreateQuantizedLstmLayer(
1703 m_flatBufferBuilder,
1704 fbQuantizedLstmBaseLayer,
1705 fbQuantizedLstmParams);
1707 CreateAnyLayer(fbQuantizedLstmLayer.o, serializer::Layer::Layer_QuantizedLstmLayer);
1710 void SerializerStrategy::SerializeUnidirectionalSequenceLstmLayer(
1713 const std::vector<armnn::ConstTensor>& constants,
1718 auto fbUnidirectionalSequenceLstmBaseLayer =
1719 CreateLayerBase(layer, serializer::LayerType::LayerType_UnidirectionalSequenceLstm);
1721 auto fbUnidirectionalSequenceLstmDescriptor = serializer::CreateUnidirectionalSequenceLstmDescriptor(
1722 m_flatBufferBuilder,
1736 auto inputToForgetWeights = CreateConstTensorInfo(constants[i++]);
1737 auto inputToCellWeights = CreateConstTensorInfo(constants[i++]);
1738 auto inputToOutputWeights = CreateConstTensorInfo(constants[i++]);
1739 auto recurrentToForgetWeights = CreateConstTensorInfo(constants[i++]);
1740 auto recurrentToCellWeights = CreateConstTensorInfo(constants[i++]);
1741 auto recurrentToOutputWeights = CreateConstTensorInfo(constants[i++]);
1742 auto forgetGateBias = CreateConstTensorInfo(constants[i++]);
1743 auto cellBias = CreateConstTensorInfo(constants[i++]);
1744 auto outputGateBias = CreateConstTensorInfo(constants[i++]);
1747 flatbuffers::Offset<serializer::ConstTensor> inputToInputWeights;
1748 flatbuffers::Offset<serializer::ConstTensor> recurrentToInputWeights;
1749 flatbuffers::Offset<serializer::ConstTensor> cellToInputWeights;
1750 flatbuffers::Offset<serializer::ConstTensor> inputGateBias;
1751 flatbuffers::Offset<serializer::ConstTensor> projectionWeights;
1752 flatbuffers::Offset<serializer::ConstTensor> projectionBias;
1753 flatbuffers::Offset<serializer::ConstTensor> cellToForgetWeights;
1754 flatbuffers::Offset<serializer::ConstTensor> cellToOutputWeights;
1755 flatbuffers::Offset<serializer::ConstTensor> inputLayerNormWeights;
1756 flatbuffers::Offset<serializer::ConstTensor> forgetLayerNormWeights;
1757 flatbuffers::Offset<serializer::ConstTensor> cellLayerNormWeights;
1758 flatbuffers::Offset<serializer::ConstTensor> outputLayerNormWeights;
1762 inputToInputWeights = CreateConstTensorInfo(constants[i++]);
1763 recurrentToInputWeights = CreateConstTensorInfo(constants[i++]);
1764 inputGateBias = CreateConstTensorInfo(constants[i++]);
1771 cellToInputWeights = CreateConstTensorInfo(constants[i++]);
1773 cellToForgetWeights = CreateConstTensorInfo(constants[i++]);
1774 cellToOutputWeights = CreateConstTensorInfo(constants[i++]);
1779 projectionWeights = CreateConstTensorInfo(constants[i++]);
1780 projectionBias = CreateConstTensorInfo(constants[i++]);
1787 inputLayerNormWeights = CreateConstTensorInfo(constants[i++]);
1789 forgetLayerNormWeights = CreateConstTensorInfo(constants[i++]);
1790 cellLayerNormWeights = CreateConstTensorInfo(constants[i++]);
1791 outputLayerNormWeights = CreateConstTensorInfo(constants[i++]);
1794 auto fbUnidirectionalSequenceLstmParams = serializer::CreateLstmInputParams(
1795 m_flatBufferBuilder,
1796 inputToForgetWeights,
1798 inputToOutputWeights,
1799 recurrentToForgetWeights,
1800 recurrentToCellWeights,
1801 recurrentToOutputWeights,
1805 inputToInputWeights,
1806 recurrentToInputWeights,
1811 cellToForgetWeights,
1812 cellToOutputWeights,
1813 inputLayerNormWeights,
1814 forgetLayerNormWeights,
1815 cellLayerNormWeights,
1816 outputLayerNormWeights);
1818 auto fbUnidirectionalSequenceLstmLayer = serializer::CreateUnidirectionalSequenceLstmLayer(
1819 m_flatBufferBuilder,
1820 fbUnidirectionalSequenceLstmBaseLayer,
1821 fbUnidirectionalSequenceLstmDescriptor,
1822 fbUnidirectionalSequenceLstmParams);
1824 CreateAnyLayer(fbUnidirectionalSequenceLstmLayer.o, serializer::Layer::Layer_UnidirectionalSequenceLstmLayer);
1827 fb::Offset<serializer::LayerBase> SerializerStrategy::CreateLayerBase(
const IConnectableLayer* layer,
1831 uint32_t fbIndex = GetSerializedId(layer->
GetGuid());
1833 std::vector<fb::Offset<serializer::InputSlot>> inputSlots = CreateInputSlots(layer);
1834 std::vector<fb::Offset<serializer::OutputSlot>> outputSlots = CreateOutputSlots(layer);
1836 return serializer::CreateLayerBase(m_flatBufferBuilder,
1838 m_flatBufferBuilder.CreateString(layer->
GetName()),
1840 m_flatBufferBuilder.CreateVector(inputSlots),
1841 m_flatBufferBuilder.CreateVector(outputSlots));
1844 void SerializerStrategy::CreateAnyLayer(
const flatbuffers::Offset<void>& layer,
const serializer::Layer serializerLayer)
1847 auto anyLayer = armnnSerializer::CreateAnyLayer(m_flatBufferBuilder, serializerLayer, layer);
1848 m_serializedLayers.push_back(anyLayer);
1851 template <
typename T>
1852 flatbuffers::Offset<flatbuffers::Vector<T>> SerializerStrategy::CreateDataVector(
const void* memory,
unsigned int size)
1854 const T* buffer =
reinterpret_cast<const T*
>(memory);
1855 std::vector<T> vector(buffer, buffer + (size /
sizeof(T)));
1856 auto fbVector = m_flatBufferBuilder.CreateVector(vector);
1860 flatbuffers::Offset<TensorInfo> SerializerStrategy::CreateTensorInfo(
const armnn::TensorInfo& tensorInfo)
1863 std::vector<unsigned int> shape;
1864 std::vector<bool> specificity;
1867 for(
unsigned int dim = 0; dim < tensorInfo.
GetShape().GetNumDimensions(); ++dim)
1873 shape.push_back(tensorInfo.
GetShape()[dim]);
1884 auto flatBufferTensorInfo =
1885 serializer::CreateTensorInfo(m_flatBufferBuilder,
1886 m_flatBufferBuilder.CreateVector(shape),
1892 static_cast<unsigned int>
1894 m_flatBufferBuilder.CreateVector(specificity));
1895 return flatBufferTensorInfo;
1899 auto flatBufferTensorInfo = serializer::CreateTensorInfo(m_flatBufferBuilder,
1900 m_flatBufferBuilder.CreateVector(shape),
1906 static_cast<unsigned int>
1908 m_flatBufferBuilder.CreateVector(specificity));
1909 return flatBufferTensorInfo;
1912 flatbuffers::Offset<serializer::ConstTensor>
1917 flatbuffers::Offset<void> fbPayload;
1924 flatbuffers::Offset<serializer::LongData> flatBuffersData = serializer::CreateLongData(
1925 m_flatBufferBuilder,
1927 fbPayload = flatBuffersData.o;
1934 flatbuffers::Offset<serializer::IntData> flatBuffersData = serializer::CreateIntData(
1935 m_flatBufferBuilder,
1937 fbPayload = flatBuffersData.o;
1945 flatbuffers::Offset<serializer::ShortData> flatBuffersData = serializer::CreateShortData(
1946 m_flatBufferBuilder,
1948 fbPayload = flatBuffersData.o;
1958 flatbuffers::Offset<serializer::ByteData> flatBuffersData = serializer::CreateByteData(
1959 m_flatBufferBuilder,
1961 fbPayload = flatBuffersData.o;
1964 flatbuffers::Offset<serializer::ConstTensor> flatBufferConstTensor = serializer::CreateConstTensor(
1965 m_flatBufferBuilder,
1966 CreateTensorInfo(tensorInfo),
1969 return flatBufferConstTensor;
1972 flatbuffers::Offset<armnnSerializer::FeatureCompatibilityVersions> SerializerStrategy::GetVersionTable()
1974 flatbuffers::Offset<armnnSerializer::FeatureCompatibilityVersions> versionsTable =
1975 serializer::CreateFeatureCompatibilityVersions(
1976 m_flatBufferBuilder,
1981 return versionsTable;
1984 std::vector<fb::Offset<serializer::InputSlot>>
1987 std::vector<fb::Offset<serializer::InputSlot>> inputSlots;
1990 for (
unsigned int slotIndex = 0; slotIndex<layer->
GetNumInputSlots(); ++slotIndex)
1998 flatbuffers::Offset<TensorInfo> overriddenTensorInfo = CreateTensorInfo(inputSlot.
GetTensorInfo());
2004 inputSlots.push_back(serializer::CreateInputSlot(m_flatBufferBuilder, slotIndex, &conn, isOverridden,
2005 overriddenTensorInfo));
2010 std::vector<fb::Offset<serializer::OutputSlot>>
2013 std::vector<fb::Offset<serializer::OutputSlot>> outputSlots;
2016 for (
unsigned int slotIndex = 0; slotIndex < layer->
GetNumOutputSlots(); ++slotIndex)
2022 outputSlots.push_back(serializer::CreateOutputSlot(m_flatBufferBuilder,
2024 CreateTensorInfo(tensorInfo)));
2031 const std::vector<armnn::ConstTensor>& constants,
2043 SerializeActivationLayer(layer, layerDescriptor, name);
2048 SerializeAdditionLayer(layer, name);
2055 SerializeArgMinMaxLayer(layer, layerDescriptor, name);
2062 SerializeBatchMatMulLayer(layer,
2071 SerializeBatchNormalizationLayer(layer,
2081 SerializeBatchToSpaceNdLayer(layer,
2088 SerializeCastLayer(layer, name);
2095 SerializeChannelShuffleLayer(layer,
2104 SerializeComparisonLayer(layer,
2113 SerializeConcatLayer(layer,
2120 SerializeConstantLayer(layer,
2129 SerializeConvolution2dLayer(layer,
2138 SerializeConvolution3dLayer(layer,
2147 SerializeDepthToSpaceLayer(layer,
2156 SerializeDepthwiseConvolution2dLayer(layer,
2163 SerializeDequantizeLayer(layer,
2171 SerializeDetectionPostProcessLayer(layer, layerDescriptor, constants, name);
2176 SerializeDivisionLayer(layer, name);
2183 SerializeElementwiseBinaryLayer(layer, layerDescriptor, name);
2190 SerializeElementwiseUnaryLayer(layer, layerDescriptor, name);
2197 SerializeFillLayer(layer, layerDescriptor, name);
2202 SerializeFloorLayer(layer, name);
2209 SerializeFullyConnectedLayer(layer, layerDescriptor, name);
2216 SerializeGatherLayer(layer, layerDescriptor, name);
2221 SerializeGatherNdLayer(layer, name);
2226 SerializeInputLayer(layer,
id, name);
2233 SerializeInstanceNormalizationLayer(layer, layerDescriptor, name);
2240 SerializeL2NormalizationLayer(layer, layerDescriptor, name);
2247 SerializeLogicalBinaryLayer(layer, layerDescriptor, name);
2254 SerializeLogSoftmaxLayer(layer, layerDescriptor, name);
2261 SerializeLstmLayer(layer, layerDescriptor, constants, name);
2268 SerializeQLstmLayer(layer, layerDescriptor, constants, name);
2273 SerializeMaximumLayer(layer, name);
2280 SerializeMeanLayer(layer, layerDescriptor, name);
2285 SerializeMergeLayer(layer, name);
2290 SerializeMinimumLayer(layer, name);
2295 SerializeMultiplicationLayer(layer, name);
2302 SerializeNormalizationLayer(layer, layerDescriptor, name);
2307 SerializeOutputLayer(layer,
id, name);
2314 SerializePadLayer(layer, layerDescriptor, name);
2321 SerializePermuteLayer(layer, layerDescriptor, name);
2328 SerializePooling2dLayer(layer, layerDescriptor, name);
2335 SerializePooling3dLayer(layer, layerDescriptor, name);
2340 SerializePreluLayer(layer, name);
2345 SerializeQuantizeLayer(layer, name);
2349 SerializeQuantizedLstmLayer(layer, constants, name);
2355 SerializeReshapeLayer(layer, layerDescriptor, name);
2360 SerializeRankLayer(layer, name);
2367 SerializeReduceLayer(layer, layerDescriptor, name);
2374 SerializeResizeLayer(layer, layerDescriptor, name);
2379 SerializeReverseV2Layer(layer, name);
2384 SerializeShapeLayer(layer, name);
2391 SerializeSliceLayer(layer, layerDescriptor, name);
2398 SerializeSoftmaxLayer(layer, layerDescriptor, name);
2405 SerializeSpaceToBatchNdLayer(layer, layerDescriptor, name);
2412 SerializeSpaceToDepthLayer(layer, layerDescriptor, name);
2419 SerializeSplitterLayer(layer, layerDescriptor, name);
2426 SerializeStackLayer(layer, layerDescriptor, name);
2433 SerializeStandInLayer(layer, layerDescriptor, name);
2440 SerializeStridedSliceLayer(layer, layerDescriptor, name);
2445 SerializeSubtractionLayer(layer, name);
2450 SerializeSwitchLayer(layer, name);
2457 SerializeTileLayer(layer, layerDescriptor, name);
2464 SerializeTransposeLayer(layer, layerDescriptor, name);
2471 SerializeTransposeConvolution2dLayer(layer, layerDescriptor, constants, name);
2478 SerializeUnidirectionalSequenceLstmLayer(layer, layerDescriptor, constants, name);
2484 fmt::format(
"A layer of unknown type was given to the serializer. Layer name: {}; Layer Id: {}",
2491 void ISerializer::SerializerImpl::Serialize(
const INetwork& inNetwork)
2495 flatbuffers::FlatBufferBuilder& fbBuilder = m_SerializerStrategy.GetFlatBufferBuilder();
2498 auto serializedGraph = serializer::CreateSerializedGraph(
2500 fbBuilder.CreateVector(m_SerializerStrategy.GetSerializedLayers()),
2501 fbBuilder.CreateVector(m_SerializerStrategy.GetInputIds()),
2502 fbBuilder.CreateVector(m_SerializerStrategy.GetOutputIds()),
2503 m_SerializerStrategy.GetVersionTable());
2506 fbBuilder.Finish(serializedGraph);
2510 bool ISerializer::SerializerImpl::SaveSerializedToStream(std::ostream& stream)
2512 flatbuffers::FlatBufferBuilder& fbBuilder = m_SerializerStrategy.GetFlatBufferBuilder();
2514 auto bytesToWrite = armnn::numeric_cast<std::streamsize>(fbBuilder.GetSize());
2515 stream.write(
reinterpret_cast<const char*
>(fbBuilder.GetBufferPointer()), bytesToWrite);
2516 return !stream.bad();