blob: ef5caf2825e57737c8c8a413e7e6430fd6836d43 [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{
Sang-Hoon Park668ccdc2021-02-03 10:32:59 +000033class CpuElementwiseBase : public ICpuOperator
34{
35public:
36 // Inherited methods overridden:
37 void run(ITensorPack &tensors) override;
38};
Sang-Hoon Park6b0bf992021-02-17 13:12:53 +000039/** Class to run @ref cpu::kernels::CpuArithmeticKernel except for division and power
Sang-Hoon Park63001ac2021-01-18 14:20:27 +000040 *
Sang-Hoon Park6b0bf992021-02-17 13:12:53 +000041 * @note Max/Min/Squared difference supports input data type of QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32
42 * @note PRelu supports inpute data type of QASYMM8/QASYMM8_SIGNED/F16/F32.
Sang-Hoon Park63001ac2021-01-18 14:20:27 +000043 */
Sang-Hoon Park6b0bf992021-02-17 13:12:53 +000044template <ArithmeticOperation op>
45class CpuElementwiseArithmetic : public CpuElementwiseBase
Sang-Hoon Park63001ac2021-01-18 14:20:27 +000046{
47public:
Sang-Hoon Park6b0bf992021-02-17 13:12:53 +000048 /** Configure the operator
Sang-Hoon Park63001ac2021-01-18 14:20:27 +000049 *
Sang-Hoon Park6b0bf992021-02-17 13:12:53 +000050 * @param[in] src0 The first source tensor information.
51 * @param[in] src1 The second source tensor information. With PRelu, this is used as alpha tensor.
52 * @param[out] dst The output tensor information.
Sang-Hoon Park63001ac2021-01-18 14:20:27 +000053 */
Sang-Hoon Park668ccdc2021-02-03 10:32:59 +000054 void configure(const ITensorInfo *src0, const ITensorInfo *src1, ITensorInfo *dst);
Georgios Pinitas2eb5d162021-07-02 09:01:49 +010055 /** Static function to check if given info will lead to a valid configuration
Sang-Hoon Park63001ac2021-01-18 14:20:27 +000056 *
Georgios Pinitas2eb5d162021-07-02 09:01:49 +010057 * Similar to @ref CpuElementwiseArithmetic::configure()
Sang-Hoon Park63001ac2021-01-18 14:20:27 +000058 *
Georgios Pinitas2eb5d162021-07-02 09:01:49 +010059 * @return a status
Sang-Hoon Park63001ac2021-01-18 14:20:27 +000060 */
Sang-Hoon Park668ccdc2021-02-03 10:32:59 +000061 static Status validate(const ITensorInfo *src0, const ITensorInfo *src1, const ITensorInfo *dst);
Sang-Hoon Park63001ac2021-01-18 14:20:27 +000062};
63
Sang-Hoon Park6b0bf992021-02-17 13:12:53 +000064/** Class to run @ref cpu::kernels::CpuArithmeticKernel except for maximum operation */
65using CpuElementwiseMax = CpuElementwiseArithmetic<ArithmeticOperation::MAX>;
66/** Class to run @ref cpu::kernels::CpuArithmeticKernel except for minimum operation */
67using CpuElementwiseMin = CpuElementwiseArithmetic<ArithmeticOperation::MIN>;
68/** Class to run @ref cpu::kernels::CpuArithmeticKernel except for squared difference operation */
69using CpuElementwiseSquaredDiff = CpuElementwiseArithmetic<ArithmeticOperation::SQUARED_DIFF>;
Sang-Hoon Park63001ac2021-01-18 14:20:27 +000070
71/** Basic function to run @ref cpu::kernels::CpuArithmeticKernel for division
72 *
73 * @note The tensor data type for the inputs must be S32/F16/F32.
74 * @note The function performs a division operation between two tensors (i.e., out[i] = in1[i] / in2[i])
75 */
Sang-Hoon Park668ccdc2021-02-03 10:32:59 +000076class CpuElementwiseDivision : public CpuElementwiseBase
Sang-Hoon Park63001ac2021-01-18 14:20:27 +000077{
78public:
Sang-Hoon Park668ccdc2021-02-03 10:32:59 +000079 /** Initialise the kernel's inputs, dst and conversion policy.
Sang-Hoon Park63001ac2021-01-18 14:20:27 +000080 *
Sang-Hoon Park668ccdc2021-02-03 10:32:59 +000081 * @param[in, out] src0 First tensor input info. Data types supported: S32/F16/F32.
82 * @param[in, out] src1 Second tensor input info. Data types supported: Same as @p src0.
83 * @param[out] dst Output tensor info. Data types supported: Same as @p src0.
Sang-Hoon Park63001ac2021-01-18 14:20:27 +000084 */
Sang-Hoon Park668ccdc2021-02-03 10:32:59 +000085 void configure(const ITensorInfo *src0, const ITensorInfo *src1, ITensorInfo *dst);
Georgios Pinitas2eb5d162021-07-02 09:01:49 +010086 /** Static function to check if given info will lead to a valid configuration
Sang-Hoon Park63001ac2021-01-18 14:20:27 +000087 *
Georgios Pinitas2eb5d162021-07-02 09:01:49 +010088 * Similar to @ref CpuElementwiseDivision::configure()
Sang-Hoon Park63001ac2021-01-18 14:20:27 +000089 *
90 * @return a status
91 */
Sang-Hoon Park668ccdc2021-02-03 10:32:59 +000092 static Status validate(const ITensorInfo *src0, const ITensorInfo *src1, const ITensorInfo *dst);
Sang-Hoon Park63001ac2021-01-18 14:20:27 +000093};
94
95/** Basic function to run @ref cpu::kernels::CpuArithmeticKernel for power
96 *
97 * @note The tensor data type for the inputs must be F16/F32.
98 * @note The function performs a elementwise power of in1 to in2 (i.e., out[i] = in1[i] ^ in2[i])
99 * @note For an exponent that is a float, this function will only work with a positive base.
100 */
Sang-Hoon Park668ccdc2021-02-03 10:32:59 +0000101class CpuElementwisePower : public CpuElementwiseBase
Sang-Hoon Park63001ac2021-01-18 14:20:27 +0000102{
103public:
Sang-Hoon Park668ccdc2021-02-03 10:32:59 +0000104 /** Initialise the kernel's inputs, dst and conversion policy.
Sang-Hoon Park63001ac2021-01-18 14:20:27 +0000105 *
Sang-Hoon Park668ccdc2021-02-03 10:32:59 +0000106 * @param[in, out] src0 First tensor input info. Data types supported: F16/F32.
107 * @param[in, out] src1 Second tensor input info. Data types supported: Same as @p src0.
108 * @param[out] dst Output tensor info. Data types supported: Same as @p src0.
Sang-Hoon Park63001ac2021-01-18 14:20:27 +0000109 */
Sang-Hoon Park668ccdc2021-02-03 10:32:59 +0000110 void configure(const ITensorInfo *src0, const ITensorInfo *src1, ITensorInfo *dst);
Georgios Pinitas2eb5d162021-07-02 09:01:49 +0100111 /** Static function to check if given info will lead to a valid configuration
Sang-Hoon Park63001ac2021-01-18 14:20:27 +0000112 *
Georgios Pinitas2eb5d162021-07-02 09:01:49 +0100113 * Similar to @ref CpuElementwisePower::configure()
Sang-Hoon Park63001ac2021-01-18 14:20:27 +0000114 *
115 * @return a status
116 */
Sang-Hoon Park668ccdc2021-02-03 10:32:59 +0000117 static Status validate(const ITensorInfo *src0, const ITensorInfo *src1, const ITensorInfo *dst);
Sang-Hoon Park63001ac2021-01-18 14:20:27 +0000118};
119
120/** Basic function to run @ref cpu::kernels::CpuComparisonKernel.
121 *
122 * @note The tensor data type for the inputs must be QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32.
123 * @note The function performs a comparison operation between two tensors.
124 */
Sang-Hoon Park668ccdc2021-02-03 10:32:59 +0000125class CpuElementwiseComparison : public CpuElementwiseBase
Sang-Hoon Park63001ac2021-01-18 14:20:27 +0000126{
127public:
Sang-Hoon Park668ccdc2021-02-03 10:32:59 +0000128 /** Initialise the kernel's inputs, dst and conversion policy.
Sang-Hoon Park63001ac2021-01-18 14:20:27 +0000129 *
Sang-Hoon Park668ccdc2021-02-03 10:32:59 +0000130 * @param[in, out] src0 First tensor input info. Data types supported: QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32.
131 * @param[in, out] src1 Second tensor input info. Data types supported: Same as @p src0.
132 * @param[out] dst Output tensor info. Data types supported: U16/U32.
133 * @param[in] op Comparison Operation to be performed.
Sang-Hoon Park63001ac2021-01-18 14:20:27 +0000134 */
Sang-Hoon Park668ccdc2021-02-03 10:32:59 +0000135 void configure(const ITensorInfo *src0, const ITensorInfo *src1, ITensorInfo *dst, ComparisonOperation op);
Georgios Pinitas2eb5d162021-07-02 09:01:49 +0100136 /** Static function to check if given info will lead to a valid configuration
Sang-Hoon Park63001ac2021-01-18 14:20:27 +0000137 *
Georgios Pinitas2eb5d162021-07-02 09:01:49 +0100138 * Similar to @ref CpuElementwiseComparison::configure()
Sang-Hoon Park63001ac2021-01-18 14:20:27 +0000139 *
140 * @return a status
141 */
Sang-Hoon Park668ccdc2021-02-03 10:32:59 +0000142 static Status validate(const ITensorInfo *src0, const ITensorInfo *src1, const ITensorInfo *dst, ComparisonOperation op);
Sang-Hoon Park63001ac2021-01-18 14:20:27 +0000143};
144
145/** Basic function to run @ref cpu::kernels::CpuComparisonKernel
146 *
147 * @note The tensor data type for the inputs must be QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32.
148 * @note The function performs a comparison operation between two tensors.
149 */
150template <ComparisonOperation op>
Sang-Hoon Park668ccdc2021-02-03 10:32:59 +0000151class CpuElementwiseComparisonStatic : public CpuElementwiseBase
Sang-Hoon Park63001ac2021-01-18 14:20:27 +0000152{
153public:
Sang-Hoon Park668ccdc2021-02-03 10:32:59 +0000154 /** Initialise the kernel's inputs, dst and conversion policy.
Sang-Hoon Park63001ac2021-01-18 14:20:27 +0000155 *
Sang-Hoon Park668ccdc2021-02-03 10:32:59 +0000156 * @param[in, out] src0 First tensor input info. Data types supported: QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32.
157 * @param[in, out] src1 Second tensor input info. Data types supported: Same as @p src0.
158 * @param[out] dst Output tensor info. Data types supported: U16/U32.
Sang-Hoon Park63001ac2021-01-18 14:20:27 +0000159 */
Sang-Hoon Park668ccdc2021-02-03 10:32:59 +0000160 void configure(const ITensorInfo *src0, const ITensorInfo *src1, ITensorInfo *dst);
Georgios Pinitas2eb5d162021-07-02 09:01:49 +0100161 /** Static function to check if given info will lead to a valid configuration
Sang-Hoon Park63001ac2021-01-18 14:20:27 +0000162 *
Georgios Pinitas2eb5d162021-07-02 09:01:49 +0100163 * Similar to @ref CpuElementwiseComparisonStatic::configure()
Sang-Hoon Park63001ac2021-01-18 14:20:27 +0000164 *
165 * @return a status
166 */
Sang-Hoon Park668ccdc2021-02-03 10:32:59 +0000167 static Status validate(const ITensorInfo *src0, const ITensorInfo *src1, const ITensorInfo *dst);
Sang-Hoon Park63001ac2021-01-18 14:20:27 +0000168};
169
170/** Basic function to run equal comparison. */
171using NEEqual = CpuElementwiseComparisonStatic<ComparisonOperation::Equal>;
172/** Basic function to run not equal comparison. */
173using NENotEqual = CpuElementwiseComparisonStatic<ComparisonOperation::NotEqual>;
174/** Basic function to run greater comparison. */
175using NEGreater = CpuElementwiseComparisonStatic<ComparisonOperation::Greater>;
176/** Basic function to run greater-equal comparison. */
177using NEGreaterEqual = CpuElementwiseComparisonStatic<ComparisonOperation::GreaterEqual>;
178/** Basic function to run less comparison. */
179using NELess = CpuElementwiseComparisonStatic<ComparisonOperation::Less>;
180/** Basic function to run less-equal comparison. */
181using NELessEqual = CpuElementwiseComparisonStatic<ComparisonOperation::LessEqual>;
182} // namespace cpu
183} // namespace arm_compute
184
185#endif /* ARM_COMPUTE_CPU_ELEMENTWISE_H */