ONE - On-device Neural Engine
Loading...
Searching...
No Matches
BinaryArithmetic.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::BinaryArithmetic &) { _supported = true; }
26
27void KernelGenerator::visit(const ir::operation::BinaryArithmetic &node)
28{
29 const auto ofm_index{node.getOutputs().at(0)};
30 const auto lhs_index{node.getInputs().at(ir::operation::BinaryArithmetic::Input::LHS)};
31 const auto rhs_index{node.getInputs().at(ir::operation::BinaryArithmetic::Input::RHS)};
32
33 const auto activation = node.param().activation;
34
35 auto ofm_tensor = _tensor_reg->getAclTensor(ofm_index);
36 auto lhs_tensor = _tensor_reg->getAclTensor(lhs_index);
37 auto rhs_tensor = _tensor_reg->getAclTensor(rhs_index);
38
39 const auto act_info = acl_common::asActivationLayerInfo(activation);
40
41 std::unique_ptr<arm_compute::IFunction> fn;
42 switch (node.param().arithmetic_type)
43 {
45 {
46 arm_compute::CLArithmeticAddition::validate(lhs_tensor->info(), rhs_tensor->info(),
47 ofm_tensor->info(),
48 arm_compute::ConvertPolicy::SATURATE, act_info)
49 .throw_if_error();
50 fn = acl_common::generateLayer<arm_compute::CLArithmeticAddition>(
51 lhs_tensor->handle(), rhs_tensor->handle(), ofm_tensor->handle(),
52 arm_compute::ConvertPolicy::SATURATE, act_info);
53 break;
54 }
56 {
57 arm_compute::CLArithmeticSubtraction::validate(lhs_tensor->info(), rhs_tensor->info(),
58 ofm_tensor->info(),
59 arm_compute::ConvertPolicy::SATURATE, act_info)
60 .throw_if_error();
61 fn = acl_common::generateLayer<arm_compute::CLArithmeticSubtraction>(
62 lhs_tensor->handle(), rhs_tensor->handle(), ofm_tensor->handle(),
63 arm_compute::ConvertPolicy::SATURATE, act_info);
64 break;
65 }
67 {
68 arm_compute::CLPixelWiseMultiplication::validate(
69 lhs_tensor->info(), rhs_tensor->info(), ofm_tensor->info(), 1.0,
70 arm_compute::ConvertPolicy::SATURATE, arm_compute::RoundingPolicy::TO_NEAREST_EVEN,
71 act_info)
72 .throw_if_error();
73 fn = acl_common::generateLayer<arm_compute::CLPixelWiseMultiplication>(
74 lhs_tensor->handle(), rhs_tensor->handle(), ofm_tensor->handle(), 1.0, // scale
75 arm_compute::ConvertPolicy::SATURATE, arm_compute::RoundingPolicy::TO_NEAREST_EVEN,
76 act_info);
77 break;
78 }
80 {
81 arm_compute::CLArithmeticDivision::validate(lhs_tensor->info(), rhs_tensor->info(),
82 ofm_tensor->info(), act_info)
83 .throw_if_error();
84 fn = acl_common::generateLayer<arm_compute::CLArithmeticDivision>(
85 lhs_tensor->handle(), rhs_tensor->handle(), ofm_tensor->handle(), act_info);
86 break;
87 }
88 default:
89 assert(false && "The BinaryArithmetic operation supports only binary arithmetic operations");
90 break;
91 }
92
94}
95
96} // namespace onert::backend::acl_cl
std::unique_ptr< exec::IFunction > _return_fn
::arm_compute::ActivationLayerInfo asActivationLayerInfo(const ir::Activation act_code)
Definition Convert.cc:131
std::unique_ptr< AclFunction > asAclFunction(std::unique_ptr<::arm_compute::IFunction > &&layer)
Definition Convert.cc:246