Compute Library
 22.11
FullyConnectedLayerNode Class Referencefinal

Fully Connected Layer node. More...

#include <FullyConnectedLayerNode.h>

Collaboration diagram for FullyConnectedLayerNode:
[legend]

Public Member Functions

 FullyConnectedLayerNode (unsigned int num_outputs, QuantizationInfo out_quant_info=QuantizationInfo(), FullyConnectedLayerInfo fc_info=FullyConnectedLayerInfo(), FastMathHint fast_math_hint=FastMathHint::Disabled)
 Constructor. 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...
 
void set_fused_activation (ActivationLayerInfo fused_activation)
 Sets fused activation. More...
 
FullyConnectedLayerInfo info () const
 Fully connected layer addition information. 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...
 
const std::list< std::unique_ptr< ConvPostOpInfo > > & post_op_info_list () const
 Post operator info list. More...
 
std::list< std::unique_ptr< ConvPostOpInfo > > & post_op_info_list ()
 Post operator info list. More...
 

Static Public Member Functions

static TensorDescriptor compute_weights_descriptor (const TensorDescriptor &input_descriptor, unsigned int num_outputs, FullyConnectedLayerInfo fc_info=FullyConnectedLayerInfo(), const QuantizationInfo &weights_quant_info=QuantizationInfo())
 Computes weights descriptor. More...
 
static TensorDescriptor compute_output_descriptor (const TensorDescriptor &input_descriptor, unsigned int num_outputs, const QuantizationInfo &out_quant_info=QuantizationInfo())
 Computes fully connected layer output descriptor. More...
 

Static Public Attributes

static constexpr NodeType node_type = NodeType::FullyConnectedLayer
 

Detailed Description

Fully Connected Layer node.

Definition at line 34 of file FullyConnectedLayerNode.h.

Constructor & Destructor Documentation

◆ FullyConnectedLayerNode()

FullyConnectedLayerNode ( unsigned int  num_outputs,
QuantizationInfo  out_quant_info = QuantizationInfo(),
FullyConnectedLayerInfo  fc_info = FullyConnectedLayerInfo(),
FastMathHint  fast_math_hint = FastMathHint::Disabled 
)

Constructor.

Parameters
[in]num_outputsNumber of neurons in the layer
[in]out_quant_info(Optional) Output quantization info
[in]fc_info(Optional) Additional information about the fully connected layer
[in]fast_math_hint(Optional) Fast math hint

Definition at line 34 of file FullyConnectedLayer.cpp.

35  : _num_outputs(num_outputs), _out_quant_info(std::move(out_quant_info)), _info(fc_info), _fast_math_hint(fast_math_hint)
36 {
37  _input_edges.resize(3, EmptyEdgeID);
38  _outputs.resize(1, NullTensorID);
39 }
FastMathHint fast_math_hint() const
Fast math hint accessor.
size_t num_outputs() const
Returns number of outputs of the node.
Definition: INode.cpp:184
constexpr EdgeID EmptyEdgeID
Definition: Types.h:78
constexpr TensorID NullTensorID
Constant NodeID specifying an equivalent of null node.
Definition: Types.h:74

Member Function Documentation

◆ accept()

void accept ( INodeVisitor v)
overridevirtual

Accepts a node visitor.

Parameters
[in]vVisitor to accept

Implements INode.

Definition at line 145 of file FullyConnectedLayer.cpp.

References INodeVisitor::visit().

146 {
147  v.visit(*this);
148 }

◆ compute_output_descriptor()

TensorDescriptor compute_output_descriptor ( const TensorDescriptor input_descriptor,
unsigned int  num_outputs,
const QuantizationInfo out_quant_info = QuantizationInfo() 
)
static

Computes fully connected layer output descriptor.

Warning
Works for inputs with 1D batch space
Parameters
[in]input_descriptorInput descriptor
[in]num_outputsNumber of output neurons
[in]out_quant_info(Optional) Weights quantization info
Returns
Output descriptor

Definition at line 90 of file FullyConnectedLayer.cpp.

References batches, QuantizationInfo::empty(), Dimensions< T >::num_dimensions(), TensorDescriptor::quant_info, and TensorDescriptor::shape.

Referenced by FullyConnectedLayerNode::configure_output().

93 {
94  // Note: Only 1D batch space is supported at the moment
95  unsigned int batches = input_descriptor.shape[1];
96  if(input_descriptor.shape.num_dimensions() > 2)
97  {
98  batches = input_descriptor.shape[3];
99  }
100 
101  // Set descriptor shape
102  TensorDescriptor output_descriptor = input_descriptor;
103  output_descriptor.shape = TensorShape(num_outputs, batches);
104 
105  // Set quantization info if present
106  if(!out_quant_info.empty())
107  {
108  output_descriptor.quant_info = out_quant_info;
109  }
110 
111  return output_descriptor;
112 }
size_t num_outputs() const
Returns number of outputs of the node.
Definition: INode.cpp:184
unsigned int batches

◆ compute_weights_descriptor()

TensorDescriptor compute_weights_descriptor ( const TensorDescriptor input_descriptor,
unsigned int  num_outputs,
FullyConnectedLayerInfo  fc_info = FullyConnectedLayerInfo(),
const QuantizationInfo weights_quant_info = QuantizationInfo() 
)
static

Computes weights descriptor.

Warning
Works for inputs with 1D batch space
Parameters
[in]input_descriptorInput descriptor
[in]num_outputsNumber of output neurons
[in]fc_info(Optional) Additional information about the fully connected layer
[in]weights_quant_info(Optional) Weights quantization info
Returns
Weights descriptor

Definition at line 55 of file FullyConnectedLayer.cpp.

References QuantizationInfo::empty(), Dimensions< T >::num_dimensions(), TensorDescriptor::quant_info, TensorDescriptor::shape, and FullyConnectedLayerInfo::transpose_weights.

Referenced by GraphBuilder::add_fully_connected_layer().

59 {
60  unsigned int num_weights = 1;
61  unsigned int num_dimensions = input_descriptor.shape.num_dimensions();
62  // Ignore the batch dimension if there is one:
63  if(num_dimensions == 2 || num_dimensions == 4)
64  {
65  num_dimensions--;
66  }
67  for(unsigned int i = 0; i < num_dimensions; i++)
68  {
69  num_weights *= input_descriptor.shape[i];
70  }
71 
72  TensorDescriptor weights_descriptor = input_descriptor;
73  weights_descriptor.shape = TensorShape(num_weights, num_outputs);
74 
75  // If weights are tranposed, use tranposed shape
76  if(!fc_info.transpose_weights)
77  {
78  weights_descriptor.shape = TensorShape(num_outputs, num_weights);
79  }
80 
81  // Set quantization info if present
82  if(!weights_quant_info.empty())
83  {
84  weights_descriptor.quant_info = weights_quant_info;
85  }
86 
87  return weights_descriptor;
88 }
size_t num_outputs() const
Returns number of outputs of the node.
Definition: INode.cpp:184

◆ 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 131 of file FullyConnectedLayer.cpp.

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_UNUSED, FullyConnectedLayerNode::compute_output_descriptor(), Tensor::desc(), INode::input(), and arm_compute::test::validation::src.

Referenced by FullyConnectedLayerNode::forward_descriptors().

132 {
133  ARM_COMPUTE_UNUSED(idx);
134  const Tensor *src = input(0);
135  ARM_COMPUTE_ERROR_ON(src == nullptr);
136 
137  return compute_output_descriptor(src->desc(), _num_outputs, _out_quant_info);
138 }
#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
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
static TensorDescriptor compute_output_descriptor(const TensorDescriptor &input_descriptor, unsigned int num_outputs, const QuantizationInfo &out_quant_info=QuantizationInfo())
Computes fully connected layer output descriptor.
Tensor * input(size_t idx) const
Returns the tensor of a given input of the node.
Definition: INode.cpp:151

◆ 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 45 of file FullyConnectedLayer.cpp.

46 {
47  return _fast_math_hint;
48 }

◆ 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 119 of file FullyConnectedLayer.cpp.

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

120 {
121  if((input_id(0) != NullTensorID) && (output_id(0) != NullTensorID))
122  {
123  Tensor *dst = output(0);
124  ARM_COMPUTE_ERROR_ON(dst == nullptr);
125  dst->desc() = configure_output(0);
126  return true;
127  }
128  return false;
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
Tensor * output(size_t idx) const
Returns the tensor of a given output of the node.
Definition: INode.cpp:159
TensorDescriptor configure_output(size_t idx) const override
Calculates output configuration.
TensorID input_id(size_t idx) const
Returns the tensor ID of a given input of the node.
Definition: INode.cpp:138
TensorID output_id(size_t idx) const
Returns the tensor ID of a given output of the node.
Definition: INode.cpp:145
constexpr TensorID NullTensorID
Constant NodeID specifying an equivalent of null node.
Definition: Types.h:74

◆ info()

FullyConnectedLayerInfo info ( ) const

Fully connected layer addition information.

Returns
Additional information about the fully connected layer

Definition at line 114 of file FullyConnectedLayer.cpp.

115 {
116  return _info;
117 }

◆ set_fast_math_hint()

void set_fast_math_hint ( FastMathHint  hint)

Sets the fast math fast hint.

Parameters
[in]hintHint to use for fullyconnected layer

Definition at line 40 of file FullyConnectedLayer.cpp.

41 {
42  _fast_math_hint = hint;
43 }

◆ set_fused_activation()

void set_fused_activation ( ActivationLayerInfo  fused_activation)

Sets fused activation.

Parameters
[in]fused_activationFused activation to set

Definition at line 50 of file FullyConnectedLayer.cpp.

References FullyConnectedLayerInfo::activation_info.

51 {
52  _info.activation_info = fused_activation;
53 }
ActivationLayerInfo activation_info
Fused activation to apply after the matrix multiplication.
Definition: Types.h:1812

◆ type()

NodeType type ( ) const
overridevirtual

Returns node's type.

Returns
Node's type

Implements INode.

Definition at line 140 of file FullyConnectedLayer.cpp.

References arm_compute::graph::FullyConnectedLayer.

Field Documentation

◆ node_type

constexpr NodeType node_type = NodeType::FullyConnectedLayer
static

Definition at line 103 of file FullyConnectedLayerNode.h.


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