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

#include <L2Pool2D.h>

Collaboration diagram for luci_interpreter::kernels::L2Pool2D:

Public Member Functions

 L2Pool2D (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 30 of file L2Pool2D.h.

Constructor & Destructor Documentation

◆ L2Pool2D()

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

Definition at line 32 of file L2Pool2D.cpp.

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

References input().

Member Function Documentation

◆ configure()

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

Implements luci_interpreter::Kernel.

Definition at line 37 of file L2Pool2D.cpp.

38{
39 LUCI_INTERPRETER_CHECK(input()->shape().num_dims() == 4);
40 LUCI_INTERPRETER_CHECK(input()->element_type() == output()->element_type());
41
42 int batches = input()->shape().dim(0);
43 int height = input()->shape().dim(1);
44 int width = input()->shape().dim(2);
45 int channels_out = input()->shape().dim(3);
46
47 // Matching GetWindowedOutputSize in TensorFlow.
48 auto padding = params().padding;
49 int out_width, out_height;
50 out_width = computeOutputSize(padding, width, params().filter_width, params().stride_width, 1);
51 out_height =
52 computeOutputSize(padding, height, params().filter_height, params().stride_height, 1);
53 _padding_width =
54 computePadding(params().stride_width, 1, width, params().filter_width, out_width);
55 _padding_height =
56 computePadding(params().stride_height, 1, height, params().filter_height, out_height);
57
58 LUCI_INTERPRETER_CHECK(input()->element_type() == DataType::FLOAT32);
59 output()->resize({batches, out_height, out_width, channels_out});
60}
int32_t dim(int i) const
Definition Tensor.h:41
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

References luci_interpreter::kernels::computeOutputSize(), luci_interpreter::kernels::computePadding(), luci_interpreter::Shape::dim(), input(), LUCI_INTERPRETER_CHECK, output(), luci_interpreter::Pool2DParams::padding, luci_interpreter::KernelWithParams< Pool2DParams >::params(), luci_interpreter::Tensor::resize(), and luci_interpreter::Tensor::shape().

◆ execute()

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

Implements luci_interpreter::Kernel.

Definition at line 62 of file L2Pool2D.cpp.

63{
64 switch (input()->element_type())
65 {
66 case DataType::FLOAT32:
67 float activation_min, activation_max;
68 calculateActivationRange(params().activation, &activation_min, &activation_max);
69 tflite::PoolParams op_params;
70 op_params.stride_height = params().stride_height;
71 op_params.stride_width = params().stride_width;
72 op_params.filter_height = params().filter_height;
73 op_params.filter_width = params().filter_width;
74 op_params.padding_values.height = _padding_height;
75 op_params.padding_values.width = _padding_width;
76 op_params.float_activation_min = activation_min;
77 op_params.float_activation_max = activation_max;
78 luci_interpreter_pal::L2Pool(op_params, getTensorShape(input()),
79 getTensorData<float>(input()), getTensorShape(output()),
80 getTensorData<float>(output()));
81 break;
82 default:
83 throw std::runtime_error("luci-intp L2Pool2D Unsupported type.");
84 }
85}
tflite::RuntimeShape getTensorShape(const Tensor *tensor)
Definition Utils.h:194
void calculateActivationRange(Activation activation, T *activation_min, T *activation_max)
Definition Utils.cpp:52

References luci_interpreter::kernels::calculateActivationRange(), luci_interpreter::Pool2DParams::filter_height, luci_interpreter::Pool2DParams::filter_width, luci_interpreter::kernels::getTensorShape(), input(), output(), luci_interpreter::KernelWithParams< Pool2DParams >::params(), luci_interpreter::Pool2DParams::stride_height, and luci_interpreter::Pool2DParams::stride_width.

◆ input()

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

Definition at line 35 of file L2Pool2D.h.

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

References luci_interpreter::Kernel::_inputs.

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

◆ output()

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

Definition at line 36 of file L2Pool2D.h.

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

References luci_interpreter::Kernel::_outputs.

Referenced by configure(), and execute().


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