From ae050524109f1ce827962665436ef7430f2ac479 Mon Sep 17 00:00:00 2001 From: David Monahan Date: Wed, 22 Mar 2023 16:48:58 +0000 Subject: IVGCVSW-7255 Update Doxygen Documentation and publish on GitHub. * Updating Doxygen documentation for 23.02 release. Signed-off-by: David Monahan Change-Id: I545574ff7664b4595d2fe6a91a3c35d2ad55df82 --- 23.02/_convolution2d_layer_8cpp_source.xhtml | 291 ++++++++++++++++++++------- 1 file changed, 214 insertions(+), 77 deletions(-) (limited to '23.02/_convolution2d_layer_8cpp_source.xhtml') diff --git a/23.02/_convolution2d_layer_8cpp_source.xhtml b/23.02/_convolution2d_layer_8cpp_source.xhtml index b6b2156758..918126ee6f 100644 --- a/23.02/_convolution2d_layer_8cpp_source.xhtml +++ b/23.02/_convolution2d_layer_8cpp_source.xhtml @@ -8,7 +8,7 @@ - + ArmNN: src/armnn/layers/Convolution2dLayer.cpp Source File @@ -19,9 +19,6 @@ - @@ -30,7 +27,8 @@ extensions: ["tex2jax.js"], jax: ["input/TeX","output/HTML-CSS"], }); - + + @@ -51,18 +49,21 @@ - + +/* @license-end */
@@ -76,7 +77,9 @@ $(function() {
@@ -98,82 +101,216 @@ $(document).ready(function(){initNavTree('_convolution2d_layer_8cpp_source.xhtml
Convolution2dLayer.cpp
-Go to the documentation of this file.
1 //
2 // Copyright © 2017,2022 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include "Convolution2dLayer.hpp"
7 #include "LayerCloneBase.hpp"
8 
9 #include <armnn/TypesUtils.hpp>
10 
12 
15 
16 #include <string>
17 
18 using namespace armnnUtils;
19 
20 namespace armnn
21 {
22 
24  : LayerWithParameters(param.GetNumInputs(), 1, LayerType::Convolution2d, param, name)
25 {
26 
27 }
28 
30 {
31  //using DescriptorType = Parameters;
32  const std::vector<TensorShape>& inputShapes =
33  {
36  };
37  const TensorShape filterShape = inputShapes[1];
38  DataLayoutIndexed dataLayoutIndex(m_Param.m_DataLayout);
39  unsigned int filterWidth = filterShape[dataLayoutIndex.GetWidthIndex()];
40  unsigned int filterHeight = filterShape[dataLayoutIndex.GetHeightIndex()];
41  unsigned int outChannels = filterShape[0];
42 
43  fn("OutputChannels",std::to_string(outChannels));
44  fn("FilterWidth",std::to_string(filterWidth));
45  fn("FilterHeight",std::to_string(filterHeight));
47 }
48 
49 std::unique_ptr<IWorkload> Convolution2dLayer::CreateWorkload(const IWorkloadFactory& factory) const
50 {
51  ARMNN_SCOPED_PROFILING_EVENT(Compute::Undefined, "Convolution2dLayer_CreateWorkload");
53  SetAdditionalInfo(descriptor);
54 
55  return factory.CreateWorkload(LayerType::Convolution2d, descriptor, PrepInfoAndDesc(descriptor));
56 }
57 
59 {
60  auto layer = CloneBase<Convolution2dLayer>(graph, m_Param, GetName());
61  return std::move(layer);
62 }
63 
64 std::vector<TensorShape> Convolution2dLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const
65 {
66  ARMNN_ASSERT(inputShapes.size() == 2);
67  const TensorShape& inputShape = inputShapes[0];
68  const TensorShape filterShape = inputShapes[1];
69 
70  // If we support multiple batch dimensions in the future, then this assert will need to change.
71  ARMNN_ASSERT_MSG(inputShape.GetNumDimensions() == 4, "Convolutions will always have 4D input.");
72 
75 
76  DataLayoutIndexed dataLayoutIndex(m_Param.m_DataLayout);
77 
78  unsigned int inWidth = inputShape[dataLayoutIndex.GetWidthIndex()];
79  unsigned int inHeight = inputShape[dataLayoutIndex.GetHeightIndex()];
80  unsigned int inBatchSize = inputShape[0];
81 
82  unsigned int filterWidth = filterShape[dataLayoutIndex.GetWidthIndex()];
83  unsigned int dilatedFilterWidth = filterWidth + (m_Param.m_DilationX - 1) * (filterWidth - 1);
84  unsigned int readWidth = (inWidth + m_Param.m_PadLeft + m_Param.m_PadRight) - dilatedFilterWidth;
85  unsigned int outWidth = 1 + (readWidth / m_Param.m_StrideX);
86 
87  unsigned int filterHeight = filterShape[dataLayoutIndex.GetHeightIndex()];
88  unsigned int dilatedFilterHeight = filterHeight + (m_Param.m_DilationY - 1) * (filterHeight - 1);
89  unsigned int readHeight = (inHeight + m_Param.m_PadTop + m_Param.m_PadBottom) - dilatedFilterHeight;
90  unsigned int outHeight = 1 + (readHeight / m_Param.m_StrideY);
91 
92  unsigned int outChannels = filterShape[0];
93  unsigned int outBatchSize = inBatchSize;
94 
96  TensorShape( { outBatchSize, outHeight, outWidth, outChannels } ) :
97  TensorShape( { outBatchSize, outChannels, outHeight, outWidth });
98 
99  return std::vector<TensorShape>({ tensorShape });
100 }
101 
103 {
105 
106  const TensorShape& outputShape = GetOutputSlot(0).GetTensorInfo().GetShape();
107 
109 
110  ARMNN_ASSERT_MSG(GetInputSlot(1).GetConnection(),
111  "Convolution2dLayer: Weights should be connected to input slot 1.");
112 
113  std::vector<TensorShape> inferredShapes = InferOutputShapes({
116 
117  ARMNN_ASSERT(inferredShapes.size() == 1);
118 
119  ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "Convolution2dLayer");
120 }
121 
123 {
125  return tensors;
126 }
127 
129 {
130  strategy.ExecuteStrategy(this, GetParameters(), {}, GetName());
131 }
132 
133 } // namespace armnn
uint32_t m_PadBottom
Padding bottom value in the height dimension.
-
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
- -
Convolution2dDescriptor m_Param
The parameters for the layer (not including tensor-valued weights etc.).
-
unsigned int GetWidthIndex() const
- -
const TensorShape & GetShape() const
Definition: Tensor.hpp:191
- - - -
A Convolution2dDescriptor for the Convolution2dLayer.
-
void SerializeLayerParameters(ParameterStringifyFunction &fn) const override
Helper to serialize the layer parameters to string (currently used in DotSerializer and company)...
-
uint32_t m_PadRight
Padding right value in the width dimension.
-
Convolution2dLayer(const Convolution2dDescriptor &param, const char *name)
Constructor to create a Convolution2dLayer.
-
void VerifyShapeInferenceType(const TensorShape &outputShape, ShapeInferenceMethod shapeInferenceMethod)
Definition: Layer.cpp:491
-
Copyright (c) 2021 ARM Limited and Contributors.
-
const Convolution2dDescriptor & GetParameters() const override
- -
const IOutputSlot * GetConnection() const override
Definition: Layer.hpp:206
-
uint32_t m_DilationY
Dilation along y axis.
-
void ValidateAndCopyShape(const TensorShape &outputShape, const TensorShape &inferredShape, const ShapeInferenceMethod shapeInferenceMethod, const std::string &layerName, const unsigned int outputSlotIndex=0)
Definition: Layer.cpp:422
-
#define ARMNN_SCOPED_PROFILING_EVENT(backendId, name)
Definition: Profiling.hpp:220
-
unsigned int GetHeightIndex() const
- -
void VerifyLayerConnections(unsigned int expectedConnections, const CheckLocation &location) const
Definition: Layer.cpp:378
-
uint32_t m_PadTop
Padding top value in the height dimension.
-
const InputSlot & GetInputSlot(unsigned int index) const override
Get a const input slot handle by slot index.
Definition: Layer.hpp:324
-
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.
-
void ValidateTensorShapesFromInputs() override
Check if the input tensor shape(s) will lead to a valid configuration of Convolution2dLayer.
- -
void ExecuteStrategy(IStrategy &strategy) const override
Apply a visitor to this layer.
-
uint32_t GetNumInputs(bool biasEnabled)
-
std::vector< std::reference_wrapper< std::shared_ptr< ConstTensorHandle > >> ConstantTensors
Definition: INetwork.hpp:124
-
#define ARMNN_ASSERT_MSG(COND, MSG)
Definition: Assert.hpp:15
-
Provides access to the appropriate indexes for Channels, Height and Width based on DataLayout...
- - - -
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14
-
Convolution2dLayer * Clone(Graph &graph) const override
Creates a dynamically-allocated copy of this layer.
-
virtual void ExecuteStrategy(const IConnectableLayer *layer, const armnn::BaseDescriptor &descriptor, const std::vector< armnn::ConstTensor > &constants, const char *name, const armnn::LayerBindingId id=0)=0
-
ConstantTensors GetConstantTensorsByRef() override
Retrieve the handles to the constant values connected to the layer.
-
#define CHECK_LOCATION()
Definition: Exceptions.hpp:203
-
uint32_t m_StrideY
Stride value when proceeding through input for the height dimension.
- -
void SetAdditionalInfo(QueueDescriptor &descriptor) const
Definition: Layer.cpp:274
- -
uint32_t m_DilationX
Dilation along x axis.
-
virtual std::unique_ptr< IWorkload > CreateWorkload(const IWorkloadFactory &factory) const override
Makes a workload for the Convolution2d type.
-
void SerializeLayerParameters(ParameterStringifyFunction &fn) const override
Helper to serialize the layer parameters to string.
- -
WorkloadInfo PrepInfoAndDesc(QueueDescriptor &descriptor) const
Helper function to reduce duplication in *Layer::CreateWorkload.
- -
const OutputSlot & GetOutputSlot(unsigned int index=0) const override
Get the const output slot handle by slot index.
Definition: Layer.hpp:326
-
virtual const TensorInfo & GetTensorInfo() const =0
-
const char * GetName() const override
Returns the name of the layer.
Definition: Layer.hpp:319
-
This layer represents a convolution 2d operation.
- -
std::vector< TensorShape > InferOutputShapes(const std::vector< TensorShape > &inputShapes) const override
By default returns inputShapes if the number of inputs are equal to number of outputs, otherwise infers the output shapes from given input shapes and layer properties.
-
std::function< void(const std::string &name, const std::string &value)> ParameterStringifyFunction
-
virtual std::unique_ptr< IWorkload > CreateWorkload(LayerType type, const QueueDescriptor &descriptor, const WorkloadInfo &info) const
-
const TensorInfo & GetTensorInfo() const override
Definition: Layer.cpp:92
-
ShapeInferenceMethod m_ShapeInferenceMethod
Definition: Layer.hpp:423
-
uint32_t m_PadLeft
Padding left value in the width dimension.
- - -
LayerType
When adding a new layer, adapt also the LastLayer enum value in the enum class LayerType below...
Definition: Types.hpp:466
+Go to the documentation of this file.
1 //
+
2 // Copyright © 2017,2022 Arm Ltd and Contributors. All rights reserved.
+
3 // SPDX-License-Identifier: MIT
+
4 //
+
5 
+
6 #include "Convolution2dLayer.hpp"
+
7 #include "LayerCloneBase.hpp"
+
8 
+
9 #include <armnn/TypesUtils.hpp>
+
10 
+ +
12 
+ + +
15 
+
16 #include <string>
+
17 
+
18 using namespace armnnUtils;
+
19 
+
20 namespace armnn
+
21 {
+
22 
+ +
24  : LayerWithParameters(param.GetNumInputs(), 1, LayerType::Convolution2d, param, name)
+
25 {
+
26 
+
27 }
+
28 
+ +
30 {
+
31  //using DescriptorType = Parameters;
+
32  const std::vector<TensorShape>& inputShapes =
+
33  {
+ + +
36  };
+
37  const TensorShape filterShape = inputShapes[1];
+
38  DataLayoutIndexed dataLayoutIndex(m_Param.m_DataLayout);
+
39  unsigned int filterWidth = filterShape[dataLayoutIndex.GetWidthIndex()];
+
40  unsigned int filterHeight = filterShape[dataLayoutIndex.GetHeightIndex()];
+
41  unsigned int outChannels = filterShape[0];
+
42 
+
43  fn("OutputChannels",std::to_string(outChannels));
+
44  fn("FilterWidth",std::to_string(filterWidth));
+
45  fn("FilterHeight",std::to_string(filterHeight));
+ +
47 }
+
48 
+
49 std::unique_ptr<IWorkload> Convolution2dLayer::CreateWorkload(const IWorkloadFactory& factory) const
+
50 {
+
51  ARMNN_SCOPED_PROFILING_EVENT(Compute::Undefined, "Convolution2dLayer_CreateWorkload");
+ +
53  SetAdditionalInfo(descriptor);
+
54 
+
55  return factory.CreateWorkload(LayerType::Convolution2d, descriptor, PrepInfoAndDesc(descriptor));
+
56 }
+
57 
+ +
59 {
+
60  auto layer = CloneBase<Convolution2dLayer>(graph, m_Param, GetName());
+
61  return std::move(layer);
+
62 }
+
63 
+
64 std::vector<TensorShape> Convolution2dLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const
+
65 {
+
66  ARMNN_ASSERT(inputShapes.size() == 2);
+
67  const TensorShape& inputShape = inputShapes[0];
+
68  const TensorShape filterShape = inputShapes[1];
+
69 
+
70  // If we support multiple batch dimensions in the future, then this assert will need to change.
+
71  ARMNN_ASSERT_MSG(inputShape.GetNumDimensions() == 4, "Convolutions will always have 4D input.");
+
72 
+ + +
75 
+
76  DataLayoutIndexed dataLayoutIndex(m_Param.m_DataLayout);
+
77 
+
78  unsigned int inWidth = inputShape[dataLayoutIndex.GetWidthIndex()];
+
79  unsigned int inHeight = inputShape[dataLayoutIndex.GetHeightIndex()];
+
80  unsigned int inBatchSize = inputShape[0];
+
81 
+
82  unsigned int filterWidth = filterShape[dataLayoutIndex.GetWidthIndex()];
+
83  unsigned int dilatedFilterWidth = filterWidth + (m_Param.m_DilationX - 1) * (filterWidth - 1);
+
84  unsigned int readWidth = (inWidth + m_Param.m_PadLeft + m_Param.m_PadRight) - dilatedFilterWidth;
+
85  unsigned int outWidth = 1 + (readWidth / m_Param.m_StrideX);
+
86 
+
87  unsigned int filterHeight = filterShape[dataLayoutIndex.GetHeightIndex()];
+
88  unsigned int dilatedFilterHeight = filterHeight + (m_Param.m_DilationY - 1) * (filterHeight - 1);
+
89  unsigned int readHeight = (inHeight + m_Param.m_PadTop + m_Param.m_PadBottom) - dilatedFilterHeight;
+
90  unsigned int outHeight = 1 + (readHeight / m_Param.m_StrideY);
+
91 
+
92  unsigned int outChannels = filterShape[0];
+
93  unsigned int outBatchSize = inBatchSize;
+
94 
+ +
96  TensorShape( { outBatchSize, outHeight, outWidth, outChannels } ) :
+
97  TensorShape( { outBatchSize, outChannels, outHeight, outWidth });
+
98 
+
99  return std::vector<TensorShape>({ tensorShape });
+
100 }
+
101 
+ +
103 {
+ +
105 
+
106  const TensorShape& outputShape = GetOutputSlot(0).GetTensorInfo().GetShape();
+
107 
+ +
109 
+
110  ARMNN_ASSERT_MSG(GetInputSlot(1).GetConnection(),
+
111  "Convolution2dLayer: Weights should be connected to input slot 1.");
+
112 
+
113  std::vector<TensorShape> inferredShapes = InferOutputShapes({
+ + +
116 
+
117  ARMNN_ASSERT(inferredShapes.size() == 1);
+
118 
+
119  ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "Convolution2dLayer");
+
120 }
+
121 
+ +
123 {
+ +
125  return tensors;
+
126 }
+
127 
+ +
129 {
+
130  strategy.ExecuteStrategy(this, GetParameters(), {}, GetName());
+
131 }
+
132 
+
133 } // namespace armnn
+
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
+ +
void ValidateTensorShapesFromInputs() override
Check if the input tensor shape(s) will lead to a valid configuration of Convolution2dLayer.
+ +
void SerializeLayerParameters(ParameterStringifyFunction &fn) const override
Helper to serialize the layer parameters to string (currently used in DotSerializer and company).
+
uint32_t m_DilationY
Dilation along y axis.
+
uint32_t m_PadBottom
Padding bottom value in the height dimension.
+
#define CHECK_LOCATION()
Definition: Exceptions.hpp:203
+
void VerifyLayerConnections(unsigned int expectedConnections, const CheckLocation &location) const
Definition: Layer.cpp:378
+
const IOutputSlot * GetConnection() const override
Definition: Layer.hpp:206
+ + +
uint32_t m_DilationX
Dilation along x axis.
+ +
unsigned int GetWidthIndex() const
+
std::vector< std::reference_wrapper< std::shared_ptr< ConstTensorHandle > >> ConstantTensors
Definition: INetwork.hpp:124
+
void VerifyShapeInferenceType(const TensorShape &outputShape, ShapeInferenceMethod shapeInferenceMethod)
Definition: Layer.cpp:491
+ + +
uint32_t m_PadTop
Padding top value in the height dimension.
+
uint32_t m_PadRight
Padding right value in the width dimension.
+
virtual std::unique_ptr< IWorkload > CreateWorkload(const IWorkloadFactory &factory) const override
Makes a workload for the Convolution2d type.
+ +
void SetAdditionalInfo(QueueDescriptor &descriptor) const
Definition: Layer.cpp:274
+
ShapeInferenceMethod m_ShapeInferenceMethod
Definition: Layer.hpp:423
+
void ValidateAndCopyShape(const TensorShape &outputShape, const TensorShape &inferredShape, const ShapeInferenceMethod shapeInferenceMethod, const std::string &layerName, const unsigned int outputSlotIndex=0)
Definition: Layer.cpp:422
+
Copyright (c) 2021 ARM Limited and Contributors.
+ +
const TensorInfo & GetTensorInfo() const override
Definition: Layer.cpp:92
+ +
void ExecuteStrategy(IStrategy &strategy) const override
Apply a visitor to this layer.
+
std::vector< TensorShape > InferOutputShapes(const std::vector< TensorShape > &inputShapes) const override
By default returns inputShapes if the number of inputs are equal to number of outputs,...
+
uint32_t GetNumInputs(bool biasEnabled)
+ +
LayerType
When adding a new layer, adapt also the LastLayer enum value in the enum class LayerType below.
Definition: Types.hpp:466
+
virtual const TensorInfo & GetTensorInfo() const =0
+
const OutputSlot & GetOutputSlot(unsigned int index=0) const override
Get the const output slot handle by slot index.
Definition: Layer.hpp:326
+ +
uint32_t m_PadLeft
Padding left value in the width dimension.
+
WorkloadInfo PrepInfoAndDesc(QueueDescriptor &descriptor) const
Helper function to reduce duplication in *Layer::CreateWorkload.
+
#define ARMNN_SCOPED_PROFILING_EVENT(backendId, name)
Definition: Profiling.hpp:220
+
ConstantTensors GetConstantTensorsByRef() override
Retrieve the handles to the constant values connected to the layer.
+
A Convolution2dDescriptor for the Convolution2dLayer.
+
const TensorShape & GetShape() const
Definition: Tensor.hpp:191
+ + +
#define ARMNN_ASSERT_MSG(COND, MSG)
Definition: Assert.hpp:15
+
std::function< void(const std::string &name, const std::string &value)> ParameterStringifyFunction
+ +
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.
+
const InputSlot & GetInputSlot(unsigned int index) const override
Get a const input slot handle by slot index.
Definition: Layer.hpp:324
+
virtual void ExecuteStrategy(const IConnectableLayer *layer, const armnn::BaseDescriptor &descriptor, const std::vector< armnn::ConstTensor > &constants, const char *name, const armnn::LayerBindingId id=0)=0
+
unsigned int GetNumDimensions() const
Function that returns the tensor rank.
Definition: Tensor.cpp:174
+ +
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14
+
Provides access to the appropriate indexes for Channels, Height and Width based on DataLayout.
+ +
virtual std::unique_ptr< IWorkload > CreateWorkload(LayerType type, const QueueDescriptor &descriptor, const WorkloadInfo &info) const
+
unsigned int GetHeightIndex() const
+
void SerializeLayerParameters(ParameterStringifyFunction &fn) const override
Helper to serialize the layer parameters to string.
+
const char * GetName() const override
Returns the name of the layer.
Definition: Layer.hpp:319
+ +
uint32_t m_StrideY
Stride value when proceeding through input for the height dimension.
+
This layer represents a convolution 2d operation.
+
const Convolution2dDescriptor & GetParameters() const override
+
Convolution2dDescriptor m_Param
The parameters for the layer (not including tensor-valued weights etc.).
+
Convolution2dLayer(const Convolution2dDescriptor &param, const char *name)
Constructor to create a Convolution2dLayer.
+
Convolution2dLayer * Clone(Graph &graph) const override
Creates a dynamically-allocated copy of this layer.
-- cgit v1.2.1