2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
3 * Copyright 2017 The TensorFlow Authors. All Rights Reserved.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 #include "kernels/Utils.h"
20 #include "MISOKernel.h"
22 #include "PALStridedSlice.h"
24 namespace luci_interpreter
29 luci_interpreter_pal::StridedSliceParams
30 buildStridedSliceParams(int32_t dims, const int32_t *begin, const int32_t *end,
31 const int32_t *strides, const circle::StridedSliceOptions *options)
33 luci_interpreter_pal::StridedSliceParams op_params;
34 op_params.start_indices_count = dims;
35 op_params.stop_indices_count = dims;
36 op_params.strides_count = dims;
38 for (int i = 0; i < dims; ++i)
40 op_params.start_indices[i] = begin[i];
41 op_params.stop_indices[i] = end[i];
42 op_params.strides[i] = strides[i];
45 op_params.begin_mask = options->begin_mask();
46 op_params.ellipsis_mask = 0;
47 op_params.end_mask = options->end_mask();
48 op_params.new_axis_mask = 0;
49 op_params.shrink_axis_mask = options->shrink_axis_mask();
55 void configure_kernel_CircleStridedSlice(const circle::Operator *cur_op,
56 BaseRuntimeGraph *runtime_graph)
58 kernels::MISOKernel miso_kernel(cur_op, runtime_graph);
60 const circle::Tensor *input = miso_kernel.input1();
61 const circle::Tensor *begin = miso_kernel.input2();
62 const circle::Tensor *end = miso_kernel.input3();
63 const circle::Tensor *strides = miso_kernel.input4();
65 LUCI_INTERPRETER_CHECK(strides != nullptr);
67 const circle::Tensor *output = miso_kernel.output();
69 LUCI_INTERPRETER_CHECK(Tensor::element_type(begin) == DataType::S32);
70 LUCI_INTERPRETER_CHECK(Tensor::element_type(end) == DataType::S32);
71 LUCI_INTERPRETER_CHECK(Tensor::element_type(strides) == DataType::S32);
72 LUCI_INTERPRETER_CHECK(Tensor::element_type(input) == Tensor::element_type(output));
75 void execute_kernel_CircleStridedSlice(const circle::Operator *cur_op,
76 BaseRuntimeGraph *runtime_graph)
78 kernels::MISOKernel miso_kernel(cur_op, runtime_graph);
80 const circle::Tensor *input = miso_kernel.input1();
81 const circle::Tensor *begin = miso_kernel.input2();
82 const circle::Tensor *end = miso_kernel.input3();
83 const circle::Tensor *strides = miso_kernel.input4();
84 const circle::Tensor *output = miso_kernel.output();
86 const int32_t dims = Tensor::num_dims(input);
88 const uint8_t *input_data = runtime_graph->getDataByTensor(input);
89 const int32_t *begin_data =
90 kernels::getTensorData<int32_t>(runtime_graph->getConstDataByTensor(begin));
91 const int32_t *end_data =
92 kernels::getTensorData<int32_t>(runtime_graph->getConstDataByTensor(end));
93 const int32_t *strides_data =
94 kernels::getTensorData<int32_t>(runtime_graph->getConstDataByTensor(strides));
95 uint8_t *output_data = runtime_graph->getDataByTensor(output);
97 LUCI_INTERPRETER_CHECK(input_data != nullptr);
98 LUCI_INTERPRETER_CHECK(begin_data != nullptr);
99 LUCI_INTERPRETER_CHECK(end_data != nullptr);
100 LUCI_INTERPRETER_CHECK(strides_data != nullptr);
101 LUCI_INTERPRETER_CHECK(output_data != nullptr);
103 const auto *options = cur_op->builtin_options_as_StridedSliceOptions();
105 auto op_params = buildStridedSliceParams(dims, begin_data, end_data, strides_data, options);
107 switch (Tensor::element_type(input))
110 case DataType::FLOAT32:
111 luci_interpreter_pal::StridedSlice(op_params, kernels::getTensorShape(input),
112 kernels::getTensorData<float>(input_data),
113 kernels::getTensorData<float>(output_data));
118 luci_interpreter_pal::StridedSlice(op_params, kernels::getTensorShape(input), input_data,
122 luci_interpreter_pal::StridedSlice(op_params, kernels::getTensorShape(input), input_data,
127 luci_interpreter_pal::StridedSlice(op_params, kernels::getTensorShape(input),
128 kernels::getTensorData<int32_t>(input_data),
129 kernels::getTensorData<int32_t>(output_data));
132 assert(false && "Unsupported type");
136 } // namespace luci_interpreter