surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 1 | // |
Finn Williams | f24effa | 2020-07-03 10:12:03 +0100 | [diff] [blame] | 2 | // Copyright © 2017 Arm Ltd and Contributors. All rights reserved. |
David Beck | ecb56cd | 2018-09-05 12:52:57 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 4 | // |
| 5 | #pragma once |
| 6 | |
| 7 | #include "LayerWithParameters.hpp" |
| 8 | |
| 9 | namespace armnn |
| 10 | { |
| 11 | |
James Conroy | 1f58f03 | 2021-04-27 17:13:27 +0100 | [diff] [blame] | 12 | class ScopedTensorHandle; |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 13 | |
Conor Kennedy | 35052ae | 2018-12-21 14:38:36 +0000 | [diff] [blame] | 14 | /// This layer represents a convolution 2d operation. |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 15 | class Convolution2dLayer : public LayerWithParameters<Convolution2dDescriptor> |
| 16 | { |
| 17 | public: |
Andre Ghattas | 23ae2ea | 2019-08-07 12:18:38 +0100 | [diff] [blame] | 18 | |
Conor Kennedy | 35052ae | 2018-12-21 14:38:36 +0000 | [diff] [blame] | 19 | /// A unique pointer to store Weight values. |
Teresa Charlin | 71b386d | 2022-09-28 10:25:40 +0100 | [diff] [blame^] | 20 | /// @Note: Deprecated. Removal date is 23.02. Weights are stored in ConstantLayers now. |
James Conroy | 1f58f03 | 2021-04-27 17:13:27 +0100 | [diff] [blame] | 21 | std::shared_ptr<ConstTensorHandle> m_Weight; |
Conor Kennedy | 35052ae | 2018-12-21 14:38:36 +0000 | [diff] [blame] | 22 | /// A unique pointer to store Bias values. |
Teresa Charlin | 71b386d | 2022-09-28 10:25:40 +0100 | [diff] [blame^] | 23 | /// @Note: Deprecated. Removal date is 23.02. Bias are stored in ConstantLayers now. |
James Conroy | 1f58f03 | 2021-04-27 17:13:27 +0100 | [diff] [blame] | 24 | std::shared_ptr<ConstTensorHandle> m_Bias; |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 25 | |
Conor Kennedy | 35052ae | 2018-12-21 14:38:36 +0000 | [diff] [blame] | 26 | /// Makes a workload for the Convolution2d type. |
| 27 | /// @param [in] graph The graph where this layer can be found. |
| 28 | /// @param [in] factory The workload factory which will create the workload. |
| 29 | /// @return A pointer to the created workload, or nullptr if not created. |
Derek Lamberti | 94a88d2 | 2019-12-10 21:12:59 +0000 | [diff] [blame] | 30 | virtual std::unique_ptr<IWorkload> CreateWorkload(const IWorkloadFactory& factory) const override; |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 31 | |
Conor Kennedy | 35052ae | 2018-12-21 14:38:36 +0000 | [diff] [blame] | 32 | /// Creates a dynamically-allocated copy of this layer. |
| 33 | /// @param [in] graph The graph into which this layer is being cloned. |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 34 | Convolution2dLayer* Clone(Graph& graph) const override; |
| 35 | |
Conor Kennedy | 35052ae | 2018-12-21 14:38:36 +0000 | [diff] [blame] | 36 | /// Check if the input tensor shape(s) |
| 37 | /// will lead to a valid configuration of @ref Convolution2dLayer. |
Teresa Charlin | cdc0149 | 2020-06-09 18:00:20 +0100 | [diff] [blame] | 38 | /// @param [in] shapeInferenceMethod Indicates if output shape shall be overwritten or just validated. |
Finn Williams | f24effa | 2020-07-03 10:12:03 +0100 | [diff] [blame] | 39 | void ValidateTensorShapesFromInputs() override; |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 40 | |
Conor Kennedy | 35052ae | 2018-12-21 14:38:36 +0000 | [diff] [blame] | 41 | /// By default returns inputShapes if the number of inputs are equal to number of outputs, |
| 42 | /// otherwise infers the output shapes from given input shapes and layer properties. |
| 43 | /// @param [in] inputShapes The input shapes layer has. |
| 44 | /// @return A vector to the inferred output shape. |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 45 | std::vector<TensorShape> InferOutputShapes(const std::vector<TensorShape>& inputShapes) const override; |
| 46 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 47 | void ExecuteStrategy(IStrategy& strategy) const override; |
| 48 | |
Andre Ghattas | 23ae2ea | 2019-08-07 12:18:38 +0100 | [diff] [blame] | 49 | void SerializeLayerParameters(ParameterStringifyFunction& fn) const override; |
| 50 | |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 51 | protected: |
Conor Kennedy | 35052ae | 2018-12-21 14:38:36 +0000 | [diff] [blame] | 52 | /// Constructor to create a Convolution2dLayer. |
| 53 | /// @param [in] param Convolution2dDescriptor to configure the convolution2d operation. |
| 54 | /// @param [in] name Optional name for the layer. |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 55 | Convolution2dLayer(const Convolution2dDescriptor& param, const char* name); |
Conor Kennedy | 35052ae | 2018-12-21 14:38:36 +0000 | [diff] [blame] | 56 | |
| 57 | /// Default destructor |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 58 | ~Convolution2dLayer() = default; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 59 | |
Keith Davis | b4dd5cc | 2022-04-07 11:32:00 +0100 | [diff] [blame] | 60 | /// @Note Deprecated. GetConstantTensorsByRef is deprecated. m_Weights and m_Bias |
| 61 | /// should be connected to layer as Constant Layers instead." |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 62 | ConstantTensors GetConstantTensorsByRef() override; |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | } // namespace |