Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 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_CPU_ELEMENTWISE_H |
| 25 | #define ARM_COMPUTE_CPU_ELEMENTWISE_H |
| 26 | |
Georgios Pinitas | 7891a73 | 2021-08-20 21:39:25 +0100 | [diff] [blame] | 27 | #include "src/cpu/ICpuOperator.h" |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 28 | |
| 29 | namespace arm_compute |
| 30 | { |
| 31 | namespace cpu |
| 32 | { |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 33 | class CpuElementwiseBase : public ICpuOperator |
| 34 | { |
| 35 | public: |
| 36 | // Inherited methods overridden: |
| 37 | void run(ITensorPack &tensors) override; |
| 38 | }; |
Sang-Hoon Park | 6b0bf99 | 2021-02-17 13:12:53 +0000 | [diff] [blame] | 39 | /** Class to run @ref cpu::kernels::CpuArithmeticKernel except for division and power |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 40 | * |
Sang-Hoon Park | 6b0bf99 | 2021-02-17 13:12:53 +0000 | [diff] [blame] | 41 | * @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 Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 43 | */ |
Sang-Hoon Park | 6b0bf99 | 2021-02-17 13:12:53 +0000 | [diff] [blame] | 44 | template <ArithmeticOperation op> |
| 45 | class CpuElementwiseArithmetic : public CpuElementwiseBase |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 46 | { |
| 47 | public: |
Sang-Hoon Park | 6b0bf99 | 2021-02-17 13:12:53 +0000 | [diff] [blame] | 48 | /** Configure the operator |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 49 | * |
Sang-Hoon Park | 6b0bf99 | 2021-02-17 13:12:53 +0000 | [diff] [blame] | 50 | * @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 Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 53 | */ |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 54 | void configure(const ITensorInfo *src0, const ITensorInfo *src1, ITensorInfo *dst); |
Georgios Pinitas | 2eb5d16 | 2021-07-02 09:01:49 +0100 | [diff] [blame] | 55 | /** Static function to check if given info will lead to a valid configuration |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 56 | * |
Georgios Pinitas | 2eb5d16 | 2021-07-02 09:01:49 +0100 | [diff] [blame] | 57 | * Similar to @ref CpuElementwiseArithmetic::configure() |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 58 | * |
Georgios Pinitas | 2eb5d16 | 2021-07-02 09:01:49 +0100 | [diff] [blame] | 59 | * @return a status |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 60 | */ |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 61 | static Status validate(const ITensorInfo *src0, const ITensorInfo *src1, const ITensorInfo *dst); |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 62 | }; |
| 63 | |
Sang-Hoon Park | 6b0bf99 | 2021-02-17 13:12:53 +0000 | [diff] [blame] | 64 | /** Class to run @ref cpu::kernels::CpuArithmeticKernel except for maximum operation */ |
| 65 | using CpuElementwiseMax = CpuElementwiseArithmetic<ArithmeticOperation::MAX>; |
| 66 | /** Class to run @ref cpu::kernels::CpuArithmeticKernel except for minimum operation */ |
| 67 | using CpuElementwiseMin = CpuElementwiseArithmetic<ArithmeticOperation::MIN>; |
| 68 | /** Class to run @ref cpu::kernels::CpuArithmeticKernel except for squared difference operation */ |
| 69 | using CpuElementwiseSquaredDiff = CpuElementwiseArithmetic<ArithmeticOperation::SQUARED_DIFF>; |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 70 | |
| 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 Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 76 | class CpuElementwiseDivision : public CpuElementwiseBase |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 77 | { |
| 78 | public: |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 79 | /** Initialise the kernel's inputs, dst and conversion policy. |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 80 | * |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 81 | * @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 Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 84 | */ |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 85 | void configure(const ITensorInfo *src0, const ITensorInfo *src1, ITensorInfo *dst); |
Georgios Pinitas | 2eb5d16 | 2021-07-02 09:01:49 +0100 | [diff] [blame] | 86 | /** Static function to check if given info will lead to a valid configuration |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 87 | * |
Georgios Pinitas | 2eb5d16 | 2021-07-02 09:01:49 +0100 | [diff] [blame] | 88 | * Similar to @ref CpuElementwiseDivision::configure() |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 89 | * |
| 90 | * @return a status |
| 91 | */ |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 92 | static Status validate(const ITensorInfo *src0, const ITensorInfo *src1, const ITensorInfo *dst); |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 93 | }; |
| 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 Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 101 | class CpuElementwisePower : public CpuElementwiseBase |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 102 | { |
| 103 | public: |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 104 | /** Initialise the kernel's inputs, dst and conversion policy. |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 105 | * |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 106 | * @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 Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 109 | */ |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 110 | void configure(const ITensorInfo *src0, const ITensorInfo *src1, ITensorInfo *dst); |
Georgios Pinitas | 2eb5d16 | 2021-07-02 09:01:49 +0100 | [diff] [blame] | 111 | /** Static function to check if given info will lead to a valid configuration |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 112 | * |
Georgios Pinitas | 2eb5d16 | 2021-07-02 09:01:49 +0100 | [diff] [blame] | 113 | * Similar to @ref CpuElementwisePower::configure() |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 114 | * |
| 115 | * @return a status |
| 116 | */ |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 117 | static Status validate(const ITensorInfo *src0, const ITensorInfo *src1, const ITensorInfo *dst); |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 118 | }; |
| 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 Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 125 | class CpuElementwiseComparison : public CpuElementwiseBase |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 126 | { |
| 127 | public: |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 128 | /** Initialise the kernel's inputs, dst and conversion policy. |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 129 | * |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 130 | * @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 Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 134 | */ |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 135 | void configure(const ITensorInfo *src0, const ITensorInfo *src1, ITensorInfo *dst, ComparisonOperation op); |
Georgios Pinitas | 2eb5d16 | 2021-07-02 09:01:49 +0100 | [diff] [blame] | 136 | /** Static function to check if given info will lead to a valid configuration |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 137 | * |
Georgios Pinitas | 2eb5d16 | 2021-07-02 09:01:49 +0100 | [diff] [blame] | 138 | * Similar to @ref CpuElementwiseComparison::configure() |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 139 | * |
| 140 | * @return a status |
| 141 | */ |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 142 | static Status validate(const ITensorInfo *src0, const ITensorInfo *src1, const ITensorInfo *dst, ComparisonOperation op); |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 143 | }; |
| 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 | */ |
| 150 | template <ComparisonOperation op> |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 151 | class CpuElementwiseComparisonStatic : public CpuElementwiseBase |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 152 | { |
| 153 | public: |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 154 | /** Initialise the kernel's inputs, dst and conversion policy. |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 155 | * |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 156 | * @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 Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 159 | */ |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 160 | void configure(const ITensorInfo *src0, const ITensorInfo *src1, ITensorInfo *dst); |
Georgios Pinitas | 2eb5d16 | 2021-07-02 09:01:49 +0100 | [diff] [blame] | 161 | /** Static function to check if given info will lead to a valid configuration |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 162 | * |
Georgios Pinitas | 2eb5d16 | 2021-07-02 09:01:49 +0100 | [diff] [blame] | 163 | * Similar to @ref CpuElementwiseComparisonStatic::configure() |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 164 | * |
| 165 | * @return a status |
| 166 | */ |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 167 | static Status validate(const ITensorInfo *src0, const ITensorInfo *src1, const ITensorInfo *dst); |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 168 | }; |
| 169 | |
| 170 | /** Basic function to run equal comparison. */ |
| 171 | using NEEqual = CpuElementwiseComparisonStatic<ComparisonOperation::Equal>; |
| 172 | /** Basic function to run not equal comparison. */ |
| 173 | using NENotEqual = CpuElementwiseComparisonStatic<ComparisonOperation::NotEqual>; |
| 174 | /** Basic function to run greater comparison. */ |
| 175 | using NEGreater = CpuElementwiseComparisonStatic<ComparisonOperation::Greater>; |
| 176 | /** Basic function to run greater-equal comparison. */ |
| 177 | using NEGreaterEqual = CpuElementwiseComparisonStatic<ComparisonOperation::GreaterEqual>; |
| 178 | /** Basic function to run less comparison. */ |
| 179 | using NELess = CpuElementwiseComparisonStatic<ComparisonOperation::Less>; |
| 180 | /** Basic function to run less-equal comparison. */ |
| 181 | using NELessEqual = CpuElementwiseComparisonStatic<ComparisonOperation::LessEqual>; |
| 182 | } // namespace cpu |
| 183 | } // namespace arm_compute |
| 184 | |
| 185 | #endif /* ARM_COMPUTE_CPU_ELEMENTWISE_H */ |