Compute Library
 21.02
ConcatenateLayerNode Class Referencefinal

Concatenation Layer node. More...

#include <ConcatenateLayerNode.h>

Collaboration diagram for ConcatenateLayerNode:
[legend]

Public Member Functions

 ConcatenateLayerNode (unsigned int total_nodes, descriptors::ConcatLayerDescriptor concat_descriptor)
 Constructor. More...
 
void set_enabled (bool is_enabled)
 Disables or not the depth concatenate node. More...
 
bool is_enabled () const
 Enabled parameter accessor. More...
 
DataLayoutDimension concatenation_axis () const
 Concatenation axis parameter accessor. More...
 
QuantizationInfo output_quantization_info () const
 Concatenation output quantization info accessor. 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 std::vector< TensorDescriptor > &input_descriptors, DataLayoutDimension axis)
 Computes concatenations output descriptor. More...
 

Detailed Description

Concatenation Layer node.

Definition at line 34 of file ConcatenateLayerNode.h.

Constructor & Destructor Documentation

◆ ConcatenateLayerNode()

ConcatenateLayerNode ( unsigned int  total_nodes,
descriptors::ConcatLayerDescriptor  concat_descriptor 
)

Constructor.

Parameters
[in]total_nodesNumber of nodes that will get concatenated
[in]concat_descriptorConcatenate Layer Descriptor

Definition at line 37 of file ConcatenateLayerNode.cpp.

References arm_compute::graph::EmptyEdgeID, and arm_compute::graph::NullTensorID.

38  : _total_nodes(total_nodes), _concat_descriptor(std::move(concat_descriptor)), _is_enabled(true)
39 {
40  _input_edges.resize(_total_nodes, EmptyEdgeID);
41  _outputs.resize(1, NullTensorID);
42 }
constexpr EdgeID EmptyEdgeID
Definition: Types.h:75
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 135 of file ConcatenateLayerNode.cpp.

References INodeVisitor::visit().

136 {
137  v.visit(*this);
138 }

◆ compute_output_descriptor()

TensorDescriptor compute_output_descriptor ( const std::vector< TensorDescriptor > &  input_descriptors,
DataLayoutDimension  axis 
)
static

Computes concatenations output descriptor.

Parameters
[in]input_descriptorsInput descriptors
[in]axisConcatenation axis
Returns
Expected output descriptor

Definition at line 64 of file ConcatenateLayerNode.cpp.

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_MSG, arm_compute::misc::shape_calculator::calculate_concatenate_shape(), and arm_compute::graph::get_dimension_idx().

Referenced by ConcatenateLayerNode::configure_output().

66 {
67  ARM_COMPUTE_ERROR_ON(input_descriptors.size() == 0);
68 
69  TensorDescriptor output_descriptor = input_descriptors[0];
70  const int axis_idx = get_dimension_idx(output_descriptor.layout, axis);
71  ARM_COMPUTE_ERROR_ON_MSG(axis_idx > 2, "Unsupported concatenation axis!");
72 
73  // Extract shapes
74  std::vector<const TensorShape *> shapes;
75  shapes.reserve(input_descriptors.size());
76  for(auto &input_descriptor : input_descriptors)
77  {
78  shapes.emplace_back(&input_descriptor.shape);
79  }
80 
81  output_descriptor.shape = arm_compute::misc::shape_calculator::calculate_concatenate_shape(shapes, axis_idx);
82 
83  return output_descriptor;
84 }
#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
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
Definition: Error.h:456
TensorShape calculate_concatenate_shape(const std::vector< T *> &input, size_t axis)
Calculate the concatenate output shape of the concatenate operation along a single axis...
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

◆ concatenation_axis()

DataLayoutDimension concatenation_axis ( ) const

Concatenation axis parameter accessor.

Returns
Concatenation axis

Definition at line 54 of file ConcatenateLayerNode.cpp.

References ConcatLayerDescriptor::axis.

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

55 {
56  return _concat_descriptor.axis;
57 }
const DataLayoutDimension axis
Concatenation Axis.

◆ 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 98 of file ConcatenateLayerNode.cpp.

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_UNUSED, ConcatLayerDescriptor::axis, ConcatenateLayerNode::compute_output_descriptor(), Tensor::desc(), QuantizationInfo::empty(), arm_compute::graph::EmptyEdgeID, arm_compute::mlgo::parser::end(), INode::input_id(), arm_compute::test::validation::output_info, ConcatLayerDescriptor::output_qinfo, and tf_frozen_model_extractor::t.

Referenced by ConcatenateLayerNode::forward_descriptors().

99 {
100  ARM_COMPUTE_UNUSED(idx);
101  ARM_COMPUTE_ERROR_ON(idx >= _outputs.size());
102 
103  // Check if all input tensors are set
104  bool are_all_inputs_set = std::all_of(std::begin(_input_edges), std::end(_input_edges), [](const EdgeID & eid)
105  {
106  return eid != EmptyEdgeID;
107  });
108 
109  TensorDescriptor output_info = {};
110 
111  if(are_all_inputs_set)
112  {
113  std::vector<TensorDescriptor> inputs_descriptors;
114  for(unsigned int i = 0; i < _input_edges.size(); ++i)
115  {
116  const Tensor *t = _graph->tensor(input_id(i));
117  ARM_COMPUTE_ERROR_ON(t == nullptr);
118  inputs_descriptors.push_back(t->desc());
119  }
120  output_info = compute_output_descriptor(inputs_descriptors, _concat_descriptor.axis);
121  if(!_concat_descriptor.output_qinfo.empty())
122  {
123  output_info.quant_info = _concat_descriptor.output_qinfo;
124  }
125  }
126 
127  return output_info;
128 }
const QuantizationInfo output_qinfo
Output quantizazion info.
#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
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
TensorID input_id(size_t idx) const
Returns the tensor ID of a given input of the node.
Definition: INode.cpp:137
static TensorDescriptor compute_output_descriptor(const std::vector< TensorDescriptor > &input_descriptors, DataLayoutDimension axis)
Computes concatenations output descriptor.
void end(TokenStream &in, bool &valid)
Definition: MLGOParser.cpp:290
constexpr EdgeID EmptyEdgeID
Definition: Types.h:75
unsigned int EdgeID
Definition: Types.h:67
bool empty() const
Indicates whether this QuantizationInfo has valid settings or not.
const DataLayoutDimension axis
Concatenation Axis.

◆ 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 86 of file ConcatenateLayerNode.cpp.

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

87 {
88  if(_outputs[0] != NullTensorID)
89  {
90  Tensor *dst = output(0);
91  ARM_COMPUTE_ERROR_ON(dst == nullptr);
92  dst->desc() = configure_output(0);
93  return true;
94  }
95  return false;
96 }
#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
TensorDescriptor configure_output(size_t idx) const override
Calculates output configuration.
constexpr TensorID NullTensorID
Constant NodeID specifying an equivalent of null node.
Definition: Types.h:71

◆ is_enabled()

bool is_enabled ( ) const

Enabled parameter accessor.

Returns
True if a backend function is to be created else false

Definition at line 49 of file ConcatenateLayerNode.cpp.

Referenced by arm_compute::graph::backends::detail::create_concatenate_layer(), ConcatenateLayerNode::set_enabled(), and DotGraphVisitor::visit().

50 {
51  return _is_enabled;
52 }

◆ output_quantization_info()

QuantizationInfo output_quantization_info ( ) const

Concatenation output quantization info accessor.

Returns
Output quantization info

Definition at line 59 of file ConcatenateLayerNode.cpp.

References ConcatLayerDescriptor::output_qinfo.

60 {
61  return _concat_descriptor.output_qinfo;
62 }
const QuantizationInfo output_qinfo
Output quantizazion info.

◆ set_enabled()

void set_enabled ( bool  is_enabled)

Disables or not the depth concatenate node.

Warning
This is used when concatenate is performed using sub-tensors, where this node is used as a placeholder.
Parameters
[in]is_enabledIf true a backend function is created to perform the concatenation (involves copying), while if false, no function is created and we assume that sub-tensors are properly set to simulate a zero copy operation.

Definition at line 44 of file ConcatenateLayerNode.cpp.

References ConcatenateLayerNode::is_enabled().

45 {
46  _is_enabled = is_enabled;
47 }
bool is_enabled() const
Enabled parameter accessor.

◆ type()

NodeType type ( ) const
overridevirtual

Returns node's type.

Returns
Node's type

Implements INode.

Definition at line 130 of file ConcatenateLayerNode.cpp.

References arm_compute::graph::ConcatenateLayer.

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


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