Compute Library
 22.11
PostOps.h
Go to the documentation of this file.
1 /*
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  */
24 #ifndef ARM_COMPUTE_EXPERIMENTAL_POSTOPS
25 #define ARM_COMPUTE_EXPERIMENTAL_POSTOPS
26 
28 
29 #include "arm_compute/core/Types.h"
30 
31 #include <vector>
32 
33 namespace arm_compute
34 {
35 namespace experimental
36 {
37 /** (EXPERIMENTAL_POST_OPS)
38  * Implementation of specific IPostOps
39 */
40 
41 template <typename TensorRelatedT>
42 struct PostOpAct : public IPostOp<TensorRelatedT>
43 {
44 public:
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  {
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  }
77 };
78 
79 template <typename TensorRelatedT>
80 struct PostOpEltwiseAdd : public IPostOp<TensorRelatedT>
81 {
82 public:
83  PostOpEltwiseAdd(TensorRelatedT addend, int prev_dst_pos, ConvertPolicy policy)
84  : _addend{ addend },
85  _prev_dst_pos{ prev_dst_pos },
86  _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;
95  int prev_dst_pos() const override
96  {
97  return _prev_dst_pos;
98  }
99  PostOpType type() const override
100  {
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;
118 };
119 
120 template <typename TensorRelatedT>
121 struct PostOpEltwisePRelu : public IPostOp<TensorRelatedT>
122 {
123 public:
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;
136  int prev_dst_pos() const override
137  {
138  return _prev_dst_pos;
139  }
140  PostOpType type() const override
141  {
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;
159 };
160 } // namespace experimental
161 } // namespace arm_compute
162 #endif //ARM_COMPUTE_EXPERIMENTAL_POSTOPS
std::unique_ptr< IPostOp< TensorRelatedT > > clone() const override
Clone method used in cases where PostOps are owned by unique_ptr.
Definition: PostOps.h:111
Definition: PostOps.h:80
std::vector< TensorRelatedT * > arguments() override
The argument tensors The order of the argument tensor is strictly preserved.
Definition: PostOps.h:64
PostOpType
Type of Post Op.
Definition: IPostOp.h:36
An elementwise n-ary operation that can be appended to and fused with (at kernel-level) other operato...
Definition: IPostOp.h:89
ActivationLayerInfo _act_info
Definition: PostOps.h:76
std::vector< TensorRelatedT * > arguments() override
The argument tensors The order of the argument tensor is strictly preserved.
Definition: PostOps.h:144
PostOpAct & operator=(const PostOpAct &)=default
Activation Layer Information class.
Definition: Types.h:1639
Copyright (c) 2017-2022 Arm Limited.
std::unique_ptr< IPostOp< TensorRelatedT > > clone() const override
Clone method used in cases where PostOps are owned by unique_ptr.
Definition: PostOps.h:72
int prev_dst_pos() const override
The position of previous op&#39;s dst in current op&#39;s argument list.
Definition: PostOps.h:95
TensorRelatedT _addend
Definition: PostOps.h:115
Definition: PostOps.h:121
ConvertPolicy _policy
Definition: PostOps.h:117
PostOpEltwiseAdd(TensorRelatedT addend, int prev_dst_pos, ConvertPolicy policy)
Definition: PostOps.h:83
std::vector< const TensorRelatedT * > arguments() const override
Definition: PostOps.h:148
std::unique_ptr< IPostOp< TensorRelatedT > > clone() const override
Clone method used in cases where PostOps are owned by unique_ptr.
Definition: PostOps.h:152
int _prev_dst_pos
Definition: PostOps.h:157
int prev_dst_pos() const override
The position of previous op&#39;s dst in current op&#39;s argument list.
Definition: PostOps.h:56
int prev_dst_pos() const override
The position of previous op&#39;s dst in current op&#39;s argument list.
Definition: PostOps.h:136
std::vector< const TensorRelatedT * > arguments() const override
Definition: PostOps.h:68
std::vector< TensorRelatedT * > arguments() override
The argument tensors The order of the argument tensor is strictly preserved.
Definition: PostOps.h:103
int _prev_dst_pos
Definition: PostOps.h:116
PostOpType type() const override
The IPostOp type.
Definition: PostOps.h:60
ConvertPolicy _policy
Definition: PostOps.h:158
TensorRelatedT _alpha_param
Definition: PostOps.h:156
PostOpType type() const override
The IPostOp type.
Definition: PostOps.h:99
std::vector< const TensorRelatedT * > arguments() const override
Definition: PostOps.h:107
PostOpAct(const ActivationLayerInfo &act_info)
Definition: PostOps.h:45
PostOpType type() const override
The IPostOp type.
Definition: PostOps.h:140
(EXPERIMENTAL_POST_OPS) Implementation of specific IPostOps
Definition: PostOps.h:42
ConvertPolicy
Policy to handle integer overflow.
Definition: Types.h:404
~PostOpAct() override=default
PostOpEltwisePRelu(TensorRelatedT alpha_param, int prev_dst_pos, ConvertPolicy policy)
Definition: PostOps.h:124