Compute Library
 21.05
StackLayerNode Class Referencefinal

Stack Layer node. More...

#include <StackLayerNode.h>

Collaboration diagram for StackLayerNode:
[legend]

Public Member Functions

 StackLayerNode (unsigned int total_nodes, int axis)
 Constructor. More...
 
int axis () const
 Stack axis parameter 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, int axis)
 Computes stack output descriptor. More...
 

Detailed Description

Stack Layer node.

Definition at line 34 of file StackLayerNode.h.

Constructor & Destructor Documentation

◆ StackLayerNode()

StackLayerNode ( unsigned int  total_nodes,
int  axis 
)

Constructor.

Parameters
[in]total_nodesNumber of nodes that will get stacked
[in]axisAxis alogn which to stack the input tensors

Definition at line 38 of file StackLayerNode.cpp.

39  : _total_nodes(total_nodes), _axis(axis)
40 {
41  _input_edges.resize(_total_nodes, EmptyEdgeID);
42  _outputs.resize(1, NullTensorID);
43 }
constexpr EdgeID EmptyEdgeID
Definition: Types.h:77
int axis() const
Stack axis parameter accessor.
constexpr TensorID NullTensorID
Constant NodeID specifying an equivalent of null node.
Definition: Types.h:73

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

Member Function Documentation

◆ accept()

void accept ( INodeVisitor v)
overridevirtual

Accepts a node visitor.

Parameters
[in]vVisitor to accept

Implements INode.

Definition at line 110 of file StackLayerNode.cpp.

111 {
112  v.visit(*this);
113 }

References INodeVisitor::visit().

◆ axis()

int axis ( ) const

Stack axis parameter accessor.

Returns
Stack axis

Definition at line 45 of file StackLayerNode.cpp.

46 {
47  return _axis;
48 }

Referenced by StackLayerNode::compute_output_descriptor(), and arm_compute::graph::backends::detail::create_stack_layer().

◆ compute_output_descriptor()

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

Computes stack output descriptor.

Parameters
[in]input_descriptorsInput descriptors
[in]axisAxis along which to stack the input tensors
Returns
Expected output descriptor

Definition at line 50 of file StackLayerNode.cpp.

52 {
53  ARM_COMPUTE_ERROR_ON(input_descriptors.size() == 0);
54 
55  TensorDescriptor output_descriptor = input_descriptors[0];
56 
57  const TensorInfo input_info(input_descriptors[0].shape, 1, input_descriptors[0].data_type);
58  const unsigned int num_tensors = input_descriptors.size();
59 
60  output_descriptor.shape = arm_compute::misc::shape_calculator::compute_stack_shape(input_info, axis, num_tensors);
61 
62  return output_descriptor;
63 }
TensorShape compute_stack_shape(const ITensorInfo &a, unsigned int axis, unsigned int num_tensors)
Calculate the stack output shape of a tensor.
#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
const DataType data_type
Definition: Im2Col.cpp:150
int axis() const
Stack axis parameter accessor.

References ARM_COMPUTE_ERROR_ON, StackLayerNode::axis(), arm_compute::misc::shape_calculator::compute_stack_shape(), arm_compute::test::validation::data_type, arm_compute::test::validation::input_info, and arm_compute::test::validation::shape.

Referenced by StackLayerNode::configure_output().

◆ 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 77 of file StackLayerNode.cpp.

78 {
79  ARM_COMPUTE_UNUSED(idx);
80  ARM_COMPUTE_ERROR_ON(idx >= _outputs.size());
81 
82  // Check if all input tensors are set
83  bool are_all_inputs_set = std::all_of(std::begin(_input_edges), std::end(_input_edges), [](const EdgeID & eid)
84  {
85  return eid != EmptyEdgeID;
86  });
87 
88  TensorDescriptor output_info = {};
89 
90  if(are_all_inputs_set)
91  {
92  std::vector<TensorDescriptor> inputs_descriptors;
93  for(unsigned int i = 0; i < _input_edges.size(); ++i)
94  {
95  const Tensor *t = _graph->tensor(input_id(i));
96  ARM_COMPUTE_ERROR_ON(t == nullptr);
97  inputs_descriptors.push_back(t->desc());
98  }
99  output_info = compute_output_descriptor(inputs_descriptors, _axis);
100  }
101 
102  return output_info;
103 }
static TensorDescriptor compute_output_descriptor(const std::vector< TensorDescriptor > &input_descriptors, int axis)
Computes stack output descriptor.
#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
void end(TokenStream &in, bool &valid)
Definition: MLGOParser.cpp:290
constexpr EdgeID EmptyEdgeID
Definition: Types.h:77
unsigned int EdgeID
Definition: Types.h:69

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_UNUSED, StackLayerNode::compute_output_descriptor(), arm_compute::graph::EmptyEdgeID, arm_compute::mlgo::parser::end(), INode::input_id(), arm_compute::test::validation::output_info, and tf_frozen_model_extractor::t.

Referenced by StackLayerNode::forward_descriptors().

◆ 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 65 of file StackLayerNode.cpp.

66 {
67  if(_outputs[0] != NullTensorID)
68  {
69  Tensor *dst = output(0);
70  ARM_COMPUTE_ERROR_ON(dst == nullptr);
71  dst->desc() = configure_output(0);
72  return true;
73  }
74  return false;
75 }
#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:73

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

◆ type()

NodeType type ( ) const
overridevirtual

Returns node's type.

Returns
Node's type

Implements INode.

Definition at line 105 of file StackLayerNode.cpp.

References arm_compute::graph::StackLayer.

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


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