ONE - On-device Neural Engine
Loading...
Searching...
No Matches
ArgMinMax.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::ArgMinMax &) { _supported = true; }
26
27void KernelGenerator::visit(const ir::operation::ArgMinMax &node)
28{
29 const auto ofm_index{node.getOutputs().at(0)};
30 const auto ifm_index{node.getInputs().at(ir::operation::ArgMinMax::Input::INPUT)};
31 const auto axis_index{node.getInputs().at(ir::operation::ArgMinMax::Input::AXIS)};
32
33 auto ifm_shape = _ctx.at(ifm_index).shape();
34 auto ofm_shape = _ctx.at(ofm_index).shape();
35
36 assert((ifm_shape.rank() - 1) == ofm_shape.rank());
37
38 auto ofm_tensor = _tensor_reg->getAclTensor(ofm_index);
39 auto ifm_tensor = _tensor_reg->getAclTensor(ifm_index);
40 const auto ifm_rank = _ctx.at(ifm_index).shape().rank();
41
42 int axis_value = _ctx.at(axis_index).asScalar<int32_t>();
43 if (axis_value < 0)
44 {
45 axis_value += ifm_rank;
46 }
47
48 auto acl_axis = acl_common::ToARMComputeAxis(ifm_rank, axis_value).value();
49 auto reduce_type = node.param().is_arg_max ? ::arm_compute::ReductionOperation::ARG_IDX_MAX
50 : ::arm_compute::ReductionOperation::ARG_IDX_MIN;
51 auto fn = acl_common::generateLayer<arm_compute::CLArgMinMaxLayer>(
52 ifm_tensor->handle(), acl_axis, ofm_tensor->handle(), reduce_type);
53
55}
56
57} // 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