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

#include <MeanLayer.h>

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

Public Member Functions

 MeanLayer ()
 
void configureBackward (IPortableTensor *back_prop_input, const IPortableTensor *back_prop_output)
 
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::MeanLayer
 MeanLayer ()
 
void MeanFloat32 ()
 
void MeanQuant8 ()
 
void configure (const IPortableTensor *input, const IPortableTensor *axes, IPortableTensor *output, bool keep_dims)
 
void run () override
 
- Public Member Functions inherited from onert::exec::IFunction
virtual ~IFunction ()=default
 
virtual void prepare ()
 

Additional Inherited Members

- Protected Attributes inherited from onert::backend::cpu::ops::MeanLayer
const IPortableTensor_input
 
const IPortableTensor_axes
 
IPortableTensor_output
 
bool _keep_dims
 

Detailed Description

Definition at line 34 of file MeanLayer.h.

Constructor & Destructor Documentation

◆ MeanLayer()

onert::backend::train::ops::MeanLayer::MeanLayer ( )

Definition at line 34 of file MeanLayer.cc.

35 : cpu::ops::MeanLayer(), _back_prop_input{nullptr}, _back_prop_output{nullptr}
36{
37 // DO NOTHING
38}

Member Function Documentation

◆ backward()

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

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

Definition at line 49 of file MeanLayer.cc.

50{
51 nnfw::cker::Shape keep_dim_shape;
52 // If _keep_dims is false, the input rank and the output rank can be different.
53 // MeanGrad does not support other ranking cases. This code corrects the shape
54 // by creating a temporary shape having the same rank as the input.
55 if (_keep_dims == false)
56 {
57 keep_dim_shape.ReplaceWith(getShape(_input));
58 auto axes_vec = cpu::ops::getReducerAxes(_axes);
59 for (const auto &axis : axes_vec)
60 {
61 keep_dim_shape.SetDim(axis, 1);
62 }
63 }
64 else
65 {
66 keep_dim_shape.ReplaceWith(getShape(_back_prop_output));
67 }
68
69 switch (_back_prop_output->data_type())
70 {
71 case OperandType::FLOAT32:
72 {
73 nnfw::cker::train::MeanGrad(keep_dim_shape, getBuffer<float>(_back_prop_output),
74 getShape(_back_prop_input), getBuffer<float>(_back_prop_input));
75 break;
76 }
77 default:
78 throw std::runtime_error("train MeanLayer: unsupported data type");
79 }
80}
void ReplaceWith(int dimensions_count, const int32_t *dims_data)
Definition Shape.h:130
void SetDim(int i, int32_t val)
Definition Shape.h:98
ir::DataType data_type() const override final
const IPortableTensor * _input
Definition MeanLayer.h:49
const IPortableTensor * _axes
Definition MeanLayer.h:50
void MeanGrad(const Shape &incoming_shape, const T *incoming_data, const Shape &grad_shape, T *grad_data)
Definition ReduceMean.h:32
std::vector< int32_t > getReducerAxes(const IPortableTensor *axes)
nnfw::cker::Shape getShape(const IPortableTensor *tensor)
Get shape of tensor.

References onert::backend::cpu::ops::MeanLayer::_axes, onert::backend::cpu::ops::MeanLayer::_input, onert::backend::cpu::ops::MeanLayer::_keep_dims, onert::backend::IPortableTensor::data_type(), onert::backend::cpu::ops::getReducerAxes(), onert::backend::train::ops::getShape(), nnfw::cker::train::MeanGrad(), nnfw::cker::Shape::ReplaceWith(), and nnfw::cker::Shape::SetDim().

◆ configureBackward()

void onert::backend::train::ops::MeanLayer::configureBackward ( IPortableTensor back_prop_input,
const IPortableTensor back_prop_output 
)

Definition at line 40 of file MeanLayer.cc.

42{
43 _back_prop_input = back_prop_input;
44 _back_prop_output = back_prop_output;
45}

◆ forward()

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

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