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 assert(_ctx.at(begins_index).data());
45 assert(_ctx.at(sizes_index).data());
46 auto beginData_base = _ctx.at(begins_index).data()->base();
47 auto sizeData_base = _ctx.at(sizes_index).data()->base();
48 [[maybe_unused]] const int beginData_size = _ctx.at(begins_index).shape().num_elements();
49 [[maybe_unused]] const int sizeData_size = _ctx.at(sizes_index).shape().num_elements();
50
51 using ir::DataType;
52
53 assert(_ctx.at(begins_index).typeInfo().type() == DataType::INT32);
54 assert(_ctx.at(sizes_index).typeInfo().type() == DataType::INT32);
55 assert(beginData_size == input_rank);
56 assert(sizeData_size == input_rank);
57
58 assert(beginData_base != nullptr);
59 for (int n = 0; n < input_rank; ++n)
60 {
61 auto axis = ::onert::backend::acl_common::ToARMComputeAxis(input_rank, n).value();
62
63 int32_t begin_value = *(reinterpret_cast<const int32_t *>(beginData_base) + n);
64 starts[axis] = begin_value;
65
66 int32_t size_value = *(reinterpret_cast<const int32_t *>(sizeData_base) + n);
67 ends[axis] = begin_value + size_value;
68 }
69 }
70
71 ::arm_compute::Coordinates starts_set;
72 ::arm_compute::Coordinates ends_set;
73
74 for (size_t i = 0; i < starts.size(); ++i)
75 {
76 starts_set.set(i, starts[i]);
77 ends_set.set(i, ends[i]);
78 }
79
80 auto fn = acl_common::generateLayer<arm_compute::CLSlice>(
81 inputData_tensor->handle(), outputData_tensor->handle(), starts_set, ends_set);
82
84}
85
86} // namespace onert::backend::acl_cl
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