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

#include <BinaryArithmeticLayer.h>

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

Public Member Functions

 BinaryArithmeticLayer ()
 
void configureBackward (IPortableTensor *back_prop_lhs, IPortableTensor *back_prop_rhs, const IPortableTensor *back_prop_output, const ir::Activation activation, const ArithmeticType arithmetic_type)
 
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::BinaryArithmeticLayer
 BinaryArithmeticLayer ()
 
void configure (const IPortableTensor *lhs, const IPortableTensor *rhs, IPortableTensor *output, const ir::Activation activation, const ArithmeticType arithmetic_type)
 
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::BinaryArithmeticLayer
const IPortableTensor_lhs
 
const IPortableTensor_rhs
 
IPortableTensor_output
 
std::function< void(const IPortableTensor *, const IPortableTensor *, IPortableTensor *)> _kernel
 

Detailed Description

Definition at line 43 of file BinaryArithmeticLayer.h.

Constructor & Destructor Documentation

◆ BinaryArithmeticLayer()

onert::backend::train::ops::BinaryArithmeticLayer::BinaryArithmeticLayer ( )

Definition at line 36 of file BinaryArithmeticLayer.cc.

37 : cpu::ops::BinaryArithmeticLayer(), _back_prop_lhs{nullptr}, _back_prop_rhs{nullptr},
38 _back_prop_output{nullptr}, _arithmetic_type{ArithmeticType::kAdd},
39 _activation{ir::Activation::NONE}, _act_back_prop_output{nullptr}
40{
41 // DO NOTHING
42}

Member Function Documentation

◆ backward()

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

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

Definition at line 65 of file BinaryArithmeticLayer.cc.

66{
67 // Calculate gradient for activation
68 if (_back_prop_output->data_type() != OperandType::FLOAT32)
69 throw std::runtime_error{"Unsupported Data Type"};
70
71 const IPortableTensor *backprop_act;
72 try
73 {
74 backprop_act =
75 backpropActivation(_activation, _output, _back_prop_output, _act_back_prop_output.get());
76 }
77 catch (const std::exception &e)
78 {
79 throw std::runtime_error{"train BinaryArithmeticLayer: " + std::string(e.what())};
80 }
81 assert(backprop_act != nullptr);
82
84 getShape(_lhs), getBuffer<float>(_lhs), getShape(_rhs), getBuffer<float>(_rhs),
85 getShape(backprop_act), getBuffer<float>(backprop_act), getShape(_back_prop_lhs),
86 getBuffer<float>(_back_prop_lhs), getShape(_back_prop_rhs), getBuffer<float>(_back_prop_rhs),
87 static_cast<nnfw::cker::train::ArithmeticType>(_arithmetic_type));
88}
ir::DataType data_type() const override final
void BinaryArithmeticGrad(const Shape &lhs_shape, const T *lhs_data, const Shape &rhs_shape, const T *rhs_data, const Shape &incoming_shape, const T *incoming_data, const Shape &lhs_grad_shape, T *lhs_grad_data, const Shape &rhs_grad_shape, T *rhs_grad_data, ArithmeticType arithmetic_type)
const IPortableTensor * backpropActivation(const ir::Activation &activation, const IPortableTensor *output, const IPortableTensor *input_backprop, IPortableTensor *output_backprop)
backpropagate acitvation
nnfw::cker::Shape getShape(const IPortableTensor *tensor)
Get shape of tensor.

References onert::backend::cpu::ops::BinaryArithmeticLayer::_lhs, onert::backend::cpu::ops::BinaryArithmeticLayer::_output, onert::backend::cpu::ops::BinaryArithmeticLayer::_rhs, onert::backend::train::ops::backpropActivation(), nnfw::cker::train::BinaryArithmeticGrad(), onert::backend::IPortableTensor::data_type(), and onert::backend::train::ops::getShape().

◆ configureBackward()

void onert::backend::train::ops::BinaryArithmeticLayer::configureBackward ( IPortableTensor back_prop_lhs,
IPortableTensor back_prop_rhs,
const IPortableTensor back_prop_output,
const ir::Activation  activation,
const ArithmeticType  arithmetic_type 
)

Definition at line 44 of file BinaryArithmeticLayer.cc.

49{
50 _back_prop_lhs = back_prop_lhs;
51 _back_prop_rhs = back_prop_rhs;
52 _back_prop_output = back_prop_output;
53 _arithmetic_type = arithmetic_type;
54 _activation = activation;
55
56 if (activation != ir::Activation::NONE)
57 {
58 _act_back_prop_output = std::make_unique<Tensor>(_output->get_info());
59 _act_back_prop_output->setBuffer(std::make_shared<basic::Allocator>(_output->total_size()));
60 }
61}
size_t total_size() const override final
const ir::OperandInfo & get_info() const

References onert::backend::cpu::ops::BinaryArithmeticLayer::_output, onert::backend::IPortableTensor::get_info(), onert::ir::NONE, and onert::backend::IPortableTensor::total_size().

◆ forward()

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

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