ONE - On-device Neural Engine
Loading...
Searching...
No Matches
luci_interpreter::kernels::PRelu Class Reference

#include <PRelu.h>

Collaboration diagram for luci_interpreter::kernels::PRelu:

Public Member Functions

 PRelu (const Tensor *input, const Tensor *alpha, Tensor *output)
 
 ~PRelu ()
 
const Tensorinput () const
 
const Tensoralpha () const
 
Tensoroutput () const
 
void configure () override
 
void execute () const override
 
- Public Member Functions inherited from luci_interpreter::Kernel
virtual ~Kernel ()=default
 
const std::vector< const Tensor * > & getInputTensors () const
 
const std::vector< Tensor * > & getOutputTensors () const
 

Additional Inherited Members

- Protected Member Functions inherited from luci_interpreter::Kernel
 Kernel (std::vector< const Tensor * > inputs, std::vector< Tensor * > outputs)
 
- Protected Attributes inherited from luci_interpreter::Kernel
const std::vector< const Tensor * > _inputs
 
const std::vector< Tensor * > _outputs
 

Detailed Description

Definition at line 30 of file PRelu.h.

Constructor & Destructor Documentation

◆ PRelu()

luci_interpreter::kernels::PRelu::PRelu ( const Tensor input,
const Tensor alpha,
Tensor output 
)

Definition at line 33 of file PRelu.cpp.

34 : Kernel({input, alpha}, {output})
35{
36}
Kernel(std::vector< const Tensor * > inputs, std::vector< Tensor * > outputs)
Definition Kernel.h:31
const Tensor * alpha() const
Definition PRelu.h:38
Tensor * output() const
Definition PRelu.h:39
const Tensor * input() const
Definition PRelu.h:37

References alpha(), and input().

◆ ~PRelu()

luci_interpreter::kernels::PRelu::~PRelu ( )

Definition at line 38 of file PRelu.cpp.

39{
40 // Destructor declared to delete vector of alpha quantized data properly
41}

Member Function Documentation

◆ alpha()

const Tensor * luci_interpreter::kernels::PRelu::alpha ( ) const
inline

Definition at line 38 of file PRelu.h.

38{ return _inputs[1]; }
const std::vector< const Tensor * > _inputs
Definition Kernel.h:52

References luci_interpreter::Kernel::_inputs.

Referenced by configure(), and PRelu().

◆ configure()

void luci_interpreter::kernels::PRelu::configure ( )
overridevirtual

Implements luci_interpreter::Kernel.

Definition at line 43 of file PRelu.cpp.

44{
45 LUCI_INTERPRETER_CHECK(input()->element_type() == output()->element_type());
46 LUCI_INTERPRETER_CHECK(alpha()->element_type() == output()->element_type());
47 LUCI_INTERPRETER_CHECK(input()->scales().size() <= 1);
48 LUCI_INTERPRETER_CHECK(output()->scales().size() <= 1);
49
50 if (input()->element_type() == DataType::U8)
51 {
52 LUCI_INTERPRETER_CHECK(alpha()->scales().size() <= 1); // remove when CWQ kernel arrives
53 _alpha_multipliers.resize(1);
54 double alpha_multiplier = input()->scale() * alpha()->scale() / output()->scale();
55 quantizeMultiplier(alpha_multiplier, &_alpha_multipliers[0].multiplier,
56 &_alpha_multipliers[0].shift);
57 double identity_multiplier = input()->scale() / output()->scale();
58 quantizeMultiplier(identity_multiplier, &_output_multiplier_identity, &_output_shift_identity);
59 }
60 else if (input()->element_type() == DataType::S16)
61 {
62 // Common check for correctness of quant params
63 LUCI_INTERPRETER_CHECK(input()->zero_point() == 0 && output()->zero_point() == 0);
64 for (size_t channel = 0; channel < alpha()->zero_points().size(); ++channel)
65 {
66 LUCI_INTERPRETER_CHECK(alpha()->zero_points()[channel] == 0);
67 }
68 // PRelu specific checks for CWQ
69 LUCI_INTERPRETER_CHECK(alpha()->quantized_dimension() == alpha()->shape().num_dims() - 1);
70 LUCI_INTERPRETER_CHECK(static_cast<int32_t>(alpha()->scales().size()) ==
71 alpha()->shape().dim(alpha()->quantized_dimension()));
73 input()->shape().dim(input()->shape().num_dims() - 1));
74
75 // all dimension of alpha except last one should be size 1
76 for (int dim = 0; dim < alpha()->shape().num_dims() - 1; ++dim)
77 {
78 LUCI_INTERPRETER_CHECK(alpha()->shape().dim(dim) == 1);
79 }
80
81 std::vector<double> real_multipliers =
83
84 _alpha_multipliers = quantizeMultipliers(real_multipliers);
85
86 double identity_multiplier = input()->scale() / output()->scale();
87 quantizeMultiplier(identity_multiplier, &_output_multiplier_identity, &_output_shift_identity);
88 }
89 output()->resize(calculateShapeForBroadcast(input()->shape(), alpha()->shape()));
90}
int num_dims() const
Definition Tensor.h:39
void resize(const Shape &new_shape)
Definition Tensor.cpp:56
const Shape & shape() const
Definition Tensor.h:107
float scale() const
Definition Tensor.h:109
const std::vector< int32_t > & zero_points() const
Definition Tensor.h:123
#define LUCI_INTERPRETER_CHECK(cond)
Definition Utils.h:36
Shape calculateShapeForBroadcast(const Shape &input1_shape, const Shape &input2_shape)
Definition Utils.cpp:204
std::vector< ChannelQuantMultipliers > quantizeMultipliers(const std::vector< double > &effective_scale)
Definition Utils.h:170
void quantizeMultiplier(double double_multiplier, int32_t *quantized_multiplier, int *shift)
Definition Utils.cpp:157
std::vector< double > getQuantizedConvolutionMultiplers(float input_scale, const std::vector< float > &filter_scale, float output_scale)
Definition Utils.h:147
uint32_t num_elements(const Shape &shape)
The number of elements of a feature map of a given shape.
Definition Shape.h:59
int32_t size[5]
Definition Slice.cpp:35

References alpha(), luci_interpreter::kernels::calculateShapeForBroadcast(), luci_interpreter::kernels::getQuantizedConvolutionMultiplers(), input(), LUCI_INTERPRETER_CHECK, luci_interpreter::Shape::num_dims(), output(), luci_interpreter::kernels::quantizeMultiplier(), luci_interpreter::kernels::quantizeMultipliers(), luci_interpreter::Tensor::resize(), luci_interpreter::Tensor::scale(), luci_interpreter::Tensor::shape(), size, and luci_interpreter::Tensor::zero_points().

◆ execute()

void luci_interpreter::kernels::PRelu::execute ( ) const
overridevirtual

Implements luci_interpreter::Kernel.

Definition at line 92 of file PRelu.cpp.

93{
94 switch (input()->element_type())
95 {
96 case DataType::FLOAT32:
97 evalFloat();
98 break;
99 case DataType::U8:
100 evalQuantized();
101 break;
102 case DataType::S16:
103 evalQuantizedS16();
104 break;
105 default:
106 throw std::runtime_error("luci-intp PRelu Unsupported type.");
107 }
108}

References input().

◆ input()

const Tensor * luci_interpreter::kernels::PRelu::input ( ) const
inline

Definition at line 37 of file PRelu.h.

37{ return _inputs[0]; }

References luci_interpreter::Kernel::_inputs.

Referenced by configure(), execute(), and PRelu().

◆ output()

Tensor * luci_interpreter::kernels::PRelu::output ( ) const
inline

Definition at line 39 of file PRelu.h.

39{ return _outputs[0]; }
const std::vector< Tensor * > _outputs
Definition Kernel.h:53

References luci_interpreter::Kernel::_outputs.

Referenced by configure().


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