Laurent Carlier | 749294b | 2020-06-01 09:03:17 +0100 | [diff] [blame] | 1 | // |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
David Beck | ecb56cd | 2018-09-05 12:52:57 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 4 | // |
| 5 | #pragma once |
| 6 | |
Jim Flynn | 906f946 | 2019-05-10 13:55:21 +0100 | [diff] [blame] | 7 | #include <armnn/Deprecated.hpp> |
David Beck | f0b4845 | 2018-10-19 15:20:56 +0100 | [diff] [blame] | 8 | #include <armnn/DescriptorsFwd.hpp> |
jimfly01 | e9e7bfd | 2019-01-24 22:29:33 +0000 | [diff] [blame] | 9 | #include <armnn/ILayerVisitor.hpp> |
Matthew Bentham | 313e1c8 | 2019-03-25 17:37:47 +0000 | [diff] [blame] | 10 | #include <armnn/NetworkFwd.hpp> |
| 11 | #include <armnn/Optional.hpp> |
| 12 | #include <armnn/TensorFwd.hpp> |
David Beck | f0b4845 | 2018-10-19 15:20:56 +0100 | [diff] [blame] | 13 | #include <armnn/Types.hpp> |
Matteo Martincigh | fc598e1 | 2019-05-14 10:36:13 +0100 | [diff] [blame] | 14 | #include <armnn/Deprecated.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 15 | |
| 16 | #include <memory> |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 17 | #include <vector> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 18 | |
| 19 | namespace armnn |
| 20 | { |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 21 | /// @brief An input connection slot for a layer. |
| 22 | /// The input slot can be connected to an output slot of the preceding layer in the graph. |
| 23 | /// Only one connection to the input slot is allowed. |
| 24 | class IInputSlot |
| 25 | { |
| 26 | public: |
| 27 | virtual const IOutputSlot* GetConnection() const = 0; |
| 28 | virtual IOutputSlot* GetConnection() = 0; |
| 29 | |
| 30 | protected: |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 31 | /// Not user deletable. |
| 32 | ~IInputSlot() {} |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 33 | }; |
| 34 | |
| 35 | /// @brief An output connection slot for a layer. |
| 36 | /// The output slot may be connected to 1 or more input slots of subsequent layers in the graph. |
| 37 | class IOutputSlot |
| 38 | { |
| 39 | public: |
| 40 | virtual unsigned int GetNumConnections() const = 0; |
| 41 | virtual const IInputSlot* GetConnection(unsigned int index) const = 0; |
| 42 | virtual IInputSlot* GetConnection(unsigned int index) = 0; |
| 43 | |
| 44 | virtual void SetTensorInfo(const TensorInfo& tensorInfo) = 0; |
| 45 | virtual const TensorInfo& GetTensorInfo() const = 0; |
| 46 | virtual bool IsTensorInfoSet() const = 0; |
| 47 | |
| 48 | virtual int Connect(IInputSlot& destination) = 0; |
| 49 | virtual void Disconnect(IInputSlot& slot) = 0; |
| 50 | |
Mike Kelly | 8c1701a | 2019-02-11 17:01:27 +0000 | [diff] [blame] | 51 | virtual unsigned int CalculateIndexOnOwner() const = 0; |
| 52 | |
| 53 | virtual LayerGuid GetOwningLayerGuid() const = 0; |
| 54 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 55 | protected: |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 56 | /// Not user deletable. |
| 57 | ~IOutputSlot() {} |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | /// @brief Interface for a layer that is connectable to other layers via InputSlots and OutputSlots. |
| 61 | class IConnectableLayer |
| 62 | { |
| 63 | public: |
Derek Lamberti | 4a9e24b | 2020-01-03 16:53:38 +0000 | [diff] [blame] | 64 | /// Returns the name of the layer |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 65 | virtual const char* GetName() const = 0; |
| 66 | |
Derek Lamberti | 4a9e24b | 2020-01-03 16:53:38 +0000 | [diff] [blame] | 67 | /// Returns the number of connectable input slots |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 68 | virtual unsigned int GetNumInputSlots() const = 0; |
Derek Lamberti | 4a9e24b | 2020-01-03 16:53:38 +0000 | [diff] [blame] | 69 | |
| 70 | /// Returns the number of connectable output slots |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 71 | virtual unsigned int GetNumOutputSlots() const = 0; |
| 72 | |
Derek Lamberti | 4a9e24b | 2020-01-03 16:53:38 +0000 | [diff] [blame] | 73 | /// Get a const input slot handle by slot index |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 74 | virtual const IInputSlot& GetInputSlot(unsigned int index) const = 0; |
Derek Lamberti | 4a9e24b | 2020-01-03 16:53:38 +0000 | [diff] [blame] | 75 | |
| 76 | /// Get the input slot handle by slot index |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 77 | virtual IInputSlot& GetInputSlot(unsigned int index) = 0; |
| 78 | |
Derek Lamberti | 4a9e24b | 2020-01-03 16:53:38 +0000 | [diff] [blame] | 79 | /// Get the const output slot handle by slot index |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 80 | virtual const IOutputSlot& GetOutputSlot(unsigned int index) const = 0; |
Derek Lamberti | 4a9e24b | 2020-01-03 16:53:38 +0000 | [diff] [blame] | 81 | |
| 82 | /// Get the output slot handle by slot index |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 83 | virtual IOutputSlot& GetOutputSlot(unsigned int index) = 0; |
| 84 | |
Derek Lamberti | 4a9e24b | 2020-01-03 16:53:38 +0000 | [diff] [blame] | 85 | /// Infer the shape of the output(s) based on the provided input shape(s) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 86 | virtual std::vector<TensorShape> InferOutputShapes(const std::vector<TensorShape>& inputShapes) const = 0; |
| 87 | |
Derek Lamberti | 4a9e24b | 2020-01-03 16:53:38 +0000 | [diff] [blame] | 88 | /// Returns the unique id of the layer |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 89 | virtual LayerGuid GetGuid() const = 0; |
jimfly01 | e9e7bfd | 2019-01-24 22:29:33 +0000 | [diff] [blame] | 90 | |
Derek Lamberti | 4a9e24b | 2020-01-03 16:53:38 +0000 | [diff] [blame] | 91 | /// Apply a visitor to this layer |
jimfly01 | e9e7bfd | 2019-01-24 22:29:33 +0000 | [diff] [blame] | 92 | virtual void Accept(ILayerVisitor& visitor) const = 0; |
Derek Lamberti | 4a9e24b | 2020-01-03 16:53:38 +0000 | [diff] [blame] | 93 | |
| 94 | /// Provide a hint for the optimizer as to which backend to prefer for this layer |
| 95 | virtual void BackendSelectionHint(Optional<BackendId> backend) = 0; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 96 | protected: |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 97 | /// Objects are not deletable via the handle |
| 98 | ~IConnectableLayer() {} |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 99 | }; |
| 100 | |
| 101 | using INetworkPtr = std::unique_ptr<INetwork, void(*)(INetwork* network)>; |
| 102 | |
| 103 | /// Main network class which provides the interface for building up a neural network. |
| 104 | /// This object is subsequently required by the IRuntime::Load() method. |
| 105 | class INetwork |
| 106 | { |
| 107 | public: |
| 108 | static INetwork* CreateRaw(); |
| 109 | static INetworkPtr Create(); |
| 110 | static void Destroy(INetwork* network); |
| 111 | |
| 112 | virtual Status PrintGraph() = 0; |
| 113 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 114 | /// Adds an input layer to the network. |
| 115 | /// @param id - User generated id to uniquely identify a particular input. The same id needs to be specified. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 116 | /// when passing the inputs to the IRuntime::EnqueueWorkload() function. |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 117 | /// @param name - Optional name for the layer. |
| 118 | /// @return - Interface for configuring the layer. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 119 | virtual IConnectableLayer* AddInputLayer(LayerBindingId id, const char* name = nullptr) = 0; |
| 120 | |
Nikhil Raj | ee391d5 | 2019-09-05 17:50:44 +0100 | [diff] [blame] | 121 | /// Adds an ArgMinMax layer to the network. |
| 122 | /// @param desc - Parameters for the L2 normalization operation. |
| 123 | /// @param name - Optional name for the layer. |
| 124 | /// @return - Interface for configuring the layer. |
| 125 | virtual IConnectableLayer* AddArgMinMaxLayer(const ArgMinMaxDescriptor& desc, |
| 126 | const char* name = nullptr) = 0; |
| 127 | |
Aron Virginas-Tar | 77bfb5e | 2019-10-16 17:45:38 +0100 | [diff] [blame] | 128 | /// Add a Comparison layer to the network. |
| 129 | /// @param name - Optional name for the layer. |
| 130 | /// @param desc - Descriptor for the comparison operation. |
| 131 | /// @ return - Interface for configuring the layer. |
| 132 | virtual IConnectableLayer* AddComparisonLayer(const ComparisonDescriptor& comparisonDescriptor, |
| 133 | const char* name = nullptr) = 0; |
| 134 | |
Jim Flynn | 906f946 | 2019-05-10 13:55:21 +0100 | [diff] [blame] | 135 | /// Adds a concatenation layer to the network. |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 136 | /// @param concatDescriptor - ConcatDescriptor (synonym for OriginsDescriptor) to configure the concatenation |
| 137 | /// process. Number of Views must be equal to the number of inputs, and their order |
| 138 | /// must match - e.g. first view corresponds to the first input, second view to the |
| 139 | /// second input, etc.... |
Jim Flynn | 906f946 | 2019-05-10 13:55:21 +0100 | [diff] [blame] | 140 | /// @param name - Optional name for the layer. |
| 141 | /// @return - Interface for configuring the layer. |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 142 | virtual IConnectableLayer* AddConcatLayer(const ConcatDescriptor& concatDescriptor, |
Jim Flynn | 906f946 | 2019-05-10 13:55:21 +0100 | [diff] [blame] | 143 | const char* name = nullptr) = 0; |
| 144 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 145 | /// Adds a 2D convolution layer to the network. |
| 146 | /// @param convolution2dDescriptor - Description of the 2D convolution layer. |
| 147 | /// @param weights - Tensor for the weights data. |
Aron Virginas-Tar | ad40270 | 2019-02-22 17:03:44 +0000 | [diff] [blame] | 148 | /// @param biases - Optional tensor for the bias data. If specified, must match the output tensor shape. |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 149 | /// @param name - Optional name for the layer. |
| 150 | /// @return - Interface for configuring the layer. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 151 | virtual IConnectableLayer* AddConvolution2dLayer(const Convolution2dDescriptor& convolution2dDescriptor, |
Aron Virginas-Tar | ad40270 | 2019-02-22 17:03:44 +0000 | [diff] [blame] | 152 | const ConstTensor& weights, |
| 153 | const Optional<ConstTensor>& biases, |
| 154 | const char* name = nullptr) = 0; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 155 | |
Matteo Martincigh | fc598e1 | 2019-05-14 10:36:13 +0100 | [diff] [blame] | 156 | ARMNN_DEPRECATED_MSG("This AddConvolution2dLayer overload is deprecated") |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 157 | virtual IConnectableLayer* AddConvolution2dLayer(const Convolution2dDescriptor& convolution2dDescriptor, |
Aron Virginas-Tar | ad40270 | 2019-02-22 17:03:44 +0000 | [diff] [blame] | 158 | const ConstTensor& weights, |
| 159 | const char* name = nullptr) = 0; |
| 160 | |
Matteo Martincigh | fc598e1 | 2019-05-14 10:36:13 +0100 | [diff] [blame] | 161 | ARMNN_DEPRECATED_MSG("This AddConvolution2dLayer overload is deprecated") |
Aron Virginas-Tar | ad40270 | 2019-02-22 17:03:44 +0000 | [diff] [blame] | 162 | virtual IConnectableLayer* AddConvolution2dLayer(const Convolution2dDescriptor& convolution2dDescriptor, |
| 163 | const ConstTensor& weights, |
| 164 | const ConstTensor& biases, |
| 165 | const char* name = nullptr) = 0; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 166 | |
Aron Virginas-Tar | dd6247f | 2019-09-19 14:31:17 +0100 | [diff] [blame] | 167 | /// Adds a depth to space layer to the network. |
| 168 | /// @param depthToSpaceDescriptor - Parameters for the depth to space operation. |
| 169 | /// @param name - Optional name for the layer. |
| 170 | /// @return - Interface for configuring the layer. |
| 171 | virtual IConnectableLayer* AddDepthToSpaceLayer(const DepthToSpaceDescriptor& depthToSpaceDescriptor, |
| 172 | const char* name = nullptr) = 0; |
| 173 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 174 | /// Adds a 2D depthwise convolution layer to the network. |
| 175 | /// @param convolution2dDescriptor - Description of the 2D depthwise convolution layer. |
Rob Hughes | 144c01b | 2018-11-21 13:34:24 +0000 | [diff] [blame] | 176 | /// @param weights - Tensor for the weights. Expected format: [channelMultiplier, inputChannels, height, width]. |
Aron Virginas-Tar | ad40270 | 2019-02-22 17:03:44 +0000 | [diff] [blame] | 177 | /// @param biases Optional tensor for the bias data. If specified, must match the output tensor shape. |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 178 | /// @param name - Optional name for the layer. |
| 179 | /// @return - Interface for configuring the layer. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 180 | virtual IConnectableLayer* AddDepthwiseConvolution2dLayer( |
| 181 | const DepthwiseConvolution2dDescriptor& convolution2dDescriptor, |
| 182 | const ConstTensor& weights, |
Aron Virginas-Tar | ad40270 | 2019-02-22 17:03:44 +0000 | [diff] [blame] | 183 | const Optional<ConstTensor>& biases, |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 184 | const char* name = nullptr) = 0; |
| 185 | |
Matteo Martincigh | fc598e1 | 2019-05-14 10:36:13 +0100 | [diff] [blame] | 186 | ARMNN_DEPRECATED_MSG("This AddDepthwiseConvolution2dLayer overload is deprecated") |
Aron Virginas-Tar | ad40270 | 2019-02-22 17:03:44 +0000 | [diff] [blame] | 187 | virtual IConnectableLayer* AddDepthwiseConvolution2dLayer( |
| 188 | const DepthwiseConvolution2dDescriptor& convolution2dDescriptor, |
| 189 | const ConstTensor& weights, |
| 190 | const char* name = nullptr) = 0; |
| 191 | |
Matteo Martincigh | fc598e1 | 2019-05-14 10:36:13 +0100 | [diff] [blame] | 192 | ARMNN_DEPRECATED_MSG("This AddDepthwiseConvolution2dLayer overload is deprecated") |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 193 | virtual IConnectableLayer* AddDepthwiseConvolution2dLayer( |
| 194 | const DepthwiseConvolution2dDescriptor& convolution2dDescriptor, |
| 195 | const ConstTensor& weights, |
| 196 | const ConstTensor& biases, |
| 197 | const char* name = nullptr) = 0; |
| 198 | |
Nattapat Chaimanowong | e4294fd | 2019-03-28 09:56:53 +0000 | [diff] [blame] | 199 | /// Adds a Dequantize layer to the network. |
| 200 | /// @return - Interface for configuring the layer. |
| 201 | virtual IConnectableLayer* AddDequantizeLayer(const char* name = nullptr) = 0; |
| 202 | |
Narumol Prangnawarat | 94dd5d8 | 2019-01-23 18:06:26 +0000 | [diff] [blame] | 203 | /// Adds a Detection PostProcess layer to the network. |
| 204 | /// @param descriptor - Description of the Detection PostProcess layer. |
Narumol Prangnawarat | 6d302bf | 2019-02-04 11:46:26 +0000 | [diff] [blame] | 205 | /// @param anchors - Tensor for anchors. |
Narumol Prangnawarat | 94dd5d8 | 2019-01-23 18:06:26 +0000 | [diff] [blame] | 206 | /// @param name - Optional name for the layer. |
| 207 | /// @return - Interface for configuring the layer. |
| 208 | virtual IConnectableLayer* AddDetectionPostProcessLayer( |
Narumol Prangnawarat | 6d302bf | 2019-02-04 11:46:26 +0000 | [diff] [blame] | 209 | const DetectionPostProcessDescriptor& descriptor, |
| 210 | const ConstTensor& anchors, |
| 211 | const char* name = nullptr) = 0; |
Narumol Prangnawarat | 94dd5d8 | 2019-01-23 18:06:26 +0000 | [diff] [blame] | 212 | |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 213 | /// Add an ElementwiseUnary layer to the network. |
| 214 | /// @param name - Optional name for the layer. |
| 215 | /// @param desc - Descriptor for the elementwiseUnary operation. |
Ryan OShea | ec6c680 | 2020-06-05 17:17:06 +0100 | [diff] [blame] | 216 | /// @return - Interface for configuring the layer. |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 217 | virtual IConnectableLayer* AddElementwiseUnaryLayer(const ElementwiseUnaryDescriptor& elementwiseUnaryDescriptor, |
| 218 | const char* name = nullptr) = 0; |
| 219 | |
Ryan OShea | ec6c680 | 2020-06-05 17:17:06 +0100 | [diff] [blame] | 220 | /// Add an Fill layer to the network. |
| 221 | /// @param name - Optional name for the layer. |
| 222 | /// @param fillDescriptor - Descriptor for the fill operation. |
| 223 | /// @return - Interface for configuring the layer. |
| 224 | virtual IConnectableLayer* AddFillLayer(const FillDescriptor& fillDescriptor, |
| 225 | const char* name = nullptr) = 0; |
| 226 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 227 | /// Adds a fully connected layer to the network. |
| 228 | /// @param fullyConnectedDescriptor - Description of the fully connected layer. |
| 229 | /// @param weights - Tensor for the weights data. |
Aron Virginas-Tar | ad40270 | 2019-02-22 17:03:44 +0000 | [diff] [blame] | 230 | /// @param biases - Optional tensor for the bias data. |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 231 | /// @param name - Optional name for the layer. |
| 232 | /// @return - Interface for configuring the layer. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 233 | virtual IConnectableLayer* AddFullyConnectedLayer(const FullyConnectedDescriptor& fullyConnectedDescriptor, |
Aron Virginas-Tar | ad40270 | 2019-02-22 17:03:44 +0000 | [diff] [blame] | 234 | const ConstTensor& weights, |
| 235 | const Optional<ConstTensor>& biases, |
| 236 | const char* name = nullptr) = 0; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 237 | |
Matteo Martincigh | fc598e1 | 2019-05-14 10:36:13 +0100 | [diff] [blame] | 238 | ARMNN_DEPRECATED_MSG("This AddFullyConnectedLayer overload is deprecated") |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 239 | virtual IConnectableLayer* AddFullyConnectedLayer(const FullyConnectedDescriptor& fullyConnectedDescriptor, |
Aron Virginas-Tar | ad40270 | 2019-02-22 17:03:44 +0000 | [diff] [blame] | 240 | const ConstTensor& weights, |
| 241 | const char* name = nullptr) = 0; |
| 242 | |
Matteo Martincigh | fc598e1 | 2019-05-14 10:36:13 +0100 | [diff] [blame] | 243 | ARMNN_DEPRECATED_MSG("This AddFullyConnectedLayer overload is deprecated") |
Aron Virginas-Tar | ad40270 | 2019-02-22 17:03:44 +0000 | [diff] [blame] | 244 | virtual IConnectableLayer* AddFullyConnectedLayer(const FullyConnectedDescriptor& fullyConnectedDescriptor, |
| 245 | const ConstTensor& weights, |
| 246 | const ConstTensor& biases, |
| 247 | const char* name = nullptr) = 0; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 248 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 249 | /// Adds a permute layer to the network. |
| 250 | /// @param permuteDescriptor - PermuteDescriptor to configure the permute. |
| 251 | /// @param name - Optional name for the layer. |
| 252 | /// @return - Interface for configuring the layer. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 253 | virtual IConnectableLayer* AddPermuteLayer(const PermuteDescriptor& permuteDescriptor, |
| 254 | const char* name = nullptr) = 0; |
| 255 | |
Éanna Ó Catháin | 4e1e136 | 2018-11-12 11:36:34 +0000 | [diff] [blame] | 256 | /// Adds a batch to space ND layer to the network. |
| 257 | /// @param batchToSpaceNdDescriptor - Description of the layer. |
| 258 | /// @param name - Optional name for the layer. |
| 259 | /// @return - Interface for configuring the layer. |
| 260 | virtual IConnectableLayer* AddBatchToSpaceNdLayer(const BatchToSpaceNdDescriptor& batchToSpaceNdDescriptor, |
| 261 | const char* name = nullptr) = 0; |
| 262 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 263 | /// Adds a pooling layer to the network. |
| 264 | /// @param pooling2dDescriptor - Pooling2dDescriptor to configure the pooling. |
| 265 | /// @param name - Optional name for the layer. |
| 266 | /// @return - Interface for configuring the layer. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 267 | virtual IConnectableLayer* AddPooling2dLayer(const Pooling2dDescriptor& pooling2dDescriptor, |
| 268 | const char* name = nullptr) = 0; |
| 269 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 270 | /// Adds an activation layer to the network. |
| 271 | /// @param activationDescriptor - ActivationDescriptor to configure the activation. |
| 272 | /// @param name - Optional name for the layer. |
| 273 | /// @return - Interface for configuring the layer. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 274 | virtual IConnectableLayer* AddActivationLayer(const ActivationDescriptor& activationDescriptor, |
| 275 | const char* name = nullptr) = 0; |
| 276 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 277 | /// Adds a normalization layer to the network. |
| 278 | /// @param normalizationDescriptor - NormalizationDescriptor to configure the normalization. |
| 279 | /// @param name - Optional name for the layer. |
| 280 | /// @return - Interface for configuring the layer. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 281 | virtual IConnectableLayer* AddNormalizationLayer(const NormalizationDescriptor& normalizationDescriptor, |
| 282 | const char* name = nullptr) = 0; |
| 283 | |
Aron Virginas-Tar | 636ab40 | 2019-09-16 14:27:45 +0100 | [diff] [blame] | 284 | /// Adds a slice layer to the network. |
| 285 | /// @param sliceDescriptor - SliceDescriptor to configure the slice operation. |
| 286 | /// @param name - Optional name for the layer. |
| 287 | /// @return - Interface for configuring the layer. |
| 288 | virtual IConnectableLayer* AddSliceLayer(const SliceDescriptor& sliceDescriptor, const char* name = nullptr) = 0; |
| 289 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 290 | /// Adds a softmax layer to the network. |
David Monahan | b855470 | 2019-04-25 16:03:38 +0100 | [diff] [blame] | 291 | /// If the data type is QAsymm8, then the output quantization parameters |
| 292 | /// must have a scale of 1/256 and an offset of 0 |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 293 | /// @param softmaxDescriptor - SoftmaxDescriptor to configure the softmax. |
| 294 | /// @param name - Optional name for the layer. |
| 295 | /// @return - Interface for configuring the layer. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 296 | virtual IConnectableLayer* AddSoftmaxLayer(const SoftmaxDescriptor& softmaxDescriptor, |
| 297 | const char* name = nullptr) = 0; |
| 298 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 299 | /// Adds a splitter layer to the network. |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 300 | /// @param splitterDescriptor - ViewsDescriptor to configure the splitting process. |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 301 | /// Number of Views must be equal to the number of outputs, |
| 302 | /// and their order must match - e.g. first view corresponds to |
| 303 | /// the first output, second view to the second output, etc.... |
| 304 | /// @param name - Optional name for the layer. |
| 305 | /// @return - Interface for configuring the layer. |
Aron Virginas-Tar | 636ab40 | 2019-09-16 14:27:45 +0100 | [diff] [blame] | 306 | virtual IConnectableLayer* AddSplitterLayer(const ViewsDescriptor& splitterDescriptor, |
| 307 | const char* name = nullptr) = 0; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 308 | |
Nattapat Chaimanowong | 1f88630 | 2019-04-05 13:37:19 +0100 | [diff] [blame] | 309 | /// Adds a merge layer to the network. |
| 310 | /// @param name - Optional name for the layer. |
| 311 | /// @return - Interface for configuring the layer. |
| 312 | virtual IConnectableLayer* AddMergeLayer(const char* name = nullptr) = 0; |
| 313 | |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 314 | /// Adds a concat layer to the network. |
| 315 | /// @param mergerDescriptor - MergerDescriptor (synonym for OriginsDescriptor) to configure the concatenation |
| 316 | /// process. Number of Views must be equal to the number of inputs, and their order |
| 317 | /// must match - e.g. first view corresponds to the first input, second view to the |
| 318 | /// second input, etc.... |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 319 | /// @param name - Optional name for the layer. |
| 320 | /// @return - Interface for configuring the layer. |
Jim Flynn | 906f946 | 2019-05-10 13:55:21 +0100 | [diff] [blame] | 321 | ARMNN_DEPRECATED_MSG("Use AddConcatLayer instead") |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 322 | virtual IConnectableLayer* AddMergerLayer(const MergerDescriptor& mergerDescriptor, |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 323 | const char* name = nullptr) = 0; |
| 324 | |
Kevin May | 868eb14 | 2019-09-04 17:29:31 +0100 | [diff] [blame] | 325 | /// Add absolute layer to the network. |
| 326 | /// @param name - Optional name for the layer. |
| 327 | /// @ return - Interface for configuring the layer. |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 328 | ARMNN_DEPRECATED_MSG("Use AddElementwiseUnaryLayer instead") |
Kevin May | 868eb14 | 2019-09-04 17:29:31 +0100 | [diff] [blame] | 329 | virtual IConnectableLayer* AddAbsLayer(const char* name = nullptr) = 0; |
| 330 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 331 | /// Adds an addition layer to the network. |
| 332 | /// @param name - Optional name for the layer. |
| 333 | /// @return - Interface for configuring the layer. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 334 | virtual IConnectableLayer* AddAdditionLayer(const char* name = nullptr) = 0; |
| 335 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 336 | /// Adds a multiplication layer to the network. |
| 337 | /// @param name - Optional name for the layer. |
| 338 | /// @return - Interface for configuring the layer. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 339 | virtual IConnectableLayer* AddMultiplicationLayer(const char* name = nullptr) = 0; |
| 340 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 341 | /// Adds a batch normalization layer to the network. |
| 342 | /// @param mean - Pre-calculated mean for each channel. |
| 343 | /// @param variance - Pre-calculated variance for each channel. |
| 344 | /// @param beta - Per-channel additive factor. |
| 345 | /// @param gamma - Per-channel multiplicative factor. |
| 346 | /// @return - Interface for configuring the layer. |
| 347 | /// @param name - Optional name for the layer. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 348 | virtual IConnectableLayer* AddBatchNormalizationLayer(const BatchNormalizationDescriptor& desc, |
| 349 | const ConstTensor& mean, |
| 350 | const ConstTensor& variance, |
| 351 | const ConstTensor& beta, |
| 352 | const ConstTensor& gamma, |
| 353 | const char* name = nullptr) = 0; |
| 354 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 355 | /// Adds a resize bilinear layer to the network. |
| 356 | /// @param resizeDesc - Parameters for the resize operation. |
| 357 | /// @param name - Optional name for the layer. |
| 358 | /// @return - Interface for configuring the layer. |
Aron Virginas-Tar | 169d2f1 | 2019-07-01 19:01:44 +0100 | [diff] [blame] | 359 | ARMNN_DEPRECATED_MSG("Use AddResizeLayer instead") |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 360 | virtual IConnectableLayer* AddResizeBilinearLayer(const ResizeBilinearDescriptor& resizeDesc, |
| 361 | const char* name = nullptr) = 0; |
| 362 | |
Teresa Charlin | a9075df | 2019-06-27 15:41:57 +0100 | [diff] [blame] | 363 | /// Adds a resize layer to the network. |
| 364 | /// @param resizeDescriptor - Parameters for the resize operation. |
| 365 | /// @param name - Optional name for the layer. |
| 366 | /// @return - Interface for configuring the layer. |
| 367 | virtual IConnectableLayer* AddResizeLayer(const ResizeDescriptor& resizeDescriptor, |
| 368 | const char* name = nullptr) = 0; |
| 369 | |
Kevin May | ce5045a | 2019-10-02 14:07:47 +0100 | [diff] [blame] | 370 | /// Adds an instance normalization layer to the network. |
| 371 | /// @param desc - Parameters for the instance normalization operation. |
| 372 | /// @param name - Optional name for the layer. |
| 373 | /// @return - Interface for configuring the layer. |
| 374 | virtual IConnectableLayer* AddInstanceNormalizationLayer(const InstanceNormalizationDescriptor& desc, |
| 375 | const char* name = nullptr) = 0; |
| 376 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 377 | /// Adds an L2 normalization layer to the network. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 378 | /// Normalization is performed along dimension 1, but requires a 4d input. |
Matteo Martincigh | bcd3c85 | 2018-09-28 14:14:12 +0100 | [diff] [blame] | 379 | /// @param desc - Parameters for the L2 normalization operation. |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 380 | /// @param name - Optional name for the layer. |
| 381 | /// @return - Interface for configuring the layer. |
Matteo Martincigh | bcd3c85 | 2018-09-28 14:14:12 +0100 | [diff] [blame] | 382 | virtual IConnectableLayer* AddL2NormalizationLayer(const L2NormalizationDescriptor& desc, |
| 383 | const char* name = nullptr) = 0; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 384 | |
Aron Virginas-Tar | f982dea | 2019-10-11 14:07:53 +0100 | [diff] [blame] | 385 | /// Adds a log softmax layer to the network. |
| 386 | /// @param logSoftmaxDescriptor - LogSoftmaxDescriptor to configure the log softmax. |
| 387 | /// @param name - Optional name for the layer. |
| 388 | /// @return - Interface for configuring the layer. |
| 389 | virtual IConnectableLayer* AddLogSoftmaxLayer(const LogSoftmaxDescriptor& logSoftmaxDescriptor, |
| 390 | const char* name = nullptr) = 0; |
| 391 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 392 | /// Adds a layer with no inputs and a single output, which always corresponds to |
| 393 | /// the passed in constant tensor. |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 394 | /// @param input - Tensor to be provided as the only output of the layer. The layer will maintain |
| 395 | /// its own copy of the tensor data, meaning the memory referenced by @a input can |
| 396 | /// be freed or reused after this function is called. |
| 397 | /// @param name - Optional name for the layer. |
| 398 | /// @return - Interface for configuring the layer. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 399 | virtual IConnectableLayer* AddConstantLayer(const ConstTensor& input, |
Matteo Martincigh | 5b2159e | 2019-02-11 13:24:38 +0000 | [diff] [blame] | 400 | const char* name = nullptr) = 0; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 401 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 402 | /// Adds a reshape layer to the network. |
| 403 | /// @param reshapeDescriptor - Parameters for the reshape operation. |
| 404 | /// @param name - Optional name for the layer. |
| 405 | /// @return - Interface for configuring the layer. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 406 | virtual IConnectableLayer* AddReshapeLayer(const ReshapeDescriptor& reshapeDescriptor, |
| 407 | const char* name = nullptr) = 0; |
| 408 | |
Nattapat Chaimanowong | 207ef9a | 2018-11-02 10:57:25 +0000 | [diff] [blame] | 409 | /// Adds a space to batch layer to the network. |
| 410 | /// @param spaceToBatchNdDescriptor - Parameters for the space to batch operation. |
| 411 | /// @param name - Optional name for the layer. |
| 412 | /// @return - Interface for configuring the layer. |
| 413 | virtual IConnectableLayer* AddSpaceToBatchNdLayer(const SpaceToBatchNdDescriptor& spaceToBatchNdDescriptor, |
| 414 | const char* name = nullptr) = 0; |
| 415 | |
Aron Virginas-Tar | 972af15 | 2019-06-11 14:14:03 +0100 | [diff] [blame] | 416 | /// Adds a space to depth layer to the network. |
| 417 | /// @param spaceToDepthDescriptor - Parameters for the space to depth operation. |
| 418 | /// @param name - Optional name for the layer. |
| 419 | /// @return - Interface for configuring the layer. |
| 420 | virtual IConnectableLayer* AddSpaceToDepthLayer(const SpaceToDepthDescriptor& spaceToDepthDescriptor, |
| 421 | const char* name = nullptr) = 0; |
| 422 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 423 | /// Adds a floor layer to the network. |
| 424 | /// @param name - Optional name for the layer. |
| 425 | /// @return - Interface for configuring the layer. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 426 | virtual IConnectableLayer* AddFloorLayer(const char* name = nullptr) = 0; |
| 427 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 428 | /// Adds an output layer to the network. |
| 429 | /// @param id - User generated id to uniquely identify a particular output. The same id needs to be specified |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 430 | /// when passing the outputs to the IRuntime::EnqueueWorkload() function. |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 431 | /// @param name - Optional name for the layer. |
| 432 | /// @return - Interface for configuring the layer. |
| 433 | virtual IConnectableLayer* AddOutputLayer(LayerBindingId id, const char* name = nullptr) = 0; |
| 434 | |
| 435 | /// Add a Lstm layer to the network |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 436 | /// @param descriptor - Parameters for the Lstm operation |
| 437 | /// @param params - Weights and biases for the LSTM cell |
| 438 | /// @param name - Optional name for the layer |
| 439 | /// @return - Interface for configuring the layer. |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 440 | virtual IConnectableLayer* AddLstmLayer(const LstmDescriptor& descriptor, |
| 441 | const LstmInputParams& params, |
| 442 | const char* name = nullptr) = 0; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 443 | |
Francis Murtagh | e7a86a4 | 2018-08-29 12:42:10 +0100 | [diff] [blame] | 444 | /// Adds a division layer to the network. |
| 445 | /// @param name - Optional name for the layer. |
| 446 | /// @return - Interface for configuring the layer. |
| 447 | virtual IConnectableLayer* AddDivisionLayer(const char* name = nullptr) = 0; |
| 448 | |
David Beck | 1952622 | 2018-09-12 16:00:08 +0100 | [diff] [blame] | 449 | /// Adds a subtraction layer to the network. |
| 450 | /// @param name - Optional name for the layer. |
| 451 | /// @return - Interface for configuring the layer. |
| 452 | virtual IConnectableLayer* AddSubtractionLayer(const char* name = nullptr) = 0; |
| 453 | |
Nattapat Chaimanowong | 5a4304a | 2018-11-28 10:44:37 +0000 | [diff] [blame] | 454 | /// Add a Maximum layer to the network. |
| 455 | /// @param name - Optional name for the layer. |
| 456 | /// @ return - Interface for configuring the layer. |
| 457 | virtual IConnectableLayer* AddMaximumLayer(const char* name = nullptr) = 0; |
| 458 | |
narpra01 | 32b9046 | 2018-09-13 11:07:48 +0100 | [diff] [blame] | 459 | /// Add a Mean layer to the network. |
| 460 | /// @param meanDescriptor - Parameters for the mean operation. |
| 461 | /// @param name - Optional name for the layer. |
| 462 | /// @ return - Interface for configuring the layer. |
| 463 | virtual IConnectableLayer* AddMeanLayer(const MeanDescriptor& meanDescriptor, const char* name = nullptr) = 0; |
| 464 | |
Mohamed Nour Abouelseoud | 5662c20 | 2018-09-24 13:30:09 +0100 | [diff] [blame] | 465 | /// Adds a fully pad layer to the network. |
| 466 | /// @param paddings - n by 2 tensor, where n is the rank of the input tensor, |
| 467 | /// such that paddings[i,0] indicates the amount of padding to add in front of dimonsion i, and |
| 468 | /// paddings[i,1] indicates the amount of padding to add after the end of dimension i |
| 469 | /// @param name - Optional name for the layer. |
| 470 | /// @return - Interface for configuring the layer. |
| 471 | virtual IConnectableLayer* AddPadLayer(const PadDescriptor& padDescriptor, |
| 472 | const char* name = nullptr) = 0; |
| 473 | |
Derek Lamberti | a9cca6a | 2019-03-25 15:41:58 +0000 | [diff] [blame] | 474 | /// Add a quantize layer to the network |
| 475 | ///@param name - Optional name for the layer. |
| 476 | /// @return - Interface for configuring the layer. |
| 477 | virtual IConnectableLayer* AddQuantizeLayer(const char* name = nullptr) = 0; |
| 478 | |
Conor Kennedy | 430b5d8 | 2018-11-14 15:28:28 +0000 | [diff] [blame] | 479 | /// Adds a strided slice layer to the network. |
| 480 | /// @param StridedSliceDescriptor - Parameters for the strided slice operation. |
| 481 | /// @param name - Optional name for the layer. |
| 482 | /// @return - Interface for configuring the layer. |
| 483 | virtual IConnectableLayer* AddStridedSliceLayer(const StridedSliceDescriptor& stridedSliceDescriptor, |
| 484 | const char* name = nullptr) = 0; |
| 485 | |
kevmay01 | 9053969 | 2018-11-29 08:40:19 +0000 | [diff] [blame] | 486 | /// Add a Minimum layer to the network. |
| 487 | /// @param name - Optional name for the layer. |
| 488 | /// @ return - Interface for configuring the layer. |
| 489 | virtual IConnectableLayer* AddMinimumLayer(const char* name = nullptr) = 0; |
| 490 | |
Matteo Martincigh | 59a950c | 2018-12-13 12:48:25 +0000 | [diff] [blame] | 491 | /// Add a Greater layer to the network. |
| 492 | /// @param name - Optional name for the layer. |
| 493 | /// @ return - Interface for configuring the layer. |
Aron Virginas-Tar | 77bfb5e | 2019-10-16 17:45:38 +0100 | [diff] [blame] | 494 | ARMNN_DEPRECATED_MSG("Use AddComparisonLayer instead") |
Matteo Martincigh | 59a950c | 2018-12-13 12:48:25 +0000 | [diff] [blame] | 495 | virtual IConnectableLayer* AddGreaterLayer(const char* name = nullptr) = 0; |
| 496 | |
FrancisMurtagh | 2099595 | 2018-12-17 12:11:36 +0000 | [diff] [blame] | 497 | /// Add a Equal layer to the network. |
| 498 | /// @param name - Optional name for the layer. |
| 499 | /// @ return - Interface for configuring the layer. |
Aron Virginas-Tar | 77bfb5e | 2019-10-16 17:45:38 +0100 | [diff] [blame] | 500 | ARMNN_DEPRECATED_MSG("Use AddComparisonLayer instead") |
FrancisMurtagh | 2099595 | 2018-12-17 12:11:36 +0000 | [diff] [blame] | 501 | virtual IConnectableLayer* AddEqualLayer(const char* name = nullptr) = 0; |
| 502 | |
Mohamed Nour Abouelseoud | a1d3c6a | 2018-12-27 12:39:16 +0000 | [diff] [blame] | 503 | /// Add Reciprocal of square root layer to the network. |
| 504 | /// @param name - Optional name for the layer. |
| 505 | /// @ return - Interface for configuring the layer. |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 506 | ARMNN_DEPRECATED_MSG("Use AddElementwiseUnaryLayer instead") |
Mohamed Nour Abouelseoud | a1d3c6a | 2018-12-27 12:39:16 +0000 | [diff] [blame] | 507 | virtual IConnectableLayer* AddRsqrtLayer(const char* name = nullptr) = 0; |
| 508 | |
narpra01 | b89b05f | 2019-01-16 09:53:09 +0000 | [diff] [blame] | 509 | /// Add Gather layer to the network. |
| 510 | /// @param name - Optional name for the layer. |
| 511 | /// @ return - Interface for configuring the layer. |
| 512 | virtual IConnectableLayer* AddGatherLayer(const char* name = nullptr) = 0; |
| 513 | |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 514 | /// Adds a switch layer to the network. |
| 515 | /// @param name - Optional name for the layer. |
| 516 | /// @return - Interface for configuring the layer. |
| 517 | virtual IConnectableLayer* AddSwitchLayer(const char* name = nullptr) = 0; |
| 518 | |
Matteo Martincigh | 0e406ee | 2019-06-12 15:42:18 +0100 | [diff] [blame] | 519 | /// Adds a PReLU layer to the network. |
| 520 | /// @param name - Optional name for the layer. |
| 521 | /// @return - Interface for configuring the layer. |
| 522 | virtual IConnectableLayer* AddPreluLayer(const char* name = nullptr) = 0; |
| 523 | |
Aron Virginas-Tar | 639fb04 | 2019-06-20 14:28:19 +0100 | [diff] [blame] | 524 | /// Adds a 2D transpose convolution layer to the network. |
| 525 | /// @param descriptor - Description of the 2D transpose convolution layer. |
| 526 | /// @param weights - Tensor for the weights data. |
| 527 | /// @param biases - Optional tensor for the bias data. |
| 528 | /// @param name - Optional name for the layer. |
| 529 | /// @return - Interface for configuring the layer. |
| 530 | virtual IConnectableLayer* AddTransposeConvolution2dLayer(const TransposeConvolution2dDescriptor& descriptor, |
| 531 | const ConstTensor& weights, |
| 532 | const Optional<ConstTensor>& biases, |
| 533 | const char* name = nullptr) = 0; |
| 534 | |
Mike Kelly | c9ea45a | 2020-02-28 18:11:58 +0000 | [diff] [blame] | 535 | /// Adds a transpose layer to the network. |
| 536 | /// @param transposeDescriptor - TransposeDescriptor to configure the transpose. |
| 537 | /// @param name - Optional name for the layer. |
| 538 | /// @return - Interface for configuring the layer. |
| 539 | virtual IConnectableLayer* AddTransposeLayer(const TransposeDescriptor& transposeDescriptor, |
| 540 | const char* name = nullptr) = 0; |
| 541 | |
Matthew Jackson | 2b8c1da | 2019-07-04 14:59:16 +0100 | [diff] [blame] | 542 | /// Adds a stack layer to the network. |
| 543 | /// @param descriptor - Description of the stack layer. |
| 544 | /// @param name - Optional name for the layer. |
| 545 | /// @return - Interface for configuring the layer. |
| 546 | virtual IConnectableLayer* AddStackLayer(const StackDescriptor& descriptor, |
| 547 | const char* name = nullptr) = 0; |
| 548 | |
Derek Lamberti | 013c390 | 2019-10-21 10:46:16 +0100 | [diff] [blame] | 549 | /// Add a stand-in layer for a type unknown to the Arm NN framework. |
| 550 | /// Note: Due to the nature of this layer, no validation can be performed by the framework. |
| 551 | /// Furthermore, Any model containing this layer cannot make use of dynamic tensors since the |
| 552 | /// tensor sizes cannot be inferred. |
| 553 | /// @descriptor - Descriptor for the StandIn layer. |
| 554 | /// @return - Interface for configuring the layer. |
| 555 | virtual IConnectableLayer* AddStandInLayer(const StandInDescriptor& descriptor, |
| 556 | const char* name = nullptr) = 0; |
| 557 | |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 558 | /// Add a QuantizedLstm layer to the network |
| 559 | /// @param params - The weights and biases for the Quantized LSTM cell |
| 560 | /// @param name - Optional name for the layer |
| 561 | /// @return - Interface for configuring the layer. |
| 562 | virtual IConnectableLayer* AddQuantizedLstmLayer(const QuantizedLstmInputParams& params, |
| 563 | const char* name = nullptr) = 0; |
| 564 | |
James Conroy | 586a9aa | 2020-03-20 08:49:33 +0000 | [diff] [blame] | 565 | /// Add a QLstm layer to the network |
| 566 | /// @param descriptor - Parameters for the QLstm operation |
| 567 | /// @param params - Weights and biases for the layer |
| 568 | /// @param name - Optional name for the layer |
| 569 | /// @return - Interface for configuring the layer. |
| 570 | virtual IConnectableLayer* AddQLstmLayer(const QLstmDescriptor& descriptor, |
| 571 | const LstmInputParams& params, |
| 572 | const char* name = nullptr) = 0; |
| 573 | |
Mike Kelly | 8c1701a | 2019-02-11 17:01:27 +0000 | [diff] [blame] | 574 | virtual void Accept(ILayerVisitor& visitor) const = 0; |
| 575 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 576 | protected: |
| 577 | ~INetwork() {} |
| 578 | }; |
| 579 | |
| 580 | using IOptimizedNetworkPtr = std::unique_ptr<IOptimizedNetwork, void(*)(IOptimizedNetwork* network)>; |
| 581 | |
| 582 | class IOptimizedNetwork |
| 583 | { |
| 584 | public: |
| 585 | static void Destroy(IOptimizedNetwork* network); |
| 586 | |
| 587 | virtual Status PrintGraph() = 0; |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 588 | virtual Status SerializeToDot(std::ostream& stream) const = 0; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 589 | |
Jan Eilers | 99d9d4a | 2019-11-06 10:02:16 +0000 | [diff] [blame] | 590 | virtual profiling::ProfilingGuid GetGuid() const = 0; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 591 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 592 | protected: |
| 593 | ~IOptimizedNetwork() {} |
| 594 | }; |
| 595 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 596 | struct OptimizerOptions |
| 597 | { |
Matteo Martincigh | 4912402 | 2019-01-11 13:25:59 +0000 | [diff] [blame] | 598 | OptimizerOptions() |
| 599 | : m_ReduceFp32ToFp16(false) |
| 600 | , m_Debug(false) |
Narumol Prangnawarat | bc7ffb5 | 2020-03-20 15:01:01 +0000 | [diff] [blame] | 601 | , m_ReduceFp32ToBf16(false) |
Teresa Charlin | cdc0149 | 2020-06-09 18:00:20 +0100 | [diff] [blame^] | 602 | , m_shapeInferenceMethod(armnn::ShapeInferenceMethod::ValidateOnly) |
keidav01 | 738c2e6 | 2018-12-11 16:14:20 +0000 | [diff] [blame] | 603 | {} |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 604 | |
Teresa Charlin | cdc0149 | 2020-06-09 18:00:20 +0100 | [diff] [blame^] | 605 | OptimizerOptions(bool reduceFp32ToFp16, bool debug, bool reduceFp32ToBf16 = false, |
| 606 | ShapeInferenceMethod shapeInferenceMethod = armnn::ShapeInferenceMethod::ValidateOnly) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 607 | : m_ReduceFp32ToFp16(reduceFp32ToFp16) |
keidav01 | 738c2e6 | 2018-12-11 16:14:20 +0000 | [diff] [blame] | 608 | , m_Debug(debug) |
Narumol Prangnawarat | bc7ffb5 | 2020-03-20 15:01:01 +0000 | [diff] [blame] | 609 | , m_ReduceFp32ToBf16(reduceFp32ToBf16) |
Teresa Charlin | cdc0149 | 2020-06-09 18:00:20 +0100 | [diff] [blame^] | 610 | , m_shapeInferenceMethod(shapeInferenceMethod) |
Narumol Prangnawarat | bc7ffb5 | 2020-03-20 15:01:01 +0000 | [diff] [blame] | 611 | { |
| 612 | if (m_ReduceFp32ToFp16 && m_ReduceFp32ToBf16) |
| 613 | { |
| 614 | throw InvalidArgumentException("BFloat16 and Float16 optimization cannot be enabled at the same time."); |
| 615 | } |
| 616 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 617 | |
| 618 | // Reduce Fp32 data to Fp16 for faster processing |
| 619 | bool m_ReduceFp32ToFp16; |
keidav01 | 738c2e6 | 2018-12-11 16:14:20 +0000 | [diff] [blame] | 620 | |
| 621 | // Add debug data for easier troubleshooting |
| 622 | bool m_Debug; |
Narumol Prangnawarat | bc7ffb5 | 2020-03-20 15:01:01 +0000 | [diff] [blame] | 623 | |
| 624 | // Reduce Fp32 data to Bf16 for faster processing |
| 625 | bool m_ReduceFp32ToBf16; |
Teresa Charlin | cdc0149 | 2020-06-09 18:00:20 +0100 | [diff] [blame^] | 626 | |
| 627 | // Infer output size when not available |
| 628 | ShapeInferenceMethod m_shapeInferenceMethod; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 629 | }; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 630 | |
| 631 | /// Create an optimized version of the network |
| 632 | /// @param network INetwork description of the network to be optimized. |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 633 | /// @param backendPreferences The choice of the backend ordered by user preferences. |
| 634 | /// @param deviceSpec DeviceSpec object as queried from the runtime. See IRuntime::GetDeviceSpec() |
Rob Hughes | 2321443 | 2019-11-05 11:27:36 +0000 | [diff] [blame] | 635 | /// @param messages If there are failures or warnings a string describing same will be added to the vector |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 636 | /// @param options OptimizerOptions object with optimizer configuration options |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 637 | /// @return An IOptimizedNetworkPtr interface to the optimized network, throws an exception derived from |
| 638 | /// armnn::Exception if process fails. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 639 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 640 | IOptimizedNetworkPtr Optimize(const INetwork& network, |
David Beck | f0b4845 | 2018-10-19 15:20:56 +0100 | [diff] [blame] | 641 | const std::vector<BackendId>& backendPreferences, |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 642 | const IDeviceSpec& deviceSpec, |
jimfly01 | 6b0b53d | 2018-10-08 14:43:01 +0100 | [diff] [blame] | 643 | const OptimizerOptions& options = OptimizerOptions(), |
Rob Hughes | 2321443 | 2019-11-05 11:27:36 +0000 | [diff] [blame] | 644 | Optional<std::vector<std::string>&> messages = EmptyOptional()); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 645 | } //namespace armnn |