blob: 440c80dfa97c0b1ef163c1b15dd1480d6fa87976 [file] [log] [blame]
surmeh013537c2c2018-05-18 16:31:43 +01001//
Finn Williamsf24effa2020-07-03 10:12:03 +01002// Copyright © 2017 Arm Ltd and Contributors. All rights reserved.
David Beckecb56cd2018-09-05 12:52:57 +01003// SPDX-License-Identifier: MIT
surmeh013537c2c2018-05-18 16:31:43 +01004//
5#pragma once
6
7#include "LayerWithParameters.hpp"
8
9namespace armnn
10{
11
12class ScopedCpuTensorHandle;
13
Conor Kennedy35052ae2018-12-21 14:38:36 +000014/// This layer represents a convolution 2d operation.
surmeh013537c2c2018-05-18 16:31:43 +010015class Convolution2dLayer : public LayerWithParameters<Convolution2dDescriptor>
16{
17public:
Andre Ghattas23ae2ea2019-08-07 12:18:38 +010018
Conor Kennedy35052ae2018-12-21 14:38:36 +000019 /// A unique pointer to store Weight values.
surmeh013537c2c2018-05-18 16:31:43 +010020 std::unique_ptr<ScopedCpuTensorHandle> m_Weight;
Conor Kennedy35052ae2018-12-21 14:38:36 +000021 /// A unique pointer to store Bias values.
surmeh013537c2c2018-05-18 16:31:43 +010022 std::unique_ptr<ScopedCpuTensorHandle> m_Bias;
23
Conor Kennedy35052ae2018-12-21 14:38:36 +000024 /// Makes a workload for the Convolution2d type.
25 /// @param [in] graph The graph where this layer can be found.
26 /// @param [in] factory The workload factory which will create the workload.
27 /// @return A pointer to the created workload, or nullptr if not created.
Derek Lamberti94a88d22019-12-10 21:12:59 +000028 virtual std::unique_ptr<IWorkload> CreateWorkload(const IWorkloadFactory& factory) const override;
surmeh013537c2c2018-05-18 16:31:43 +010029
Conor Kennedy35052ae2018-12-21 14:38:36 +000030 /// Creates a dynamically-allocated copy of this layer.
31 /// @param [in] graph The graph into which this layer is being cloned.
surmeh013537c2c2018-05-18 16:31:43 +010032 Convolution2dLayer* Clone(Graph& graph) const override;
33
Conor Kennedy35052ae2018-12-21 14:38:36 +000034 /// Check if the input tensor shape(s)
35 /// will lead to a valid configuration of @ref Convolution2dLayer.
Teresa Charlincdc01492020-06-09 18:00:20 +010036 /// @param [in] shapeInferenceMethod Indicates if output shape shall be overwritten or just validated.
Finn Williamsf24effa2020-07-03 10:12:03 +010037 void ValidateTensorShapesFromInputs() override;
surmeh013537c2c2018-05-18 16:31:43 +010038
Conor Kennedy35052ae2018-12-21 14:38:36 +000039 /// By default returns inputShapes if the number of inputs are equal to number of outputs,
40 /// otherwise infers the output shapes from given input shapes and layer properties.
41 /// @param [in] inputShapes The input shapes layer has.
42 /// @return A vector to the inferred output shape.
telsoa01c577f2c2018-08-31 09:22:23 +010043 std::vector<TensorShape> InferOutputShapes(const std::vector<TensorShape>& inputShapes) const override;
44
jimfly01e9e7bfd2019-01-24 22:29:33 +000045 void Accept(ILayerVisitor& visitor) const override;
46
Finn Williamsb454c5c2021-02-09 15:56:23 +000047 void ExecuteStrategy(IStrategy& strategy) const override;
48
Andre Ghattas23ae2ea2019-08-07 12:18:38 +010049 void SerializeLayerParameters(ParameterStringifyFunction& fn) const override;
50
surmeh013537c2c2018-05-18 16:31:43 +010051protected:
Conor Kennedy35052ae2018-12-21 14:38:36 +000052 /// Constructor to create a Convolution2dLayer.
53 /// @param [in] param Convolution2dDescriptor to configure the convolution2d operation.
54 /// @param [in] name Optional name for the layer.
surmeh013537c2c2018-05-18 16:31:43 +010055 Convolution2dLayer(const Convolution2dDescriptor& param, const char* name);
Conor Kennedy35052ae2018-12-21 14:38:36 +000056
57 /// Default destructor
surmeh013537c2c2018-05-18 16:31:43 +010058 ~Convolution2dLayer() = default;
telsoa01c577f2c2018-08-31 09:22:23 +010059
Conor Kennedy35052ae2018-12-21 14:38:36 +000060 /// Retrieve the handles to the constant values stored by the layer.
61 /// @return A vector of the constant tensors stored by this layer.
telsoa01c577f2c2018-08-31 09:22:23 +010062 ConstantTensors GetConstantTensorsByRef() override;
surmeh013537c2c2018-05-18 16:31:43 +010063};
64
65} // namespace