blob: 43c5466e6968b1e3bf41291a0478b92c73dad27e [file] [log] [blame]
telsoa01c577f2c2018-08-31 09:22:23 +01001//
Teresa Charlinfd33a692022-06-29 15:35:57 +01002// Copyright © 2022 Arm Ltd and Contributors. All rights reserved.
David Beckecb56cd2018-09-05 12:52:57 +01003// SPDX-License-Identifier: MIT
telsoa01c577f2c2018-08-31 09:22:23 +01004//
5#pragma once
6
7#include "armnn/INetwork.hpp"
8#include "armnnTfLiteParser/ITfLiteParser.hpp"
Nattapat Chaimanowongb66504b2018-10-17 15:19:14 +01009#include "armnn/Types.hpp"
telsoa01c577f2c2018-08-31 09:22:23 +010010
11#include <schema_generated.h>
12#include <functional>
Aron Virginas-Tarc975f922019-10-23 17:38:17 +010013#include <unordered_map>
telsoa01c577f2c2018-08-31 09:22:23 +010014#include <vector>
15
Matthew Sloyan4d217c02021-10-07 11:48:58 +010016#include <tensorflow/lite/version.h>
17
18#if TF_MAJOR_VERSION > 2 || (TF_MAJOR_VERSION == 2 && TF_MINOR_VERSION > 3)
19#define ARMNN_POST_TFLITE_2_3
20#endif
21
telsoa01c577f2c2018-08-31 09:22:23 +010022namespace armnnTfLiteParser
23{
24
Kevin May7d96b162021-02-03 17:38:41 +000025class TfLiteParserImpl
telsoa01c577f2c2018-08-31 09:22:23 +010026{
27public:
28 // Shorthands for TfLite types
29 using ModelPtr = std::unique_ptr<tflite::ModelT>;
Derek Lambertiff05cc52019-04-26 13:05:17 +010030 using SubgraphPtr = std::unique_ptr<tflite::SubGraphT>;
telsoa01c577f2c2018-08-31 09:22:23 +010031 using OperatorPtr = std::unique_ptr<tflite::OperatorT>;
32 using OperatorCodePtr = std::unique_ptr<tflite::OperatorCodeT>;
33 using TensorPtr = std::unique_ptr<tflite::TensorT>;
34 using TensorRawPtr = const tflite::TensorT *;
35 using TensorRawPtrVector = std::vector<TensorRawPtr>;
36 using TensorIdRawPtr = std::pair<size_t, TensorRawPtr>;
37 using TensorIdRawPtrVector = std::vector<TensorIdRawPtr>;
38 using BufferPtr = std::unique_ptr<tflite::BufferT>;
39 using BufferRawPtr = const tflite::BufferT *;
40
41public:
42 /// Create the network from a flatbuffers binary file on disk
Kevin May7d96b162021-02-03 17:38:41 +000043 armnn::INetworkPtr CreateNetworkFromBinaryFile(const char* graphFile);
telsoa01c577f2c2018-08-31 09:22:23 +010044
45 /// Create the network from a flatbuffers binary
Kevin May7d96b162021-02-03 17:38:41 +000046 armnn::INetworkPtr CreateNetworkFromBinary(const std::vector<uint8_t> & binaryContent);
telsoa01c577f2c2018-08-31 09:22:23 +010047
48
49 /// Retrieve binding info (layer id and tensor info) for the network input identified by
50 /// the given layer name and subgraph id
Kevin May7d96b162021-02-03 17:38:41 +000051 BindingPointInfo GetNetworkInputBindingInfo(size_t subgraphId,
52 const std::string& name) const;
telsoa01c577f2c2018-08-31 09:22:23 +010053
54 /// Retrieve binding info (layer id and tensor info) for the network output identified by
55 /// the given layer name and subgraph id
Kevin May7d96b162021-02-03 17:38:41 +000056 BindingPointInfo GetNetworkOutputBindingInfo(size_t subgraphId,
57 const std::string& name) const;
telsoa01c577f2c2018-08-31 09:22:23 +010058
59 /// Return the number of subgraphs in the parsed model
Kevin May7d96b162021-02-03 17:38:41 +000060 size_t GetSubgraphCount() const;
telsoa01c577f2c2018-08-31 09:22:23 +010061
62 /// Return the input tensor names for a given subgraph
Kevin May7d96b162021-02-03 17:38:41 +000063 std::vector<std::string> GetSubgraphInputTensorNames(size_t subgraphId) const;
telsoa01c577f2c2018-08-31 09:22:23 +010064
65 /// Return the output tensor names for a given subgraph
Kevin May7d96b162021-02-03 17:38:41 +000066 std::vector<std::string> GetSubgraphOutputTensorNames(size_t subgraphId) const;
telsoa01c577f2c2018-08-31 09:22:23 +010067
Kevin May7d96b162021-02-03 17:38:41 +000068 TfLiteParserImpl(const armnn::Optional<ITfLiteParser::TfLiteParserOptions>& options = armnn::EmptyOptional());
69 ~TfLiteParserImpl() = default;
telsoa01c577f2c2018-08-31 09:22:23 +010070
71public:
72 // testable helpers
Finn Williamsb49ed182021-06-29 15:50:08 +010073 armnn::INetworkPtr CreateNetworkFromBinaryAsDynamic(const std::vector<uint8_t>& binaryContent);
74
75 armnn::INetworkPtr LoadModel(std::unique_ptr<tflite::ModelT> model);
76
Teresa Charlin3ab85482021-06-08 16:59:29 +010077 static ModelPtr LoadModelFromFile(const char* fileName);
78 static ModelPtr LoadModelFromBinary(const uint8_t* binaryContent, size_t len);
79 static TensorRawPtrVector GetInputs(const ModelPtr& model, size_t subgraphIndex, size_t operatorIndex);
80 static TensorRawPtrVector GetOutputs(const ModelPtr& model, size_t subgraphIndex, size_t operatorIndex);
81 static TensorIdRawPtrVector GetSubgraphInputs(const ModelPtr& model, size_t subgraphIndex);
82 static TensorIdRawPtrVector GetSubgraphOutputs(const ModelPtr& model, size_t subgraphIndex);
telsoa01c577f2c2018-08-31 09:22:23 +010083 static std::vector<int32_t>& GetInputTensorIds(const ModelPtr& model, size_t subgraphIndex, size_t operatorIndex);
84 static std::vector<int32_t>& GetOutputTensorIds(const ModelPtr& model, size_t subgraphIndex, size_t operatorIndex);
85
86 static BufferRawPtr GetBuffer(const ModelPtr& model, size_t bufferIndex);
Teresa Charlin3ab85482021-06-08 16:59:29 +010087 static armnn::TensorInfo OutputShapeOfSqueeze(std::vector<uint32_t> squeezeDims,
88 const armnn::TensorInfo& inputTensorInfo);
89 static armnn::TensorInfo OutputShapeOfReshape(const armnn::TensorInfo& inputTensorInfo,
90 const std::vector<int32_t>& targetDimsIn);
telsoa01c577f2c2018-08-31 09:22:23 +010091
Matthew Sloyanac001ee2021-02-03 10:43:04 +000092 /// Retrieve version in X.Y.Z form
93 static const std::string GetVersion();
94
telsoa01c577f2c2018-08-31 09:22:23 +010095private:
Finn Williamsd4fa5452021-03-01 12:31:41 +000096
telsoa01c577f2c2018-08-31 09:22:23 +010097 // No copying allowed until it is wanted and properly implemented
Kevin May7d96b162021-02-03 17:38:41 +000098 TfLiteParserImpl(const TfLiteParserImpl &) = delete;
99 TfLiteParserImpl & operator=(const TfLiteParserImpl &) = delete;
telsoa01c577f2c2018-08-31 09:22:23 +0100100
101 /// Create the network from an already loaded flatbuffers model
102 armnn::INetworkPtr CreateNetworkFromModel();
103
104 // signature for the parser functions
Kevin May7d96b162021-02-03 17:38:41 +0000105 using OperatorParsingFunction = void(TfLiteParserImpl::*)(size_t subgraphIndex, size_t operatorIndex);
telsoa01c577f2c2018-08-31 09:22:23 +0100106
Aron Virginas-Tarc975f922019-10-23 17:38:17 +0100107 void ParseCustomOperator(size_t subgraphIndex, size_t operatorIndex);
telsoa01c577f2c2018-08-31 09:22:23 +0100108 void ParseUnsupportedOperator(size_t subgraphIndex, size_t operatorIndex);
Aron Virginas-Tarc975f922019-10-23 17:38:17 +0100109
Matthew Sloyaned7fce42021-04-15 20:46:24 +0100110 void ParseAbs(size_t subgraphIndex, size_t operatorIndex);
Finn Williamsc42c3842019-01-22 14:18:11 +0000111 void ParseActivation(size_t subgraphIndex, size_t operatorIndex, armnn::ActivationFunction activationType);
Nina Drozd200e3802019-04-15 09:47:39 +0100112 void ParseAdd(size_t subgraphIndex, size_t operatorIndex);
Matthew Sloyan28f177c2021-04-09 14:38:52 +0100113 void ParseArgMinMax(size_t subgraphIndex, size_t operatorIndex, armnn::ArgMinMaxFunction argMinMaxFunction);
114 void ParseArgMin(size_t subgraphIndex, size_t operatorIndex);
115 void ParseArgMax(size_t subgraphIndex, size_t operatorIndex);
telsoa01c577f2c2018-08-31 09:22:23 +0100116 void ParseAveragePool2D(size_t subgraphIndex, size_t operatorIndex);
Bruno Goncalvesdb947e22019-02-08 18:52:21 -0200117 void ParseBatchToSpaceND(size_t subgraphIndex, size_t operatorIndex);
mathad01b392e982021-04-07 12:07:30 +0100118 void ParseCast(size_t subgraphIndex, size_t operatorIndex);
Bruno Goncalves2d0eb862021-07-11 14:10:15 -0300119 void ParseComparison(size_t subgraphIndex, size_t operatorIndex, armnn::ComparisonOperation comparisonOperation);
Sadik Armagan479045b2018-10-01 11:51:37 +0100120 void ParseConcatenation(size_t subgraphIndex, size_t operatorIndex);
telsoa01c577f2c2018-08-31 09:22:23 +0100121 void ParseConv2D(size_t subgraphIndex, size_t operatorIndex);
Matthew Sloyan4d217c02021-10-07 11:48:58 +0100122 // Conv3D support was added in TF 2.5, so for backwards compatibility a hash define is needed.
123 #if defined(ARMNN_POST_TFLITE_2_3)
Matthew Sloyaneb5f8102021-10-05 17:31:42 +0100124 void ParseConv3D(size_t subgraphIndex, size_t operatorIndex);
Matthew Sloyan4d217c02021-10-07 11:48:58 +0100125 #endif
Sadik Armagan26868492021-01-22 14:25:31 +0000126 void ParseDepthToSpace(size_t subgraphIndex, size_t operatorIndex);
telsoa01c577f2c2018-08-31 09:22:23 +0100127 void ParseDepthwiseConv2D(size_t subgraphIndex, size_t operatorIndex);
Finn Williamsed66d142019-12-06 09:55:55 +0000128 void ParseDequantize(size_t subgraphIndex, size_t operatorIndex);
keidav011b3e2ea2019-02-21 10:07:37 +0000129 void ParseDetectionPostProcess(size_t subgraphIndex, size_t operatorIndex);
Matthew Sloyan28f177c2021-04-09 14:38:52 +0100130 void ParseDiv(size_t subgraphIndex, size_t operatorIndex);
Matthew Sloyaned7fce42021-04-15 20:46:24 +0100131 void ParseElementwiseUnary(size_t subgraphIndex, size_t operatorIndex, armnn::UnaryOperation unaryOperation);
Matthew Sloyan7515d072020-12-16 12:50:01 +0000132 void ParseElu(size_t subgraphIndex, size_t operatorIndex);
Bruno Goncalves2d0eb862021-07-11 14:10:15 -0300133 void ParseEqual(size_t subgraphIndex, size_t operatorIndex);
Derek Lambertif0176992020-04-28 13:37:49 +0100134 void ParseExp(size_t subgraphIndex, size_t operatorIndex);
Teresa Charlin3ab85482021-06-08 16:59:29 +0100135 void ParseExpandDims(size_t subgraphIndex, size_t operatorIndex);
Teresa Charlincdbd40b2022-02-25 13:21:55 +0000136 void ParseFloorDiv(size_t subgraphIndex, size_t operatorIndex);
Sadik Armagan8853c1f2018-10-22 09:04:18 +0100137 void ParseFullyConnected(size_t subgraphIndex, size_t operatorIndex);
Sadik Armagan26868492021-01-22 14:25:31 +0000138 void ParseGather(size_t subgraphIndex, size_t operatorIndex);
Teresa Charlin91a53ea2022-04-25 15:47:29 +0100139 void ParseGatherNd(size_t subgraphIndex, size_t operatorIndex);
Bruno Goncalves2d0eb862021-07-11 14:10:15 -0300140 void ParseGreater(size_t subgraphIndex, size_t operatorIndex);
141 void ParseGreaterOrEqual(size_t subgraphIndex, size_t operatorIndex);
Jan Eilers2f746b32020-07-28 14:00:06 +0100142 void ParseHardSwish(size_t subgraphIndex, size_t operatorIndex);
Sadik Armagan12239e72020-05-27 11:06:17 +0100143 void ParseLeakyRelu(size_t subgraphIndex, size_t operatorIndex);
Bruno Goncalves2d0eb862021-07-11 14:10:15 -0300144 void ParseLess(size_t subgraphIndex, size_t operatorIndex);
145 void ParseLessOrEqual(size_t subgraphIndex, size_t operatorIndex);
Mike Kelly31dce2b2021-09-01 21:22:37 +0100146 void ParseLocalResponseNormalization(size_t subgraphIndex, size_t operatorIndex);
Matthew Sloyaned7fce42021-04-15 20:46:24 +0100147 void ParseLogicalNot(size_t subgraphIndex, size_t operatorIndex);
Finn Williamsc42c3842019-01-22 14:18:11 +0000148 void ParseLogistic(size_t subgraphIndex, size_t operatorIndex);
Teresa Charlinfd33a692022-06-29 15:35:57 +0100149 void ParseLogSoftmax(size_t subgraphIndex, size_t operatorIndex);
Matthew Jackson28c94572019-07-18 10:47:03 +0100150 void ParseL2Normalization(size_t subgraphIndex, size_t operatorIndex);
Nattapat Chaimanowongb66504b2018-10-17 15:19:14 +0100151 void ParseMaxPool2D(size_t subgraphIndex, size_t operatorIndex);
Bruno Goncalvesb8d805e2019-02-12 22:57:13 -0200152 void ParseMaximum(size_t subgraphIndex, size_t operatorIndex);
Nina Drozd200e3802019-04-15 09:47:39 +0100153 void ParseMean(size_t subgraphIndex, size_t operatorIndex);
Bruno Goncalves8f6d7a72019-02-12 22:58:18 -0200154 void ParseMinimum(size_t subgraphIndex, size_t operatorIndex);
Matthew Sloyanaf3a4ef2021-10-22 15:48:12 +0100155 void ParseMirrorPad(size_t subgraphIndex, size_t operatorIndex);
Nina Drozd200e3802019-04-15 09:47:39 +0100156 void ParseMul(size_t subgraphIndex, size_t operatorIndex);
Darshan Patel83fcf982020-05-26 22:22:42 +0530157 void ParseNeg(size_t subgraphIndex, size_t operatorIndex);
Bruno Goncalves2d0eb862021-07-11 14:10:15 -0300158 void ParseNotEqual(size_t subgraphIndex, size_t operatorIndex);
Matthew Jacksonbcca1f42019-07-16 11:39:21 +0100159 void ParsePack(size_t subgraphIndex, size_t operatorIndex);
Nina Drozd200e3802019-04-15 09:47:39 +0100160 void ParsePad(size_t subgraphIndex, size_t operatorIndex);
161 void ParsePool(size_t subgraphIndex, size_t operatorIndex, armnn::PoolingAlgorithm algorithm);
Narumol Prangnawaratbfaee6b2021-05-24 18:50:24 +0100162 void ParsePrelu(size_t subgraphIndex, size_t operatorIndex);
Sadik Armagan66dedc72019-12-10 16:32:07 +0000163 void ParseQuantize(size_t subgraphIndex, size_t operatorIndex);
Sadik Armagana2747482021-02-09 10:28:54 +0000164 void ParseReduce(size_t subgraphIndex, size_t operatorIndex, armnn::ReduceOperation reduceOperation);
165 void ParseReduceMax(size_t subgraphIndex, size_t operatorIndex);
166 void ParseReduceMin(size_t subgraphIndex, size_t operatorIndex);
Teresa Charlin4e3e8312021-08-05 12:34:37 +0100167 void ParseReduceProd(size_t subgraphIndex, size_t operatorIndex);
Sadik Armagan58f39192018-09-17 14:14:39 +0100168 void ParseRelu(size_t subgraphIndex, size_t operatorIndex);
169 void ParseRelu6(size_t subgraphIndex, size_t operatorIndex);
Sadikb94967b2018-09-19 15:30:00 +0100170 void ParseReshape(size_t subgraphIndex, size_t operatorIndex);
Sadik Armagana3b31f02019-12-05 09:08:53 +0000171 void ParseResize(size_t subgraphIndex, size_t operatorIndex, armnn::ResizeMethod resizeMethod);
Bruno Goncalves3f58ddb2019-02-07 18:40:11 -0200172 void ParseResizeBilinear(size_t subgraphIndex, size_t operatorIndex);
Sadik Armagana3b31f02019-12-05 09:08:53 +0000173 void ParseResizeNearestNeighbor(size_t subgraphIndex, size_t operatorIndex);
Matthew Sloyaned7fce42021-04-15 20:46:24 +0100174 void ParseRsqrt(size_t subgraphIndex, size_t operatorIndex);
Keith Davis0176fd82021-06-01 17:36:32 +0100175 void ParseShape(size_t subgraphIndex, size_t operatorIndex);
josh minorba424d22019-11-13 10:55:17 -0600176 void ParseSlice(size_t subgraphIndex, size_t operatorIndex);
Sadik Armagan479045b2018-10-01 11:51:37 +0100177 void ParseSoftmax(size_t subgraphIndex, size_t operatorIndex);
Teresa Charlinf0fce5b2022-05-04 17:24:43 +0100178 void ParseSqrt(size_t subgraphIndex, size_t operatorIndex);
Bruno Goncalvesbaded142019-02-08 19:02:48 -0200179 void ParseSpaceToBatchND(size_t subgraphIndex, size_t operatorIndex);
Nina Drozd200e3802019-04-15 09:47:39 +0100180 void ParseSplit(size_t subgraphIndex, size_t operatorIndex);
Derek Lambertif0176992020-04-28 13:37:49 +0100181 void ParseSplitV(size_t subgraphIndex, size_t operatorIndex);
Sadik Armagan479045b2018-10-01 11:51:37 +0100182 void ParseSqueeze(size_t subgraphIndex, size_t operatorIndex);
Bruno Goncalves451d95b2019-02-12 22:59:22 -0200183 void ParseStridedSlice(size_t subgraphIndex, size_t operatorIndex);
Bruno Goncalvesbbeae262019-02-07 18:37:39 -0200184 void ParseSub(size_t subgraphIndex, size_t operatorIndex);
Sadik Armagan0c3ea5b2021-02-03 09:29:30 +0000185 void ParseSum(size_t subgraphIndex, size_t operatorIndex);
Nina Drozd99851762019-04-09 09:37:38 +0100186 void ParseTanH(size_t subgraphIndex, size_t operatorIndex);
Keith Davis4cd29a02019-09-09 14:49:20 +0100187 void ParseTranspose(size_t subgraphIndex, size_t operatorIndex);
Matthew Jackson74bf7da2019-08-16 16:51:42 +0100188 void ParseTransposeConv(size_t subgraphIndex, size_t operatorIndex);
Mike Kelly5880b912022-01-28 16:18:54 +0000189 void ParseUnidirectionalSequenceLSTM(size_t subgraphIndex, size_t operatorIndex);
Nina Drozd200e3802019-04-15 09:47:39 +0100190 void ParseUnpack(size_t subgraphIndex, size_t operatorIndex);
Nattapat Chaimanowongb66504b2018-10-17 15:19:14 +0100191
telsoa01c577f2c2018-08-31 09:22:23 +0100192 void RegisterProducerOfTensor(size_t subgraphIndex, size_t tensorIndex, armnn::IOutputSlot* slot);
193 void RegisterConsumerOfTensor(size_t subgraphIndex, size_t tensorIndex, armnn::IInputSlot* slot);
194 void RegisterInputSlots(size_t subgraphIndex,
195 size_t operatorIndex,
196 armnn::IConnectableLayer* layer,
Finn Williamsd4fa5452021-03-01 12:31:41 +0000197 const std::vector<unsigned int>& tensorIndexes,
198 unsigned int startingSlotIndex = 0);
telsoa01c577f2c2018-08-31 09:22:23 +0100199 void RegisterOutputSlots(size_t subgraphIndex,
200 size_t operatorIndex,
201 armnn::IConnectableLayer* layer,
202 const std::vector<unsigned int>& tensorIndexes);
203
204 void SetupInputLayers(size_t subgraphIndex);
205 void SetupOutputLayers(size_t subgraphIndex);
Bruno Goncalves3d7efe92018-12-27 14:21:43 -0200206 void SetupConstantLayers(size_t subgraphIndex);
telsoa01c577f2c2018-08-31 09:22:23 +0100207
208 void ResetParser();
209
Bruno Goncalves9c761a62018-12-27 14:20:35 -0200210 void AddBroadcastReshapeLayer(size_t subgraphIndex,
211 size_t operatorIndex,
212 armnn::IConnectableLayer* layer);
213
telsoa01c577f2c2018-08-31 09:22:23 +0100214 /// Attach an activation layer to the one passed as a parameter
Sadik Armagan58f39192018-09-17 14:14:39 +0100215 armnn::IConnectableLayer* AddFusedActivationLayer(armnn::IConnectableLayer* layer,
216 unsigned int outputSlot,
217 tflite::ActivationFunctionType activationType);
telsoa01c577f2c2018-08-31 09:22:23 +0100218
Teresa Charlincdbd40b2022-02-25 13:21:55 +0000219 /// Attach a floor layer to the one passed as a parameter
220 armnn::IConnectableLayer* AddFusedFloorLayer(armnn::IConnectableLayer* layer, unsigned int outputSlot);
221
telsoa01c577f2c2018-08-31 09:22:23 +0100222 // SupportedDataStorage's purpose is to hold data till we pass over to the network.
223 // We don't care about the content, and we want a single datatype to simplify the code.
224 struct SupportedDataStorage
225 {
Matteo Martincigh747ef822018-12-18 09:26:39 +0000226 public:
227 // Convenience constructors
228 SupportedDataStorage(std::unique_ptr<float[]>&& data);
229 SupportedDataStorage(std::unique_ptr<uint8_t[]>&& data);
Keith Davisd305e1a2020-01-22 11:57:54 +0000230 SupportedDataStorage(std::unique_ptr<int8_t[]>&& data);
Matteo Martincigh747ef822018-12-18 09:26:39 +0000231 SupportedDataStorage(std::unique_ptr<int32_t[]>&& data);
telsoa01c577f2c2018-08-31 09:22:23 +0100232
Matteo Martincigh747ef822018-12-18 09:26:39 +0000233 private:
234 // Pointers to the data buffers
235 std::unique_ptr<float[]> m_FloatData;
236 std::unique_ptr<uint8_t[]> m_Uint8Data;
Keith Davisd305e1a2020-01-22 11:57:54 +0000237 std::unique_ptr<int8_t[]> m_Int8Data;
Matteo Martincigh747ef822018-12-18 09:26:39 +0000238 std::unique_ptr<int32_t[]> m_Int32Data;
telsoa01c577f2c2018-08-31 09:22:23 +0100239 };
240
Mike Kelly5880b912022-01-28 16:18:54 +0000241 bool ShouldConstantTensorBeCreated(unsigned int tensorIndex);
Finn Williamsd4fa5452021-03-01 12:31:41 +0000242 bool IsConstTensor(TensorRawPtr tensorPtr);
243 armnn::ConstTensor CreateConstTensorNonPermuted(TensorRawPtr tensorPtr,
244 armnn::TensorInfo& tensorInfo);
Mike Kelly5880b912022-01-28 16:18:54 +0000245
Finn Williamsd4fa5452021-03-01 12:31:41 +0000246 std::pair<armnn::ConstTensor, SupportedDataStorage>
247 CreateConstTensorPermuted(TensorRawPtr tensorPtr,
248 armnn::TensorInfo& tensorInfo,
249 armnn::Optional<armnn::PermutationVector&> permutationVector);
Mike Kelly5880b912022-01-28 16:18:54 +0000250 std::pair<armnn::ConstTensor, std::unique_ptr<float[]>>
251 CreateConstTensorNonPermuted(TensorRawPtr tensorPtr,
252 armnn::TensorInfo& tensorInfo,
253 armnn::DataType inputDataType);
Matteo Martincigh747ef822018-12-18 09:26:39 +0000254
255 template<typename T>
Kevin May7d96b162021-02-03 17:38:41 +0000256 std::pair<armnn::ConstTensor, TfLiteParserImpl::SupportedDataStorage>
257 CreateConstTensorAndStoreData(TfLiteParserImpl::BufferRawPtr bufferPtr,
258 TfLiteParserImpl::TensorRawPtr tensorPtr,
Matteo Martincigh747ef822018-12-18 09:26:39 +0000259 armnn::TensorInfo& tensorInfo,
260 armnn::Optional<armnn::PermutationVector&> permutationVector);
Mike Kelly5880b912022-01-28 16:18:54 +0000261 std::pair<armnn::ConstTensor*, std::unique_ptr<float[]>>
262 CreateConstTensorPtr(TensorRawPtr tensorPtr,
263 armnn::TensorInfo& inputTensorInfo);
Matteo Martincigh747ef822018-12-18 09:26:39 +0000264
Aron Virginas-Tarc975f922019-10-23 17:38:17 +0100265 // Settings for configuring the TfLiteParser
266 armnn::Optional<ITfLiteParser::TfLiteParserOptions> m_Options;
267
telsoa01c577f2c2018-08-31 09:22:23 +0100268 /// The network we're building. Gets cleared after it is passed to the user
269 armnn::INetworkPtr m_Network;
telsoa01c577f2c2018-08-31 09:22:23 +0100270 ModelPtr m_Model;
271
Aron Virginas-Tarc975f922019-10-23 17:38:17 +0100272 std::vector<OperatorParsingFunction> m_ParserFunctions;
273 std::unordered_map<std::string, OperatorParsingFunction> m_CustomParserFunctions;
274
telsoa01c577f2c2018-08-31 09:22:23 +0100275 /// A mapping of an output slot to each of the input slots it should be connected to
276 /// The outputSlot is from the layer that creates this tensor as one of its ouputs
277 /// The inputSlots are from the layers that use this tensor as one of their inputs
278 struct TensorSlots
279 {
280 armnn::IOutputSlot* outputSlot;
281 std::vector<armnn::IInputSlot*> inputSlots;
282
283 TensorSlots() : outputSlot(nullptr) { }
284 };
285 typedef std::vector<TensorSlots> TensorConnections;
286 /// Connections for tensors in each subgraph
287 /// The first index is the subgraph ID, the second index is the tensor ID
288 std::vector<TensorConnections> m_SubgraphConnections;
Narumol Prangnawarat4628d052019-02-25 17:26:05 +0000289
Mike Kelly5880b912022-01-28 16:18:54 +0000290 /// This is used in case that the model does not specify the output.
Narumol Prangnawarat4628d052019-02-25 17:26:05 +0000291 /// The shape can be calculated from the options.
292 std::vector<std::vector<unsigned int>> m_OverridenOutputShapes;
Mike Kelly5880b912022-01-28 16:18:54 +0000293
294 std::vector<unsigned int> m_ConstantsToDequantize;
295 std::vector<unsigned int> m_ConstantsToBeCreated;
telsoa01c577f2c2018-08-31 09:22:23 +0100296};
297
298}