ONE - On-device Neural Engine
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
SplitV.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "OMStatus.h"
18
19#include "core/OMUtils.h"
22
23using namespace onert_micro;
24using namespace onert_micro::core;
25
26namespace
27{
28
29constexpr uint32_t inputTensorIdx = 0;
30constexpr uint32_t sizeTensorIdx = 1;
31constexpr uint32_t axisTensorIdx = 2;
32constexpr uint32_t outputTensorIdx = 0;
33
34} // namespace
35
36namespace onert_micro
37{
38namespace import
39{
40
42{
43 OMRuntimeContext &runtime_context = config_args.runtime_context;
44 OMRuntimeStorage &runtime_storage = config_args.runtime_storage;
45 uint16_t op_index = config_args.kernel_index;
46
48
49 OMStatus status = runtime_kernel.readKernel(op_index, runtime_context);
50 if (status != Ok)
51 return status;
52
53 const circle::Tensor *input = runtime_kernel.inputs[inputTensorIdx];
54 const circle::Tensor *size = runtime_kernel.inputs[sizeTensorIdx];
55 const circle::Tensor *axis = runtime_kernel.inputs[axisTensorIdx];
56 const circle::Tensor *output = runtime_kernel.outputs[outputTensorIdx];
57
58 assert(input != nullptr);
59 assert(axis != nullptr);
60 assert(size != nullptr);
61 assert(output != nullptr);
62
63 status = utils::checkCondition(output->type() == input->type());
64 if (status != Ok)
65 return status;
66
67 // Check all outputs have the same type
68 for (uint32_t i = 1; i < runtime_kernel.outputs_num; ++i)
69 {
70 status = utils::checkCondition(output->type() == runtime_kernel.outputs[i]->type());
71 if (status != Ok)
72 return status;
73 }
74
75 status = utils::checkCondition(axis->type() == circle::TensorType_INT32);
76 if (status != Ok)
77 return status;
78
79 status = utils::checkCondition(size->type() == circle::TensorType_INT32);
80 if (status != Ok)
81 return status;
82
83 // Check size tensor contains exactly output_nums_tensors values
84 status = utils::checkCondition(OMRuntimeShape(size).flatSize() == runtime_kernel.outputs_num);
85
86 // Check it is scalar
87 status = utils::checkCondition(OMRuntimeShape(axis).flatSize() == 1);
88 if (status != Ok)
89 return status;
90
91 // Check axis value
92 runtime_kernel.getDataFromStorage(op_index, runtime_storage, runtime_context);
93 auto *axis_data = reinterpret_cast<int32_t *>(runtime_kernel.inputs_data[axisTensorIdx]);
94 status = utils::checkCondition(axis_data != nullptr);
95 if (status != Ok)
96 return status;
97
98 int32_t axis_value = axis_data[0];
99
100 OMRuntimeShape input_shape(input);
101 if (axis_value < 0)
102 {
103 axis_value += input_shape.dimensionsCount() + 1;
104 }
105
106 status = utils::checkCondition(axis_value <= input_shape.dimensionsCount() and axis_value >= 0);
107 if (status != Ok)
108 return status;
109
110 return status;
111}
112
113} // namespace import
114} // namespace onert_micro
OMStatus getDataFromStorage(uint16_t op_index, core::OMRuntimeStorage &storage, core::OMRuntimeContext &context)
OMStatus readKernel(uint16_t op_index, core::OMRuntimeContext &runtime_context)
const circle::Tensor * outputs[maxOutputSize]
const circle::Tensor * inputs[maxInputSize]
constexpr uint32_t outputTensorIdx
OMStatus configure_kernel_CircleSplitV(const OMConfigureArgs &config_args)
Definition SplitV.cpp:41
int32_t size[5]
Definition Slice.cpp:35
core::OMRuntimeContext & runtime_context
core::OMRuntimeStorage & runtime_storage