telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1 | // |
| 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 | |
David Beck | f0b4845 | 2018-10-19 15:20:56 +0100 | [diff] [blame] | 7 | #include <armnn/NetworkFwd.hpp> |
| 8 | #include <armnn/DescriptorsFwd.hpp> |
| 9 | #include <armnn/TensorFwd.hpp> |
| 10 | #include <armnn/Optional.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 11 | |
David Beck | f0b4845 | 2018-10-19 15:20:56 +0100 | [diff] [blame] | 12 | #include <armnn/Types.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 13 | |
| 14 | #include <memory> |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 15 | #include <vector> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 16 | |
| 17 | namespace armnn |
| 18 | { |
| 19 | |
| 20 | /// @brief An input connection slot for a layer. |
| 21 | /// The input slot can be connected to an output slot of the preceding layer in the graph. |
| 22 | /// Only one connection to the input slot is allowed. |
| 23 | class IInputSlot |
| 24 | { |
| 25 | public: |
| 26 | virtual const IOutputSlot* GetConnection() const = 0; |
| 27 | virtual IOutputSlot* GetConnection() = 0; |
| 28 | |
| 29 | protected: |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 30 | /// Not user deletable. |
| 31 | ~IInputSlot() {} |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 32 | }; |
| 33 | |
| 34 | /// @brief An output connection slot for a layer. |
| 35 | /// The output slot may be connected to 1 or more input slots of subsequent layers in the graph. |
| 36 | class IOutputSlot |
| 37 | { |
| 38 | public: |
| 39 | virtual unsigned int GetNumConnections() const = 0; |
| 40 | virtual const IInputSlot* GetConnection(unsigned int index) const = 0; |
| 41 | virtual IInputSlot* GetConnection(unsigned int index) = 0; |
| 42 | |
| 43 | virtual void SetTensorInfo(const TensorInfo& tensorInfo) = 0; |
| 44 | virtual const TensorInfo& GetTensorInfo() const = 0; |
| 45 | virtual bool IsTensorInfoSet() const = 0; |
| 46 | |
| 47 | virtual int Connect(IInputSlot& destination) = 0; |
| 48 | virtual void Disconnect(IInputSlot& slot) = 0; |
| 49 | |
| 50 | protected: |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 51 | /// Not user deletable. |
| 52 | ~IOutputSlot() {} |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 53 | }; |
| 54 | |
| 55 | /// @brief Interface for a layer that is connectable to other layers via InputSlots and OutputSlots. |
| 56 | class IConnectableLayer |
| 57 | { |
| 58 | public: |
| 59 | virtual const char* GetName() const = 0; |
| 60 | |
| 61 | virtual unsigned int GetNumInputSlots() const = 0; |
| 62 | virtual unsigned int GetNumOutputSlots() const = 0; |
| 63 | |
| 64 | virtual const IInputSlot& GetInputSlot(unsigned int index) const = 0; |
| 65 | virtual IInputSlot& GetInputSlot(unsigned int index) = 0; |
| 66 | |
| 67 | virtual const IOutputSlot& GetOutputSlot(unsigned int index) const = 0; |
| 68 | virtual IOutputSlot& GetOutputSlot(unsigned int index) = 0; |
| 69 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 70 | virtual std::vector<TensorShape> InferOutputShapes(const std::vector<TensorShape>& inputShapes) const = 0; |
| 71 | |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 72 | virtual LayerGuid GetGuid() const = 0; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 73 | protected: |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 74 | /// Objects are not deletable via the handle |
| 75 | ~IConnectableLayer() {} |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | using INetworkPtr = std::unique_ptr<INetwork, void(*)(INetwork* network)>; |
| 79 | |
| 80 | /// Main network class which provides the interface for building up a neural network. |
| 81 | /// This object is subsequently required by the IRuntime::Load() method. |
| 82 | class INetwork |
| 83 | { |
| 84 | public: |
| 85 | static INetwork* CreateRaw(); |
| 86 | static INetworkPtr Create(); |
| 87 | static void Destroy(INetwork* network); |
| 88 | |
| 89 | virtual Status PrintGraph() = 0; |
| 90 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 91 | /// Adds an input layer to the network. |
| 92 | /// @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] | 93 | /// when passing the inputs to the IRuntime::EnqueueWorkload() function. |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 94 | /// @param name - Optional name for the layer. |
| 95 | /// @return - Interface for configuring the layer. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 96 | virtual IConnectableLayer* AddInputLayer(LayerBindingId id, const char* name = nullptr) = 0; |
| 97 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 98 | /// Adds a 2D convolution layer to the network. |
| 99 | /// @param convolution2dDescriptor - Description of the 2D convolution layer. |
| 100 | /// @param weights - Tensor for the weights data. |
| 101 | /// @param biases - (Optional) Tensor for the bias data. Must match the output tensor shape. |
| 102 | /// @param name - Optional name for the layer. |
| 103 | /// @return - Interface for configuring the layer. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 104 | virtual IConnectableLayer* AddConvolution2dLayer(const Convolution2dDescriptor& convolution2dDescriptor, |
| 105 | const ConstTensor& weights, |
| 106 | const char* name = nullptr) = 0; |
| 107 | |
| 108 | virtual IConnectableLayer* AddConvolution2dLayer(const Convolution2dDescriptor& convolution2dDescriptor, |
| 109 | const ConstTensor& weights, |
| 110 | const ConstTensor& biases, |
| 111 | const char* name = nullptr) = 0; |
| 112 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 113 | /// Adds a 2D depthwise convolution layer to the network. |
| 114 | /// @param convolution2dDescriptor - Description of the 2D depthwise convolution layer. |
Rob Hughes | 144c01b | 2018-11-21 13:34:24 +0000 | [diff] [blame] | 115 | /// @param weights - Tensor for the weights. Expected format: [channelMultiplier, inputChannels, height, width]. |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 116 | /// @param biases (Optional) - Tensor for the bias data. Must match the output tensor shape. |
| 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* AddDepthwiseConvolution2dLayer( |
| 120 | const DepthwiseConvolution2dDescriptor& convolution2dDescriptor, |
| 121 | const ConstTensor& weights, |
| 122 | const char* name = nullptr) = 0; |
| 123 | |
| 124 | virtual IConnectableLayer* AddDepthwiseConvolution2dLayer( |
| 125 | const DepthwiseConvolution2dDescriptor& convolution2dDescriptor, |
| 126 | const ConstTensor& weights, |
| 127 | const ConstTensor& biases, |
| 128 | const char* name = nullptr) = 0; |
| 129 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 130 | /// Adds a fully connected layer to the network. |
| 131 | /// @param fullyConnectedDescriptor - Description of the fully connected layer. |
| 132 | /// @param weights - Tensor for the weights data. |
| 133 | /// @param biases - (Optional) Tensor for the bias data. |
| 134 | /// @param name - Optional name for the layer. |
| 135 | /// @return - Interface for configuring the layer. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 136 | virtual IConnectableLayer* AddFullyConnectedLayer(const FullyConnectedDescriptor& fullyConnectedDescriptor, |
| 137 | const ConstTensor& weights, |
| 138 | const char* name = nullptr) = 0; |
| 139 | |
| 140 | virtual IConnectableLayer* AddFullyConnectedLayer(const FullyConnectedDescriptor& fullyConnectedDescriptor, |
| 141 | const ConstTensor& weights, |
| 142 | const ConstTensor& biases, |
| 143 | const char* name = nullptr) = 0; |
| 144 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 145 | /// Adds a permute layer to the network. |
| 146 | /// @param permuteDescriptor - PermuteDescriptor to configure the permute. |
| 147 | /// @param name - Optional name for the layer. |
| 148 | /// @return - Interface for configuring the layer. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 149 | virtual IConnectableLayer* AddPermuteLayer(const PermuteDescriptor& permuteDescriptor, |
| 150 | const char* name = nullptr) = 0; |
| 151 | |
Éanna Ó Catháin | 4e1e136 | 2018-11-12 11:36:34 +0000 | [diff] [blame] | 152 | /// Adds a batch to space ND layer to the network. |
| 153 | /// @param batchToSpaceNdDescriptor - Description of the layer. |
| 154 | /// @param name - Optional name for the layer. |
| 155 | /// @return - Interface for configuring the layer. |
| 156 | virtual IConnectableLayer* AddBatchToSpaceNdLayer(const BatchToSpaceNdDescriptor& batchToSpaceNdDescriptor, |
| 157 | const char* name = nullptr) = 0; |
| 158 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 159 | /// Adds a pooling layer to the network. |
| 160 | /// @param pooling2dDescriptor - Pooling2dDescriptor to configure the pooling. |
| 161 | /// @param name - Optional name for the layer. |
| 162 | /// @return - Interface for configuring the layer. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 163 | virtual IConnectableLayer* AddPooling2dLayer(const Pooling2dDescriptor& pooling2dDescriptor, |
| 164 | const char* name = nullptr) = 0; |
| 165 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 166 | /// Adds an activation layer to the network. |
| 167 | /// @param activationDescriptor - ActivationDescriptor to configure the activation. |
| 168 | /// @param name - Optional name for the layer. |
| 169 | /// @return - Interface for configuring the layer. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 170 | virtual IConnectableLayer* AddActivationLayer(const ActivationDescriptor& activationDescriptor, |
| 171 | const char* name = nullptr) = 0; |
| 172 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 173 | /// Adds a normalization layer to the network. |
| 174 | /// @param normalizationDescriptor - NormalizationDescriptor to configure the normalization. |
| 175 | /// @param name - Optional name for the layer. |
| 176 | /// @return - Interface for configuring the layer. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 177 | virtual IConnectableLayer* AddNormalizationLayer(const NormalizationDescriptor& normalizationDescriptor, |
| 178 | const char* name = nullptr) = 0; |
| 179 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 180 | /// Adds a softmax layer to the network. |
| 181 | /// @param softmaxDescriptor - SoftmaxDescriptor to configure the softmax. |
| 182 | /// @param name - Optional name for the layer. |
| 183 | /// @return - Interface for configuring the layer. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 184 | virtual IConnectableLayer* AddSoftmaxLayer(const SoftmaxDescriptor& softmaxDescriptor, |
| 185 | const char* name = nullptr) = 0; |
| 186 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 187 | /// Adds a splitter layer to the network. |
| 188 | /// @param splitterDescriptor - WindowsDescriptor to configure the splitting process. |
| 189 | /// Number of Views must be equal to the number of outputs, |
| 190 | /// and their order must match - e.g. first view corresponds to |
| 191 | /// the first output, second view to the second output, etc.... |
| 192 | /// @param name - Optional name for the layer. |
| 193 | /// @return - Interface for configuring the layer. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 194 | virtual IConnectableLayer* AddSplitterLayer(const ViewsDescriptor& splitterDescriptor |
| 195 | , const char* name = nullptr) = 0; |
| 196 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 197 | /// Adds a merger layer to the network. |
| 198 | /// @param mergerDescriptor - WindowsDescriptor to configure the merging process. Number of Views must be equal to |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 199 | /// the number of inputs, and their order must match - e.g. first view corresponds to |
| 200 | /// the first input, second view to the second input, etc.... |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 201 | /// @param name - Optional name for the layer. |
| 202 | /// @return - Interface for configuring the layer. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 203 | virtual IConnectableLayer* AddMergerLayer(const OriginsDescriptor& mergerDescriptor, |
| 204 | const char* name = nullptr) = 0; |
| 205 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 206 | /// Adds an addition layer to the network. |
| 207 | /// @param name - Optional name for the layer. |
| 208 | /// @return - Interface for configuring the layer. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 209 | virtual IConnectableLayer* AddAdditionLayer(const char* name = nullptr) = 0; |
| 210 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 211 | /// Adds a multiplication layer to the network. |
| 212 | /// @param name - Optional name for the layer. |
| 213 | /// @return - Interface for configuring the layer. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 214 | virtual IConnectableLayer* AddMultiplicationLayer(const char* name = nullptr) = 0; |
| 215 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 216 | /// Adds a batch normalization layer to the network. |
| 217 | /// @param mean - Pre-calculated mean for each channel. |
| 218 | /// @param variance - Pre-calculated variance for each channel. |
| 219 | /// @param beta - Per-channel additive factor. |
| 220 | /// @param gamma - Per-channel multiplicative factor. |
| 221 | /// @return - Interface for configuring the layer. |
| 222 | /// @param name - Optional name for the layer. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 223 | virtual IConnectableLayer* AddBatchNormalizationLayer(const BatchNormalizationDescriptor& desc, |
| 224 | const ConstTensor& mean, |
| 225 | const ConstTensor& variance, |
| 226 | const ConstTensor& beta, |
| 227 | const ConstTensor& gamma, |
| 228 | const char* name = nullptr) = 0; |
| 229 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 230 | /// Adds a resize bilinear layer to the network. |
| 231 | /// @param resizeDesc - Parameters for the resize operation. |
| 232 | /// @param name - Optional name for the layer. |
| 233 | /// @return - Interface for configuring the layer. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 234 | virtual IConnectableLayer* AddResizeBilinearLayer(const ResizeBilinearDescriptor& resizeDesc, |
| 235 | const char* name = nullptr) = 0; |
| 236 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 237 | /// Adds an L2 normalization layer to the network. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 238 | /// Normalization is performed along dimension 1, but requires a 4d input. |
Matteo Martincigh | bcd3c85 | 2018-09-28 14:14:12 +0100 | [diff] [blame] | 239 | /// @param desc - Parameters for the L2 normalization operation. |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 240 | /// @param name - Optional name for the layer. |
| 241 | /// @return - Interface for configuring the layer. |
Matteo Martincigh | bcd3c85 | 2018-09-28 14:14:12 +0100 | [diff] [blame] | 242 | virtual IConnectableLayer* AddL2NormalizationLayer(const L2NormalizationDescriptor& desc, |
| 243 | const char* name = nullptr) = 0; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 244 | |
| 245 | /// Adds a layer with no inputs and a single output, which always corresponds to |
| 246 | /// the passed in constant tensor. |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 247 | /// @param input - Tensor to be provided as the only output of the layer. The layer will maintain |
| 248 | /// its own copy of the tensor data, meaning the memory referenced by @a input can |
| 249 | /// be freed or reused after this function is called. |
| 250 | /// @param name - Optional name for the layer. |
| 251 | /// @return - Interface for configuring the layer. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 252 | virtual IConnectableLayer* AddConstantLayer(const ConstTensor& input, |
| 253 | const char* name = nullptr) = 0; |
| 254 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 255 | /// Adds a reshape layer to the network. |
| 256 | /// @param reshapeDescriptor - Parameters for the reshape operation. |
| 257 | /// @param name - Optional name for the layer. |
| 258 | /// @return - Interface for configuring the layer. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 259 | virtual IConnectableLayer* AddReshapeLayer(const ReshapeDescriptor& reshapeDescriptor, |
| 260 | const char* name = nullptr) = 0; |
| 261 | |
Nattapat Chaimanowong | 207ef9a | 2018-11-02 10:57:25 +0000 | [diff] [blame] | 262 | /// Adds a space to batch layer to the network. |
| 263 | /// @param spaceToBatchNdDescriptor - Parameters for the space to batch operation. |
| 264 | /// @param name - Optional name for the layer. |
| 265 | /// @return - Interface for configuring the layer. |
| 266 | virtual IConnectableLayer* AddSpaceToBatchNdLayer(const SpaceToBatchNdDescriptor& spaceToBatchNdDescriptor, |
| 267 | const char* name = nullptr) = 0; |
| 268 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 269 | /// Adds a floor layer to the network. |
| 270 | /// @param name - Optional name for the layer. |
| 271 | /// @return - Interface for configuring the layer. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 272 | virtual IConnectableLayer* AddFloorLayer(const char* name = nullptr) = 0; |
| 273 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 274 | /// Adds an output layer to the network. |
| 275 | /// @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] | 276 | /// when passing the outputs to the IRuntime::EnqueueWorkload() function. |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 277 | /// @param name - Optional name for the layer. |
| 278 | /// @return - Interface for configuring the layer. |
| 279 | virtual IConnectableLayer* AddOutputLayer(LayerBindingId id, const char* name = nullptr) = 0; |
| 280 | |
| 281 | /// Add a Lstm layer to the network |
| 282 | /// @param descriptor Parameters for the Lstm operation |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 283 | /// @param name Optional name for the layer |
| 284 | /// @return Interface for configuring the layer. |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 285 | virtual IConnectableLayer* AddLstmLayer(const LstmDescriptor& descriptor, |
| 286 | const LstmInputParams& params, |
| 287 | const char* name = nullptr) = 0; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 288 | |
Francis Murtagh | e7a86a4 | 2018-08-29 12:42:10 +0100 | [diff] [blame] | 289 | /// Adds a division layer to the network. |
| 290 | /// @param name - Optional name for the layer. |
| 291 | /// @return - Interface for configuring the layer. |
| 292 | virtual IConnectableLayer* AddDivisionLayer(const char* name = nullptr) = 0; |
| 293 | |
David Beck | 1952622 | 2018-09-12 16:00:08 +0100 | [diff] [blame] | 294 | /// Adds a subtraction layer to the network. |
| 295 | /// @param name - Optional name for the layer. |
| 296 | /// @return - Interface for configuring the layer. |
| 297 | virtual IConnectableLayer* AddSubtractionLayer(const char* name = nullptr) = 0; |
| 298 | |
Nattapat Chaimanowong | 5a4304a | 2018-11-28 10:44:37 +0000 | [diff] [blame^] | 299 | /// Add a Maximum layer to the network. |
| 300 | /// @param name - Optional name for the layer. |
| 301 | /// @ return - Interface for configuring the layer. |
| 302 | virtual IConnectableLayer* AddMaximumLayer(const char* name = nullptr) = 0; |
| 303 | |
narpra01 | 32b9046 | 2018-09-13 11:07:48 +0100 | [diff] [blame] | 304 | /// Add a Mean layer to the network. |
| 305 | /// @param meanDescriptor - Parameters for the mean operation. |
| 306 | /// @param name - Optional name for the layer. |
| 307 | /// @ return - Interface for configuring the layer. |
| 308 | virtual IConnectableLayer* AddMeanLayer(const MeanDescriptor& meanDescriptor, const char* name = nullptr) = 0; |
| 309 | |
Mohamed Nour Abouelseoud | 5662c20 | 2018-09-24 13:30:09 +0100 | [diff] [blame] | 310 | /// Adds a fully pad layer to the network. |
| 311 | /// @param paddings - n by 2 tensor, where n is the rank of the input tensor, |
| 312 | /// such that paddings[i,0] indicates the amount of padding to add in front of dimonsion i, and |
| 313 | /// paddings[i,1] indicates the amount of padding to add after the end of dimension i |
| 314 | /// @param name - Optional name for the layer. |
| 315 | /// @return - Interface for configuring the layer. |
| 316 | virtual IConnectableLayer* AddPadLayer(const PadDescriptor& padDescriptor, |
| 317 | const char* name = nullptr) = 0; |
| 318 | |
Conor Kennedy | 430b5d8 | 2018-11-14 15:28:28 +0000 | [diff] [blame] | 319 | /// Adds a strided slice layer to the network. |
| 320 | /// @param StridedSliceDescriptor - Parameters for the strided slice operation. |
| 321 | /// @param name - Optional name for the layer. |
| 322 | /// @return - Interface for configuring the layer. |
| 323 | virtual IConnectableLayer* AddStridedSliceLayer(const StridedSliceDescriptor& stridedSliceDescriptor, |
| 324 | const char* name = nullptr) = 0; |
| 325 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 326 | protected: |
| 327 | ~INetwork() {} |
| 328 | }; |
| 329 | |
| 330 | using IOptimizedNetworkPtr = std::unique_ptr<IOptimizedNetwork, void(*)(IOptimizedNetwork* network)>; |
| 331 | |
| 332 | class IOptimizedNetwork |
| 333 | { |
| 334 | public: |
| 335 | static void Destroy(IOptimizedNetwork* network); |
| 336 | |
| 337 | virtual Status PrintGraph() = 0; |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 338 | virtual Status SerializeToDot(std::ostream& stream) const = 0; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 339 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 340 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 341 | protected: |
| 342 | ~IOptimizedNetwork() {} |
| 343 | }; |
| 344 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 345 | struct OptimizerOptions |
| 346 | { |
| 347 | OptimizerOptions() : m_ReduceFp32ToFp16(false) {} |
| 348 | |
| 349 | OptimizerOptions(bool reduceFp32ToFp16) |
| 350 | : m_ReduceFp32ToFp16(reduceFp32ToFp16) |
| 351 | { |
| 352 | } |
| 353 | |
| 354 | // Reduce Fp32 data to Fp16 for faster processing |
| 355 | bool m_ReduceFp32ToFp16; |
| 356 | }; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 357 | |
| 358 | /// Create an optimized version of the network |
| 359 | /// @param network INetwork description of the network to be optimized. |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 360 | /// @param backendPreferences The choice of the backend ordered by user preferences. |
| 361 | /// @param deviceSpec DeviceSpec object as queried from the runtime. See IRuntime::GetDeviceSpec() |
jimfly01 | 6b0b53d | 2018-10-08 14:43:01 +0100 | [diff] [blame] | 362 | /// @param errMessages 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] | 363 | /// @param options OptimizerOptions object with optimizer configuration options |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 364 | /// @return An IOptimizedNetworkPtr interface to the optimized network, throws an exception derived from |
| 365 | /// armnn::Exception if process fails. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 366 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 367 | IOptimizedNetworkPtr Optimize(const INetwork& network, |
David Beck | f0b4845 | 2018-10-19 15:20:56 +0100 | [diff] [blame] | 368 | const std::vector<BackendId>& backendPreferences, |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 369 | const IDeviceSpec& deviceSpec, |
jimfly01 | 6b0b53d | 2018-10-08 14:43:01 +0100 | [diff] [blame] | 370 | const OptimizerOptions& options = OptimizerOptions(), |
| 371 | Optional<std::vector<std::string>&> errMessages = EmptyOptional()); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 372 | } //namespace armnn |