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

#include <PadV2.h>

Collaboration diagram for luci_interpreter::kernels::PadV2:

Public Member Functions

 PadV2 (const Tensor *input, const Tensor *paddings, const Tensor *constant_values, Tensor *output)
 
const Tensorinput () const
 
const Tensorpaddings () const
 
const Tensorconstant_values () 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 27 of file PadV2.h.

Constructor & Destructor Documentation

◆ PadV2()

luci_interpreter::kernels::PadV2::PadV2 ( const Tensor input,
const Tensor paddings,
const Tensor constant_values,
Tensor output 
)

Definition at line 30 of file PadV2.cpp.

33{
34}
Kernel(std::vector< const Tensor * > inputs, std::vector< Tensor * > outputs)
Definition Kernel.h:31
const Tensor * input() const
Definition PadV2.h:32
const Tensor * constant_values() const
Definition PadV2.h:34
Tensor * output() const
Definition PadV2.h:35
const Tensor * paddings() const
Definition PadV2.h:33

References constant_values(), input(), and paddings().

Member Function Documentation

◆ configure()

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

Implements luci_interpreter::Kernel.

Definition at line 36 of file PadV2.cpp.

37{
38 const Shape &input_shape = input()->shape();
39 const int num_dims = input_shape.num_dims();
40
41 if (num_dims > 4)
42 throw std::runtime_error("Unsupported number of dimensions.");
43
44 assert(output()->element_type() == input()->element_type());
45 assert(paddings()->element_type() == DataType::S32);
46 assert(constant_values()->element_type() == output()->element_type());
47 // Paddings shape should be [N, 2].
48 assert(paddings()->shape().num_dims() == 2);
49 assert(paddings()->shape().dim(0) == num_dims);
50 assert(paddings()->shape().dim(1) == 2);
51 // Constant values elements number should be 1.
52 assert(constant_values()->shape().num_elements() == 1);
53
54 Shape output_shape(num_dims);
55 const auto *paddings_data = getTensorData<int32_t>(paddings());
56 for (int i = 0; i < num_dims; ++i)
57 {
58 const int32_t padding_before = paddings_data[i * 2];
59 const int32_t padding_after = paddings_data[i * 2 + 1];
60 assert(padding_before >= 0 && padding_after >= 0);
61 output_shape.dim(i) = input_shape.dim(i) + padding_before + padding_after;
62 }
63
65}
void resize(const Shape &new_shape)
Definition Tensor.cpp:56
const Shape & shape() const
Definition Tensor.h:107
const luci_interpreter::RuntimeShape output_shape
uint32_t num_elements(const Shape &shape)
The number of elements of a feature map of a given shape.
Definition Shape.h:59
Definition Shape.h:28

References constant_values(), luci_interpreter::Shape::dim(), input(), luci_interpreter::Shape::num_dims(), output(), output_shape, paddings(), luci_interpreter::Tensor::resize(), and luci_interpreter::Tensor::shape().

◆ constant_values()

const Tensor * luci_interpreter::kernels::PadV2::constant_values ( ) const
inline

Definition at line 34 of file PadV2.h.

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

References luci_interpreter::Kernel::_inputs.

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

◆ execute()

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

Implements luci_interpreter::Kernel.

Definition at line 67 of file PadV2.cpp.

68{
69 const int num_dims = input()->shape().num_dims();
70
71 tflite::PadParams params{};
72 params.left_padding_count = num_dims;
73 params.right_padding_count = num_dims;
74
75 const auto *paddings_data = getTensorData<int32_t>(paddings());
76 for (int i = num_dims - 1; i >= 0; --i)
77 {
78 params.left_padding[i] = paddings_data[i * 2];
79 params.right_padding[i] = paddings_data[i * 2 + 1];
80 }
81
82 switch (input()->element_type())
83 {
84 case DataType::FLOAT32:
85 {
86 const auto pad_value = getTensorData<float>(constant_values())[0];
87 tflite::reference_ops::Pad(params, getTensorShape(input()), getTensorData<float>(input()),
88 &pad_value, getTensorShape(output()),
89 getTensorData<float>(output()));
90 break;
91 }
92 case DataType::U8:
93 {
94 assert(output()->zero_point() >= std::numeric_limits<uint8_t>::min());
95 assert(output()->zero_point() <= std::numeric_limits<uint8_t>::max());
96 const auto pad_value = getTensorData<uint8_t>(constant_values())[0];
97 tflite::reference_ops::Pad(params, getTensorShape(input()), getTensorData<uint8_t>(input()),
98 &pad_value, getTensorShape(output()),
99 getTensorData<uint8_t>(output()));
100 break;
101 }
102 default:
103 throw std::runtime_error("luci-intp PadV2 Unsupported type.");
104 }
105}
int num_dims() const
Definition Tensor.h:39
tflite::RuntimeShape getTensorShape(const Tensor *tensor)
Definition Utils.h:194

References constant_values(), luci_interpreter::kernels::getTensorShape(), input(), luci_interpreter::Shape::num_dims(), output(), paddings(), and luci_interpreter::Tensor::shape().

◆ input()

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

Definition at line 32 of file PadV2.h.

32{ return _inputs[0]; }

References luci_interpreter::Kernel::_inputs.

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

◆ output()

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

Definition at line 35 of file PadV2.h.

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

References luci_interpreter::Kernel::_outputs.

Referenced by configure(), and execute().

◆ paddings()

const Tensor * luci_interpreter::kernels::PadV2::paddings ( ) const
inline

Definition at line 33 of file PadV2.h.

33{ return _inputs[1]; }

References luci_interpreter::Kernel::_inputs.

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


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