ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Gather.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::Gather &) { _supported = true; }
26
27void KernelGenerator::visit(const ir::operation::Gather &node)
28{
29 const auto ofm_index{node.getOutputs().at(0)};
30
31 const auto ifm_index{node.getInputs().at(ir::operation::Gather::Input::INPUT)};
32 const auto indices_index{node.getInputs().at(ir::operation::Gather::Input::INDICES)};
33
34 const auto ifm_rank = _ctx.at(ifm_index).shape().rank();
35 const auto axis_raw = node.param().axis;
36 const auto axis_value = (axis_raw < 0 ? (ifm_rank + axis_raw) : axis_raw);
37 const int axis = ::onert::backend::acl_common::ToARMComputeAxis(ifm_rank, axis_value).value();
38
39 auto ofm_tensor = _tensor_reg->getAclTensor(ofm_index);
40 auto ifm_tensor = _tensor_reg->getAclTensor(ifm_index);
41 auto indices_tensor = _tensor_reg->getAclTensor(indices_index);
42
43 // input is n-D, indices k-D, output is (n + k - 1)-D
44 size_t n = ifm_rank;
45 assert(n == ifm_tensor->num_dimensions());
46 size_t k = _ctx.at(indices_index).shape().rank();
47 assert(k == indices_tensor->num_dimensions());
48
49 // Disable applied dim_correction
50 if (n != ifm_tensor->info()->num_dimensions())
51 {
52 // This means that high dimension's value is 1 and ifm tensor is applied dim_correction
54 }
55 if (k != indices_tensor->info()->num_dimensions())
56 {
57 // This means that high dimension's value is 1 and indices tensor is applied dim_correction
59 }
60
61 auto fn = acl_common::generateLayer<arm_compute::CLGather>(
62 ifm_tensor->handle(), indices_tensor->handle(), ofm_tensor->handle(), axis);
63
64 // Revert disabling applied dim_correction
65 if (ifm_tensor->dimension(0) == 1)
66 {
68 }
69 if (indices_tensor->dimension(0) == 1)
70 {
71 acl_common::enableDimCorrection(indices_tensor);
72 }
73
75}
76
77} // 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
void enableDimCorrection(IACLTensor *tensor)
std::unique_ptr< AclFunction > asAclFunction(std::unique_ptr<::arm_compute::IFunction > &&layer)
Definition Convert.cc:246
void disableDimCorrection(IACLTensor *tensor)