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

#include <SpaceToBatchND.h>

Collaboration diagram for luci_interpreter::kernels::SpaceToBatchND:

Public Member Functions

 SpaceToBatchND (const Tensor *input, const Tensor *block_shape, const Tensor *paddings, Tensor *output)
 
const Tensorinput () const
 
const Tensorblock_shape () const
 
const Tensorpaddings () 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 SpaceToBatchND.h.

Constructor & Destructor Documentation

◆ SpaceToBatchND()

luci_interpreter::kernels::SpaceToBatchND::SpaceToBatchND ( const Tensor input,
const Tensor block_shape,
const Tensor paddings,
Tensor output 
)

Definition at line 37 of file SpaceToBatchND.cpp.

40{
41}
Kernel(std::vector< const Tensor * > inputs, std::vector< Tensor * > outputs)
Definition Kernel.h:31

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

Member Function Documentation

◆ block_shape()

const Tensor * luci_interpreter::kernels::SpaceToBatchND::block_shape ( ) const
inline

Definition at line 34 of file SpaceToBatchND.h.

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

References luci_interpreter::Kernel::_inputs.

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

◆ configure()

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

Implements luci_interpreter::Kernel.

Definition at line 43 of file SpaceToBatchND.cpp.

44{
45 const auto *block_shape_data = block_shape()->data<int32_t>();
46 const auto *paddings_data = paddings()->data<int32_t>();
47 LUCI_INTERPRETER_CHECK(input()->shape().num_dims() >= kInputMinDimensionNum);
48 LUCI_INTERPRETER_CHECK(input()->shape().num_dims() <= kInputMaxDimensionNum);
49 LUCI_INTERPRETER_CHECK(input()->element_type() == output()->element_type());
50
51 int spatial_dims_num = input()->shape().num_dims() - 2;
52
53 LUCI_INTERPRETER_CHECK(block_shape()->shape().num_dims() == 1);
54 LUCI_INTERPRETER_CHECK(block_shape()->shape().dim(0) == spatial_dims_num);
55
56 LUCI_INTERPRETER_CHECK(paddings()->shape().num_dims() == 2);
57 LUCI_INTERPRETER_CHECK(paddings()->shape().dim(0) == spatial_dims_num);
58 LUCI_INTERPRETER_CHECK(paddings()->shape().dim(1) == 2);
59
60 Shape output_shape = Shape(input()->shape().num_dims());
61 int output_batch_size = input()->shape().dim(0);
62 for (int i = 0; i < spatial_dims_num; ++i)
63 {
64 int final_dim_size =
65 (input()->shape().dim(i + 1) + paddings_data[i * 2] + paddings_data[i * 2 + 1]);
66 LUCI_INTERPRETER_CHECK(final_dim_size % block_shape_data[i] == 0);
67 output_shape.dim(i + 1) = final_dim_size / block_shape_data[i];
68 output_batch_size = output_batch_size * block_shape_data[i];
69 }
70 output_shape.dim(0) = output_batch_size;
71 output_shape.dim(input()->shape().num_dims() - 1) =
72 input()->shape().dim(input()->shape().num_dims() - 1);
74}
int32_t dim(int i) const
Definition Tensor.h:41
int num_dims() const
Definition Tensor.h:39
void resize(const Shape &new_shape)
Definition Tensor.cpp:56
const Shape & shape() const
Definition Tensor.h:107
const T * data() const
Definition Tensor.h:127
#define LUCI_INTERPRETER_CHECK(cond)
Definition Utils.h:36
const luci_interpreter::RuntimeShape output_shape
Definition Shape.h:28

References block_shape(), luci_interpreter::Tensor::data(), 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::SpaceToBatchND::execute ( ) const
overridevirtual

Implements luci_interpreter::Kernel.

Definition at line 76 of file SpaceToBatchND.cpp.

77{
78 switch (input()->element_type())
79 {
80 tflite::SpaceToBatchParams op_params;
81 case DataType::FLOAT32:
82 op_params.output_offset = 0;
83 luci_interpreter_pal::SpaceToBatchND(
84 op_params, getTensorShape(input()), getTensorData<float>(input()),
85 getTensorShape(block_shape()), getTensorData<int32_t>(block_shape()),
86 getTensorShape(paddings()), getTensorData<int32_t>(paddings()), getTensorShape(output()),
87 getTensorData<float>(output()));
88 break;
89 case DataType::U8:
90 op_params.output_offset = output()->zero_point();
91 luci_interpreter_pal::SpaceToBatchND(
92 op_params, getTensorShape(input()), getTensorData<uint8_t>(input()),
93 getTensorShape(block_shape()), getTensorData<int32_t>(block_shape()),
94 getTensorShape(paddings()), getTensorData<int32_t>(paddings()), getTensorShape(output()),
95 getTensorData<uint8_t>(output()));
96 break;
97 default:
98 throw std::runtime_error("luci-intp ShapeToBatchND Unsupported type.");
99 }
100}
int32_t zero_point() const
Definition Tensor.h:115
tflite::RuntimeShape getTensorShape(const Tensor *tensor)
Definition Utils.h:194

References block_shape(), luci_interpreter::kernels::getTensorShape(), input(), output(), paddings(), and luci_interpreter::Tensor::zero_point().

◆ input()

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

Definition at line 33 of file SpaceToBatchND.h.

33{ return _inputs[0]; }

References luci_interpreter::Kernel::_inputs.

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

◆ output()

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

Definition at line 36 of file SpaceToBatchND.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::SpaceToBatchND::paddings ( ) const
inline

Definition at line 35 of file SpaceToBatchND.h.

35{ return _inputs[2]; }

References luci_interpreter::Kernel::_inputs.

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


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