Compute Library
 21.05
SplitLayerNode Class Referencefinal

Split Layer node. More...

#include <SplitLayerNode.h>

Collaboration diagram for SplitLayerNode:
[legend]

Public Member Functions

 SplitLayerNode (unsigned int num_splits, int axis=0, std::vector< int > size_splits=std::vector< int >())
 Default Constructor. More...
 
std::pair< TensorDescriptor, Coordinatescompute_output_descriptor (const TensorDescriptor &input_descriptor, unsigned int num_splits, int axis, unsigned int idx)
 Computes split layer output descriptor. More...
 
unsigned int num_splits () const
 Number of splits accessor. More...
 
unsigned int axis () const
 Split axis accessor. More...
 
Status validate () const override
 Validate node. 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...
 
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...
 

Detailed Description

Split Layer node.

Definition at line 36 of file SplitLayerNode.h.

Constructor & Destructor Documentation

◆ SplitLayerNode()

SplitLayerNode ( unsigned int  num_splits,
int  axis = 0,
std::vector< int >  size_splits = std::vector<int>() 
)

Default Constructor.

Parameters
[in]num_splitsNumber of splits
[in]axis(Optional) Axis to split on. Defaults to 0
[in]size_splits(Optional) The sizes of each output tensor along the split dimension. Must sum to the dimension of value along split_dim. Can contain one -1 indicating that dimension is to be inferred.

Definition at line 35 of file SplitLayerNode.cpp.

36  : _num_splits(num_splits), _axis(axis), _size_splits(size_splits)
37 {
38  _input_edges.resize(1, EmptyEdgeID);
39  _outputs.resize(num_splits, NullTensorID);
40 }
unsigned int num_splits() const
Number of splits accessor.
unsigned int axis() const
Split axis accessor.
constexpr EdgeID EmptyEdgeID
Definition: Types.h:77
constexpr TensorID NullTensorID
Constant NodeID specifying an equivalent of null node.
Definition: Types.h:73

References arm_compute::graph::EmptyEdgeID, arm_compute::graph::NullTensorID, and SplitLayerNode::num_splits().

Member Function Documentation

◆ accept()

void accept ( INodeVisitor v)
overridevirtual

Accepts a node visitor.

Parameters
[in]vVisitor to accept

Implements INode.

Definition at line 154 of file SplitLayerNode.cpp.

155 {
156  v.visit(*this);
157 }

References INodeVisitor::visit().

◆ axis()

unsigned int axis ( ) const

Split axis accessor.

Returns
Split axis

Definition at line 47 of file SplitLayerNode.cpp.

48 {
49  return _axis;
50 }

Referenced by SplitLayerNode::compute_output_descriptor().

◆ compute_output_descriptor()

std::pair< TensorDescriptor, Coordinates > compute_output_descriptor ( const TensorDescriptor input_descriptor,
unsigned int  num_splits,
int  axis,
unsigned int  idx 
)

Computes split layer output descriptor.

Parameters
[in]input_descriptorDescriptor of the input tensor
[in]num_splitsNumber of splits
[in]axisAxis to perform the split on
[in]idxIndex of the split
Returns
A pair with the descriptor of the split and the starting coordinates

Definition at line 52 of file SplitLayerNode.cpp.

54 {
55  // Handle negative axis, negative index is used to specify axis from the end (e.g. -1 for the last axis).
56  int num_dimension = static_cast<int32_t>(input_descriptor.shape.num_dimensions());
57  int tmp_axis = wrap_around(axis, num_dimension);
58  Coordinates coords;
59  TensorDescriptor output_descriptor = input_descriptor;
60  int split_size = input_descriptor.shape[tmp_axis] / num_splits;
61  if(_size_splits.empty())
62  {
63  output_descriptor.shape.set(tmp_axis, split_size);
64  coords.set(tmp_axis, idx * split_size);
65  }
66  else
67  {
68  int split_size = _size_splits[idx];
69  if(split_size == -1)
70  {
71  split_size = input_descriptor.shape[tmp_axis];
72  for(unsigned int i = 0; i < _size_splits.size() - 1; ++i)
73  split_size -= _size_splits[i];
74  }
75  output_descriptor.shape.set(tmp_axis, split_size);
76  int coord_value = 0;
77  for(unsigned int i = 0; i < idx; ++i)
78  coord_value += _size_splits[i];
79  coords.set(tmp_axis, coord_value);
80  }
81 
82  return std::make_pair(output_descriptor, coords);
83 }
unsigned int num_splits() const
Number of splits accessor.
T wrap_around(T x, T m)
Wrap-around a number within the range 0 <= x < m.
Definition: Helpers.h:231
unsigned int axis() const
Split axis accessor.

References SplitLayerNode::axis(), Dimensions< T >::num_dimensions(), SplitLayerNode::num_splits(), Dimensions< T >::set(), TensorShape::set(), TensorDescriptor::shape, and arm_compute::wrap_around().

◆ 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 104 of file SplitLayerNode.cpp.

105 {
106  ARM_COMPUTE_UNUSED(idx);
107  ARM_COMPUTE_ERROR_ON(idx >= _outputs.size());
108 
109  const Tensor *src = input(0);
110  ARM_COMPUTE_ERROR_ON(src == nullptr);
111 
112  TensorDescriptor input_descriptor = src->desc();
113  TensorDescriptor output_descriptor = input_descriptor;
114 
115  // Handle negative axis, negative index is used to specify axis from the end (e.g. -1 for the last axis).
116  int num_dimension = static_cast<int32_t>(src->desc().shape.num_dimensions());
117  int tmp_axis = wrap_around(_axis, num_dimension);
118 
119  int split_size = (_size_splits.empty()) ? (input_descriptor.shape[tmp_axis] / _num_splits) : _size_splits[idx];
120  if(split_size == -1)
121  {
122  split_size = input_descriptor.shape[tmp_axis];
123  for(unsigned int i = 0; i < _size_splits.size() - 1; ++i)
124  split_size -= _size_splits[i];
125  }
126  output_descriptor.shape.set(tmp_axis, split_size);
127 
128  return output_descriptor;
129 }
#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
T wrap_around(T x, T m)
Wrap-around a number within the range 0 <= x < m.
Definition: Helpers.h:231
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
Tensor * input(size_t idx) const
Returns the tensor of a given input of the node.
Definition: INode.cpp:150

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_UNUSED, INode::input(), TensorShape::set(), TensorDescriptor::shape, arm_compute::test::validation::src, and arm_compute::wrap_around().

Referenced by SplitLayerNode::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 85 of file SplitLayerNode.cpp.

86 {
87  if(input_id(0) != NullTensorID)
88  {
89  validate();
90  for(unsigned int i = 0; i < _outputs.size(); ++i)
91  {
92  if(output_id(i) != NullTensorID)
93  {
94  Tensor *dst_i = output(i);
95  ARM_COMPUTE_ERROR_ON(dst_i == nullptr);
96  dst_i->desc() = configure_output(i);
97  }
98  }
99  return true;
100  }
101  return false;
102 }
#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:73
Status validate() const override
Validate node.
TensorDescriptor configure_output(size_t idx) const override
Calculates output configuration.

References ARM_COMPUTE_ERROR_ON, SplitLayerNode::configure_output(), Tensor::desc(), INode::input_id(), arm_compute::graph::NullTensorID, INode::output(), INode::output_id(), and SplitLayerNode::validate().

◆ num_splits()

unsigned int num_splits ( ) const

Number of splits accessor.

Returns
Number of splits

Definition at line 42 of file SplitLayerNode.cpp.

43 {
44  return _num_splits;
45 }

Referenced by SplitLayerNode::compute_output_descriptor(), and SplitLayerNode::SplitLayerNode().

◆ type()

NodeType type ( ) const
overridevirtual

Returns node's type.

Returns
Node's type

Implements INode.

Definition at line 149 of file SplitLayerNode.cpp.

References arm_compute::graph::SplitLayer.

◆ validate()

Status validate ( ) const
overridevirtual

Validate node.

Returns
Status containing any errors

Reimplemented from INode.

Definition at line 131 of file SplitLayerNode.cpp.

132 {
133  const Tensor *src = input(0);
134  ARM_COMPUTE_RETURN_ERROR_ON(src == nullptr);
135  int num_dimension = static_cast<int32_t>(src->desc().shape.num_dimensions());
136  ARM_COMPUTE_RETURN_ERROR_ON(_axis < (-num_dimension) || _axis >= num_dimension);
137 
138  // Handle negative axis, negative index is used to specify axis from the end (e.g. -1 for the last axis).
139  int tmp_axis = wrap_around(_axis, num_dimension);
140 
141  if(_size_splits.empty())
142  {
143  ARM_COMPUTE_RETURN_ERROR_ON_MSG(src->desc().shape[tmp_axis] % _num_splits, "Split should be exact");
144  }
145 
146  return Status{};
147 }
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
Definition: Error.h:296
SimpleTensor< float > src
Definition: DFT.cpp:155
T wrap_around(T x, T m)
Wrap-around a number within the range 0 <= x < m.
Definition: Helpers.h:231
#define ARM_COMPUTE_RETURN_ERROR_ON_MSG(cond, msg)
If the condition is true, an error is returned.
Definition: Error.h:244
Tensor * input(size_t idx) const
Returns the tensor of a given input of the node.
Definition: INode.cpp:150

References ARM_COMPUTE_RETURN_ERROR_ON, ARM_COMPUTE_RETURN_ERROR_ON_MSG, INode::input(), arm_compute::test::validation::src, and arm_compute::wrap_around().

Referenced by SplitLayerNode::forward_descriptors().


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