ONE - On-device Neural Engine
Loading...
Searching...
No Matches
PALSlice.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved
3 * Copyright 2020 The TensorFlow Authors. All Rights Reserved.
4 *
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
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
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.
16 */
17
18#ifndef ONERT_MICRO_EXECUTE_PAL_SLICE_H
19#define ONERT_MICRO_EXECUTE_PAL_SLICE_H
20
21namespace onert_micro
22{
23namespace execute
24{
25namespace pal
26{
27
28template <typename T>
29OMStatus Slice(const core::SliceParams &op_params, const core::OMRuntimeShape &input_shape,
30 const T *input_data, T *output_data)
31{
32 const core::OMRuntimeShape ext_shape = core::OMRuntimeShape::extendedShape(5, input_shape);
33 const int begin_count = op_params.begin_count;
34 const int size_count = op_params.size_count;
35 // We front-pad the begin and size vectors.
36 int start[5];
37 int stop[5];
38 for (int i = 0; i < 5; ++i)
39 {
40 int padded_i = 5 - i;
41 start[i] = begin_count < padded_i ? 0 : op_params.begin[begin_count - padded_i];
42 stop[i] = (size_count < padded_i || op_params.size[size_count - padded_i] == -1)
43 ? ext_shape.dims(i)
44 : start[i] + op_params.size[size_count - padded_i];
45 }
46
47 for (int i0 = start[0]; i0 < stop[0]; ++i0)
48 {
49 for (int i1 = start[1]; i1 < stop[1]; ++i1)
50 {
51 for (int i2 = start[2]; i2 < stop[2]; ++i2)
52 {
53 for (int i3 = start[3]; i3 < stop[3]; ++i3)
54 {
55 for (int i4 = start[4]; i4 < stop[4]; ++i4)
56 {
57 auto position =
58 (((i0 * ext_shape.dims(1) + i1) * ext_shape.dims(2) + i2) * ext_shape.dims(3) + i3) *
59 ext_shape.dims(4) +
60 i4;
61 *output_data++ = input_data[position];
62 }
63 }
64 }
65 }
66 }
67 return Ok;
68}
69
70} // namespace pal
71} // namespace execute
72} // namespace onert_micro
73
74#endif // ONERT_MICRO_EXECUTE_PAL_SLICE_H
static OMRuntimeShape extendedShape(int new_shape_size, const OMRuntimeShape &shape)
OMStatus Slice(const core::SliceParams &op_params, const core::OMRuntimeShape &input_shape, const T *input_data, T *output_data)
Definition PALSlice.h:29
int8_t size_count
Definition Slice.cpp:34
int8_t begin_count
Definition Slice.cpp:32