ONE - On-device Neural Engine
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 37 of file BinaryArithmeticLayer.h.

Constructor & Destructor Documentation

◆ BinaryArithmeticLayer()

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

Definition at line 30 of file BinaryArithmeticLayer.cc.

31 : cpu::ops::BinaryArithmeticLayer(), _back_prop_lhs{nullptr}, _back_prop_rhs{nullptr},
32 _back_prop_output{nullptr}, _arithmetic_type{ArithmeticType::kAdd},
33 _activation{ir::Activation::NONE}, _act_back_prop_output{nullptr}
34{
35 // DO NOTHING
36}

Member Function Documentation

◆ backward()

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

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

Definition at line 59 of file BinaryArithmeticLayer.cc.

60{
61 // Calculate gradient for activation
62 if (_back_prop_output->data_type() != OperandType::FLOAT32)
63 throw std::runtime_error{"Unsupported Data Type"};
64
65 const IPortableTensor *backprop_act;
66 try
67 {
68 backprop_act =
69 backpropActivation(_activation, _output, _back_prop_output, _act_back_prop_output.get());
70 }
71 catch (const std::exception &e)
72 {
73 throw std::runtime_error{"train BinaryArithmeticLayer: " + std::string(e.what())};
74 }
75 assert(backprop_act != nullptr);
76
78 getShape(_lhs), getBuffer<float>(_lhs), getShape(_rhs), getBuffer<float>(_rhs),
79 getShape(backprop_act), getBuffer<float>(backprop_act), getShape(_back_prop_lhs),
80 getBuffer<float>(_back_prop_lhs), getShape(_back_prop_rhs), getBuffer<float>(_back_prop_rhs),
81 static_cast<nnfw::cker::train::ArithmeticType>(_arithmetic_type));
82}
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 38 of file BinaryArithmeticLayer.cc.

43{
44 _back_prop_lhs = back_prop_lhs;
45 _back_prop_rhs = back_prop_rhs;
46 _back_prop_output = back_prop_output;
47 _arithmetic_type = arithmetic_type;
48 _activation = activation;
49
50 if (activation != ir::Activation::NONE)
51 {
52 _act_back_prop_output = std::make_unique<Tensor>(_output->get_info());
53 _act_back_prop_output->setBuffer(std::make_shared<basic::Allocator>(_output->total_size()));
54 }
55}
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: