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

#include <AveragePool2D.h>

Collaboration diagram for luci_interpreter::kernels::AveragePool2D:

Public Member Functions

 AveragePool2D (const Tensor *input, Tensor *output, Tensor *scratchpad, const Pool2DParams &params)
 
const Tensorinput () const
 
Tensoroutput () const
 
void configure () override
 
void execute () const override
 
- Public Member Functions inherited from luci_interpreter::KernelWithParams< Pool2DParams >
const Pool2DParamsparams () const
 
- 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::KernelWithParams< Pool2DParams >
 KernelWithParams (std::vector< const Tensor * > inputs, std::vector< Tensor * > outputs, const Pool2DParams &params)
 
- Protected Member Functions inherited from luci_interpreter::Kernel
 Kernel (std::vector< const Tensor * > inputs, std::vector< Tensor * > outputs)
 
- Protected Attributes inherited from luci_interpreter::KernelWithParams< Pool2DParams >
const Pool2DParams _params
 
- Protected Attributes inherited from luci_interpreter::Kernel
const std::vector< const Tensor * > _inputs
 
const std::vector< Tensor * > _outputs
 

Detailed Description

Definition at line 28 of file AveragePool2D.h.

Constructor & Destructor Documentation

◆ AveragePool2D()

luci_interpreter::kernels::AveragePool2D::AveragePool2D ( const Tensor input,
Tensor output,
Tensor scratchpad,
const Pool2DParams params 
)

Definition at line 31 of file AveragePool2D.cpp.

33 : KernelWithParams<Pool2DParams>({input}, {output, scratchpad}, params)
34{
35}
const Pool2DParams & params() const
Definition Kernel.h:67

References input().

Member Function Documentation

◆ configure()

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

Implements luci_interpreter::Kernel.

Definition at line 37 of file AveragePool2D.cpp.

38{
39 if (input()->element_type() != output()->element_type())
40 {
41 throw std::runtime_error("Input Tensor and Output Tensor Type must be same");
42 }
43 if (input()->shape().num_dims() != 4)
44 {
45 throw std::runtime_error("Input Tensor Shape must be 4-D");
46 }
47 const Shape &input_shape = input()->shape();
48
49 const int32_t batches = input_shape.dim(0);
50 const int32_t input_height = input_shape.dim(1);
51 const int32_t input_width = input_shape.dim(2);
52 const int32_t depth = input_shape.dim(3);
53
54 const int32_t output_height =
56 const int32_t output_width =
58
59 _padding_height =
60 computePadding(_params.stride_height, 1, input_height, _params.filter_height, output_height);
61 _padding_width =
62 computePadding(_params.stride_width, 1, input_width, _params.filter_width, output_width);
63 if (input()->element_type() == DataType::U8)
64 {
65 LUCI_INTERPRETER_CHECK(std::abs(output()->scale() - input()->scale()) <= 1.0e-6);
66 LUCI_INTERPRETER_CHECK(output()->zero_point() == input()->zero_point());
67 }
68 else if (input()->element_type() == DataType::S16)
69 {
70 LUCI_INTERPRETER_CHECK(std::abs(output()->scale() - input()->scale()) <= 1.0e-6);
71 LUCI_INTERPRETER_CHECK(input()->zero_point() == 0 && output()->zero_point() == 0);
72 }
73 else if (input()->element_type() == DataType::S8)
74 {
75 LUCI_INTERPRETER_CHECK(std::abs(output()->scale() - input()->scale()) <= 1.0e-6);
76 LUCI_INTERPRETER_CHECK(output()->zero_point() == input()->zero_point());
77 }
78 output()->resize({batches, output_height, output_width, depth});
79
80 auto scratchpad = getOutputTensors()[1];
81 luci_interpreter_pal::SetupScratchpadTensor(scratchpad, input()->element_type(),
83}
const std::vector< Tensor * > & getOutputTensors() const
Definition Kernel.h:40
void resize(const Shape &new_shape)
Definition Tensor.cpp:56
const Shape & shape() const
Definition Tensor.h:107
#define LUCI_INTERPRETER_CHECK(cond)
Definition Utils.h:36
int32_t computePadding(int32_t stride, int32_t dilation_rate, int32_t in_size, int32_t filter_size, int32_t out_size)
Definition Utils.h:41
tflite::RuntimeShape getTensorShape(const Tensor *tensor)
Definition Utils.h:194
int32_t computeOutputSize(Padding padding, int32_t image_size, int32_t filter_size, int32_t stride, int32_t dilation_rate=1)
Definition Utils.h:59
Definition Shape.h:28

References luci_interpreter::KernelWithParams< Pool2DParams >::_params, luci_interpreter::kernels::computeOutputSize(), luci_interpreter::kernels::computePadding(), luci_interpreter::Shape::dim(), luci_interpreter::Pool2DParams::filter_height, luci_interpreter::Pool2DParams::filter_width, luci_interpreter::Kernel::getOutputTensors(), luci_interpreter::kernels::getTensorShape(), input(), LUCI_INTERPRETER_CHECK, output(), luci_interpreter::Pool2DParams::padding, luci_interpreter::Tensor::resize(), luci_interpreter::Tensor::shape(), luci_interpreter::Pool2DParams::stride_height, and luci_interpreter::Pool2DParams::stride_width.

◆ execute()

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

Implements luci_interpreter::Kernel.

Definition at line 85 of file AveragePool2D.cpp.

86{
87 switch (input()->element_type())
88 {
89 case DataType::FLOAT32:
90 evalFloat();
91 break;
92 case DataType::U8:
93 evalQuantized();
94 break;
95 case DataType::S16:
96 evalSInt16();
97 break;
98 case DataType::S8:
99 evalSInt8();
100 break;
101 default:
102 throw std::runtime_error("luci-intp AveragePool2D Unsupported type.");
103 }
104}

References input().

◆ input()

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

Definition at line 34 of file AveragePool2D.h.

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

References luci_interpreter::Kernel::_inputs.

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

◆ output()

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

Definition at line 35 of file AveragePool2D.h.

35{ 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: