Compute Library
 21.02
ConvolutionLayerNode Class Referencefinal

Convolution Layer node. More...

#include <ConvolutionLayerNode.h>

Collaboration diagram for ConvolutionLayerNode:
[legend]

Public Member Functions

 ConvolutionLayerNode (PadStrideInfo info, unsigned int num_groups=1, ConvolutionMethod method=ConvolutionMethod::Default, FastMathHint fast_math_hint=FastMathHint::Disabled, QuantizationInfo out_quant_info=QuantizationInfo())
 Constructor. More...
 
void set_convolution_method (ConvolutionMethod method)
 Sets the convolution layer method to use. More...
 
ConvolutionMethod convolution_method () const
 Convolution layer method accessor. More...
 
void set_fast_math_hint (FastMathHint hint)
 Sets the fast math fast hint. More...
 
FastMathHint fast_math_hint () const
 Fast math hint accessor. More...
 
PadStrideInfo convolution_info () const
 Convolution metadata accessor. More...
 
unsigned int num_groups () const
 Number of groups in convolution accessor. More...
 
ActivationLayerInfo fused_activation () const
 Returns fused activation. More...
 
void set_fused_activation (ActivationLayerInfo fused_activation)
 Sets fused activation. More...
 
NodeType type () const override
 Returns node's type. More...
 
bool forward_descriptors () override
 Forwards descriptor information to outputs if possible. More...
 
TensorDescriptor configure_output (size_t idx) const override
 Calculates output configuration. More...
 
void accept (INodeVisitor &v) override
 Accepts a node visitor. More...
 
- Public Member Functions inherited from INode
 INode ()
 Constructor. More...
 
virtual ~INode ()=default
 Destructor. More...
 
 INode (const INode &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
INodeoperator= (const INode &)=delete
 Prevent instances of this class from being copy assigned (As this class contains pointers) More...
 
 INode (INode &&)=default
 Allow instances of this class to be moved. More...
 
INodeoperator= (INode &&)=default
 Allow instances of this class to be move assigned. More...
 
virtual Status validate () const
 Validate node. More...
 
std::string name () const
 Returns node's name. More...
 
NodeID id () const
 Returns node's ID. More...
 
const Graphgraph () const
 Returns node's Graph. More...
 
Graphgraph ()
 Returns node's Graph. More...
 
void set_graph (Graph *g)
 Sets the graph that this node is registered to. More...
 
void set_id (NodeID id)
 Sets the node id. More...
 
void set_common_node_parameters (NodeParams common_params)
 Sets common node parameters. More...
 
void set_requested_target (Target target)
 Sets target preference. More...
 
void set_assigned_target (Target target)
 Sets the final execution target. More...
 
void set_output_tensor (TensorID tid, size_t idx)
 Sets the output tensor of at a given index. More...
 
const std::vector< TensorID > & inputs () const
 Returns inputs of the node. More...
 
const std::vector< TensorID > & outputs () const
 Returns outputs of the node. More...
 
const std::vector< EdgeID > & input_edges () const
 Returns input edge set. More...
 
const std::set< EdgeID > & output_edges () const
 Returns output edge set. More...
 
TensorID input_id (size_t idx) const
 Returns the tensor ID of a given input of the node. More...
 
TensorID output_id (size_t idx) const
 Returns the tensor ID of a given output of the node. More...
 
Tensorinput (size_t idx) const
 Returns the tensor of a given input of the node. More...
 
Tensoroutput (size_t idx) const
 Returns the tensor of a given output of the node. More...
 
EdgeID input_edge_id (size_t idx) const
 Returns the edge ID of a given input of the node. More...
 
Edgeinput_edge (size_t idx) const
 Returns the edge of a given input of the node. More...
 
size_t num_inputs () const
 Returns number of inputs of the node. More...
 
size_t num_outputs () const
 Returns number of outputs of the node. More...
 
NodeParams common_node_params () const
 Returns common node parameters. More...
 
Target requested_target () const
 Returns requested target for this node. More...
 
Target assigned_target () const
 Returns assigned target for this node. More...
 

Static Public Member Functions

static TensorDescriptor compute_output_descriptor (const TensorDescriptor &input_descriptor, const TensorDescriptor &weights_descriptor, const PadStrideInfo &info)
 Computes convolution output descriptor. More...
 

Static Public Attributes

static constexpr NodeType node_type = NodeType::ConvolutionLayer
 

Detailed Description

Convolution Layer node.

Definition at line 34 of file ConvolutionLayerNode.h.

Constructor & Destructor Documentation

◆ ConvolutionLayerNode()

ConvolutionLayerNode ( PadStrideInfo  info,
unsigned int  num_groups = 1,
ConvolutionMethod  method = ConvolutionMethod::Default,
FastMathHint  fast_math_hint = FastMathHint::Disabled,
QuantizationInfo  out_quant_info = QuantizationInfo() 
)

Constructor.

Parameters
[in]infoConvolution layer attributes
[in]num_groups(Optional) Number of groups (Defaults to 1)
[in]method(Optional) Convolution method to use
[in]fast_math_hint(Optional) Fast math hint
[in]out_quant_info(Optional) Output quantization info

Definition at line 35 of file ConvolutionLayerNode.cpp.

40  : _info(std::move(info)), _num_groups(num_groups), _method(method), _fast_math_hint(fast_math_hint), _out_quant_info(std::move(out_quant_info)), _fused_activation()
41 {
42  _input_edges.resize(3, EmptyEdgeID);
43  _outputs.resize(1, NullTensorID);
44 }
FastMathHint fast_math_hint() const
Fast math hint accessor.
unsigned int num_groups() const
Number of groups in convolution accessor.
constexpr EdgeID EmptyEdgeID
Definition: Types.h:75
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
constexpr TensorID NullTensorID
Constant NodeID specifying an equivalent of null node.
Definition: Types.h:71

Member Function Documentation

◆ accept()

void accept ( INodeVisitor v)
overridevirtual

Accepts a node visitor.

Parameters
[in]vVisitor to accept

Implements INode.

Definition at line 143 of file ConvolutionLayerNode.cpp.

References INodeVisitor::visit().

144 {
145  v.visit(*this);
146 }

◆ compute_output_descriptor()

TensorDescriptor compute_output_descriptor ( const TensorDescriptor input_descriptor,
const TensorDescriptor weights_descriptor,
const PadStrideInfo info 
)
static

Computes convolution output descriptor.

Parameters
[in]input_descriptorInput descriptor
[in]weights_descriptorWeights descriptor
[in]infoConvolution operation attributes
Returns
Output descriptor

Definition at line 86 of file ConvolutionLayerNode.cpp.

References arm_compute::CHANNEL, arm_compute::test::validation::data_layout, arm_compute::graph::get_dimension_idx(), arm_compute::graph::get_dimension_size(), arm_compute::HEIGHT, input_height, input_width, TensorDescriptor::layout, arm_compute::scaled_dimensions(), TensorShape::set(), TensorDescriptor::shape, and arm_compute::WIDTH.

Referenced by ConvolutionLayerNode::configure_output().

89 {
90  unsigned int output_width = 0;
91  unsigned int output_height = 0;
92 
93  const unsigned int input_width = get_dimension_size(input_descriptor, DataLayoutDimension::WIDTH);
94  const unsigned int input_height = get_dimension_size(input_descriptor, DataLayoutDimension::HEIGHT);
95  const unsigned int kernel_width = get_dimension_size(weights_descriptor, DataLayoutDimension::WIDTH);
96  const unsigned int kernel_height = get_dimension_size(weights_descriptor, DataLayoutDimension::HEIGHT);
97 
98  std::tie(output_width, output_height) = scaled_dimensions(input_width, input_height, kernel_width, kernel_height, info);
99 
100  const DataLayout data_layout = input_descriptor.layout;
101  TensorDescriptor output_descriptor = input_descriptor;
102  output_descriptor.shape.set(get_dimension_idx(data_layout, DataLayoutDimension::WIDTH), output_width);
103  output_descriptor.shape.set(get_dimension_idx(data_layout, DataLayoutDimension::HEIGHT), output_height);
104  output_descriptor.shape.set(get_dimension_idx(data_layout, DataLayoutDimension::CHANNEL), weights_descriptor.shape[3]);
105 
106  return output_descriptor;
107 }
size_t get_dimension_size(const TensorDescriptor &descriptor, const DataLayoutDimension data_layout_dimension)
Get size of a tensor&#39;s given dimension depending on its layout.
Definition: Utils.cpp:123
const DataLayout data_layout
Definition: Im2Col.cpp:151
std::pair< unsigned int, unsigned int > scaled_dimensions(int width, int height, int kernel_width, int kernel_height, const PadStrideInfo &pad_stride_info, const Size2D &dilation=Size2D(1U, 1U))
Returns expected width and height of output scaled tensor depending on dimensions rounding mode...
Definition: Utils.cpp:419
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
DataLayout
[DataLayout enum definition]
Definition: Types.h:120
size_t get_dimension_idx(DataLayout data_layout, const DataLayoutDimension data_layout_dimension)
Get index of a tensor&#39;s given dimension depending on its layout.
Definition: Utils.cpp:129

◆ configure_output()

TensorDescriptor configure_output ( size_t  idx) const
overridevirtual

Calculates output configuration.

Parameters
[in]idxOutput index to configure
Returns
Output descriptor configuration

Implements INode.

Definition at line 121 of file ConvolutionLayerNode.cpp.

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_UNUSED, ConvolutionLayerNode::compute_output_descriptor(), Tensor::desc(), QuantizationInfo::empty(), INode::input(), arm_compute::test::validation::output_info, TensorDescriptor::quant_info, and arm_compute::test::validation::src.

Referenced by ConvolutionLayerNode::forward_descriptors().

122 {
123  ARM_COMPUTE_UNUSED(idx);
124  const Tensor *src = input(0);
125  const Tensor *weights = input(1);
126 
127  ARM_COMPUTE_ERROR_ON(src == nullptr || weights == nullptr);
128 
129  TensorDescriptor output_info = compute_output_descriptor(src->desc(), weights->desc(), _info);
130  if(!_out_quant_info.empty())
131  {
132  output_info.quant_info = _out_quant_info;
133  }
134 
135  return output_info;
136 }
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
SimpleTensor< float > src
Definition: DFT.cpp:155
QuantizationInfo quant_info
Quantization info.
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
static TensorDescriptor compute_output_descriptor(const TensorDescriptor &input_descriptor, const TensorDescriptor &weights_descriptor, const PadStrideInfo &info)
Computes convolution output descriptor.
bool empty() const
Indicates whether this QuantizationInfo has valid settings or not.
Tensor * input(size_t idx) const
Returns the tensor of a given input of the node.
Definition: INode.cpp:150

◆ convolution_info()

PadStrideInfo convolution_info ( ) const

Convolution metadata accessor.

Returns
Convolution information

Definition at line 66 of file ConvolutionLayerNode.cpp.

Referenced by arm_compute::graph::backends::detail::validate_convolution_layer().

67 {
68  return _info;
69 }

◆ convolution_method()

ConvolutionMethod convolution_method ( ) const

Convolution layer method accessor.

Note
This is an indication on which convolution layer implementation to use, if it fails to be created the library's heuristic approach will be used
Returns
Convolution layer method to be used by the node

Definition at line 51 of file ConvolutionLayerNode.cpp.

Referenced by arm_compute::graph::backends::detail::validate_convolution_layer(), and DotGraphVisitor::visit().

52 {
53  return _method;
54 }

◆ fast_math_hint()

FastMathHint fast_math_hint ( ) const

Fast math hint accessor.

Returns
Fast math hint to be used by the node

Definition at line 61 of file ConvolutionLayerNode.cpp.

Referenced by arm_compute::graph::backends::detail::validate_convolution_layer().

62 {
63  return _fast_math_hint;
64 }

◆ forward_descriptors()

bool forward_descriptors ( )
overridevirtual

Forwards descriptor information to outputs if possible.

Returns
True if descriptor information could be forwarded otherwise false

Implements INode.

Definition at line 109 of file ConvolutionLayerNode.cpp.

References ARM_COMPUTE_ERROR_ON, ConvolutionLayerNode::configure_output(), Tensor::desc(), arm_compute::test::validation::dst, INode::input_id(), arm_compute::graph::NullTensorID, INode::output(), and INode::output_id().

110 {
111  if((input_id(0) != NullTensorID) && (input_id(1) != NullTensorID) && (output_id(0) != NullTensorID))
112  {
113  Tensor *dst = output(0);
114  ARM_COMPUTE_ERROR_ON(dst == nullptr);
115  dst->desc() = configure_output(0);
116  return true;
117  }
118  return false;
119 }
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
Tensor * output(size_t idx) const
Returns the tensor of a given output of the node.
Definition: INode.cpp:158
TensorID input_id(size_t idx) const
Returns the tensor ID of a given input of the node.
Definition: INode.cpp:137
TensorID output_id(size_t idx) const
Returns the tensor ID of a given output of the node.
Definition: INode.cpp:144
constexpr TensorID NullTensorID
Constant NodeID specifying an equivalent of null node.
Definition: Types.h:71
TensorDescriptor configure_output(size_t idx) const override
Calculates output configuration.

◆ fused_activation()

ActivationLayerInfo fused_activation ( ) const

Returns fused activation.

Returns
Fused activation

Definition at line 76 of file ConvolutionLayerNode.cpp.

Referenced by ConvolutionLayerNode::set_fused_activation().

77 {
78  return _fused_activation;
79 }

◆ num_groups()

unsigned int num_groups ( ) const

Number of groups in convolution accessor.

Returns
Number of groups in convolution

Definition at line 71 of file ConvolutionLayerNode.cpp.

Referenced by arm_compute::graph::backends::detail::validate_convolution_layer().

72 {
73  return _num_groups;
74 }

◆ set_convolution_method()

void set_convolution_method ( ConvolutionMethod  method)

Sets the convolution layer method to use.

Parameters
[in]methodMethod to use for convolution

Definition at line 46 of file ConvolutionLayerNode.cpp.

47 {
48  _method = method;
49 }

◆ set_fast_math_hint()

void set_fast_math_hint ( FastMathHint  hint)

Sets the fast math fast hint.

Parameters
[in]hintHint to use for convolution

Definition at line 56 of file ConvolutionLayerNode.cpp.

57 {
58  _fast_math_hint = hint;
59 }

◆ set_fused_activation()

void set_fused_activation ( ActivationLayerInfo  fused_activation)

Sets fused activation.

Parameters
[in]fused_activationFused activation to set

Definition at line 81 of file ConvolutionLayerNode.cpp.

References ConvolutionLayerNode::fused_activation().

82 {
83  _fused_activation = fused_activation;
84 }
ActivationLayerInfo fused_activation() const
Returns fused activation.

◆ type()

NodeType type ( ) const
overridevirtual

Returns node's type.

Returns
Node's type

Implements INode.

Definition at line 138 of file ConvolutionLayerNode.cpp.

References ConvolutionLayerNode::node_type.

139 {
141 }

Field Documentation

◆ node_type

constexpr NodeType node_type = NodeType::ConvolutionLayer
static

Definition at line 112 of file ConvolutionLayerNode.h.

Referenced by ConvolutionLayerNode::type().


The documentation for this class was generated from the following files: