ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Slice.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2025 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 "../KernelGenerator.h"
18#include "../Validator.h"
19
20#include <AclKernelGen.h>
21
23{
24
25void Validator::visit(const ir::operation::Slice &) { _supported = true; }
26
27void KernelGenerator::visit(const ir::operation::Slice &node)
28{
29 const auto output_index{node.getOutputs().at(0)};
30 const auto input_index{node.getInputs().at(ir::operation::Slice::Input::INPUT)};
31 const auto begins_index{node.getInputs().at(ir::operation::Slice::Input::BEGINS)};
32 const auto sizes_index{node.getInputs().at(ir::operation::Slice::Input::SIZES)};
33
34 auto outputData_tensor = _tensor_reg->getAclTensor(output_index);
35 auto inputData_tensor = _tensor_reg->getAclTensor(input_index);
36
37 // Set initializers for indices data such as order of inputData
38 int input_rank = _ctx.at(input_index).shape().rank();
39 std::vector<int32_t> starts;
40 std::vector<int32_t> ends;
41 starts.resize(input_rank, 0);
42 ends.resize(input_rank, 0);
43 {
44 auto beginData_base = _ctx.at(begins_index).data()->base();
45 auto sizeData_base = _ctx.at(sizes_index).data()->base();
46 [[maybe_unused]] const int beginData_size = _ctx.at(begins_index).shape().num_elements();
47 [[maybe_unused]] const int sizeData_size = _ctx.at(sizes_index).shape().num_elements();
48
49 using ir::DataType;
50
51 assert(_ctx.at(begins_index).typeInfo().type() == DataType::INT32);
52 assert(_ctx.at(sizes_index).typeInfo().type() == DataType::INT32);
53 assert(beginData_size == input_rank);
54 assert(sizeData_size == input_rank);
55
56 assert(beginData_base != nullptr);
57 for (int n = 0; n < input_rank; ++n)
58 {
59 auto axis = ::onert::backend::acl_common::ToARMComputeAxis(input_rank, n).value();
60
61 int32_t begin_value = *(reinterpret_cast<const int32_t *>(beginData_base) + n);
62 starts[axis] = begin_value;
63
64 int32_t size_value = *(reinterpret_cast<const int32_t *>(sizeData_base) + n);
65 ends[axis] = begin_value + size_value;
66 }
67 }
68
69 ::arm_compute::Coordinates starts_set;
70 ::arm_compute::Coordinates ends_set;
71
72 for (size_t i = 0; i < starts.size(); ++i)
73 {
74 starts_set.set(i, starts[i]);
75 ends_set.set(i, ends[i]);
76 }
77
78 auto fn = acl_common::generateLayer<arm_compute::NESlice>(
79 inputData_tensor->handle(), outputData_tensor->handle(), starts_set, ends_set);
80
82}
83
84} // namespace onert::backend::acl_neon
std::unique_ptr< exec::IFunction > _return_fn
const Object & at(const Index &index) const
Get the object that is associated with the given index.
ARMComputeAxis ToARMComputeAxis(uint32_t rank, uint32_t axis)
Definition Swizzle.h:45
std::unique_ptr< AclFunction > asAclFunction(std::unique_ptr<::arm_compute::IFunction > &&layer)
Definition Convert.cc:246
OperandType type
Definition Operand.h:42