ONE - On-device Neural Engine
Loading...
Searching...
No Matches
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 53 of file LogSoftmaxLayer.cc.

53 : _input(nullptr), _output(nullptr), _beta(0.0), _axis(0)
54{
55 // DO NOTHING
56}

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 90 of file LogSoftmaxLayer.cc.

92{
93 _input = input;
94 _output = output;
95 _beta = beta;
96 _axis = axis;
97 if (_input->data_type() == OperandType::QUANT_UINT8_ASYMM)
98 {
100 }
101}
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 68 of file LogSoftmaxLayer.cc.

69{
71 op_params.beta = _beta;
72 op_params.axis = _axis;
73 nnfw::cker::LogSoftmax(op_params, getShape(_input), getBuffer<float>(_input), getShape(_output),
74 getBuffer<float>(_output));
75}
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 77 of file LogSoftmaxLayer.cc.

78{
80 op_params.beta = _beta;
81 op_params.axis = _axis;
82 op_params.table = _table;
83 op_params.zero_point = _output->data_zero_point();
84 op_params.scale = _output->data_scale();
85 nnfw::cker::LogSoftmax(op_params, _input->data_scale(), getShape(_input),
86 getBuffer<uint8_t>(_input), getShape(_output),
87 getBuffer<uint8_t>(_output));
88}
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 58 of file LogSoftmaxLayer.cc.

59{
60 const float scale = -_input->data_scale() * kBeta;
61 const int32_t max_uint8 = std::numeric_limits<uint8_t>::max();
62 for (int32_t val = 0; val <= max_uint8; ++val)
63 {
64 _table[max_uint8 - val] = expf(scale * val);
65 }
66}

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 103 of file LogSoftmaxLayer.cc.

104{
105 if (_input->data_type() == OperandType::FLOAT32)
106 {
108 }
109 else if (_input->data_type() == OperandType::QUANT_UINT8_ASYMM)
110 {
112 }
113 else
114 {
115 throw std::runtime_error{"LogSoftmax : unsupported data type"};
116 }
117}

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


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