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

#include <PadLayer.h>

Collaboration diagram for onert::backend::cpu::ops::PadLayer:

Public Member Functions

 PadLayer ()
 
template<typename T >
void padImpl (const T *constant_value_data)
 
void configure (const IPortableTensor *input, const IPortableTensor *pad, const IPortableTensor *value, IPortableTensor *output)
 
void run () override
 
- Public Member Functions inherited from onert::exec::IFunction
virtual ~IFunction ()=default
 
virtual void prepare ()
 

Protected Attributes

const IPortableTensor_input
 
const IPortableTensor_pad
 
const IPortableTensor_value
 
IPortableTensor_output
 
ConstDataPtr _constantValueData
 

Detailed Description

Definition at line 36 of file PadLayer.h.

Constructor & Destructor Documentation

◆ PadLayer()

onert::backend::cpu::ops::PadLayer::PadLayer ( )

Definition at line 30 of file PadLayer.cc.

31 : _input(nullptr), _pad(nullptr), _value(nullptr), _output(nullptr), _constantValueData()
32{
33 // DO NOTHING
34}
const IPortableTensor * _input
Definition PadLayer.h:50
const IPortableTensor * _value
Definition PadLayer.h:52
const IPortableTensor * _pad
Definition PadLayer.h:51

Member Function Documentation

◆ configure()

void onert::backend::cpu::ops::PadLayer::configure ( const IPortableTensor input,
const IPortableTensor pad,
const IPortableTensor value,
IPortableTensor output 
)

Definition at line 46 of file PadLayer.cc.

References _input, _output, _pad, and _value.

◆ padImpl()

template<typename T >
void onert::backend::cpu::ops::PadLayer::padImpl ( const T *  constant_value_data)

Definition at line 36 of file PadLayer.cc.

37{
38 assert(_pad->data_type() == onert::ir::DataType::INT32);
39 assert(_pad->buffer());
40 const auto pad_data = reinterpret_cast<const int32_t *>(_pad->buffer());
41 auto pad_rank = _pad->getShape().dim(0);
42 nnfw::cker::Pad<T>(pad_data, pad_rank, getShape(_input), getBuffer<T>(_input), getShape(_output),
43 getBuffer<T>(_output), constant_value_data);
44}
ir::DataType data_type() const override final
ir::Shape getShape() const override final
Get ir::Shape of tensor.
virtual uint8_t * buffer() const =0
nnfw::cker::Shape getShape(const IPortableTensor *tensor)

References _input, _output, _pad, onert::backend::ITensor::buffer(), onert::backend::IPortableTensor::data_type(), onert::backend::IPortableTensor::getShape(), and onert::backend::cpu::ops::getShape().

◆ run()

void onert::backend::cpu::ops::PadLayer::run ( )
overridevirtual

Implements onert::exec::IFunction.

Definition at line 55 of file PadLayer.cc.

56{
57 if (_value != nullptr) // isPadV2
58 {
59 assert(_value->buffer());
60 _constantValueData.v = reinterpret_cast<const void *>(_value->buffer());
61 }
62
63 switch (_input->data_type())
64 {
65 case OperandType::FLOAT32:
66 padImpl<float>(_constantValueData.f);
67 break;
68 case OperandType::QUANT_UINT8_ASYMM:
69 if (_constantValueData.u8 == nullptr)
70 {
71 uint8_t pad_value = static_cast<uint8_t>(_output->data_zero_point());
72 padImpl<uint8_t>(&pad_value);
73 }
74 else
75 {
76 padImpl<uint8_t>(_constantValueData.u8);
77 }
78 break;
79 case OperandType::QUANT_INT8_ASYMM:
80 if (_constantValueData.i8 == nullptr)
81 {
82 int8_t pad_value = static_cast<int8_t>(_output->data_zero_point());
83 padImpl<int8_t>(&pad_value);
84 }
85 else
86 {
87 padImpl<int8_t>(_constantValueData.i8);
88 }
89 break;
90 default:
91 throw std::runtime_error{"Pad: unsupported data type"};
92 }
93}
int32_t data_zero_point() const override final

References _constantValueData, _input, _output, _value, onert::backend::ITensor::buffer(), onert::backend::IPortableTensor::data_type(), onert::backend::IPortableTensor::data_zero_point(), onert::backend::cpu::ops::ConstDataPtr::f, onert::backend::cpu::ops::ConstDataPtr::i8, onert::backend::cpu::ops::ConstDataPtr::u8, and onert::backend::cpu::ops::ConstDataPtr::v.

Referenced by onert::backend::train::ops::PadLayer::forward(), and package.infer.session::inference().

Field Documentation

◆ _constantValueData

ConstDataPtr onert::backend::cpu::ops::PadLayer::_constantValueData
protected

Definition at line 54 of file PadLayer.h.

Referenced by run().

◆ _input

const IPortableTensor* onert::backend::cpu::ops::PadLayer::_input
protected

Definition at line 50 of file PadLayer.h.

Referenced by configure(), padImpl(), and run().

◆ _output

IPortableTensor* onert::backend::cpu::ops::PadLayer::_output
protected

Definition at line 53 of file PadLayer.h.

Referenced by configure(), padImpl(), and run().

◆ _pad

const IPortableTensor* onert::backend::cpu::ops::PadLayer::_pad
protected

Definition at line 51 of file PadLayer.h.

Referenced by configure(), onert::backend::train::ops::PadLayer::depad(), and padImpl().

◆ _value

const IPortableTensor* onert::backend::cpu::ops::PadLayer::_value
protected

Definition at line 52 of file PadLayer.h.

Referenced by configure(), and run().


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