blob: 3d4be1a7fa71263c39492e72aa54629044783853 [file] [log] [blame]
Laurent Carlier749294b2020-06-01 09:03:17 +01001//
Teresa Charlin52664732020-06-29 16:27:03 +01002// Copyright © 2017 Arm Ltd and Contributors. All rights reserved.
David Beckecb56cd2018-09-05 12:52:57 +01003// SPDX-License-Identifier: MIT
telsoa014fcda012018-03-09 14:13:49 +00004//
5#pragma once
6
Finn Williamsf24effa2020-07-03 10:12:03 +01007#include <armnn/BackendOptions.hpp>
Jim Flynn906f9462019-05-10 13:55:21 +01008#include <armnn/Deprecated.hpp>
David Beckf0b48452018-10-19 15:20:56 +01009#include <armnn/DescriptorsFwd.hpp>
Finn Williamsb454c5c2021-02-09 15:56:23 +000010#include <armnn/IStrategy.hpp>
Matthew Bentham313e1c82019-03-25 17:37:47 +000011#include <armnn/NetworkFwd.hpp>
12#include <armnn/Optional.hpp>
13#include <armnn/TensorFwd.hpp>
Jan Eilers6a71bb52021-10-26 17:41:18 +010014#include <armnn/Logging.hpp>
Nikhil Raj2e241752022-02-01 16:42:15 +000015#include <armnn/backends/TensorHandle.hpp>
telsoa014fcda012018-03-09 14:13:49 +000016
17#include <memory>
telsoa01c577f2c2018-08-31 09:22:23 +010018#include <vector>
telsoa014fcda012018-03-09 14:13:49 +000019
20namespace armnn
21{
telsoa014fcda012018-03-09 14:13:49 +000022/// @brief An input connection slot for a layer.
23/// The input slot can be connected to an output slot of the preceding layer in the graph.
24/// Only one connection to the input slot is allowed.
25class IInputSlot
26{
27public:
28 virtual const IOutputSlot* GetConnection() const = 0;
29 virtual IOutputSlot* GetConnection() = 0;
Francis Murtagh9d74ba62022-01-19 16:31:58 +000030 virtual const IConnectableLayer& GetOwningIConnectableLayer() const = 0;
Nabeel Ahmad09fa24d2022-06-16 13:55:00 +010031 virtual IConnectableLayer& GetOwningIConnectableLayer() = 0;
Francis Murtaghcea3d492022-06-27 12:44:50 +010032 virtual unsigned int GetSlotIndex() const = 0;
telsoa014fcda012018-03-09 14:13:49 +000033
34protected:
telsoa01c577f2c2018-08-31 09:22:23 +010035 /// Not user deletable.
36 ~IInputSlot() {}
telsoa014fcda012018-03-09 14:13:49 +000037};
38
39/// @brief An output connection slot for a layer.
40/// The output slot may be connected to 1 or more input slots of subsequent layers in the graph.
41class IOutputSlot
42{
43public:
44 virtual unsigned int GetNumConnections() const = 0;
45 virtual const IInputSlot* GetConnection(unsigned int index) const = 0;
Keith Davisb4dd5cc2022-04-07 11:32:00 +010046 virtual IInputSlot* GetConnection(unsigned int outputindex) = 0;
telsoa014fcda012018-03-09 14:13:49 +000047
48 virtual void SetTensorInfo(const TensorInfo& tensorInfo) = 0;
49 virtual const TensorInfo& GetTensorInfo() const = 0;
50 virtual bool IsTensorInfoSet() const = 0;
51
52 virtual int Connect(IInputSlot& destination) = 0;
53 virtual void Disconnect(IInputSlot& slot) = 0;
54
Mike Kelly8c1701a2019-02-11 17:01:27 +000055 virtual unsigned int CalculateIndexOnOwner() const = 0;
56
57 virtual LayerGuid GetOwningLayerGuid() const = 0;
58
Francis Murtagh56ccf682021-12-13 18:48:12 +000059 virtual const IConnectableLayer& GetOwningIConnectableLayer() const = 0;
Nabeel Ahmad09fa24d2022-06-16 13:55:00 +010060 virtual IConnectableLayer& GetOwningIConnectableLayer() = 0;
Francis Murtagh56ccf682021-12-13 18:48:12 +000061
telsoa014fcda012018-03-09 14:13:49 +000062protected:
telsoa01c577f2c2018-08-31 09:22:23 +010063 /// Not user deletable.
64 ~IOutputSlot() {}
telsoa014fcda012018-03-09 14:13:49 +000065};
66
67/// @brief Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
68class IConnectableLayer
69{
70public:
Derek Lamberti4a9e24b2020-01-03 16:53:38 +000071 /// Returns the name of the layer
telsoa014fcda012018-03-09 14:13:49 +000072 virtual const char* GetName() const = 0;
73
Derek Lamberti4a9e24b2020-01-03 16:53:38 +000074 /// Returns the number of connectable input slots
telsoa014fcda012018-03-09 14:13:49 +000075 virtual unsigned int GetNumInputSlots() const = 0;
Derek Lamberti4a9e24b2020-01-03 16:53:38 +000076
77 /// Returns the number of connectable output slots
telsoa014fcda012018-03-09 14:13:49 +000078 virtual unsigned int GetNumOutputSlots() const = 0;
79
Derek Lamberti4a9e24b2020-01-03 16:53:38 +000080 /// Get a const input slot handle by slot index
telsoa014fcda012018-03-09 14:13:49 +000081 virtual const IInputSlot& GetInputSlot(unsigned int index) const = 0;
Derek Lamberti4a9e24b2020-01-03 16:53:38 +000082
83 /// Get the input slot handle by slot index
telsoa014fcda012018-03-09 14:13:49 +000084 virtual IInputSlot& GetInputSlot(unsigned int index) = 0;
85
Derek Lamberti4a9e24b2020-01-03 16:53:38 +000086 /// Get the const output slot handle by slot index
telsoa014fcda012018-03-09 14:13:49 +000087 virtual const IOutputSlot& GetOutputSlot(unsigned int index) const = 0;
Derek Lamberti4a9e24b2020-01-03 16:53:38 +000088
89 /// Get the output slot handle by slot index
telsoa014fcda012018-03-09 14:13:49 +000090 virtual IOutputSlot& GetOutputSlot(unsigned int index) = 0;
91
Derek Lamberti4a9e24b2020-01-03 16:53:38 +000092 /// Infer the shape of the output(s) based on the provided input shape(s)
telsoa01c577f2c2018-08-31 09:22:23 +010093 virtual std::vector<TensorShape> InferOutputShapes(const std::vector<TensorShape>& inputShapes) const = 0;
94
Derek Lamberti4a9e24b2020-01-03 16:53:38 +000095 /// Returns the unique id of the layer
surmeh01bceff2f2018-03-29 16:29:27 +010096 virtual LayerGuid GetGuid() const = 0;
jimfly01e9e7bfd2019-01-24 22:29:33 +000097
Finn Williamsb454c5c2021-02-09 15:56:23 +000098 /// Apply a visitor to this layer
99 virtual void ExecuteStrategy(IStrategy& strategy) const = 0;
100
Derek Lamberti4a9e24b2020-01-03 16:53:38 +0000101 /// Provide a hint for the optimizer as to which backend to prefer for this layer
102 virtual void BackendSelectionHint(Optional<BackendId> backend) = 0;
Finn Williamsb454c5c2021-02-09 15:56:23 +0000103
104 /// Returns the armnn::LayerType of this layer
105 virtual LayerType GetType() const = 0;
106
Jim Flynne4665962022-01-31 16:08:53 +0000107 /// If the layer has a descriptor return it.
108 /// The base descriptor can then be cast to the correct descriptor class.
109 /// If the layer has no associated descriptor a struct of type NullDescriptor will be returned.
110 /// Note: NullDescriptors can be detected because they return true when
111 /// the BaseDescriptor IsNull function is invoked.
112 virtual const BaseDescriptor& GetParameters() const = 0;
113
Nikhil Raj2e241752022-02-01 16:42:15 +0000114 using ConstantTensors = std::vector<std::reference_wrapper<std::shared_ptr<ConstTensorHandle>>>;
115
116 // Returns ConstantTensors of this Layer if it has any, otherwise returns empty vector.
117 virtual ConstantTensors GetConstantTensorsByRef() = 0;
118
telsoa014fcda012018-03-09 14:13:49 +0000119protected:
telsoa01c577f2c2018-08-31 09:22:23 +0100120 /// Objects are not deletable via the handle
121 ~IConnectableLayer() {}
telsoa014fcda012018-03-09 14:13:49 +0000122};
123
telsoa014fcda012018-03-09 14:13:49 +0000124
Jan Eilersb1c62f12021-10-26 14:56:47 +0100125/// ArmNN performs an optimization on each model/network before it gets loaded for execution. OptimizerOptions provides
126/// a set of features that allows the user to customize this optimization on a per model basis.
telsoa01c577f2c2018-08-31 09:22:23 +0100127struct OptimizerOptions
128{
Matteo Martincigh49124022019-01-11 13:25:59 +0000129 OptimizerOptions()
130 : m_ReduceFp32ToFp16(false)
131 , m_Debug(false)
Narumol Prangnawaratbc7ffb52020-03-20 15:01:01 +0000132 , m_ReduceFp32ToBf16(false)
Teresa Charlincdc01492020-06-09 18:00:20 +0100133 , m_shapeInferenceMethod(armnn::ShapeInferenceMethod::ValidateOnly)
Narumol Prangnawarata2493a02020-08-19 14:39:07 +0100134 , m_ImportEnabled(false)
Sadik Armagan045f6be2020-09-10 13:37:32 +0100135 , m_ModelOptions()
Derek Lambertif1e0ad32021-10-13 18:02:25 +0100136 , m_ProfilingEnabled(false)
Francis Murtagh626bd902022-06-21 13:16:23 +0000137 , m_ExportEnabled(false)
keidav01738c2e62018-12-11 16:14:20 +0000138 {}
telsoa01c577f2c2018-08-31 09:22:23 +0100139
Sadik Armagan045f6be2020-09-10 13:37:32 +0100140 OptimizerOptions(bool reduceFp32ToFp16, bool debug, bool reduceFp32ToBf16, bool importEnabled,
Francis Murtagh626bd902022-06-21 13:16:23 +0000141 ModelOptions modelOptions = {}, bool exportEnabled = false)
Narumol Prangnawaratea063df2020-08-21 10:03:49 +0100142 : m_ReduceFp32ToFp16(reduceFp32ToFp16)
143 , m_Debug(debug)
144 , m_ReduceFp32ToBf16(reduceFp32ToBf16)
145 , m_shapeInferenceMethod(armnn::ShapeInferenceMethod::ValidateOnly)
146 , m_ImportEnabled(importEnabled)
Sadik Armagan045f6be2020-09-10 13:37:32 +0100147 , m_ModelOptions(modelOptions)
Derek Lambertif1e0ad32021-10-13 18:02:25 +0100148 , m_ProfilingEnabled(false)
Francis Murtagh626bd902022-06-21 13:16:23 +0000149 , m_ExportEnabled(exportEnabled)
Narumol Prangnawaratea063df2020-08-21 10:03:49 +0100150 {
151 if (m_ReduceFp32ToFp16 && m_ReduceFp32ToBf16)
152 {
153 throw InvalidArgumentException("BFloat16 and Float16 optimization cannot be enabled at the same time.");
154 }
155 }
156
Teresa Charlincdc01492020-06-09 18:00:20 +0100157 OptimizerOptions(bool reduceFp32ToFp16, bool debug, bool reduceFp32ToBf16 = false,
Narumol Prangnawarata2493a02020-08-19 14:39:07 +0100158 ShapeInferenceMethod shapeInferenceMethod = armnn::ShapeInferenceMethod::ValidateOnly,
Francis Murtagh626bd902022-06-21 13:16:23 +0000159 bool importEnabled = false, ModelOptions modelOptions = {}, bool exportEnabled = false)
telsoa01c577f2c2018-08-31 09:22:23 +0100160 : m_ReduceFp32ToFp16(reduceFp32ToFp16)
keidav01738c2e62018-12-11 16:14:20 +0000161 , m_Debug(debug)
Narumol Prangnawaratbc7ffb52020-03-20 15:01:01 +0000162 , m_ReduceFp32ToBf16(reduceFp32ToBf16)
Teresa Charlincdc01492020-06-09 18:00:20 +0100163 , m_shapeInferenceMethod(shapeInferenceMethod)
Narumol Prangnawarata2493a02020-08-19 14:39:07 +0100164 , m_ImportEnabled(importEnabled)
Sadik Armagan045f6be2020-09-10 13:37:32 +0100165 , m_ModelOptions(modelOptions)
Derek Lambertif1e0ad32021-10-13 18:02:25 +0100166 , m_ProfilingEnabled(false)
Francis Murtagh626bd902022-06-21 13:16:23 +0000167 , m_ExportEnabled(exportEnabled)
Narumol Prangnawaratbc7ffb52020-03-20 15:01:01 +0000168 {
169 if (m_ReduceFp32ToFp16 && m_ReduceFp32ToBf16)
170 {
171 throw InvalidArgumentException("BFloat16 and Float16 optimization cannot be enabled at the same time.");
172 }
173 }
telsoa01c577f2c2018-08-31 09:22:23 +0100174
Jan Eilers6a71bb52021-10-26 17:41:18 +0100175 const std::string ToString() const
176 {
177 std::stringstream stream;
178 stream << "OptimizerOptions: \n";
179 stream << "\tReduceFp32ToFp16: " << m_ReduceFp32ToFp16 << "\n";
180 stream << "\tReduceFp32ToBf16: " << m_ReduceFp32ToBf16 << "\n";
Jan Eilers17d34da2021-12-08 16:15:12 +0000181 stream << "\tDebug: " << m_Debug << "\n";
182 stream << "\tShapeInferenceMethod: " <<
Jan Eilers6a71bb52021-10-26 17:41:18 +0100183 (m_shapeInferenceMethod == ShapeInferenceMethod::ValidateOnly ? "ValidateOnly" : "InferAndValidate") << "\n";
184 stream << "\tImportEnabled: " << m_ImportEnabled << "\n";
Francis Murtagh626bd902022-06-21 13:16:23 +0000185 stream << "\tExportEnabled: " << m_ExportEnabled << "\n";
Jan Eilers6a71bb52021-10-26 17:41:18 +0100186 stream << "\tProfilingEnabled: " << m_ProfilingEnabled << "\n";
187
188 stream << "\tModelOptions: \n";
189 for (auto optionsGroup : m_ModelOptions)
190 {
191 for (size_t i=0; i < optionsGroup.GetOptionCount(); i++)
192 {
193 const armnn::BackendOptions::BackendOption option = optionsGroup.GetOption(i);
Jan Eilers17d34da2021-12-08 16:15:12 +0000194 stream << "\t\tBackend: " << optionsGroup.GetBackendId() << "\n"
195 << "\t\t\tOption: " << option.GetName() << "\n"
196 << "\t\t\tValue: " << std::string(option.GetValue().ToString()) << "\n";
Jan Eilers6a71bb52021-10-26 17:41:18 +0100197 }
198 }
199
200 return stream.str();
201 }
202
Jan Eilersb1c62f12021-10-26 14:56:47 +0100203 /// Reduces all Fp32 operators in the model to Fp16 for faster processing.
204 /// @Note This feature works best if all operators of the model are in Fp32. ArmNN will add conversion layers
205 /// between layers that weren't in Fp32 in the first place or if the operator is not supported in Fp16.
206 /// The overhead of these conversions can lead to a slower overall performance if too many conversions are
207 /// required.
telsoa01c577f2c2018-08-31 09:22:23 +0100208 bool m_ReduceFp32ToFp16;
keidav01738c2e62018-12-11 16:14:20 +0000209
210 // Add debug data for easier troubleshooting
211 bool m_Debug;
Narumol Prangnawaratbc7ffb52020-03-20 15:01:01 +0000212
Jan Eilersb1c62f12021-10-26 14:56:47 +0100213 /// Reduces all Fp32 operators in the model to Bf16 for faster processing.
214 /// @Note This feature works best if all operators of the model are in Fp32. ArmNN will add conversion layers
215 /// between layers that weren't in Fp32 in the first place or if the operator is not supported in Bf16.
216 /// The overhead of these conversions can lead to a slower overall performance if too many conversions are
217 /// required.
Narumol Prangnawaratbc7ffb52020-03-20 15:01:01 +0000218 bool m_ReduceFp32ToBf16;
Teresa Charlincdc01492020-06-09 18:00:20 +0100219
220 // Infer output size when not available
221 ShapeInferenceMethod m_shapeInferenceMethod;
Narumol Prangnawarata2493a02020-08-19 14:39:07 +0100222
223 // Enable Import
224 bool m_ImportEnabled;
Sadik Armagan045f6be2020-09-10 13:37:32 +0100225
226 // Enable Model Options
227 ModelOptions m_ModelOptions;
Derek Lambertif1e0ad32021-10-13 18:02:25 +0100228
229 // Enable profiling dump of the optimizer phase
230 bool m_ProfilingEnabled;
Francis Murtagh626bd902022-06-21 13:16:23 +0000231
232 // Enable Export
233 bool m_ExportEnabled;
telsoa01c577f2c2018-08-31 09:22:23 +0100234};
telsoa014fcda012018-03-09 14:13:49 +0000235
Francis Murtagh3d2b4b22021-02-15 18:23:17 +0000236class IWorkloadFactory;
237class NetworkImpl;
238using INetworkPtr = std::unique_ptr<INetwork, void(*)(INetwork* network)>;
239using IOptimizedNetworkPtr = std::unique_ptr<IOptimizedNetwork, void(*)(IOptimizedNetwork* network)>;
240
Cathal Corbett18655b82021-12-13 13:03:22 +0000241using CompiledBlobDeleter = std::function<void(const void*)>;
242using CompiledBlobPtr = std::unique_ptr<void, CompiledBlobDeleter>;
243
Francis Murtagh3d2b4b22021-02-15 18:23:17 +0000244/// Main network class which provides the interface for building up a neural network.
245/// This object is subsequently required by the IRuntime::Load() method.
246class INetwork
247{
248public:
249 static INetwork* CreateRaw(NetworkOptions networkOptions = {});
250 static INetworkPtr Create(NetworkOptions networkOptions = {});
251 static void Destroy(INetwork* network);
252
253 Status PrintGraph();
254
255 /// Adds an input layer to the network.
256 /// @param id - User generated id to uniquely identify a particular input. The same id needs to be specified.
257 /// when passing the inputs to the IRuntime::EnqueueWorkload() function.
258 /// @param name - Optional name for the layer.
259 /// @return - Interface for configuring the layer.
260 IConnectableLayer* AddInputLayer(LayerBindingId id, const char* name = nullptr);
261
262 /// Adds an ArgMinMax layer to the network.
263 /// @param desc - Parameters for the L2 normalization operation.
264 /// @param name - Optional name for the layer.
265 /// @return - Interface for configuring the layer.
266 IConnectableLayer* AddArgMinMaxLayer(const ArgMinMaxDescriptor& desc,
267 const char* name = nullptr);
268
mathad01b392e982021-04-07 12:07:30 +0100269 /// Adds a cast layer to the network.
270 /// @param name - Optional name for the layer.
271 /// @return - Interface for configuring the layer.
272 IConnectableLayer* AddCastLayer(const char* name = nullptr);
273
Francis Murtagh3d2b4b22021-02-15 18:23:17 +0000274 /// Add a Comparison layer to the network.
275 /// @param name - Optional name for the layer.
276 /// @param desc - Descriptor for the comparison operation.
277 /// @return - Interface for configuring the layer.
278 IConnectableLayer* AddComparisonLayer(const ComparisonDescriptor& comparisonDescriptor,
279 const char* name = nullptr);
280
281 /// Adds a concatenation layer to the network.
282 /// @param concatDescriptor - ConcatDescriptor (synonym for OriginsDescriptor) to configure the concatenation
283 /// process. Number of Views must be equal to the number of inputs, and their order
284 /// must match - e.g. first view corresponds to the first input, second view to the
285 /// second input, etc....
286 /// @param name - Optional name for the layer.
287 /// @return - Interface for configuring the layer.
288 IConnectableLayer* AddConcatLayer(const ConcatDescriptor& concatDescriptor,
289 const char* name = nullptr);
290
291 /// Adds a 2D convolution layer to the network.
292 /// @param convolution2dDescriptor - Description of the 2D convolution layer.
Keith Davisb4dd5cc2022-04-07 11:32:00 +0100293 /// @param name - Optional name for the layer.
294 /// @return - Interface for configuring the layer.
295 IConnectableLayer* AddConvolution2dLayer(const Convolution2dDescriptor& convolution2dDescriptor,
296 const char* name = nullptr);
297
298 /// Adds a 2D convolution layer to the network.
299 /// @param convolution2dDescriptor - Description of the 2D convolution layer.
Francis Murtagh3d2b4b22021-02-15 18:23:17 +0000300 /// @param weights - Tensor for the weights data.
301 /// @param biases - Optional tensor for the bias data. If specified, must match the output tensor shape.
302 /// @param name - Optional name for the layer.
303 /// @return - Interface for configuring the layer.
Keith Davisb4dd5cc2022-04-07 11:32:00 +0100304 ARMNN_DEPRECATED_MSG_REMOVAL_DATE("This AddConvolution2dLayer overload is deprecated", "22.08")
Francis Murtagh3d2b4b22021-02-15 18:23:17 +0000305 IConnectableLayer* AddConvolution2dLayer(const Convolution2dDescriptor& convolution2dDescriptor,
306 const ConstTensor& weights,
307 const Optional<ConstTensor>& biases,
308 const char* name = nullptr);
309
Jan Eilers1b2654f2021-09-24 15:45:46 +0100310 ARMNN_DEPRECATED_MSG_REMOVAL_DATE("This AddConvolution2dLayer overload is deprecated", "22.08")
Francis Murtagh3d2b4b22021-02-15 18:23:17 +0000311 IConnectableLayer* AddConvolution2dLayer(const Convolution2dDescriptor& convolution2dDescriptor,
312 const ConstTensor& weights,
313 const char* name = nullptr);
314
Jan Eilers1b2654f2021-09-24 15:45:46 +0100315 ARMNN_DEPRECATED_MSG_REMOVAL_DATE("This AddConvolution2dLayer overload is deprecated", "22.08")
Francis Murtagh3d2b4b22021-02-15 18:23:17 +0000316 IConnectableLayer* AddConvolution2dLayer(const Convolution2dDescriptor& convolution2dDescriptor,
317 const ConstTensor& weights,
318 const ConstTensor& biases,
319 const char* name = nullptr);
320
Matthew Sloyanb63a3112021-09-08 13:05:51 +0100321 /// Adds a 3D convolution layer to the network.
322 /// @param convolution3dDescriptor - Description of the 3D convolution layer.
Matthew Sloyanb63a3112021-09-08 13:05:51 +0100323 /// @param name - Optional name for the layer.
324 /// @return - Interface for configuring the layer.
325 IConnectableLayer* AddConvolution3dLayer(const Convolution3dDescriptor& convolution3dDescriptor,
Matthew Sloyanb63a3112021-09-08 13:05:51 +0100326 const char* name = nullptr);
327
Francis Murtagh3d2b4b22021-02-15 18:23:17 +0000328 /// Adds a depth to space layer to the network.
329 /// @param depthToSpaceDescriptor - Parameters for the depth to space operation.
330 /// @param name - Optional name for the layer.
331 /// @return - Interface for configuring the layer.
332 IConnectableLayer* AddDepthToSpaceLayer(const DepthToSpaceDescriptor& depthToSpaceDescriptor,
333 const char* name = nullptr);
334
335 /// Adds a 2D depthwise convolution layer to the network.
336 /// @param convolution2dDescriptor - Description of the 2D depthwise convolution layer.
Cathal Corbett06902652022-04-14 17:55:11 +0100337 /// @param name - Optional name for the layer.
338 /// @return - Interface for configuring the layer.
Keith Davisb4dd5cc2022-04-07 11:32:00 +0100339 IConnectableLayer* AddDepthwiseConvolution2dLayer(const DepthwiseConvolution2dDescriptor& convolution2dDescriptor,
340 const char* name = nullptr);
Cathal Corbett06902652022-04-14 17:55:11 +0100341
342 /// Adds a 2D depthwise convolution layer to the network.
343 /// @param convolution2dDescriptor - Description of the 2D depthwise convolution layer.
Francis Murtagh3d2b4b22021-02-15 18:23:17 +0000344 /// @param weights - Tensor for the weights. Expected format: [channelMultiplier, inputChannels, height, width].
345 /// @param biases Optional tensor for the bias data. If specified, must match the output tensor shape.
346 /// @param name - Optional name for the layer.
347 /// @return - Interface for configuring the layer.
Cathal Corbett06902652022-04-14 17:55:11 +0100348 ARMNN_DEPRECATED_MSG("This AddDepthwiseConvolution2dLayer overload is deprecated")
Francis Murtagh3d2b4b22021-02-15 18:23:17 +0000349 IConnectableLayer* AddDepthwiseConvolution2dLayer(
350 const DepthwiseConvolution2dDescriptor& convolution2dDescriptor,
351 const ConstTensor& weights,
352 const Optional<ConstTensor>& biases,
353 const char* name = nullptr);
354
Francis Murtagh3d2b4b22021-02-15 18:23:17 +0000355 /// Adds a Dequantize layer to the network.
356 /// @return - Interface for configuring the layer.
357 IConnectableLayer* AddDequantizeLayer(const char* name = nullptr);
358
359 /// Adds a Detection PostProcess layer to the network.
360 /// @param descriptor - Description of the Detection PostProcess layer.
361 /// @param anchors - Tensor for anchors.
362 /// @param name - Optional name for the layer.
363 /// @return - Interface for configuring the layer.
364 IConnectableLayer* AddDetectionPostProcessLayer(
365 const DetectionPostProcessDescriptor& descriptor,
366 const ConstTensor& anchors,
367 const char* name = nullptr);
368
369 /// Add an ElementwiseUnary layer to the network.
370 /// @param name - Optional name for the layer.
371 /// @param desc - Descriptor for the elementwiseUnary operation.
372 /// @return - Interface for configuring the layer.
373 IConnectableLayer* AddElementwiseUnaryLayer(const ElementwiseUnaryDescriptor& elementwiseUnaryDescriptor,
374 const char* name = nullptr);
375
376 /// Add an Fill layer to the network.
377 /// @param name - Optional name for the layer.
378 /// @param fillDescriptor - Descriptor for the fill operation.
379 /// @return - Interface for configuring the layer.
380 IConnectableLayer* AddFillLayer(const FillDescriptor& fillDescriptor,
381 const char* name = nullptr);
382
Matthew Sloyan81beae32021-07-13 19:46:11 +0100383
Francis Murtagh3d2b4b22021-02-15 18:23:17 +0000384 /// Adds a fully connected layer to the network.
385 /// @param fullyConnectedDescriptor - Description of the fully connected layer.
Sadik Armaganf0a6dec2021-03-25 07:46:55 +0000386 /// @return - Interface for configuring the layer.
Matthew Sloyan57d2c7e2021-08-12 17:41:04 +0100387 ///
388 /// @note Weights and biases are passed in as inputs. If they are constant tensors you can simply store
389 /// them in a ConstantLayer as seen below. A full example can be found in samples/SimpleSample.cpp.
390 ///
391 /// @code
392 /// // Make sure the IsConstant flag is set on the weightsInfo before passing it to the ConstTensor.
393 /// ConstTensor weights(weightsInfo, weightsData);
394 ///
395 /// // Constant layer that now holds weights data for FullyConnected
396 /// IConnectableLayer* const constantWeightsLayer = myNetwork->AddConstantLayer(weights, "weights");
397 ///
398 /// FullyConnectedDescriptor fullyConnectedDesc;
399 /// IConnectableLayer* const fullyConnectedLayer = myNetwork->AddFullyConnectedLayer(fullyConnectedDesc,
400 /// "fully connected");
401 /// IConnectableLayer* InputLayer = myNetwork->AddInputLayer(0);
402 /// InputLayer->GetOutputSlot(0).Connect(fullyConnectedLayer->GetInputSlot(0));
403 /// constantWeightsLayer->GetOutputSlot(0).Connect(fullyConnectedLayer->GetInputSlot(1));
404 /// @endcode
Sadik Armaganf0a6dec2021-03-25 07:46:55 +0000405 IConnectableLayer* AddFullyConnectedLayer(const FullyConnectedDescriptor& fullyConnectedDescriptor,
Matthew Sloyan81beae32021-07-13 19:46:11 +0100406 const char* name = nullptr);
407
Francis Murtagh3d2b4b22021-02-15 18:23:17 +0000408 /// Adds a permute layer to the network.
409 /// @param permuteDescriptor - PermuteDescriptor to configure the permute.
410 /// @param name - Optional name for the layer.
411 /// @return - Interface for configuring the layer.
412 IConnectableLayer* AddPermuteLayer(const PermuteDescriptor& permuteDescriptor,
413 const char* name = nullptr);
414
415 /// Adds a batch to space ND layer to the network.
416 /// @param batchToSpaceNdDescriptor - Description of the layer.
417 /// @param name - Optional name for the layer.
418 /// @return - Interface for configuring the layer.
419 IConnectableLayer* AddBatchToSpaceNdLayer(const BatchToSpaceNdDescriptor& batchToSpaceNdDescriptor,
420 const char* name = nullptr);
421
Tamás Nyíri7b885b32021-10-26 14:47:57 +0100422 /// Adds a 2D pooling layer to the network.
Francis Murtagh3d2b4b22021-02-15 18:23:17 +0000423 /// @param pooling2dDescriptor - Pooling2dDescriptor to configure the pooling.
424 /// @param name - Optional name for the layer.
425 /// @return - Interface for configuring the layer.
426 IConnectableLayer* AddPooling2dLayer(const Pooling2dDescriptor& pooling2dDescriptor,
427 const char* name = nullptr);
428
Tamás Nyíri7b885b32021-10-26 14:47:57 +0100429 /// Adds a 3D pooling layer to the network.
430 /// @param pooling3dDescriptor - Pooling3dDescriptor to configure the pooling.
431 /// @param name - Optional name for the layer.
432 /// @return - Interface for configuring the layer.
433 IConnectableLayer* AddPooling3dLayer(const Pooling3dDescriptor& pooling3dDescriptor,
434 const char* name = nullptr);
435
Cathal Corbett18655b82021-12-13 13:03:22 +0000436 /// Adds a Precompiled layer to the network.
437 /// Method use is for backend users.
438 /// @param preCompiledDescriptor - PreCompiledDescriptor contains parameters for the Precompiled layer.
439 /// @param compiledBlobPtr - CompiledBlobPtr pre-compiled object set for the Precompiled layer.
440 /// @param backend - optional BackendId set for the Precompiled layer.
441 /// @return - Interface for configuring the layer.
442 IConnectableLayer* AddPrecompiledLayer(const PreCompiledDescriptor& preCompiledDescriptor,
Cathal Corbett3ea01072022-01-06 10:29:43 +0000443 CompiledBlobPtr compiledBlobPtr,
Cathal Corbettcbfd7182021-12-15 17:12:59 +0000444 const Optional<BackendId>& backend,
445 const char* name = nullptr);
Cathal Corbett18655b82021-12-13 13:03:22 +0000446
Francis Murtagh3d2b4b22021-02-15 18:23:17 +0000447 /// Adds an activation layer to the network.
448 /// @param activationDescriptor - ActivationDescriptor to configure the activation.
449 /// @param name - Optional name for the layer.
450 /// @return - Interface for configuring the layer.
451 IConnectableLayer* AddActivationLayer(const ActivationDescriptor& activationDescriptor,
452 const char* name = nullptr);
453
454 /// Adds a normalization layer to the network.
455 /// @param normalizationDescriptor - NormalizationDescriptor to configure the normalization.
456 /// @param name - Optional name for the layer.
457 /// @return - Interface for configuring the layer.
458 IConnectableLayer* AddNormalizationLayer(const NormalizationDescriptor& normalizationDescriptor,
459 const char* name = nullptr);
460
461 /// Adds a slice layer to the network.
462 /// @param sliceDescriptor - SliceDescriptor to configure the slice operation.
463 /// @param name - Optional name for the layer.
464 /// @return - Interface for configuring the layer.
465 IConnectableLayer* AddSliceLayer(const SliceDescriptor& sliceDescriptor, const char* name = nullptr);
466
467 /// Adds a softmax layer to the network.
468 /// If the data type is QAsymm8, then the output quantization parameters
469 /// must have a scale of 1/256 and an offset of 0
470 /// @param softmaxDescriptor - SoftmaxDescriptor to configure the softmax.
471 /// @param name - Optional name for the layer.
472 /// @return - Interface for configuring the layer.
473 IConnectableLayer* AddSoftmaxLayer(const SoftmaxDescriptor& softmaxDescriptor,
474 const char* name = nullptr);
475
476 /// Adds a splitter layer to the network.
477 /// @param splitterDescriptor - ViewsDescriptor to configure the splitting process.
478 /// Number of Views must be equal to the number of outputs,
479 /// and their order must match - e.g. first view corresponds to
480 /// the first output, second view to the second output, etc....
481 /// @param name - Optional name for the layer.
482 /// @return - Interface for configuring the layer.
483 IConnectableLayer* AddSplitterLayer(const ViewsDescriptor& splitterDescriptor,
484 const char* name = nullptr);
485
486 /// Adds a merge layer to the network.
487 /// @param name - Optional name for the layer.
488 /// @return - Interface for configuring the layer.
489 IConnectableLayer* AddMergeLayer(const char* name = nullptr);
490
Francis Murtagh3d2b4b22021-02-15 18:23:17 +0000491 /// Adds an addition layer to the network.
492 /// @param name - Optional name for the layer.
493 /// @return - Interface for configuring the layer.
494 IConnectableLayer* AddAdditionLayer(const char* name = nullptr);
495
496 /// Adds a multiplication layer to the network.
497 /// @param name - Optional name for the layer.
498 /// @return - Interface for configuring the layer.
499 IConnectableLayer* AddMultiplicationLayer(const char* name = nullptr);
500
501 /// Adds a batch normalization layer to the network.
502 /// @param mean - Pre-calculated mean for each channel.
503 /// @param variance - Pre-calculated variance for each channel.
504 /// @param beta - Per-channel additive factor.
505 /// @param gamma - Per-channel multiplicative factor.
506 /// @return - Interface for configuring the layer.
507 /// @param name - Optional name for the layer.
508 IConnectableLayer* AddBatchNormalizationLayer(const BatchNormalizationDescriptor& desc,
509 const ConstTensor& mean,
510 const ConstTensor& variance,
511 const ConstTensor& beta,
512 const ConstTensor& gamma,
513 const char* name = nullptr);
514
515 /// Adds a rank layer to the network.
516 /// @param name - Optional name for the layer.
517 /// @return - Interface for configuring the layer.
518 IConnectableLayer* AddRankLayer(const char* name = nullptr);
519
Francis Murtagh3d2b4b22021-02-15 18:23:17 +0000520 /// Adds a resize layer to the network.
521 /// @param resizeDescriptor - Parameters for the resize operation.
522 /// @param name - Optional name for the layer.
523 /// @return - Interface for configuring the layer.
524 IConnectableLayer* AddResizeLayer(const ResizeDescriptor& resizeDescriptor,
525 const char* name = nullptr);
526
527 /// Adds a reduce layer to the network.
528 /// @param ReduceDescriptor - Parameters for the reduce operation.
529 /// @param name - Optional name for the layer.
530 /// @return - Interface for configuring the layer.
531 IConnectableLayer* AddReduceLayer(const ReduceDescriptor& reduceDescriptor,
532 const char* name = nullptr);
533
534 /// Adds an instance normalization layer to the network.
535 /// @param desc - Parameters for the instance normalization operation.
536 /// @param name - Optional name for the layer.
537 /// @return - Interface for configuring the layer.
538 IConnectableLayer* AddInstanceNormalizationLayer(const InstanceNormalizationDescriptor& desc,
539 const char* name = nullptr);
540
541 /// Adds an L2 normalization layer to the network.
542 /// Normalization is performed along dimension 1, but requires a 4d input.
543 /// @param desc - Parameters for the L2 normalization operation.
544 /// @param name - Optional name for the layer.
545 /// @return - Interface for configuring the layer.
546 IConnectableLayer* AddL2NormalizationLayer(const L2NormalizationDescriptor& desc,
547 const char* name = nullptr);
548
549 /// Adds a log softmax layer to the network.
550 /// @param logSoftmaxDescriptor - LogSoftmaxDescriptor to configure the log softmax.
551 /// @param name - Optional name for the layer.
552 /// @return - Interface for configuring the layer.
553 IConnectableLayer* AddLogSoftmaxLayer(const LogSoftmaxDescriptor& logSoftmaxDescriptor,
554 const char* name = nullptr);
555
556 /// Adds a layer with no inputs and a single output, which always corresponds to
557 /// the passed in constant tensor.
558 /// @param input - Tensor to be provided as the only output of the layer. The layer will maintain
559 /// its own copy of the tensor data, meaning the memory referenced by @a input can
560 /// be freed or reused after this function is called.
561 /// @param name - Optional name for the layer.
562 /// @return - Interface for configuring the layer.
563 IConnectableLayer* AddConstantLayer(const ConstTensor& input,
564 const char* name = nullptr);
565
566 /// Adds a reshape layer to the network.
567 /// @param reshapeDescriptor - Parameters for the reshape operation.
568 /// @param name - Optional name for the layer.
569 /// @return - Interface for configuring the layer.
570 IConnectableLayer* AddReshapeLayer(const ReshapeDescriptor& reshapeDescriptor,
571 const char* name = nullptr);
572
Keith Davis3ae3f972021-05-21 16:33:48 +0100573 /// Adds a shape layer to the network.
574 /// @param name - Optional name for the layer.
575 /// @return - Interface for configuring the layer.
576 IConnectableLayer* AddShapeLayer(const char* name = nullptr);
577
Francis Murtagh3d2b4b22021-02-15 18:23:17 +0000578 /// Adds a space to batch layer to the network.
579 /// @param spaceToBatchNdDescriptor - Parameters for the space to batch operation.
580 /// @param name - Optional name for the layer.
581 /// @return - Interface for configuring the layer.
582 IConnectableLayer* AddSpaceToBatchNdLayer(const SpaceToBatchNdDescriptor& spaceToBatchNdDescriptor,
583 const char* name = nullptr);
584
585 /// Adds a space to depth layer to the network.
586 /// @param spaceToDepthDescriptor - Parameters for the space to depth operation.
587 /// @param name - Optional name for the layer.
588 /// @return - Interface for configuring the layer.
589 IConnectableLayer* AddSpaceToDepthLayer(const SpaceToDepthDescriptor& spaceToDepthDescriptor,
590 const char* name = nullptr);
591
592 /// Adds a floor layer to the network.
593 /// @param name - Optional name for the layer.
594 /// @return - Interface for configuring the layer.
595 IConnectableLayer* AddFloorLayer(const char* name = nullptr);
596
597 /// Adds an output layer to the network.
598 /// @param id - User generated id to uniquely identify a particular output. The same id needs to be specified
599 /// when passing the outputs to the IRuntime::EnqueueWorkload() function.
600 /// @param name - Optional name for the layer.
601 /// @return - Interface for configuring the layer.
602 IConnectableLayer* AddOutputLayer(LayerBindingId id, const char* name = nullptr);
603
604 /// Add a Lstm layer to the network
605 /// @param descriptor - Parameters for the Lstm operation
606 /// @param params - Weights and biases for the LSTM cell
607 /// @param name - Optional name for the layer
608 /// @return - Interface for configuring the layer.
609 IConnectableLayer* AddLstmLayer(const LstmDescriptor& descriptor,
610 const LstmInputParams& params,
611 const char* name = nullptr);
612
613 /// Adds a division layer to the network.
614 /// @param name - Optional name for the layer.
615 /// @return - Interface for configuring the layer.
616 IConnectableLayer* AddDivisionLayer(const char* name = nullptr);
617
618 /// Adds a subtraction layer to the network.
619 /// @param name - Optional name for the layer.
620 /// @return - Interface for configuring the layer.
621 IConnectableLayer* AddSubtractionLayer(const char* name = nullptr);
622
623 /// Add a Maximum layer to the network.
624 /// @param name - Optional name for the layer.
625 /// @return - Interface for configuring the layer.
626 IConnectableLayer* AddMaximumLayer(const char* name = nullptr);
627
628 /// Add a Mean layer to the network.
629 /// @param meanDescriptor - Parameters for the mean operation.
630 /// @param name - Optional name for the layer.
631 /// @return - Interface for configuring the layer.
632 IConnectableLayer* AddMeanLayer(const MeanDescriptor& meanDescriptor, const char* name = nullptr);
633
634 /// Adds a fully pad layer to the network.
635 /// @param paddings - n by 2 tensor, where n is the rank of the input tensor,
636 /// such that paddings[i,0] indicates the amount of padding to add in front of dimonsion i, and
637 /// paddings[i,1] indicates the amount of padding to add after the end of dimension i
638 /// @param name - Optional name for the layer.
639 /// @return - Interface for configuring the layer.
640 IConnectableLayer* AddPadLayer(const PadDescriptor& padDescriptor,
641 const char* name = nullptr);
642
643 /// Add a quantize layer to the network
644 ///@param name - Optional name for the layer.
645 /// @return - Interface for configuring the layer.
646 IConnectableLayer* AddQuantizeLayer(const char* name = nullptr);
647
648 /// Adds a strided slice layer to the network.
649 /// @param StridedSliceDescriptor - Parameters for the strided slice operation.
650 /// @param name - Optional name for the layer.
651 /// @return - Interface for configuring the layer.
652 IConnectableLayer* AddStridedSliceLayer(const StridedSliceDescriptor& stridedSliceDescriptor,
653 const char* name = nullptr);
654
655 /// Add a Minimum layer to the network.
656 /// @param name - Optional name for the layer.
657 /// @return - Interface for configuring the layer.
658 IConnectableLayer* AddMinimumLayer(const char* name = nullptr);
659
Francis Murtagh3d2b4b22021-02-15 18:23:17 +0000660 /// Add Gather layer to the network.
661 /// @param descriptor - Description of the gather layer.
662 /// @param name - Optional name for the layer.
663 /// @return - Interface for configuring the layer.
664 IConnectableLayer* AddGatherLayer(const GatherDescriptor& descriptor,
665 const char* name = nullptr);
666
Teresa Charlinb2d3ec52022-04-12 22:07:09 +0100667 /// Add GatherNd layer to the network.
668 /// @param name - Optional name for the layer.
669 /// @return - Interface for configuring the layer.
670 IConnectableLayer* AddGatherNdLayer(const char* name = nullptr);
671
Francis Murtagh3d2b4b22021-02-15 18:23:17 +0000672 /// Adds a switch layer to the network.
673 /// @param name - Optional name for the layer.
674 /// @return - Interface for configuring the layer.
675 IConnectableLayer* AddSwitchLayer(const char* name = nullptr);
676
677 /// Adds a PReLU layer to the network.
678 /// @param name - Optional name for the layer.
679 /// @return - Interface for configuring the layer.
680 IConnectableLayer* AddPreluLayer(const char* name = nullptr);
681
682 /// Adds a 2D transpose convolution layer to the network.
683 /// @param descriptor - Description of the 2D transpose convolution layer.
684 /// @param weights - Tensor for the weights data.
685 /// @param biases - Optional tensor for the bias data.
686 /// @param name - Optional name for the layer.
687 /// @return - Interface for configuring the layer.
688 IConnectableLayer* AddTransposeConvolution2dLayer(const TransposeConvolution2dDescriptor& descriptor,
689 const ConstTensor& weights,
690 const Optional<ConstTensor>& biases,
691 const char* name = nullptr);
692
693 /// Adds a transpose layer to the network.
694 /// @param transposeDescriptor - TransposeDescriptor to configure the transpose.
695 /// @param name - Optional name for the layer.
696 /// @return - Interface for configuring the layer.
697 IConnectableLayer* AddTransposeLayer(const TransposeDescriptor& transposeDescriptor,
698 const char* name = nullptr);
699
700 /// Adds a stack layer to the network.
701 /// @param descriptor - Description of the stack layer.
702 /// @param name - Optional name for the layer.
703 /// @return - Interface for configuring the layer.
704 IConnectableLayer* AddStackLayer(const StackDescriptor& descriptor,
705 const char* name = nullptr);
706
707 /// Add a stand-in layer for a type unknown to the Arm NN framework.
708 /// Note: Due to the nature of this layer, no validation can be performed by the framework.
709 /// Furthermore, Any model containing this layer cannot make use of dynamic tensors since the
710 /// tensor sizes cannot be inferred.
711 /// @descriptor - Descriptor for the StandIn layer.
712 /// @return - Interface for configuring the layer.
713 IConnectableLayer* AddStandInLayer(const StandInDescriptor& descriptor,
714 const char* name = nullptr);
715
716 /// Add a QuantizedLstm layer to the network
717 /// @param params - The weights and biases for the Quantized LSTM cell
718 /// @param name - Optional name for the layer
719 /// @return - Interface for configuring the layer.
720 IConnectableLayer* AddQuantizedLstmLayer(const QuantizedLstmInputParams& params,
721 const char* name = nullptr);
722
723 /// Add a QLstm layer to the network
724 /// @param descriptor - Parameters for the QLstm operation
725 /// @param params - Weights and biases for the layer
726 /// @param name - Optional name for the layer
727 /// @return - Interface for configuring the layer.
728 IConnectableLayer* AddQLstmLayer(const QLstmDescriptor& descriptor,
729 const LstmInputParams& params,
730 const char* name = nullptr);
731
732 /// Adds a Logical Binary layer to the network.
733 /// @param descriptor - Description of the Logical Binary layer.
734 /// @param name - Optional name for the layer.
735 /// @return - Interface for configuring the layer.
736 IConnectableLayer* AddLogicalBinaryLayer(const LogicalBinaryDescriptor& descriptor,
737 const char* name = nullptr);
738
Narumol Prangnawarat8ed39ae2021-07-15 16:16:25 +0100739 /// Add a UnidirectionalSequenceLstm layer to the network
740 /// @param descriptor - Parameters for the UnidirectionalSequenceLstm operation
741 /// @param params - Weights and biases for the UnidirectionalSequenceLstm
742 /// @param name - Optional name for the layer
743 /// @return - Interface for configuring the layer.
744 IConnectableLayer* AddUnidirectionalSequenceLstmLayer(const UnidirectionalSequenceLstmDescriptor& descriptor,
745 const LstmInputParams& params,
746 const char* name = nullptr);
747
Simon Obute51f67772021-09-03 15:50:13 +0100748 /// Add a ChannelShuffle layer to the network
749 /// @param descriptor - Parameters for the ChannelShuffle operation
750 /// @param name - Optional name for the layer
751 /// @return - Interface for configuring the layer
752 IConnectableLayer* AddChannelShuffleLayer(const ChannelShuffleDescriptor& descriptor,
753 const char* name = nullptr);
754
Francis Murtagh3d2b4b22021-02-15 18:23:17 +0000755
756 void ExecuteStrategy(IStrategy& strategy) const;
757
758protected:
759 ~INetwork();
760
Francis Murtagh3d2b4b22021-02-15 18:23:17 +0000761 friend void VisitLayersTopologically(const INetwork* inputNetwork, IStrategy& strategy);
762 friend class TestConnectionPreservation;
763 friend TensorInfo GetInputTensorInfo(const INetwork* network);
764 friend IOptimizedNetworkPtr Optimize(const INetwork& network,
765 const std::vector<BackendId>& backendPreferences,
766 const IDeviceSpec& deviceSpec,
767 const OptimizerOptions& options,
768 Optional<std::vector<std::string>&> messages);
769
770 INetwork(NetworkOptions networkOptions = {});
771
772 std::unique_ptr<NetworkImpl> pNetworkImpl;
773};
774
Mike Kelly386ff1a2021-03-29 15:04:50 +0100775namespace experimental
776{
Sadik Armagana0042512021-03-30 11:05:36 +0100777class AsyncNetworkImpl;
Mike Kelly386ff1a2021-03-29 15:04:50 +0100778class WorkingMemHandle;
779}
780
Francis Murtagh3d2b4b22021-02-15 18:23:17 +0000781struct BackendSettings;
782struct OptimizationResult;
783class OptimizedNetworkImpl;
Derek Lambertie155bbf2021-10-13 14:32:12 +0100784class IProfiler;
Francis Murtagh3d2b4b22021-02-15 18:23:17 +0000785class IOptimizedNetwork
786{
787public:
788 static void Destroy(IOptimizedNetwork* network);
789
790 Status PrintGraph();
791 Status SerializeToDot(std::ostream& stream) const;
792
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000793 arm::pipe::ProfilingGuid GetGuid() const;
Francis Murtagh3d2b4b22021-02-15 18:23:17 +0000794
Sadik Armaganb7851f92021-10-06 16:37:02 +0100795 size_t GetNumInputs() const;
796 size_t GetNumOutputs() const;
797
Mike Kelly0d677db2021-06-27 22:39:21 +0100798 // Creates a copy of the IOptimizedNetwork. The IOptimizedNetwork will not be reoptimized,
799 // the provided ModelOptions will only be used when creating a LoadedNetwork.
800 IOptimizedNetwork(const IOptimizedNetwork& other, const ModelOptions& modelOptions);
Francis Murtagh3d2b4b22021-02-15 18:23:17 +0000801 IOptimizedNetwork(std::unique_ptr<Graph> graph);
802 IOptimizedNetwork(std::unique_ptr<OptimizedNetworkImpl> impl);
803 ~IOptimizedNetwork();
804
Derek Lambertie155bbf2021-10-13 14:32:12 +0100805 const std::shared_ptr<IProfiler>& GetProfiler() const;
806
Francis Murtagh3d2b4b22021-02-15 18:23:17 +0000807protected:
808 friend class LoadedNetwork;
Mike Kelly386ff1a2021-03-29 15:04:50 +0100809
Sadik Armagana0042512021-03-30 11:05:36 +0100810 friend class experimental::AsyncNetworkImpl;
Mike Kelly386ff1a2021-03-29 15:04:50 +0100811 friend class experimental::WorkingMemHandle;
812
Francis Murtagh3d2b4b22021-02-15 18:23:17 +0000813 friend Graph& GetGraphForTesting(IOptimizedNetwork* optNetPtr);
814 friend ModelOptions& GetModelOptionsForTesting(IOptimizedNetwork* optNetPtr);
815 friend IOptimizedNetworkPtr Optimize(const INetwork& inNetwork,
816 const std::vector<BackendId>& backendPreferences,
817 const IDeviceSpec& deviceSpec,
818 const OptimizerOptions& options,
819 Optional<std::vector<std::string>&> messages);
Cathal Corbetta3f4fba2022-03-21 09:27:08 +0000820 friend IOptimizedNetworkPtr Optimize(const Graph& inGraph,
821 const std::vector<BackendId>& backendPreferences,
822 const IDeviceSpec& deviceSpec,
823 const OptimizerOptions& options,
824 Optional<std::vector<std::string>&> messages);
Francis Murtagh3d2b4b22021-02-15 18:23:17 +0000825
Francis Murtagh3d2b4b22021-02-15 18:23:17 +0000826 IOptimizedNetwork(std::unique_ptr<Graph> graph, const ModelOptions& modelOptions);
827
828 std::unique_ptr<OptimizedNetworkImpl> pOptimizedNetworkImpl;
829};
830
telsoa014fcda012018-03-09 14:13:49 +0000831/// Create an optimized version of the network
832/// @param network INetwork description of the network to be optimized.
telsoa01c577f2c2018-08-31 09:22:23 +0100833/// @param backendPreferences The choice of the backend ordered by user preferences.
834/// @param deviceSpec DeviceSpec object as queried from the runtime. See IRuntime::GetDeviceSpec()
Rob Hughes23214432019-11-05 11:27:36 +0000835/// @param messages If there are failures or warnings a string describing same will be added to the vector
telsoa01c577f2c2018-08-31 09:22:23 +0100836/// @param options OptimizerOptions object with optimizer configuration options
telsoa014fcda012018-03-09 14:13:49 +0000837/// @return An IOptimizedNetworkPtr interface to the optimized network, throws an exception derived from
838/// armnn::Exception if process fails.
telsoa014fcda012018-03-09 14:13:49 +0000839
telsoa01c577f2c2018-08-31 09:22:23 +0100840IOptimizedNetworkPtr Optimize(const INetwork& network,
David Beckf0b48452018-10-19 15:20:56 +0100841 const std::vector<BackendId>& backendPreferences,
telsoa01c577f2c2018-08-31 09:22:23 +0100842 const IDeviceSpec& deviceSpec,
jimfly016b0b53d2018-10-08 14:43:01 +0100843 const OptimizerOptions& options = OptimizerOptions(),
Rob Hughes23214432019-11-05 11:27:36 +0000844 Optional<std::vector<std::string>&> messages = EmptyOptional());
Cathal Corbetta3f4fba2022-03-21 09:27:08 +0000845
846/// Create an optimized version of the network
847/// @param inGraph Graph to be optimized.
848/// @param backendPreferences The choice of the backend ordered by user preferences.
849/// @param deviceSpec DeviceSpec object as queried from the runtime. See IRuntime::GetDeviceSpec()
850/// @param messages If there are failures or warnings a string describing same will be added to the vector
851/// @param options OptimizerOptions object with optimizer configuration options
852/// @return An IOptimizedNetworkPtr interface to the optimized network, throws an exception derived from
853/// armnn::Exception if process fails.
854
855IOptimizedNetworkPtr Optimize(const Graph& inGraph,
856 const std::vector<BackendId>& backendPreferences,
857 const IDeviceSpec& deviceSpec,
858 const OptimizerOptions& options,
859 Optional<std::vector<std::string>&> messages = EmptyOptional());
telsoa014fcda012018-03-09 14:13:49 +0000860} //namespace armnn