blob: 611a374c2695741c0e9c4736374b2233a84270bb [file] [log] [blame]
Sang-Hoon Park63001ac2021-01-18 14:20:27 +00001/*
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_CPU_ELEMENTWISE_H
25#define ARM_COMPUTE_CPU_ELEMENTWISE_H
26
27#include "src/runtime/cpu/ICpuOperator.h"
28
29namespace arm_compute
30{
31namespace cpu
32{
33/** Basic function to run @ref cpu::kernels::CpuArithmeticKernel for max
34 *
35 * @note The tensor data type for the inputs must be QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32.
36 * @note The function performs a max operation between two tensors.
37 */
38class CpuElementwiseMax : public ICpuOperator
39{
40public:
41 /** Initialise the kernel's inputs, output and conversion policy.
42 *
43 * @param[in, out] input1 First tensor input info. Data types supported: QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32.
44 * @param[in, out] input2 Second tensor input info. Data types supported: Same as @p input1.
45 * @param[out] output Output tensor info. Data types supported: Same as @p input1.
46 */
47 void configure(const ITensorInfo *input1, const ITensorInfo *input2, ITensorInfo *output);
48 /** Static function to check if given info will lead to a valid configuration of @ref cpu::kernels::CpuArithmeticKernel for max
49 *
50 * @param[in] input1 First tensor input info. Data types supported: QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32.
51 * @param[in] input2 Second tensor input info. Data types supported: Same as @p input1.
52 * @param[in] output Output tensor info. Data types supported: Same as @p input1.
53 *
54 * @return a status
55 */
56 static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output);
57};
58
59/** Basic function to run @ref cpu::kernels::CpuArithmeticKernel for min
60 *
61 * @note The tensor data type for the inputs must be QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32.
62 * @note The function performs a min operation between two tensors.
63 */
64class CpuElementwiseMin : public ICpuOperator
65{
66public:
67 /** Initialise the kernel's inputs, output and conversion policy.
68 *
69 * @param[in, out] input1 First tensor input info. Data types supported: QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32.
70 * @param[in, out] input2 Second tensor input info. Data types supported: Same as @p input1.
71 * @param[out] output Output tensor info. Data types supported: Same as @p input1.
72 */
73 void configure(const ITensorInfo *input1, const ITensorInfo *input2, ITensorInfo *output);
74 /** Static function to check if given info will lead to a valid configuration of @ref cpu::kernels::CpuArithmeticKernel for min
75 *
76 * @param[in] input1 First tensor input info. Data types supported: QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32.
77 * @param[in] input2 Second tensor input info. Data types supported: Same as @p input1.
78 * @param[in] output Output tensor info. Data types supported: Same as @p input1.
79 *
80 * @return a status
81 */
82 static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output);
83};
84
85/** Basic function to run @ref cpu::kernels::CpuArithmeticKernel for squared difference
86 *
87 * @note The tensor data type for the inputs must be QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32.
88 * @note The function performs a squared different operation between two tensors (i.e., out[i] = (in1[i] - in2[i])^2
89 */
90class CpuElementwiseSquaredDiff : public ICpuOperator
91{
92public:
93 /** Initialise the kernel's inputs, output and conversion policy.
94 *
95 * @param[in, out] input1 First tensor input info. Data types supported: QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32.
96 * @param[in, out] input2 Second tensor input info. Data types supported: Same as @p input1.
97 * @param[out] output Output tensor info. Data types supported: Same as @p input1.
98 */
99 void configure(const ITensorInfo *input1, const ITensorInfo *input2, ITensorInfo *output);
100 /** Static function to check if given info will lead to a valid configuration of @ref cpu::kernels::CpuArithmeticKernel for squared difference
101 *
102 * @param[in] input1 First tensor input info. Data types supported: QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32.
103 * @param[in] input2 Second tensor input info. Data types supported: Same as @p input1.
104 * @param[in] output Output tensor info. Data types supported: Same as @p input1.
105 *
106 * @return a status
107 */
108 static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output);
109};
110
111/** Basic function to run @ref cpu::kernels::CpuArithmeticKernel for division
112 *
113 * @note The tensor data type for the inputs must be S32/F16/F32.
114 * @note The function performs a division operation between two tensors (i.e., out[i] = in1[i] / in2[i])
115 */
116class CpuElementwiseDivision : public ICpuOperator
117{
118public:
119 /** Initialise the kernel's inputs, output and conversion policy.
120 *
121 * @param[in, out] input1 First tensor input info. Data types supported: S32/F16/F32.
122 * @param[in, out] input2 Second tensor input info. Data types supported: Same as @p input1.
123 * @param[out] output Output tensor info. Data types supported: Same as @p input1.
124 */
125 void configure(const ITensorInfo *input1, const ITensorInfo *input2, ITensorInfo *output);
126 /** Static function to check if given info will lead to a valid configuration of @ref cpu::kernels::CpuArithmeticKernel for division
127 *
128 * @param[in] input1 First tensor input info. Data types supported: S32/F16/F32.
129 * @param[in] input2 Second tensor input info. Data types supported: Same as @p input1.
130 * @param[in] output Output tensor info. Data types supported: Same as @p input1.
131 *
132 * @return a status
133 */
134 static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output);
135};
136
137/** Basic function to run @ref cpu::kernels::CpuArithmeticKernel for power
138 *
139 * @note The tensor data type for the inputs must be F16/F32.
140 * @note The function performs a elementwise power of in1 to in2 (i.e., out[i] = in1[i] ^ in2[i])
141 * @note For an exponent that is a float, this function will only work with a positive base.
142 */
143class CpuElementwisePower : public ICpuOperator
144{
145public:
146 /** Initialise the kernel's inputs, output and conversion policy.
147 *
148 * @param[in, out] input1 First tensor input info. Data types supported: F16/F32.
149 * @param[in, out] input2 Second tensor input info. Data types supported: Same as @p input1.
150 * @param[out] output Output tensor info. Data types supported: Same as @p input1.
151 */
152 void configure(const ITensorInfo *input1, const ITensorInfo *input2, ITensorInfo *output);
153 /** Static function to check if given info will lead to a valid configuration of @ref cpu::kernels::CpuArithmeticKernel for power
154 *
155 * @param[in] input1 First tensor input info. Data types supported: F16/F32.
156 * @param[in] input2 Second tensor input info. Data types supported: Same as @p input1.
157 * @param[in] output Output tensor info. Data types supported: Same as @p input1.
158 *
159 * @return a status
160 */
161 static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output);
162};
163
164/** Basic function to run @ref cpu::kernels::CpuComparisonKernel.
165 *
166 * @note The tensor data type for the inputs must be QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32.
167 * @note The function performs a comparison operation between two tensors.
168 */
169class CpuElementwiseComparison : public ICpuOperator
170{
171public:
172 /** Initialise the kernel's inputs, output and conversion policy.
173 *
174 * @param[in, out] input1 First tensor input info. Data types supported: QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32.
175 * @param[in, out] input2 Second tensor input info. Data types supported: Same as @p input1.
176 * @param[out] output Output tensor info. Data types supported: U16/U32.
177 * @param[in] op Comparison Operation to be performed.
178 */
179 void configure(const ITensorInfo *input1, const ITensorInfo *input2, ITensorInfo *output, ComparisonOperation op);
180 /** Static function to check if given info will lead to a valid configuration of @ref cpu::kernels::CpuComparisonKernel
181 *
182 * @param[in] input1 First tensor input info. Data types supported: QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32.
183 * @param[in] input2 Second tensor input info. Data types supported: Same as @p input1.
184 * @param[in] output Output tensor info. Data types supported: U16/U32.
185 * @param[in] op Comparison Operation to be performed.
186 *
187 * @return a status
188 */
189 static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, ComparisonOperation op);
190};
191
192/** Basic function to run @ref cpu::kernels::CpuComparisonKernel
193 *
194 * @note The tensor data type for the inputs must be QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32.
195 * @note The function performs a comparison operation between two tensors.
196 */
197template <ComparisonOperation op>
198class CpuElementwiseComparisonStatic : public ICpuOperator
199{
200public:
201 /** Initialise the kernel's inputs, output and conversion policy.
202 *
203 * @param[in, out] input1 First tensor input info. Data types supported: QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32.
204 * @param[in, out] input2 Second tensor input info. Data types supported: Same as @p input1.
205 * @param[out] output Output tensor info. Data types supported: U16/U32.
206 */
207 void configure(const ITensorInfo *input1, const ITensorInfo *input2, ITensorInfo *output);
208 /** Static function to check if given info will lead to a valid configuration of @ref cpu::kernels::CpuComparisonKernel
209 *
210 * @param[in] input1 First tensor input info. Data types supported: QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32.
211 * @param[in] input2 Second tensor input info. Data types supported: Same as @p input1.
212 * @param[in] output Output tensor info. Data types supported: U16/U32.
213 *
214 * @return a status
215 */
216 static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output);
217};
218
219/** Basic function to run equal comparison. */
220using NEEqual = CpuElementwiseComparisonStatic<ComparisonOperation::Equal>;
221/** Basic function to run not equal comparison. */
222using NENotEqual = CpuElementwiseComparisonStatic<ComparisonOperation::NotEqual>;
223/** Basic function to run greater comparison. */
224using NEGreater = CpuElementwiseComparisonStatic<ComparisonOperation::Greater>;
225/** Basic function to run greater-equal comparison. */
226using NEGreaterEqual = CpuElementwiseComparisonStatic<ComparisonOperation::GreaterEqual>;
227/** Basic function to run less comparison. */
228using NELess = CpuElementwiseComparisonStatic<ComparisonOperation::Less>;
229/** Basic function to run less-equal comparison. */
230using NELessEqual = CpuElementwiseComparisonStatic<ComparisonOperation::LessEqual>;
231} // namespace cpu
232} // namespace arm_compute
233
234#endif /* ARM_COMPUTE_CPU_ELEMENTWISE_H */