Compute Library
 21.05
ClElementwiseOperations.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_CL_ELEMENTWISE_OPERATIONS_H
25 #define ARM_COMPUTE_CL_ELEMENTWISE_OPERATIONS_H
26 
29 
30 namespace arm_compute
31 {
32 namespace opencl
33 {
34 /** Basic function to run @ref opencl::kernels::ClArithmeticKernel for division
35  *
36  * @note The tensor data type for the inputs must be F16/F32.
37  * @note The function performs an arithmetic division between two tensors.
38  */
40 {
41 public:
42  /** Default Constructor */
43  ClElementwiseDivision() = default;
44  /** Configure function for a given list of arguments.
45  *
46  * @param[in] compile_context The compile context to be used.
47  * @param[in] src1 First source tensor info. Data types supported: F16/F32.
48  * @param[in] src2 Second source tensor info. same as @p src1.
49  * @param[out] dst Destination tensor info. Data types supported: same as @p src1.
50  * @param[in] act_info (Optional) Activation layer information in case of a fused activation.
51  */
52  void configure(const ClCompileContext &compile_context, ITensorInfo *src1, ITensorInfo *src2, ITensorInfo *dst, const ActivationLayerInfo &act_info = ActivationLayerInfo());
53  /** Static function to check if given info will lead to a valid configuration of @ref ClElementwiseDivision
54  *
55  * @param[in] src1 First source tensor info. Data types supported: F16/F32.
56  * @param[in] src2 Second source tensor info. Data types supported: same as @p src1.
57  * @param[in] dst Destination tensor info. Data types supported: same as @p src1.
58  * @param[in] act_info (Optional) Activation layer information in case of a fused activation.
59  *
60  * @return a status
61  */
62  static Status validate(const ITensorInfo *src1, const ITensorInfo *src2, const ITensorInfo *dst, const ActivationLayerInfo &act_info = ActivationLayerInfo());
63 };
64 
65 /** Basic function to run @ref opencl::kernels::ClArithmeticKernel for max
66  *
67  * @note The tensor data type for the inputs must be U8/QASYMM8/S16/QSYMM16/S32/U32/F16/F32.
68  * @note The function performs a max operation between two tensors.
69  */
71 {
72 public:
73  /** Default Constructor */
74  ClElementwiseMax() = default;
75  /** Configure function for a given list of arguments.
76  *
77  * @param[in] compile_context The compile context to be used.
78  * @param[in] src1 First source tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/QSYMM16/S32/U32/F16/F32.
79  * @param[in] src2 Second source tensor info. Data types supported: same as @p src1.
80  * @param[out] dst Destination tensor info. Data types supported: same as @p src1.
81  * @param[in] act_info (Optional) Activation layer information in case of a fused activation.
82  */
83  void configure(const ClCompileContext &compile_context, ITensorInfo *src1, ITensorInfo *src2, ITensorInfo *dst, const ActivationLayerInfo &act_info = ActivationLayerInfo());
84  /** Static function to check if given info will lead to a valid configuration of @ref opencl::kernels::ClArithmeticKernel for max
85  *
86  * @param[in] src1 First source tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/QSYMM16/S32/U32/F16/F32.
87  * @param[in] src2 Second source tensor info. Data types supported: same as @p src1.
88  * @param[in] dst Destination tensor info. Data types supported: same as @p src1.
89  * @param[in] act_info (Optional) Activation layer information in case of a fused activation.
90  *
91  * @return a status
92  */
93  static Status validate(const ITensorInfo *src1, const ITensorInfo *src2, const ITensorInfo *dst, const ActivationLayerInfo &act_info = ActivationLayerInfo());
94 };
95 
96 /** Basic function to run @ref opencl::kernels::ClArithmeticKernel for min
97  *
98  * @note The tensor data type for the inputs must be U8/QASYMM8/S16/QSYMM16/S32/U32/F16/F32.
99  * @note The function performs a max operation between two tensors.
100  */
102 {
103 public:
104  /** Default Constructor */
105  ClElementwiseMin() = default;
106  /** Configure function for a given list of arguments.
107  *
108  * @param[in] compile_context The compile context to be used.
109  * @param[in] src1 First source tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/QSYMM16/S32/U32/F16/F32.
110  * @param[in] src2 Second source tensor info. Data types supported: same as @p src1.
111  * @param[out] dst Destination tensor info. Data types supported: same as @p src1.
112  * @param[in] act_info (Optional) Activation layer information in case of a fused activation.
113  */
114  void configure(const ClCompileContext &compile_context, ITensorInfo *src1, ITensorInfo *src2, ITensorInfo *dst, const ActivationLayerInfo &act_info = ActivationLayerInfo());
115  /** Static function to check if given info will lead to a valid configuration of @ref opencl::kernels::ClArithmeticKernel for min
116  *
117  * @param[in] src1 First source tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/QSYMM16/S32/U32/F16/F32.
118  * @param[in] src2 Second source tensor info. Data types supported: same as @p src1.
119  * @param[in] dst Destination tensor info. Data types supported: same as @p src1.
120  * @param[in] act_info (Optional) Activation layer information in case of a fused activation.
121  *
122  * @return a status
123  */
124  static Status validate(const ITensorInfo *src1, const ITensorInfo *src2, const ITensorInfo *dst, const ActivationLayerInfo &act_info = ActivationLayerInfo());
125 };
126 
127 /** Basic function to run @ref opencl::kernels::ClArithmeticKernel for squared difference
128  *
129  * @note The tensor data type for the inputs must be QASYMM8/U8/S16/QSYMM16/F16/F32.
130  * @note The function performs a squared different operation between two tensors (i.e., out[i] = (in1[i] - in2[i])^2
131  */
133 {
134 public:
135  /** Default Constructor */
136  ClElementwiseSquaredDiff() = default;
137  /** Configure function for a given list of arguments.
138  *
139  * @param[in] compile_context The compile context to be used.
140  * @param[in] src1 First source tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/QSYMM16/F16/F32.
141  * @param[in] src2 Second source tensor info. Data types supported: same as @p src1.
142  * @param[out] dst Destination tensor info. Data types supported: same as @p src1.
143  * @param[in] act_info (Optional) Activation layer information in case of a fused activation.
144  */
145  void configure(const ClCompileContext &compile_context, ITensorInfo *src1, ITensorInfo *src2, ITensorInfo *dst, const ActivationLayerInfo &act_info = ActivationLayerInfo());
146  /** Static function to check if given info will lead to a valid configuration of @ref opencl::kernels::ClArithmeticKernel for squared difference
147  *
148  * @param[in] src1 First source tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/QSYMM16/F16/F32.
149  * @param[in] src2 Second source tensor info. Data types supported: same as @p src1.
150  * @param[in] dst Destination tensor info. Data types supported: same as @p src1.
151  * @param[in] act_info (Optional) Activation layer information in case of a fused activation.
152  *
153  * @return a status
154  */
155  static Status validate(const ITensorInfo *src1, const ITensorInfo *src2, const ITensorInfo *dst, const ActivationLayerInfo &act_info = ActivationLayerInfo());
156 };
157 
158 /** Basic function to run @ref opencl::kernels::ClArithmeticKernel for power
159  *
160  * @note The tensor data type for the inputs must be F16/F32.
161  * @note The function performs an elementwise power of in1 to in2 (i.e., out[i] = in1[i] ^ in2[i])
162  */
164 {
165 public:
166  /** Default Constructor */
167  ClElementwisePower() = default;
168  /** Configure function for a given list of arguments.
169  *
170  * @param[in] compile_context The compile context to be used.
171  * @param[in] src1 First source tensor info. Data types supported: F16/F32.
172  * @param[in] src2 Second source tensor info. Data types supported: F16/F32.
173  * @param[out] dst Destination tensor info. Data types supported:F16/F32.
174  * @param[in] act_info (Optional) Activation layer information in case of a fused activation.
175  */
176  void configure(const ClCompileContext &compile_context, ITensorInfo *src1, ITensorInfo *src2, ITensorInfo *dst, const ActivationLayerInfo &act_info = ActivationLayerInfo());
177  /** Static function to check if given info will lead to a valid configuration of @ref opencl::kernels::ClArithmeticKernel for power
178  *
179  * @param[in] src1 First source tensor info. Data types supported: F16/F32.
180  * @param[in] src2 Second source tensor info. Data types supported: F16/F32.
181  * @param[in] dst Destination tensor info. Data types supported: F16/F32.
182  * @param[in] act_info (Optional) Activation layer information in case of a fused activation.
183  *
184  * @return a status
185  */
186  static Status validate(const ITensorInfo *src1, const ITensorInfo *src2, const ITensorInfo *dst, const ActivationLayerInfo &act_info = ActivationLayerInfo());
187 };
188 } // namespace opencl
189 } // namespace arm_compute
190 #endif /* ARM_COMPUTE_CL_ELEMENTWISE_OPERATIONS_H */
ClElementwisePower()=default
Default Constructor.
static Status validate(const ITensorInfo *src1, const ITensorInfo *src2, const ITensorInfo *dst, const ActivationLayerInfo &act_info=ActivationLayerInfo())
Static function to check if given info will lead to a valid configuration of ClElementwiseDivision.
ClElementwiseSquaredDiff()=default
Default Constructor.
static Status validate(const ITensorInfo *src1, const ITensorInfo *src2, const ITensorInfo *dst, const ActivationLayerInfo &act_info=ActivationLayerInfo())
Static function to check if given info will lead to a valid configuration of opencl::kernels::ClArith...
ClElementwiseDivision()=default
Default Constructor.
Basic function to run opencl::kernels::ClArithmeticKernel for max.
static Status validate(const ITensorInfo *src1, const ITensorInfo *src2, const ITensorInfo *dst, const ActivationLayerInfo &act_info=ActivationLayerInfo())
Static function to check if given info will lead to a valid configuration of opencl::kernels::ClArith...
Store the tensor's metadata.
Definition: ITensorInfo.h:40
Status class.
Definition: Error.h:52
void configure(const ClCompileContext &compile_context, ITensorInfo *src1, ITensorInfo *src2, ITensorInfo *dst, const ActivationLayerInfo &act_info=ActivationLayerInfo())
Configure function for a given list of arguments.
Activation Layer Information class.
Definition: Types.h:1478
Copyright (c) 2017-2021 Arm Limited.
Basic function to run opencl::kernels::ClArithmeticKernel for power.
Basic function to run opencl::kernels::ClArithmeticKernel for division.
void configure(const ClCompileContext &compile_context, ITensorInfo *src1, ITensorInfo *src2, ITensorInfo *dst, const ActivationLayerInfo &act_info=ActivationLayerInfo())
Configure function for a given list of arguments.
CLCompileContext class.
void configure(const ClCompileContext &compile_context, ITensorInfo *src1, ITensorInfo *src2, ITensorInfo *dst, const ActivationLayerInfo &act_info=ActivationLayerInfo())
Configure function for a given list of arguments.
Basic function to run opencl::kernels::ClArithmeticKernel for min.
Basic function to run opencl::kernels::ClArithmeticKernel for squared difference.
ClElementwiseMin()=default
Default Constructor.
Basic interface for functions which have a single async CL kernel.
Definition: ICLOperator.h:41
void configure(const ClCompileContext &compile_context, ITensorInfo *src1, ITensorInfo *src2, ITensorInfo *dst, const ActivationLayerInfo &act_info=ActivationLayerInfo())
Configure function for a given list of arguments.
static Status validate(const ITensorInfo *src1, const ITensorInfo *src2, const ITensorInfo *dst, const ActivationLayerInfo &act_info=ActivationLayerInfo())
Static function to check if given info will lead to a valid configuration of opencl::kernels::ClArith...
void configure(const ClCompileContext &compile_context, ITensorInfo *src1, ITensorInfo *src2, ITensorInfo *dst, const ActivationLayerInfo &act_info=ActivationLayerInfo())
Configure function for a given list of arguments.
static Status validate(const ITensorInfo *src1, const ITensorInfo *src2, const ITensorInfo *dst, const ActivationLayerInfo &act_info=ActivationLayerInfo())
Static function to check if given info will lead to a valid configuration of opencl::kernels::ClArith...
ClElementwiseMax()=default
Default Constructor.