ONE - On-device Neural Engine
Loading...
Searching...
No Matches
onert::backend::train::ops::FullyConnectedLayer Class Reference

#include <FullyConnectedLayer.h>

Collaboration diagram for onert::backend::train::ops::FullyConnectedLayer:

Public Member Functions

 FullyConnectedLayer ()
 
 ~FullyConnectedLayer ()
 
void configureBackward (const IPortableTensor *input, const IPortableTensor *weights, IPortableTensor *output, IPortableTensor *back_prop_input, IPortableTensor *grad_weights, IPortableTensor *grad_bias, const IPortableTensor *back_prop_output, ir::Activation activation, ir::FullyConnectedWeightsFormat weights_format)
 
void forward (bool training) override
 
void backward () override
 
- Public Member Functions inherited from onert::exec::train::ITrainableFunction
virtual ~ITrainableFunction ()=default
 
virtual std::optional< backend::train::LayerScopeTensorsregisterLayerScopeTensors ()
 
- Public Member Functions inherited from onert::backend::cpu::ops::FullyConnectedLayer
 FullyConnectedLayer ()
 
 ~FullyConnectedLayer ()
 
void fullyConnectedFloat32 ()
 
void fullyConnectedQuant8 ()
 
void fullyConnectedHybrid ()
 
void fullyConnectedSparseWeight ()
 
void fullyConnectedGGMLWeight ()
 
void fullyConnected16x1Float32 ()
 
void configure (const IPortableTensor *input, const IPortableTensor *weights, const IPortableTensor *bias, ir::Activation activation, ir::FullyConnectedWeightsFormat weights_format, IPortableTensor *output, const std::shared_ptr< ExternalContext > &external_context)
 
void run () override
 
void prepare () override
 
- Public Member Functions inherited from onert::exec::IFunction
virtual ~IFunction ()=default
 

Additional Inherited Members

- Protected Attributes inherited from onert::backend::cpu::ops::FullyConnectedLayer
const IPortableTensor_input
 
const IPortableTensor_weights
 
const IPortableTensor_bias
 
IPortableTensor_output
 
ir::Activation _activation
 
std::unique_ptr< nnfw::cker::FCTempArena_temp_arena
 
std::shared_ptr< ExternalContext_external_context
 
bool _is_hybrid: 1
 
bool _is_shuffled16x1float32: 1
 

Detailed Description

Definition at line 35 of file FullyConnectedLayer.h.

Constructor & Destructor Documentation

◆ FullyConnectedLayer()

onert::backend::train::ops::FullyConnectedLayer::FullyConnectedLayer ( )

Definition at line 55 of file FullyConnectedLayer.cc.

56 : cpu::ops::FullyConnectedLayer{}, _grad_weights{nullptr}, _grad_bias{nullptr},
57 _back_prop_input{nullptr}, _back_prop_output{nullptr}, _transposed_weights{nullptr},
58 _transposed_input{nullptr}, _transposed_back_prop_output{nullptr},
59 _act_back_prop_output{nullptr}
60{
61 // DO NOTHING
62}

◆ ~FullyConnectedLayer()

onert::backend::train::ops::FullyConnectedLayer::~FullyConnectedLayer ( )
default

Member Function Documentation

◆ backward()

void onert::backend::train::ops::FullyConnectedLayer::backward ( )
overridevirtual

Implements onert::exec::train::ITrainableFunction.

Definition at line 108 of file FullyConnectedLayer.cc.

109{
110 const auto data_type = _back_prop_output->data_type();
111 assert(data_type == _input->data_type());
112 switch (data_type)
113 {
114 case OperandType::FLOAT32:
115 {
116 assert(data_type == _grad_weights->data_type());
117 assert(_grad_bias == nullptr || data_type == _grad_bias->data_type());
118 backwardFloat32();
119 break;
120 }
121 default:
122 throw std::runtime_error{"train FullyConnectedLayer: unsupported data type"};
123 }
124}
ir::DataType data_type() const override final

References onert::backend::cpu::ops::FullyConnectedLayer::_input, and onert::backend::IPortableTensor::data_type().

◆ configureBackward()

void onert::backend::train::ops::FullyConnectedLayer::configureBackward ( const IPortableTensor input,
const IPortableTensor weights,
IPortableTensor output,
IPortableTensor back_prop_input,
IPortableTensor grad_weights,
IPortableTensor grad_bias,
const IPortableTensor back_prop_output,
ir::Activation  activation,
ir::FullyConnectedWeightsFormat  weights_format 
)

Definition at line 66 of file FullyConnectedLayer.cc.

71{
72 _back_prop_input = back_prop_input;
73 _grad_weights = grad_weights;
74 _grad_bias = grad_bias;
75 _back_prop_output = back_prop_output;
76
77 if (weights_format != ir::FullyConnectedWeightsFormat::Default)
78 throw std::runtime_error{
79 "train FullyConnectedLayer: Weight formats other than default are not supported."};
80
81 if (input->get_info().shape().rank() != 2 || weights->get_info().shape().rank() != 2 ||
82 output->get_info().shape().rank() != 2 || back_prop_input->get_info().shape().rank() != 2 ||
83 grad_weights->get_info().shape().rank() != 2 ||
84 back_prop_output->get_info().shape().rank() != 2)
85 throw std::runtime_error{
86 "train FullyConnectedLayer: Input other ranks than 2 are not supported."};
87
88 _transposed_weights = createTransposedTensor(weights);
89 _transposed_weights->setBuffer(std::make_shared<basic::Allocator>(weights->total_size()));
90
91 _transposed_input = createTransposedTensor(input);
92 _transposed_input->setBuffer(std::make_shared<basic::Allocator>(input->total_size()));
93
94 _transposed_back_prop_output = createTransposedTensor(back_prop_output);
95 _transposed_back_prop_output->setBuffer(
96 std::make_shared<basic::Allocator>(back_prop_output->total_size()));
97
98 if (activation != ir::Activation::NONE)
99 {
100 _act_back_prop_output = std::make_unique<Tensor>(_back_prop_output->get_info());
101 _act_back_prop_output->setBuffer(
102 std::make_shared<basic::Allocator>(_back_prop_output->total_size()));
103 }
104}
size_t total_size() const override final
const ir::OperandInfo & get_info() const

References onert::ir::Default, onert::backend::IPortableTensor::get_info(), onert::ir::NONE, onert::ir::OperandInfo::shape(), and onert::backend::IPortableTensor::total_size().

◆ forward()

void onert::backend::train::ops::FullyConnectedLayer::forward ( bool  training)
overridevirtual

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