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

#include <SplitV.h>

Collaboration diagram for luci_interpreter::kernels::SplitV:

Public Member Functions

 SplitV (const Tensor *input, const Tensor *size_splits, const Tensor *axis, std::vector< Tensor * > outputs)
 
const Tensorinput () const
 
const Tensorsize_splits () const
 
const Tensoraxis () const
 
Tensoroutput (int index) 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 28 of file SplitV.h.

Constructor & Destructor Documentation

◆ SplitV()

luci_interpreter::kernels::SplitV::SplitV ( const Tensor input,
const Tensor size_splits,
const Tensor axis,
std::vector< Tensor * >  outputs 
)

Definition at line 28 of file SplitV.cpp.

30 : Kernel({input, size_splits, axis}, std::move(outputs))
31{
32}
Kernel(std::vector< const Tensor * > inputs, std::vector< Tensor * > outputs)
Definition Kernel.h:31
const Tensor * axis() const
Definition SplitV.h:36
const Tensor * size_splits() const
Definition SplitV.h:35
const Tensor * input() const
Definition SplitV.h:34

References axis(), input(), and size_splits().

Member Function Documentation

◆ axis()

const Tensor * luci_interpreter::kernels::SplitV::axis ( ) const
inline

Definition at line 36 of file SplitV.h.

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

References luci_interpreter::Kernel::_inputs.

Referenced by configure(), and SplitV().

◆ configure()

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

Implements luci_interpreter::Kernel.

Definition at line 34 of file SplitV.cpp.

35{
36 assert(axis()->shape().num_elements() == 1);
37 _axis_value = getTensorData<int32_t>(axis())[0];
38 if (_axis_value < 0)
39 _axis_value += input()->shape().num_dims();
40 assert(_axis_value >= 0 && _axis_value < input()->shape().num_dims());
41
42 auto num_split = static_cast<int32_t>(_outputs.size());
43 auto sizes_data = getTensorData<int32_t>(size_splits());
44
45 assert(size_splits()->shape().num_dims() == 1);
46
47 int32_t sum = 0;
48 const auto num_dims_size_spits = size_splits()->shape().dim(0);
49 int32_t count_neg_dim = 0;
50
51 for (int32_t i = 0; i < num_dims_size_spits - 1; ++i)
52 {
53 if (sizes_data[i] != -1)
54 {
55 sum += sizes_data[i];
56 }
57 else
58 {
59 count_neg_dim++;
60 }
61 }
62 assert(count_neg_dim < 2);
63 assert(size_splits()->shape().num_elements() == num_split);
64
65 auto output_shape = input()->shape();
66 for (int32_t i = 0; i < num_split; ++i)
67 {
68 if (sizes_data[i] == -1)
69 {
70 output_shape.dim(_axis_value) = input()->shape().dim(_axis_value) - sum;
71 }
72 else
73 {
74 output_shape.dim(_axis_value) = sizes_data[i];
75 }
77 }
78}
const std::vector< Tensor * > _outputs
Definition Kernel.h:53
void resize(int dimensions_count)
Definition Tensor.h:121
int32_t dim(int i) const
Definition Tensor.h:41
int num_dims() const
Definition Tensor.h:39
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

References luci_interpreter::Kernel::_outputs, axis(), luci_interpreter::Shape::dim(), input(), luci_interpreter::Shape::num_dims(), output_shape, luci_interpreter::RuntimeShape::resize(), luci_interpreter::Tensor::shape(), and size_splits().

◆ execute()

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

Implements luci_interpreter::Kernel.

Definition at line 80 of file SplitV.cpp.

81{
82 tflite::SplitParams params{};
83 params.num_split = _outputs.size();
84 params.axis = _axis_value;
85
86#define TF_LITE_SPLIT(scalar) \
87 { \
88 VectorOfTensors<scalar, false> all_outputs(_outputs); \
89 tflite::optimized_ops::Split(params, getTensorShape(input()), getTensorData<scalar>(input()), \
90 all_outputs.shapes(), all_outputs.data()); \
91 }
92
93 switch (input()->element_type())
94 {
95 case DataType::FLOAT32:
96 TF_LITE_SPLIT(float);
97 break;
98 case DataType::U8:
99 TF_LITE_SPLIT(uint8_t);
100 break;
101 case DataType::S16:
102 TF_LITE_SPLIT(int16_t);
103 break;
104 default:
105 throw std::runtime_error("luci-intp SplitV Unsupported type.");
106 }
107#undef TF_LITE_SPLIT
108}
#define TF_LITE_SPLIT(scalar)

References luci_interpreter::Kernel::_outputs, input(), and TF_LITE_SPLIT.

◆ input()

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

Definition at line 34 of file SplitV.h.

34{ return _inputs[0]; }

References luci_interpreter::Kernel::_inputs.

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

◆ output()

Tensor * luci_interpreter::kernels::SplitV::output ( int  index) const
inline

Definition at line 37 of file SplitV.h.

37{ return _outputs[index]; }
loco::GraphInputIndex index(const TFPlaceholder *node)
Definition TFNode.cpp:54

References luci_interpreter::Kernel::_outputs.

◆ size_splits()

const Tensor * luci_interpreter::kernels::SplitV::size_splits ( ) const
inline

Definition at line 35 of file SplitV.h.

35{ return _inputs[1]; }

References luci_interpreter::Kernel::_inputs.

Referenced by configure(), and SplitV().


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