ONE - On-device Neural Engine
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
onert::backend::cpu::ops::LogSoftMaxLayer Class Reference

#include <LogSoftMaxLayer.h>

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

Public Member Functions

 LogSoftMaxLayer ()
 
void logsoftmaxFloat32 ()
 
void logsoftmaxQuant8 ()
 
void configure (const IPortableTensor *input, const float beta, const int axis, IPortableTensor *output)
 
void run ()
 
void PopulateLookupTable (const float kBeta)
 
- Public Member Functions inherited from onert::exec::IFunction
virtual ~IFunction ()=default
 
virtual void prepare ()
 

Detailed Description

Definition at line 27 of file LogSoftMaxLayer.h.

Constructor & Destructor Documentation

◆ LogSoftMaxLayer()

onert::backend::cpu::ops::LogSoftMaxLayer::LogSoftMaxLayer ( )

Definition at line 26 of file LogSoftMaxLayer.cc.

26 : _input(nullptr), _output(nullptr), _beta(0.0), _axis(0)
27{
28 // DO NOTHING
29}

Member Function Documentation

◆ configure()

void onert::backend::cpu::ops::LogSoftMaxLayer::configure ( const IPortableTensor input,
const float  beta,
const int  axis,
IPortableTensor output 
)

Definition at line 63 of file LogSoftMaxLayer.cc.

65{
66 _input = input;
67 _output = output;
68 _beta = beta;
69 _axis = axis;
70 if (_input->data_type() == OperandType::QUANT_UINT8_ASYMM)
71 {
73 }
74}
ir::DataType data_type() const override final

References onert::backend::IPortableTensor::data_type(), and PopulateLookupTable().

◆ logsoftmaxFloat32()

void onert::backend::cpu::ops::LogSoftMaxLayer::logsoftmaxFloat32 ( )

Definition at line 41 of file LogSoftMaxLayer.cc.

42{
44 op_params.beta = _beta;
45 op_params.axis = _axis;
46 nnfw::cker::LogSoftmax(op_params, getShape(_input), getBuffer<float>(_input), getShape(_output),
47 getBuffer<float>(_output));
48}
void LogSoftmax(const SoftmaxParams &params, const Shape &input_shape, const float *input_data, const Shape &output_shape, float *output_data)
Definition LogSoftMax.h:34
nnfw::cker::Shape getShape(const IPortableTensor *tensor)

References nnfw::cker::SoftmaxParams::axis, nnfw::cker::SoftmaxParams::beta, onert::backend::cpu::ops::getShape(), and nnfw::cker::LogSoftmax().

Referenced by run().

◆ logsoftmaxQuant8()

void onert::backend::cpu::ops::LogSoftMaxLayer::logsoftmaxQuant8 ( )

Definition at line 50 of file LogSoftMaxLayer.cc.

51{
53 op_params.beta = _beta;
54 op_params.axis = _axis;
55 op_params.table = _table;
56 op_params.zero_point = _output->data_zero_point();
57 op_params.scale = _output->data_scale();
58 nnfw::cker::LogSoftmax(op_params, _input->data_scale(), getShape(_input),
59 getBuffer<uint8_t>(_input), getShape(_output),
60 getBuffer<uint8_t>(_output));
61}
float data_scale() const override final
int32_t data_zero_point() const override final

References nnfw::cker::SoftmaxParams::axis, nnfw::cker::SoftmaxParams::beta, onert::backend::IPortableTensor::data_scale(), onert::backend::IPortableTensor::data_zero_point(), onert::backend::cpu::ops::getShape(), nnfw::cker::LogSoftmax(), nnfw::cker::SoftmaxParams::scale, nnfw::cker::SoftmaxParams::table, and nnfw::cker::SoftmaxParams::zero_point.

Referenced by run().

◆ PopulateLookupTable()

void onert::backend::cpu::ops::LogSoftMaxLayer::PopulateLookupTable ( const float  kBeta)

Definition at line 31 of file LogSoftMaxLayer.cc.

32{
33 const float scale = -_input->data_scale() * kBeta;
34 const int32_t max_uint8 = std::numeric_limits<uint8_t>::max();
35 for (int32_t val = 0; val <= max_uint8; ++val)
36 {
37 _table[max_uint8 - val] = expf(scale * val);
38 }
39}

References onert::backend::IPortableTensor::data_scale().

Referenced by configure().

◆ run()

void onert::backend::cpu::ops::LogSoftMaxLayer::run ( )
virtual

Implements onert::exec::IFunction.

Definition at line 76 of file LogSoftMaxLayer.cc.

77{
78 if (_input->data_type() == OperandType::FLOAT32)
79 {
81 }
82 else if (_input->data_type() == OperandType::QUANT_UINT8_ASYMM)
83 {
85 }
86 else
87 {
88 throw std::runtime_error{"LogSoftmax : unsupported data type"};
89 }
90}

References onert::backend::IPortableTensor::data_type(), logsoftmaxFloat32(), and logsoftmaxQuant8().


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