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 33 of file LogSoftMaxLayer.h.

Constructor & Destructor Documentation

◆ LogSoftMaxLayer()

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

Definition at line 32 of file LogSoftMaxLayer.cc.

32 : _input(nullptr), _output(nullptr), _beta(0.0), _axis(0)
33{
34 // DO NOTHING
35}

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 69 of file LogSoftMaxLayer.cc.

71{
72 _input = input;
73 _output = output;
74 _beta = beta;
75 _axis = axis;
76 if (_input->data_type() == OperandType::QUANT_UINT8_ASYMM)
77 {
79 }
80}
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 47 of file LogSoftMaxLayer.cc.

48{
50 op_params.beta = _beta;
51 op_params.axis = _axis;
52 nnfw::cker::LogSoftmax(op_params, getShape(_input), getBuffer<float>(_input), getShape(_output),
53 getBuffer<float>(_output));
54}
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 56 of file LogSoftMaxLayer.cc.

57{
59 op_params.beta = _beta;
60 op_params.axis = _axis;
61 op_params.table = _table;
62 op_params.zero_point = _output->data_zero_point();
63 op_params.scale = _output->data_scale();
64 nnfw::cker::LogSoftmax(op_params, _input->data_scale(), getShape(_input),
65 getBuffer<uint8_t>(_input), getShape(_output),
66 getBuffer<uint8_t>(_output));
67}
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 37 of file LogSoftMaxLayer.cc.

38{
39 const float scale = -_input->data_scale() * kBeta;
40 const int32_t max_uint8 = std::numeric_limits<uint8_t>::max();
41 for (int32_t val = 0; val <= max_uint8; ++val)
42 {
43 _table[max_uint8 - val] = expf(scale * val);
44 }
45}

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 82 of file LogSoftMaxLayer.cc.

83{
84 if (_input->data_type() == OperandType::FLOAT32)
85 {
87 }
88 else if (_input->data_type() == OperandType::QUANT_UINT8_ASYMM)
89 {
91 }
92 else
93 {
94 throw std::runtime_error{"LogSoftmax : unsupported data type"};
95 }
96}

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

Referenced by package.infer.session::inference().


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