blob: de7c018d7534b5a107323e3b8d0d50feaef4b3b2 [file] [log] [blame]
Michele Di Giorgio237be032021-01-25 15:44:02 +00001/*
Matthew Benthamf1aeab92023-05-30 13:35:34 +00002 * Copyright (c) 2021, 2023 Arm Limited.
Michele Di Giorgio237be032021-01-25 15:44:02 +00003 *
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
SiCong Li91295492023-07-21 18:16:13 +010027#include "arm_compute/function_info/ActivationLayerInfo.h"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010028
Georgios Pinitas7891a732021-08-20 21:39:25 +010029#include "src/gpu/cl/ClCompileContext.h"
30#include "src/gpu/cl/IClOperator.h"
Michele Di Giorgio237be032021-01-25 15:44:02 +000031
32namespace arm_compute
33{
34namespace opencl
35{
36/** Basic function to run @ref opencl::kernels::ClArithmeticKernel for division
37 *
38 * @note The tensor data type for the inputs must be F16/F32.
39 * @note The function performs an arithmetic division between two tensors.
40 */
41class ClElementwiseDivision : public IClOperator
42{
43public:
Michele Di Giorgio237be032021-01-25 15:44:02 +000044 /** 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 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010052 void configure(const ClCompileContext &compile_context,
53 ITensorInfo *src1,
54 ITensorInfo *src2,
55 ITensorInfo *dst,
56 const ActivationLayerInfo &act_info = ActivationLayerInfo());
Georgios Pinitas2eb5d162021-07-02 09:01:49 +010057 /** Static function to check if given info will lead to a valid configuration
Michele Di Giorgio237be032021-01-25 15:44:02 +000058 *
Georgios Pinitas2eb5d162021-07-02 09:01:49 +010059 * Similar to @ref ClElementwiseDivision::configure()
Michele Di Giorgio237be032021-01-25 15:44:02 +000060 *
61 * @return a status
62 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010063 static Status validate(const ITensorInfo *src1,
64 const ITensorInfo *src2,
65 const ITensorInfo *dst,
66 const ActivationLayerInfo &act_info = ActivationLayerInfo());
Michele Di Giorgio237be032021-01-25 15:44:02 +000067};
68
69/** Basic function to run @ref opencl::kernels::ClArithmeticKernel for max
70 *
71 * @note The tensor data type for the inputs must be U8/QASYMM8/S16/QSYMM16/S32/U32/F16/F32.
72 * @note The function performs a max operation between two tensors.
73 */
74class ClElementwiseMax : public IClOperator
75{
76public:
Michele Di Giorgio237be032021-01-25 15:44:02 +000077 /** Configure function for a given list of arguments.
78 *
79 * @param[in] compile_context The compile context to be used.
80 * @param[in] src1 First source tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/QSYMM16/S32/U32/F16/F32.
81 * @param[in] src2 Second source tensor info. Data types supported: same as @p src1.
82 * @param[out] dst Destination tensor info. Data types supported: same as @p src1.
83 * @param[in] act_info (Optional) Activation layer information in case of a fused activation.
84 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010085 void configure(const ClCompileContext &compile_context,
86 ITensorInfo *src1,
87 ITensorInfo *src2,
88 ITensorInfo *dst,
89 const ActivationLayerInfo &act_info = ActivationLayerInfo());
Georgios Pinitas2eb5d162021-07-02 09:01:49 +010090 /** Static function to check if given info will lead to a valid configuration
Michele Di Giorgio237be032021-01-25 15:44:02 +000091 *
Georgios Pinitas2eb5d162021-07-02 09:01:49 +010092 * Similar to @ref ClElementwiseMax::configure()
Michele Di Giorgio237be032021-01-25 15:44:02 +000093 *
94 * @return a status
95 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010096 static Status validate(const ITensorInfo *src1,
97 const ITensorInfo *src2,
98 const ITensorInfo *dst,
99 const ActivationLayerInfo &act_info = ActivationLayerInfo());
Michele Di Giorgio237be032021-01-25 15:44:02 +0000100};
101
102/** Basic function to run @ref opencl::kernels::ClArithmeticKernel for min
103 *
104 * @note The tensor data type for the inputs must be U8/QASYMM8/S16/QSYMM16/S32/U32/F16/F32.
105 * @note The function performs a max operation between two tensors.
106 */
107class ClElementwiseMin : public IClOperator
108{
109public:
Michele Di Giorgio237be032021-01-25 15:44:02 +0000110 /** Configure function for a given list of arguments.
111 *
112 * @param[in] compile_context The compile context to be used.
113 * @param[in] src1 First source tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/QSYMM16/S32/U32/F16/F32.
114 * @param[in] src2 Second source tensor info. Data types supported: same as @p src1.
115 * @param[out] dst Destination tensor info. Data types supported: same as @p src1.
116 * @param[in] act_info (Optional) Activation layer information in case of a fused activation.
117 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100118 void configure(const ClCompileContext &compile_context,
119 ITensorInfo *src1,
120 ITensorInfo *src2,
121 ITensorInfo *dst,
122 const ActivationLayerInfo &act_info = ActivationLayerInfo());
Georgios Pinitas2eb5d162021-07-02 09:01:49 +0100123 /** Static function to check if given info will lead to a valid configuration
Michele Di Giorgio237be032021-01-25 15:44:02 +0000124 *
Georgios Pinitas2eb5d162021-07-02 09:01:49 +0100125 * Similar to @ref ClElementwiseMin::configure()
Michele Di Giorgio237be032021-01-25 15:44:02 +0000126 *
127 * @return a status
128 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100129 static Status validate(const ITensorInfo *src1,
130 const ITensorInfo *src2,
131 const ITensorInfo *dst,
132 const ActivationLayerInfo &act_info = ActivationLayerInfo());
Michele Di Giorgio237be032021-01-25 15:44:02 +0000133};
134
135/** Basic function to run @ref opencl::kernels::ClArithmeticKernel for squared difference
136 *
137 * @note The tensor data type for the inputs must be QASYMM8/U8/S16/QSYMM16/F16/F32.
138 * @note The function performs a squared different operation between two tensors (i.e., out[i] = (in1[i] - in2[i])^2
139 */
140class ClElementwiseSquaredDiff : public IClOperator
141{
142public:
Michele Di Giorgio237be032021-01-25 15:44:02 +0000143 /** Configure function for a given list of arguments.
144 *
145 * @param[in] compile_context The compile context to be used.
146 * @param[in] src1 First source tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/QSYMM16/F16/F32.
147 * @param[in] src2 Second source tensor info. Data types supported: same as @p src1.
148 * @param[out] dst Destination tensor info. Data types supported: same as @p src1.
149 * @param[in] act_info (Optional) Activation layer information in case of a fused activation.
150 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100151 void configure(const ClCompileContext &compile_context,
152 ITensorInfo *src1,
153 ITensorInfo *src2,
154 ITensorInfo *dst,
155 const ActivationLayerInfo &act_info = ActivationLayerInfo());
Georgios Pinitas2eb5d162021-07-02 09:01:49 +0100156 /** Static function to check if given info will lead to a valid configuration
Michele Di Giorgio237be032021-01-25 15:44:02 +0000157 *
Georgios Pinitas2eb5d162021-07-02 09:01:49 +0100158 * Similar to @ref ClElementwiseSquaredDiff::configure()
Michele Di Giorgio237be032021-01-25 15:44:02 +0000159 *
160 * @return a status
161 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100162 static Status validate(const ITensorInfo *src1,
163 const ITensorInfo *src2,
164 const ITensorInfo *dst,
165 const ActivationLayerInfo &act_info = ActivationLayerInfo());
Michele Di Giorgio237be032021-01-25 15:44:02 +0000166};
167
168/** Basic function to run @ref opencl::kernels::ClArithmeticKernel for power
169 *
170 * @note The tensor data type for the inputs must be F16/F32.
171 * @note The function performs an elementwise power of in1 to in2 (i.e., out[i] = in1[i] ^ in2[i])
172 */
173class ClElementwisePower : public IClOperator
174{
175public:
Michele Di Giorgio237be032021-01-25 15:44:02 +0000176 /** Configure function for a given list of arguments.
177 *
178 * @param[in] compile_context The compile context to be used.
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[out] 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 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100184 void configure(const ClCompileContext &compile_context,
185 ITensorInfo *src1,
186 ITensorInfo *src2,
187 ITensorInfo *dst,
188 const ActivationLayerInfo &act_info = ActivationLayerInfo());
Georgios Pinitas2eb5d162021-07-02 09:01:49 +0100189 /** Static function to check if given info will lead to a valid configuration
Michele Di Giorgio237be032021-01-25 15:44:02 +0000190 *
Georgios Pinitas2eb5d162021-07-02 09:01:49 +0100191 * Similar to @ref ClElementwisePower::configure()
Michele Di Giorgio237be032021-01-25 15:44:02 +0000192 *
193 * @return a status
194 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100195 static Status validate(const ITensorInfo *src1,
196 const ITensorInfo *src2,
197 const ITensorInfo *dst,
198 const ActivationLayerInfo &act_info = ActivationLayerInfo());
Michele Di Giorgio237be032021-01-25 15:44:02 +0000199};
200} // namespace opencl
201} // namespace arm_compute
202#endif /* ARM_COMPUTE_CL_ELEMENTWISE_OPERATIONS_H */