blob: f57591097c5418fa2ffa8344f9f94b7d71b2e03b [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 depthwise convolution 2d operation.
surmeh013537c2c2018-05-18 16:31:43 +010015class DepthwiseConvolution2dLayer : public LayerWithParameters<DepthwiseConvolution2dDescriptor>
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 DepthwiseConvolution2d 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 DepthwiseConvolution2dLayer* 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 DepthwiseConvolution2dLayer.
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
jimfly01e9e7bfd2019-01-24 22:29:33 +000044 void Accept(ILayerVisitor& visitor) const override;
45
Andre Ghattas23ae2ea2019-08-07 12:18:38 +010046 void SerializeLayerParameters(ParameterStringifyFunction& fn) const override;
47
surmeh013537c2c2018-05-18 16:31:43 +010048protected:
Conor Kennedy35052ae2018-12-21 14:38:36 +000049 /// Constructor to create a DepthwiseConvolution2dLayer.
50 /// @param [in] param DepthwiseConvolution2dDescriptor to configure the depthwise convolution2d.
51 /// @param [in] name Optional name for the layer.
surmeh013537c2c2018-05-18 16:31:43 +010052 DepthwiseConvolution2dLayer(const DepthwiseConvolution2dDescriptor& param, const char* name);
Conor Kennedy35052ae2018-12-21 14:38:36 +000053
54 /// Default destructor
surmeh013537c2c2018-05-18 16:31:43 +010055 ~DepthwiseConvolution2dLayer() = default;
telsoa01c577f2c2018-08-31 09:22:23 +010056
Conor Kennedy35052ae2018-12-21 14:38:36 +000057 /// Retrieve the handles to the constant values stored by the layer.
58 /// @return A vector of the constant tensors stored by this layer.
telsoa01c577f2c2018-08-31 09:22:23 +010059 ConstantTensors GetConstantTensorsByRef() override;
surmeh013537c2c2018-05-18 16:31:43 +010060};
61
62} // namespace