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::CLActivationLayer>(
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::CLCopy>(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::CLCastBool>(input_tensor->handle(),
57 output_tensor->handle());
58 }
59 else
60 {
61 // TODO Support converting float to int32 as round down
62 fn = acl_common::generateLayer<arm_compute::CLCast>(
63 input_tensor->handle(), output_tensor->handle(), arm_compute::ConvertPolicy::SATURATE);
64 }
65 break;
66 }
68 {
69 fn = acl_common::generateLayer<arm_compute::CLDequantizationLayer>(input_tensor->handle(),
70 output_tensor->handle());
71 break;
72 }
74 {
75 fn = acl_common::generateLayer<arm_compute::CLExpLayer>(input_tensor->handle(),
76 output_tensor->handle());
77 break;
78 }
80 {
81 fn = acl_common::generateLayer<arm_compute::CLFloor>(input_tensor->handle(),
82 output_tensor->handle());
83 break;
84 }
86 {
87 fn = acl_common::generateLayer<arm_compute::CLBitwiseNot>(input_tensor->handle(),
88 output_tensor->handle());
89 break;
90 }
92 {
93 fn = acl_common::generateLayer<arm_compute::CLNegLayer>(input_tensor->handle(),
94 output_tensor->handle());
95 break;
96 }
98 {
99 fn = acl_common::generateLayer<arm_compute::CLRsqrtLayer>(input_tensor->handle(),
100 output_tensor->handle());
101 break;
102 }
104 {
105 const ::arm_compute::ActivationLayerInfo act_info{
106 ::arm_compute::ActivationLayerInfo::ActivationFunction::SQRT};
107
108 fn = acl_common::generateLayer<arm_compute::CLActivationLayer>(
109 input_tensor->handle(), output_tensor->handle(), act_info);
110 break;
111 }
112 default:
113 {
114 throw std::runtime_error("acl_cl KernelGenerator : " + node.name() + "is not supported yet");
115 break;
116 }
117 }
118
119 auto acl_fn = acl_common::asAclFunction(std::move(fn));
120
121 _return_fn = std::move(acl_fn);
122}
123
124} // 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::unique_ptr< AclFunction > asAclFunction(std::unique_ptr<::arm_compute::IFunction > &&layer)
Definition Convert.cc:246
OperandType type
Definition Operand.h:42