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

#include <MirrorPad.h>

Collaboration diagram for luci_interpreter::kernels::MirrorPad:

Public Member Functions

 MirrorPad (const Tensor *input, const Tensor *paddings, Tensor *output, const MirrorPadParams &params)
 
const Tensorinput () const
 
const Tensorpaddings () const
 
Tensoroutput () const
 
void configure () override
 
void execute () const override
 
- Public Member Functions inherited from luci_interpreter::KernelWithParams< MirrorPadParams >
const MirrorPadParamsparams () 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< MirrorPadParams >
 KernelWithParams (std::vector< const Tensor * > inputs, std::vector< Tensor * > outputs, const MirrorPadParams &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< MirrorPadParams >
const MirrorPadParams _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 MirrorPad.h.

Constructor & Destructor Documentation

◆ MirrorPad()

luci_interpreter::kernels::MirrorPad::MirrorPad ( const Tensor input,
const Tensor paddings,
Tensor output,
const MirrorPadParams params 
)

Definition at line 29 of file MirrorPad.cpp.

31 : KernelWithParams<MirrorPadParams>({input, paddings}, {output}, params)
32{
33}
const MirrorPadParams & params() const
Definition Kernel.h:67
const Tensor * input() const
Definition MirrorPad.h:34
const Tensor * paddings() const
Definition MirrorPad.h:35

References input(), and paddings().

Member Function Documentation

◆ configure()

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

Implements luci_interpreter::Kernel.

Definition at line 35 of file MirrorPad.cpp.

36{
37 const Shape &input_shape = input()->shape();
38 const int num_dims = input_shape.num_dims();
39
40 if (num_dims > 4)
41 throw std::runtime_error("Unsupported number of dimensions.");
42
43 LUCI_INTERPRETER_CHECK(output()->element_type() == input()->element_type());
44 LUCI_INTERPRETER_CHECK(paddings()->element_type() == DataType::S32);
45 // Paddings shape should be [N, 2].
46 LUCI_INTERPRETER_CHECK(paddings()->shape().num_dims() == 2);
47 LUCI_INTERPRETER_CHECK(paddings()->shape().dim(0) == num_dims);
48 LUCI_INTERPRETER_CHECK(paddings()->shape().dim(1) == 2);
49
50 Shape output_shape(num_dims);
51 const auto *paddings_data = getTensorData<int32_t>(paddings());
52 for (int i = 0; i < num_dims; ++i)
53 {
54 const int32_t padding_before = paddings_data[i * 2];
55 const int32_t padding_after = paddings_data[i * 2 + 1];
56 LUCI_INTERPRETER_CHECK(padding_before >= 0 && padding_after >= 0);
57 output_shape.dim(i) = input_shape.dim(i) + padding_before + padding_after;
58 }
59
61}
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
const luci_interpreter::RuntimeShape output_shape
Definition Shape.h:28

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

◆ execute()

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

Implements luci_interpreter::Kernel.

Definition at line 147 of file MirrorPad.cpp.

148{
149 const Tensor &t_input = *input();
150 const Tensor &t_paddings = *paddings();
151 Tensor &t_output = *output();
152
153 const auto offset = params().mode != MirrorPadMode::REFLECT ? 0 : 1;
154 const auto input_dims = t_input.shape().num_dims();
155 const auto output_size = t_output.shape().num_elements();
156
157 int output_dims_num_elements[5];
158 int input_dims_num_elements[5];
159 int32_t input_shape_dim[5];
160
161 for (int i = 0; i < input_dims; i++)
162 {
163 output_dims_num_elements[i] = 1;
164 input_dims_num_elements[i] = 1;
165 input_shape_dim[i] = t_input.shape().dim(i);
166 }
167
168 for (int i = input_dims - 2; i >= 0; i--)
169 {
170 output_dims_num_elements[i] = output_dims_num_elements[i + 1] * t_output.shape().dim(i + 1);
171 input_dims_num_elements[i] = input_dims_num_elements[i + 1] * t_input.shape().dim(i + 1);
172 }
173
174 switch (t_input.element_type())
175 {
176 case DataType::FLOAT32:
177 eval(t_paddings.element_type(), t_paddings.data<uint8_t>(), input_shape_dim,
178 output_dims_num_elements, input_dims_num_elements, t_input.data<float>(),
179 t_output.data<float>(), offset, input_dims, output_size);
180 break;
181
182 case DataType::U8:
183 eval(t_paddings.element_type(), t_paddings.data<uint8_t>(), input_shape_dim,
184 output_dims_num_elements, input_dims_num_elements, t_input.data<uint8_t>(),
185 t_output.data<uint8_t>(), offset, input_dims, output_size);
186 break;
187
188 default:
189 throw std::runtime_error("luci-intp MirrorPad Unsupported type.");
190 }
191}
float * data()
int dim(int d) const
__global uchar * offset(const Image *img, int x, int y)
Definition helpers.h:540

References luci_interpreter::Tensor::data(), luci_interpreter::Shape::dim(), luci_interpreter::Tensor::element_type(), input(), luci_interpreter::MirrorPadParams::mode, luci_interpreter::Shape::num_dims(), luci_interpreter::Shape::num_elements(), offset(), output(), paddings(), luci_interpreter::KernelWithParams< MirrorPadParams >::params(), and luci_interpreter::Tensor::shape().

◆ input()

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

Definition at line 34 of file MirrorPad.h.

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

References luci_interpreter::Kernel::_inputs.

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

◆ output()

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

Definition at line 36 of file MirrorPad.h.

36{ 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::MirrorPad::paddings ( ) const
inline

Definition at line 35 of file MirrorPad.h.

35{ return _inputs[1]; }

References luci_interpreter::Kernel::_inputs.

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


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