ONE - On-device Neural Engine
Loading...
Searching...
No Matches
ElementwiseUnary.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::ElementwiseUnary &) { _supported = true; }
26
27void KernelGenerator::visit(const ir::operation::ElementwiseUnary &node)
28{
29 const auto output_index{node.getOutputs().at(0)};
30 const auto input_index{node.getInputs().at(ir::operation::ElementwiseUnary::Input::INPUT)};
31
32 auto output_tensor = _tensor_reg->getAclTensor(output_index);
33 auto input_tensor = _tensor_reg->getAclTensor(input_index);
34
35 std::unique_ptr<arm_compute::IFunction> fn;
36 switch (node.param().op_type)
37 {
39 {
40 const ::arm_compute::ActivationLayerInfo act_info{
41 ::arm_compute::ActivationLayerInfo::ActivationFunction::ABS};
42
43 fn = acl_common::generateLayer<arm_compute::NEActivationLayer>(
44 input_tensor->handle(), output_tensor->handle(), act_info);
45 break;
46 }
48 {
49 if (input_tensor->data_type() == output_tensor->data_type())
50 {
51 fn = acl_common::generateLayer<arm_compute::NECopy>(input_tensor->handle(),
52 output_tensor->handle());
53 }
54 else if (_ctx.at(input_index).typeInfo().type() == ir::DataType::BOOL8)
55 {
56 fn = acl_common::generateLayer<arm_compute::NECastBool>(input_tensor->handle(),
57 output_tensor->handle());
58 }
59 else
60 {
61 fn = acl_common::generateLayer<arm_compute::NECast>(
62 input_tensor->handle(), output_tensor->handle(), arm_compute::ConvertPolicy::SATURATE);
63 }
64 break;
65 }
67 {
68 fn = acl_common::generateLayer<arm_compute::NEDequantizationLayer>(input_tensor->handle(),
69 output_tensor->handle());
70 break;
71 }
73 {
74 fn = acl_common::generateLayer<arm_compute::NEExpLayer>(input_tensor->handle(),
75 output_tensor->handle());
76 break;
77 }
79 {
80 fn = acl_common::generateLayer<arm_compute::NEFloor>(input_tensor->handle(),
81 output_tensor->handle());
82 break;
83 }
85 {
86 fn = acl_common::generateLayer<arm_compute::NEBitwiseNot>(input_tensor->handle(),
87 output_tensor->handle());
88 break;
89 }
91 {
92 fn = acl_common::generateLayer<arm_compute::NENegLayer>(input_tensor->handle(),
93 output_tensor->handle());
94 break;
95 }
97 {
98 fn = acl_common::generateLayer<arm_compute::NERsqrtLayer>(input_tensor->handle(),
99 output_tensor->handle());
100 break;
101 }
103 {
104 const ::arm_compute::ActivationLayerInfo act_info{
105 ::arm_compute::ActivationLayerInfo::ActivationFunction::SQRT};
106
107 fn = acl_common::generateLayer<arm_compute::NEActivationLayer>(
108 input_tensor->handle(), output_tensor->handle(), act_info);
109 break;
110 }
111 default:
112 {
113 throw std::runtime_error("acl_neon KernelGenerator : " + node.name() +
114 "is not supported yet");
115 break;
116 }
117 }
118 _return_fn = acl_common::asAclFunction(std::move(fn));
119}
120
121} // namespace onert::backend::acl_neon
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::unique_ptr< AclFunction > asAclFunction(std::unique_ptr<::arm_compute::IFunction > &&layer)
Definition Convert.cc:246
OperandType type
Definition Operand.h:42