2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef LUCI_INTERPRETER_KERNELS_SPLIT_IMPL_H
18 #define LUCI_INTERPRETER_KERNELS_SPLIT_IMPL_H
23 namespace luci_interpreter
27 void splitImpl(const circle::Operator *cur_op, const circle::Tensor *input, int axis_value,
28 BaseRuntimeGraph *runtime_graph)
30 const int output_count = cur_op->outputs()->size();
32 const auto output0_index = cur_op->outputs()->operator[](0);
33 assert(output0_index != -1);
35 const auto output0 = runtime_graph->getCircleTensorByIndex(output0_index);
36 assert(output0 != nullptr);
38 const int split_dimensions = Tensor::num_dims(input);
40 assert(axis_value < split_dimensions);
41 assert(Tensor::num_dims(output0) == split_dimensions);
43 int64_t outer_size = 1;
44 for (int i = 0; i < axis_value; ++i)
46 outer_size *= Tensor::dim(input, i);
49 int64_t base_inner_size = 1;
50 for (int i = axis_value + 1; i < split_dimensions; ++i)
52 base_inner_size *= Tensor::dim(input, i);
55 const T *input_ptr = kernels::getTensorData<T>(runtime_graph->getDataByTensor(input));
56 assert(input_ptr != nullptr);
57 for (int k = 0; k < outer_size; ++k)
59 for (int i = 0; i < output_count; ++i)
61 const auto output_index = cur_op->outputs()->operator[](i);
62 assert(output_index != -1);
64 const auto output = runtime_graph->getCircleTensorByIndex(output_index);
65 assert(output != nullptr);
67 T *output_data = kernels::getTensorData<T>(runtime_graph->getDataByTensor(output));
68 assert(output_data != nullptr);
69 const int copy_size = Tensor::dim(output, axis_value) * base_inner_size;
70 T *output_ptr = output_data + k * copy_size;
71 assert(output_ptr != nullptr);
72 for (int j = 0; j < copy_size; ++j)
73 output_ptr[j] = input_ptr[j];
74 input_ptr += copy_size;
79 } // namespace luci_interpreter
81 #endif // LUCI_INTERPRETER_KERNELS_SPLIT_IMPL_H