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

#include <MaxPool2D.h>

Collaboration diagram for luci_interpreter::kernels::MaxPool2D:

Public Member Functions

 MaxPool2D (const Tensor *input, Tensor *output, 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 MaxPool2D.h.

Constructor & Destructor Documentation

◆ MaxPool2D()

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

Definition at line 32 of file MaxPool2D.cpp.

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

References input().

Member Function Documentation

◆ configure()

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

Implements luci_interpreter::Kernel.

Definition at line 37 of file MaxPool2D.cpp.

38{
39 LUCI_INTERPRETER_CHECK(input()->element_type() == output()->element_type());
40 assert(input()->shape().num_dims() == 4);
41 const Shape &input_shape = input()->shape();
42 const int32_t batches = input_shape.dim(0);
43 const int32_t input_height = input_shape.dim(1);
44 const int32_t input_width = input_shape.dim(2);
45 const int32_t depth = input_shape.dim(3);
46
47 const int32_t output_height =
49 const int32_t output_width =
51
52 _padding_height =
53 computePadding(_params.stride_height, 1, input_height, _params.filter_height, output_height);
54 _padding_width =
55 computePadding(_params.stride_width, 1, input_width, _params.filter_width, output_width);
56
57 output()->resize({batches, output_height, output_width, depth});
58 if (input()->element_type() == DataType::U8)
59 {
60 LUCI_INTERPRETER_CHECK(std::abs(output()->scale() - input()->scale()) <= 1.0e-6);
61 LUCI_INTERPRETER_CHECK(output()->zero_point() == input()->zero_point());
62 }
63 else if (input()->element_type() == DataType::S16)
64 {
65 LUCI_INTERPRETER_CHECK(std::abs(output()->scale() - input()->scale()) <= 1.0e-6);
66 LUCI_INTERPRETER_CHECK(input()->zero_point() == 0 && output()->zero_point() == 0);
67 }
68}
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
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, 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::MaxPool2D::execute ( ) const
overridevirtual

Implements luci_interpreter::Kernel.

Definition at line 70 of file MaxPool2D.cpp.

71{
72 switch (input()->element_type())
73 {
74 case DataType::FLOAT32:
75 evalFloat();
76 break;
77 case DataType::U8:
78 evalQuantized();
79 break;
80 case DataType::S16:
81 evalSInt16();
82 break;
83 default:
84 throw std::runtime_error("luci-intp MaxPool2D Unsupported type.");
85 }
86}

References input().

◆ input()

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

Definition at line 33 of file MaxPool2D.h.

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

References luci_interpreter::Kernel::_inputs.

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

◆ output()

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

Definition at line 34 of file MaxPool2D.h.

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