blob: a5585bab5d6ea2e777d4e4703a6c30dc53b87adc [file] [log] [blame]
SiCongLi1af54162021-10-06 15:25:57 +01001/*
Matthew Benthamf1aeab92023-05-30 13:35:34 +00002 * Copyright (c) 2021, 2023 Arm Limited.
SiCongLi1af54162021-10-06 15:25:57 +01003 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
SiCongLi31778612021-11-12 17:33:45 +000024#ifndef ARM_COMPUTE_EXPERIMENTAL_POSTOPS
25#define ARM_COMPUTE_EXPERIMENTAL_POSTOPS
SiCongLi1af54162021-10-06 15:25:57 +010026
27#include "arm_compute/core/experimental/IPostOp.h"
28
29#include "arm_compute/core/Types.h"
SiCong Li91295492023-07-21 18:16:13 +010030#include "arm_compute/function_info/ActivationLayerInfo.h"
SiCongLi1af54162021-10-06 15:25:57 +010031
32#include <vector>
33
SiCongLi1af54162021-10-06 15:25:57 +010034namespace arm_compute
35{
36namespace experimental
37{
SiCongLi31778612021-11-12 17:33:45 +000038/** (EXPERIMENTAL_POST_OPS)
39 * Implementation of specific IPostOps
40*/
41
SiCongLi1af54162021-10-06 15:25:57 +010042template <typename TensorRelatedT>
43struct PostOpAct : public IPostOp<TensorRelatedT>
44{
45public:
46 PostOpAct(const ActivationLayerInfo &act_info)
47 : _act_info{ act_info }
48 {
49 }
50 // NOTE: PostOps do not own any resources pointed to by TensorRelatedT if it's a pointer type, thus allow shallow copy
51 ~PostOpAct() override = default;
52 PostOpAct(const PostOpAct &) = default;
53 PostOpAct &operator=(const PostOpAct &) = default;
54 PostOpAct(PostOpAct &&) = default;
55 PostOpAct &operator=(PostOpAct &&) = default;
56
57 int prev_dst_pos() const override
58 {
59 return 0;
60 }
61 PostOpType type() const override
62 {
63 return PostOpType::Activation;
64 }
65 std::vector<TensorRelatedT *> arguments() override
66 {
67 return {};
68 }
69 std::vector<const TensorRelatedT *> arguments() const override
70 {
71 return {};
72 }
73 std::unique_ptr<IPostOp<TensorRelatedT>> clone() const override
74 {
75 return std::make_unique<PostOpAct<TensorRelatedT>>(*this);
76 }
77 ActivationLayerInfo _act_info;
78};
79
80template <typename TensorRelatedT>
81struct PostOpEltwiseAdd : public IPostOp<TensorRelatedT>
82{
83public:
SiCongLieb8bd812021-10-29 15:05:49 +010084 PostOpEltwiseAdd(TensorRelatedT addend, int prev_dst_pos, ConvertPolicy policy)
SiCongLi1af54162021-10-06 15:25:57 +010085 : _addend{ addend },
SiCongLieb8bd812021-10-29 15:05:49 +010086 _prev_dst_pos{ prev_dst_pos },
SiCongLi1af54162021-10-06 15:25:57 +010087 _policy{ policy }
88 {
89 }
90 // NOTE: PostOps do not own any resources pointed to by TensorRelatedT if it's a pointer type, thus allow shallow copy
91 ~PostOpEltwiseAdd() override = default;
92 PostOpEltwiseAdd(const PostOpEltwiseAdd &) = default;
93 PostOpEltwiseAdd &operator=(const PostOpEltwiseAdd &) = default;
94 PostOpEltwiseAdd(PostOpEltwiseAdd &&) = default;
95 PostOpEltwiseAdd &operator=(PostOpEltwiseAdd &&) = default;
96 int prev_dst_pos() const override
97 {
SiCongLieb8bd812021-10-29 15:05:49 +010098 return _prev_dst_pos;
SiCongLi1af54162021-10-06 15:25:57 +010099 }
100 PostOpType type() const override
101 {
102 return PostOpType::Eltwise_Add;
103 }
104 std::vector<TensorRelatedT *> arguments() override
105 {
106 return { &_addend };
107 }
108 std::vector<const TensorRelatedT *> arguments() const override
109 {
110 return { &_addend };
111 }
112 std::unique_ptr<IPostOp<TensorRelatedT>> clone() const override
113 {
114 return std::make_unique<PostOpEltwiseAdd<TensorRelatedT>>(*this);
115 }
116 TensorRelatedT _addend;
SiCongLieb8bd812021-10-29 15:05:49 +0100117 int _prev_dst_pos;
SiCongLi1af54162021-10-06 15:25:57 +0100118 ConvertPolicy _policy;
119};
120
ramelg016049eda2021-10-29 10:52:53 +0100121template <typename TensorRelatedT>
122struct PostOpEltwisePRelu : public IPostOp<TensorRelatedT>
123{
124public:
125 PostOpEltwisePRelu(TensorRelatedT alpha_param, int prev_dst_pos, ConvertPolicy policy)
126 : _alpha_param{ alpha_param },
127 _prev_dst_pos{ prev_dst_pos },
128 _policy{ policy }
129 {
130 }
131 // NOTE: PostOps do not own any resources pointed to by TensorRelatedT if it's a pointer type, thus allow shallow copy
132 ~PostOpEltwisePRelu() override = default;
133 PostOpEltwisePRelu(const PostOpEltwisePRelu &) = default;
134 PostOpEltwisePRelu &operator=(const PostOpEltwisePRelu &) = default;
135 PostOpEltwisePRelu(PostOpEltwisePRelu &&) = default;
136 PostOpEltwisePRelu &operator=(PostOpEltwisePRelu &&) = default;
137 int prev_dst_pos() const override
138 {
139 return _prev_dst_pos;
140 }
141 PostOpType type() const override
142 {
143 return PostOpType::Eltwise_PRelu;
144 }
145 std::vector<TensorRelatedT *> arguments() override
146 {
147 return { &_alpha_param };
148 }
149 std::vector<const TensorRelatedT *> arguments() const override
150 {
151 return { &_alpha_param };
152 }
153 std::unique_ptr<IPostOp<TensorRelatedT>> clone() const override
154 {
155 return std::make_unique<PostOpEltwisePRelu<TensorRelatedT>>(*this);
156 }
157 TensorRelatedT _alpha_param;
158 int _prev_dst_pos;
159 ConvertPolicy _policy;
160};
SiCongLi1af54162021-10-06 15:25:57 +0100161} // namespace experimental
162} // namespace arm_compute
Matthew Benthamf1aeab92023-05-30 13:35:34 +0000163#endif //ARM_COMPUTE_EXPERIMENTAL_POSTOPS