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

#include <SoftmaxLayer.h>

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

Public Member Functions

 SoftMaxLayer ()
 
void softmaxFloat32 ()
 
template<typename T >
void softmaxQuant8 ()
 
void configure (const IPortableTensor *input, const float beta, IPortableTensor *output)
 
void run () override
 
- Public Member Functions inherited from onert::exec::IFunction
virtual ~IFunction ()=default
 
virtual void prepare ()
 

Protected Attributes

const IPortableTensor_input
 
IPortableTensor_output
 

Detailed Description

Definition at line 27 of file SoftmaxLayer.h.

Constructor & Destructor Documentation

◆ SoftMaxLayer()

onert::backend::cpu::ops::SoftMaxLayer::SoftMaxLayer ( )

Definition at line 52 of file SoftmaxLayer.cc.

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

Member Function Documentation

◆ configure()

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

Definition at line 108 of file SoftmaxLayer.cc.

110{
111 _input = input;
112 _output = output;
113 _beta = beta;
114
115 if (_input->data_type() == OperandType::QUANT_UINT8_ASYMM ||
116 _input->data_type() == OperandType::QUANT_INT8_ASYMM)
117 {
118#ifdef TFLITE_SOFTMAX_USE_UINT16_LUT
119 // Only apply when both input & output are uint8/int8 & build with clang
120 // on aarch64.
121 nnfw::cker::PopulateSoftmaxUInt8LookupTable(_uint8_table1, _uint8_table2, _input->data_scale(),
122 _beta);
123#else
125#endif
126 }
127}
float data_scale() const override final
ir::DataType data_type() const override final
void PopulateSoftmaxLookupTable(float *table, float input_scale, float beta)
Definition SoftMax.h:148

References _input, _output, onert::backend::IPortableTensor::data_scale(), onert::backend::IPortableTensor::data_type(), and nnfw::cker::PopulateSoftmaxLookupTable().

◆ run()

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

Implements onert::exec::IFunction.

Definition at line 129 of file SoftmaxLayer.cc.

130{
131 switch (_input->data_type())
132 {
133 case OperandType::FLOAT32:
135 break;
136 case OperandType::QUANT_UINT8_ASYMM:
137 softmaxQuant8<uint8_t>();
138 break;
139 case OperandType::QUANT_INT8_ASYMM:
140 softmaxQuant8<int8_t>();
141 break;
142 default:
143 throw std::runtime_error{"SoftMax: unsupported data type"};
144 }
145}

References _input, onert::backend::IPortableTensor::data_type(), and softmaxFloat32().

Referenced by onert::backend::train::ops::SoftMaxLayer::forward().

◆ softmaxFloat32()

void onert::backend::cpu::ops::SoftMaxLayer::softmaxFloat32 ( )

Definition at line 57 of file SoftmaxLayer.cc.

58{
60 {
61 uint32_t input_size = getNumberOfElements(_input);
62 nnfw::cker::Softmax(getBuffer<float>(_input), input_size, 1, _beta, getBuffer<float>(_output));
63 }
64 else if (getNumberOfDimensions(_input) == 2)
65 {
66 uint32_t batch_size = getSizeOfDimension(_input, 0);
67 if (batch_size == 0)
68 throw std::runtime_error("batch_size should not be 0");
69
70 uint32_t input_size = getNumberOfElements(_input) / batch_size;
71 nnfw::cker::Softmax(getBuffer<float>(_input), input_size, batch_size, _beta,
72 getBuffer<float>(_output));
73 }
74 else if (getNumberOfDimensions(_input) == 4)
75 {
77 op_params.beta = _beta;
78 nnfw::cker::Softmax(op_params, getShape(_input), getBuffer<float>(_input), getShape(_output),
79 getBuffer<float>(_output));
80 }
81 else
82 {
84 op_params.beta = _beta;
85 nnfw::cker::reference::Softmax(op_params, getShape(_input), getBuffer<float>(_input),
86 getShape(_output), getBuffer<float>(_output));
87 }
88}
uint32_t getNumberOfElements(const Shape &shape)
Definition Shape.cpp:48
uint32_t getSizeOfDimension(const Shape &shape, uint32_t dimensionIdx)
Definition Shape.cpp:60
uint32_t getNumberOfDimensions(const Shape &shape)
Definition Shape.cpp:58
void Softmax(const SoftmaxParams &params, const Shape &input_shape, const float *input_data, const Shape &output_shape, float *output_data)
Definition SoftMax.h:43
void Softmax(const float *in, const int input_size, const int batch_size, const float beta, float *out)
Definition SoftMax.h:79
nnfw::cker::Shape getShape(const IPortableTensor *tensor)

References _input, _output, nnfw::cker::SoftmaxParams::beta, getNumberOfDimensions(), getNumberOfElements(), onert::backend::cpu::ops::getShape(), getSizeOfDimension(), nnfw::cker::Softmax(), and nnfw::cker::reference::Softmax().

Referenced by run().

◆ softmaxQuant8()

template<typename T >
void onert::backend::cpu::ops::SoftMaxLayer::softmaxQuant8 ( )

Definition at line 90 of file SoftmaxLayer.cc.

91{
93 op_params.scale = _output->data_scale();
94 op_params.zero_point = _output->data_zero_point();
95 op_params.uint8_table1 = _uint8_table1;
96 op_params.uint8_table2 = _uint8_table2;
97 op_params.table = _table;
98
99#ifdef TFLITE_SOFTMAX_USE_UINT16_LUT
100 nnfw::cker::SoftmaxInt8LUT<T, T>(op_params, getShape(_input), getBuffer<T>(_input),
101 getShape(_output), getBuffer<T>(_output));
102#else
103 nnfw::cker::Softmax<T, T>(op_params, getShape(_input), getBuffer<T>(_input), getShape(_output),
104 getBuffer<T>(_output));
105#endif
106}
int32_t data_zero_point() const override final

References _input, _output, onert::backend::IPortableTensor::data_scale(), onert::backend::IPortableTensor::data_zero_point(), onert::backend::cpu::ops::getShape(), nnfw::cker::SoftmaxParams::scale, nnfw::cker::SoftmaxParams::table, nnfw::cker::SoftmaxParams::uint8_table1, nnfw::cker::SoftmaxParams::uint8_table2, and nnfw::cker::SoftmaxParams::zero_point.

Field Documentation

◆ _input

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

◆ _output

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

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