ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Reduce.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::Reduce &) { _supported = true; }
26
27void KernelGenerator::visit(const ir::operation::Reduce &node)
28{
29 const auto output_index{node.getOutputs().at(0)};
30 const auto input_index{node.getInputs().at(ir::operation::Reduce::Input::INPUT)};
31 const auto axes_index{node.getInputs().at(ir::operation::Reduce::Input::AXES)};
32 const auto keep_dims{node.param().keep_dims};
33 const auto reduce_type = node.param().reduce_type;
34
35 auto output_tensor = _tensor_reg->getAclTensor(output_index);
36 auto input_tensor = _tensor_reg->getAclTensor(input_index);
37
38 // Convert to ACL axes taking into account negative values and possible duplicates.
39 const auto &axes = _ctx.at(axes_index);
40 const auto input_rank = _ctx.at(input_index).shape().rank();
41
42 std::unique_ptr<arm_compute::IFunction> fn;
44 {
45 const auto acl_axes = acl_common::asCoordinates(axes, input_rank);
46 fn = acl_common::generateLayer<arm_compute::CLReduceMean>(input_tensor->handle(), acl_axes,
47 keep_dims, output_tensor->handle());
48 }
49 else
50 {
51 const auto acl_axes = acl_common::asSet(axes, input_rank);
52
53 fn = acl_common::generateLayer<arm_compute::CLReduceOperation>(
54 _tensor_builder->acl_tensor_manager()->internal_buffer_manager(), input_tensor->handle(),
55 output_tensor->handle(), acl_axes, keep_dims, acl_common::convertReduceType(reduce_type));
56 }
57
59}
60
61} // 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.
std::set< uint32_t > asSet(const ir::Operand &operand, int32_t rank)
Definition Convert.cc:220
arm_compute::ReductionOperation convertReduceType(ir::operation::Reduce::ReduceType reduce_type_ir)
Definition Convert.cc:296
arm_compute::Coordinates asCoordinates(const ir::Operand &operand, int32_t rank)
Definition Convert.cc:207
std::unique_ptr< AclFunction > asAclFunction(std::unique_ptr<::arm_compute::IFunction > &&layer)
Definition Convert.cc:246