blob: b812b1becee2b7fc7221f1029c5aea9548c3a77c [file] [log] [blame]
surmeh013537c2c2018-05-18 16:31:43 +01001//
2// Copyright © 2017 Arm Ltd. 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:
Conor Kennedy35052ae2018-12-21 14:38:36 +000018 /// A unique pointer to store Weight values.
surmeh013537c2c2018-05-18 16:31:43 +010019 std::unique_ptr<ScopedCpuTensorHandle> m_Weight;
Conor Kennedy35052ae2018-12-21 14:38:36 +000020 /// A unique pointer to store Bias values.
surmeh013537c2c2018-05-18 16:31:43 +010021 std::unique_ptr<ScopedCpuTensorHandle> m_Bias;
22
Conor Kennedy35052ae2018-12-21 14:38:36 +000023 /// Makes a workload for the Convolution2d type.
24 /// @param [in] graph The graph where this layer can be found.
25 /// @param [in] factory The workload factory which will create the workload.
26 /// @return A pointer to the created workload, or nullptr if not created.
surmeh013537c2c2018-05-18 16:31:43 +010027 virtual std::unique_ptr<IWorkload> CreateWorkload(const Graph& graph,
28 const IWorkloadFactory& factory) const override;
29
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.
surmeh013537c2c2018-05-18 16:31:43 +010036 void ValidateTensorShapesFromInputs() override;
37
Conor Kennedy35052ae2018-12-21 14:38:36 +000038 /// By default returns inputShapes if the number of inputs are equal to number of outputs,
39 /// otherwise infers the output shapes from given input shapes and layer properties.
40 /// @param [in] inputShapes The input shapes layer has.
41 /// @return A vector to the inferred output shape.
telsoa01c577f2c2018-08-31 09:22:23 +010042 std::vector<TensorShape> InferOutputShapes(const std::vector<TensorShape>& inputShapes) const override;
43
surmeh013537c2c2018-05-18 16:31:43 +010044protected:
Conor Kennedy35052ae2018-12-21 14:38:36 +000045 /// Constructor to create a Convolution2dLayer.
46 /// @param [in] param Convolution2dDescriptor to configure the convolution2d operation.
47 /// @param [in] name Optional name for the layer.
surmeh013537c2c2018-05-18 16:31:43 +010048 Convolution2dLayer(const Convolution2dDescriptor& param, const char* name);
Conor Kennedy35052ae2018-12-21 14:38:36 +000049
50 /// Default destructor
surmeh013537c2c2018-05-18 16:31:43 +010051 ~Convolution2dLayer() = default;
telsoa01c577f2c2018-08-31 09:22:23 +010052
Conor Kennedy35052ae2018-12-21 14:38:36 +000053 /// Retrieve the handles to the constant values stored by the layer.
54 /// @return A vector of the constant tensors stored by this layer.
telsoa01c577f2c2018-08-31 09:22:23 +010055 ConstantTensors GetConstantTensorsByRef() override;
surmeh013537c2c2018-05-18 16:31:43 +010056};
57
58} // namespace