ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Slice.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"
20#include "core/OMKernelData.h"
21
23#include "execute/OMUtils.h"
25
26#include "PALSlice.h"
27
28using namespace onert_micro;
29using namespace onert_micro::core;
30using namespace onert_micro::execute;
31
32namespace
33{
34
35const int MAX_DIM = 5;
36
37constexpr uint32_t input1TensorIdx = 0;
38constexpr uint32_t input2TensorIdx = 1;
39constexpr uint32_t input3TensorIdx = 2;
40
41constexpr uint32_t outputTensorIdx = 0;
42
43void getBeginAndSizeVectors(int dimensions, const int32_t *begin_data, const int32_t *size_data,
44 int32_t *begins, int32_t *sizes)
45{
46 int offset = MAX_DIM - dimensions;
47 for (int idx = 0; idx < dimensions; ++idx)
48 {
49 begins[offset + idx] = begin_data[idx];
50 sizes[offset + idx] = size_data[idx];
51 }
52}
53
54} // namespace
55
56// NOTE: doesnt currently support dynamic shapes
57OMStatus onert_micro::execute::execute_kernel_CircleSlice(const OMExecuteArgs &execute_args)
58{
59 core::OMRuntimeContext &runtime_context = execute_args.runtime_context;
60 core::OMRuntimeStorage &runtime_storage = execute_args.runtime_storage;
61 uint16_t op_index = execute_args.kernel_index;
62
63 const circle::Tensor *input1 = nullptr;
64 const circle::Tensor *input2 = nullptr;
65 const circle::Tensor *input3 = nullptr;
66
67 const circle::Tensor *output = nullptr;
68
69 uint8_t *input1_data;
70 const int32_t *input2_data;
71 const int32_t *input3_data;
72 uint8_t *output_data;
73
74 OMStatus status = Ok;
75 const circle::SliceOptions *options;
76 // Read kernel
77 {
78 execute::OMRuntimeKernel runtime_kernel;
79 runtime_kernel.readKernel(op_index, runtime_context);
80
81 input1 = runtime_kernel.inputs[input1TensorIdx];
82 input2 = runtime_kernel.inputs[input2TensorIdx];
83 input3 = runtime_kernel.inputs[input3TensorIdx];
84
85 output = runtime_kernel.outputs[outputTensorIdx];
86 assert(input1 != nullptr);
87 assert(input2 != nullptr);
88 assert(input3 != nullptr);
89 assert(output != nullptr);
90
91 status = runtime_kernel.getDataFromStorage(op_index, runtime_storage, runtime_context);
92 if (status != Ok)
93 return status;
94
95 input1_data = runtime_kernel.inputs_data[input1TensorIdx];
96 input2_data = utils::castInputData<int32_t>(runtime_kernel.inputs_data[input2TensorIdx]);
97 input3_data = utils::castInputData<int32_t>(runtime_kernel.inputs_data[input3TensorIdx]);
99
100 assert(input1_data != nullptr);
101 assert(input2_data != nullptr);
102 assert(input3_data != nullptr);
103 assert(output_data != nullptr);
104
105 options = runtime_kernel.first_operator->builtin_options_as_SliceOptions();
106 }
107
108 OMRuntimeShape input_shape(input1);
109
110 SliceParams op_params{};
111 op_params.begin_count = MAX_DIM;
112 op_params.size_count = MAX_DIM;
113 for (int i = 0; i < MAX_DIM; i++)
114 {
115 op_params.begin[i] = 0;
116 op_params.size[i] = 1;
117 }
118 auto num_dim = input_shape.dimensionsCount();
119
120 getBeginAndSizeVectors(num_dim, input2_data, input3_data, op_params.begin, op_params.size);
121
122 switch (input1->type())
123 {
124#ifndef DIS_FLOAT
125 case circle::TensorType_FLOAT32:
126 {
127 status = pal::Slice(op_params, input_shape, utils::castInputData<float>(input1_data),
128 utils::castOutputData<float>(output_data));
129 }
130 break;
131#endif // DIS_FLOAT
132 case circle::TensorType_INT32:
133 {
134 status = pal::Slice(op_params, input_shape, utils::castInputData<int32_t>(input1_data),
135 utils::castOutputData<int32_t>(output_data));
136 }
137 break;
138 case circle::TensorType_INT64:
139 {
140 status = pal::Slice(op_params, input_shape, utils::castInputData<int64_t>(input1_data),
141 utils::castOutputData<int64_t>(output_data));
142 }
143 break;
144 default:
145 {
146 status = UnsupportedActivation;
147 assert(false && "Unsupported type.");
148 }
149 }
150
151 return status;
152}
uint8_t * outputs_data[maxOutputSize]
const circle::Operator * first_operator
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]
__global uchar * offset(const Image *img, int x, int y)
Definition helpers.h:540
constexpr uint32_t input1TensorIdx
constexpr uint32_t outputTensorIdx
constexpr uint32_t input2TensorIdx
void getBeginAndSizeVectors(int dimensions, const Tensor *begin, const Tensor *size, std::vector< int > *begins, std::vector< int > *sizes)
Definition Slice.cpp:64
OMStatus Slice(const core::SliceParams &op_params, const core::OMRuntimeShape &input_shape, const T *input_data, T *output_data)
Definition PALSlice.h:29
@ UnsupportedActivation
Definition OMStatus.h:28
core::OMRuntimeContext & runtime_context
core::OMRuntimeStorage & runtime_storage