blob: 4ea90fc348931907d58d849ea7e777498d15b580 [file] [log] [blame]
SiCongLi1af54162021-10-06 15:25:57 +01001/*
2 * Copyright (c) 2021 Arm Limited.
3 *
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"
SiCongLi1af54162021-10-06 15:25:57 +010030
31#include <vector>
32
SiCongLi1af54162021-10-06 15:25:57 +010033namespace arm_compute
34{
35namespace experimental
36{
SiCongLi31778612021-11-12 17:33:45 +000037/** (EXPERIMENTAL_POST_OPS)
38 * Implementation of specific IPostOps
39*/
40
SiCongLi1af54162021-10-06 15:25:57 +010041template <typename TensorRelatedT>
42struct PostOpAct : public IPostOp<TensorRelatedT>
43{
44public:
45 PostOpAct(const ActivationLayerInfo &act_info)
46 : _act_info{ act_info }
47 {
48 }
49 // NOTE: PostOps do not own any resources pointed to by TensorRelatedT if it's a pointer type, thus allow shallow copy
50 ~PostOpAct() override = default;
51 PostOpAct(const PostOpAct &) = default;
52 PostOpAct &operator=(const PostOpAct &) = default;
53 PostOpAct(PostOpAct &&) = default;
54 PostOpAct &operator=(PostOpAct &&) = default;
55
56 int prev_dst_pos() const override
57 {
58 return 0;
59 }
60 PostOpType type() const override
61 {
62 return PostOpType::Activation;
63 }
64 std::vector<TensorRelatedT *> arguments() override
65 {
66 return {};
67 }
68 std::vector<const TensorRelatedT *> arguments() const override
69 {
70 return {};
71 }
72 std::unique_ptr<IPostOp<TensorRelatedT>> clone() const override
73 {
74 return std::make_unique<PostOpAct<TensorRelatedT>>(*this);
75 }
76 ActivationLayerInfo _act_info;
77};
78
79template <typename TensorRelatedT>
80struct PostOpEltwiseAdd : public IPostOp<TensorRelatedT>
81{
82public:
SiCongLieb8bd812021-10-29 15:05:49 +010083 PostOpEltwiseAdd(TensorRelatedT addend, int prev_dst_pos, ConvertPolicy policy)
SiCongLi1af54162021-10-06 15:25:57 +010084 : _addend{ addend },
SiCongLieb8bd812021-10-29 15:05:49 +010085 _prev_dst_pos{ prev_dst_pos },
SiCongLi1af54162021-10-06 15:25:57 +010086 _policy{ policy }
87 {
88 }
89 // NOTE: PostOps do not own any resources pointed to by TensorRelatedT if it's a pointer type, thus allow shallow copy
90 ~PostOpEltwiseAdd() override = default;
91 PostOpEltwiseAdd(const PostOpEltwiseAdd &) = default;
92 PostOpEltwiseAdd &operator=(const PostOpEltwiseAdd &) = default;
93 PostOpEltwiseAdd(PostOpEltwiseAdd &&) = default;
94 PostOpEltwiseAdd &operator=(PostOpEltwiseAdd &&) = default;
95 int prev_dst_pos() const override
96 {
SiCongLieb8bd812021-10-29 15:05:49 +010097 return _prev_dst_pos;
SiCongLi1af54162021-10-06 15:25:57 +010098 }
99 PostOpType type() const override
100 {
101 return PostOpType::Eltwise_Add;
102 }
103 std::vector<TensorRelatedT *> arguments() override
104 {
105 return { &_addend };
106 }
107 std::vector<const TensorRelatedT *> arguments() const override
108 {
109 return { &_addend };
110 }
111 std::unique_ptr<IPostOp<TensorRelatedT>> clone() const override
112 {
113 return std::make_unique<PostOpEltwiseAdd<TensorRelatedT>>(*this);
114 }
115 TensorRelatedT _addend;
SiCongLieb8bd812021-10-29 15:05:49 +0100116 int _prev_dst_pos;
SiCongLi1af54162021-10-06 15:25:57 +0100117 ConvertPolicy _policy;
118};
119
ramelg016049eda2021-10-29 10:52:53 +0100120template <typename TensorRelatedT>
121struct PostOpEltwisePRelu : public IPostOp<TensorRelatedT>
122{
123public:
124 PostOpEltwisePRelu(TensorRelatedT alpha_param, int prev_dst_pos, ConvertPolicy policy)
125 : _alpha_param{ alpha_param },
126 _prev_dst_pos{ prev_dst_pos },
127 _policy{ policy }
128 {
129 }
130 // NOTE: PostOps do not own any resources pointed to by TensorRelatedT if it's a pointer type, thus allow shallow copy
131 ~PostOpEltwisePRelu() override = default;
132 PostOpEltwisePRelu(const PostOpEltwisePRelu &) = default;
133 PostOpEltwisePRelu &operator=(const PostOpEltwisePRelu &) = default;
134 PostOpEltwisePRelu(PostOpEltwisePRelu &&) = default;
135 PostOpEltwisePRelu &operator=(PostOpEltwisePRelu &&) = default;
136 int prev_dst_pos() const override
137 {
138 return _prev_dst_pos;
139 }
140 PostOpType type() const override
141 {
142 return PostOpType::Eltwise_PRelu;
143 }
144 std::vector<TensorRelatedT *> arguments() override
145 {
146 return { &_alpha_param };
147 }
148 std::vector<const TensorRelatedT *> arguments() const override
149 {
150 return { &_alpha_param };
151 }
152 std::unique_ptr<IPostOp<TensorRelatedT>> clone() const override
153 {
154 return std::make_unique<PostOpEltwisePRelu<TensorRelatedT>>(*this);
155 }
156 TensorRelatedT _alpha_param;
157 int _prev_dst_pos;
158 ConvertPolicy _policy;
159};
SiCongLi1af54162021-10-06 15:25:57 +0100160} // namespace experimental
161} // namespace arm_compute
SiCongLi31778612021-11-12 17:33:45 +0000162#endif //ARM_COMPUTE_EXPERIMENTAL_POSTOPS