giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 1 | /* |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 2 | * Copyright (c) 2021 Arm Limited. |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 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 |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 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 | */ |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 24 | #ifndef ARM_COMPUTE_CPU_ELEMENTWISE_KERNEL_H |
| 25 | #define ARM_COMPUTE_CPU_ELEMENTWISE_KERNEL_H |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 26 | |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 27 | #include "src/core/common/Macros.h" |
| 28 | #include "src/core/cpu/ICpuKernel.h" |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 29 | |
| 30 | namespace arm_compute |
| 31 | { |
| 32 | class ITensor; |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 33 | namespace cpu |
| 34 | { |
| 35 | namespace kernels |
| 36 | { |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 37 | /** Interface for an element-wise operation kernel |
| 38 | * |
| 39 | * Element-wise operation is computed by: |
| 40 | * @f[ output(x,y) = OP(input1(x,y), input2(x,y))@f] |
| 41 | * |
| 42 | */ |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 43 | class CpuElementwiseKernel : public ICpuKernel |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 44 | { |
| 45 | public: |
| 46 | const char *name() const override |
| 47 | { |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 48 | return "CpuElementwiseKernel"; |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 49 | } |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 50 | |
| 51 | CpuElementwiseKernel() = default; |
| 52 | ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE(CpuElementwiseKernel); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 53 | |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 54 | /** Common signature for all the specialised arithmetic functions |
| 55 | * |
Michele Di Giorgio | f9b595a | 2020-07-03 13:34:52 +0100 | [diff] [blame] | 56 | * @param[in] input1 First tensor input info. Data types supported: QASYMM8/S16/F16/S32/F32. |
| 57 | * @param[in] input2 Second tensor input info. Data types supported: Same as @p input1. |
| 58 | * @param[out] output Output tensor info. Data types supported: Dependent on subclass. |
| 59 | * @param[in] window Region on which to execute the kernel. |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 60 | */ |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 61 | using ElementwiseFunction = void(const ITensor *, const ITensor *, ITensor *, const Window &); |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 62 | |
Michalis Spyrou | ce0c675 | 2020-06-18 10:14:57 +0100 | [diff] [blame] | 63 | // Inherited methods overridden: |
Georgios Pinitas | 0499dff | 2020-07-31 22:21:38 +0100 | [diff] [blame] | 64 | void run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) override; |
Michalis Spyrou | ce0c675 | 2020-06-18 10:14:57 +0100 | [diff] [blame] | 65 | |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 66 | protected: |
| 67 | /** Validate the argument passed to the kernel |
| 68 | * |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 69 | * @param[in] input1 First tensor input. Data types supported: QASYMM8/S16/F16/S32/F32. |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 70 | * @param[in] input2 Second tensor input. Data types supported: Same as @p input1. |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 71 | * @param[in] output Output tensor. Data types supported: Dependent on subclass. |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 72 | */ |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 73 | static Status validate_arguments_common(const ITensorInfo &input1, const ITensorInfo &input2, const ITensorInfo &output); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 74 | |
| 75 | /** Commmon configure function for element-wise operators with no additional options (e.g. Min, Max, SquaredDiff) |
| 76 | * |
| 77 | */ |
Michalis Spyrou | ce0c675 | 2020-06-18 10:14:57 +0100 | [diff] [blame] | 78 | void configure_common(const ITensorInfo *input1, const ITensorInfo *input2, ITensorInfo *output); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 79 | |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 80 | /** Function to get the micro kernel implementation |
| 81 | * |
| 82 | * @param[in] input1 First input tensor information |
| 83 | * @param[in] input2 Second input tensor information |
| 84 | * @param[in] output Output tensor information |
| 85 | * |
| 86 | * @return the function instance for the micro kernel |
| 87 | */ |
| 88 | virtual std::function<ElementwiseFunction> get_implementation(const ITensorInfo *input1, const ITensorInfo *input2, ITensorInfo *output) = 0; |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 89 | }; |
| 90 | |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 91 | class CpuArithmeticKernel : public CpuElementwiseKernel |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 92 | { |
| 93 | public: |
George Wort | a1e7e28 | 2019-01-15 11:00:29 +0000 | [diff] [blame] | 94 | /** Default constructor */ |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 95 | CpuArithmeticKernel() = default; |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 96 | |
Georgios Pinitas | 1813422 | 2020-09-03 21:00:23 +0100 | [diff] [blame] | 97 | /** Configure kernel |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 98 | * |
Michele Di Giorgio | f9b595a | 2020-07-03 13:34:52 +0100 | [diff] [blame] | 99 | * @param[in] op Arithmetic operation to be executed. |
| 100 | * @param[in] input1 First tensor input info. Data types supported: QASYMM8/S16/F16/S32/F32. |
| 101 | * @param[in] input2 Second tensor input info. Data types supported: Same as @p input1. |
| 102 | * @param[out] output Output tensor info. Data types supported: Same as @p input1. |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 103 | */ |
Michalis Spyrou | ce0c675 | 2020-06-18 10:14:57 +0100 | [diff] [blame] | 104 | void configure(ArithmeticOperation op, const ITensorInfo *input1, const ITensorInfo *input2, ITensorInfo *output); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 105 | |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 106 | /** Static function to check if given info will lead to a valid configuration of @ref cpu::kernels::CpuArithmeticKernel |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 107 | * |
| 108 | * @param[in] op Arithmetic operation to be executed. |
| 109 | * @param[in] input1 First tensor input info. Data types supported: QASYMM8/S16/F16/S32/F32. |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 110 | * @param[in] input2 Second tensor input info. Data types supported: Same as @p input1. |
| 111 | * @param[in] output Output tensor info. Data types supported: Same as @p input1. |
| 112 | * |
| 113 | * @return a Status |
| 114 | */ |
| 115 | static Status validate(ArithmeticOperation op, const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output); |
| 116 | |
| 117 | protected: |
| 118 | // Inherited methods overridden: |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 119 | static Status validate_arguments(const ITensorInfo &input1, const ITensorInfo &input2, const ITensorInfo &output); |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 120 | |
| 121 | ArithmeticOperation _op{}; |
| 122 | |
| 123 | private: |
| 124 | /** Function to get the micro kernel implementation |
| 125 | * |
| 126 | * @param[in] input1 First input tensor information |
| 127 | * @param[in] input2 Second input tensor information |
| 128 | * @param[in] output Output tensor information |
| 129 | * |
| 130 | * @return the function instance for the micro kernel |
| 131 | */ |
| 132 | std::function<ElementwiseFunction> get_implementation(const ITensorInfo *input1, const ITensorInfo *input2, ITensorInfo *output) override; |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 133 | }; |
| 134 | |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 135 | class CpuDivisionKernel : public CpuArithmeticKernel |
George Wort | a1e7e28 | 2019-01-15 11:00:29 +0000 | [diff] [blame] | 136 | { |
| 137 | public: |
| 138 | /** Default constructor */ |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 139 | CpuDivisionKernel() = default; |
George Wort | a1e7e28 | 2019-01-15 11:00:29 +0000 | [diff] [blame] | 140 | |
Georgios Pinitas | 1813422 | 2020-09-03 21:00:23 +0100 | [diff] [blame] | 141 | /** Configure kernel |
George Wort | a1e7e28 | 2019-01-15 11:00:29 +0000 | [diff] [blame] | 142 | * |
Georgios Pinitas | 1813422 | 2020-09-03 21:00:23 +0100 | [diff] [blame] | 143 | * @param[in] input1 First tensor input info. Data types supported: S32/F16/F32. |
Michele Di Giorgio | f9b595a | 2020-07-03 13:34:52 +0100 | [diff] [blame] | 144 | * @param[in] input2 Second tensor input info. Data types supported: Same as @p input1. |
| 145 | * @param[out] output Output tensor info. Data types supported: Same as @p input1. |
George Wort | a1e7e28 | 2019-01-15 11:00:29 +0000 | [diff] [blame] | 146 | */ |
Michalis Spyrou | ce0c675 | 2020-06-18 10:14:57 +0100 | [diff] [blame] | 147 | void configure(const ITensorInfo *input1, const ITensorInfo *input2, ITensorInfo *output); |
George Wort | a1e7e28 | 2019-01-15 11:00:29 +0000 | [diff] [blame] | 148 | |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 149 | /** Static function to check if given info will lead to a valid configuration of @ref CpuDivisionKernel |
George Wort | a1e7e28 | 2019-01-15 11:00:29 +0000 | [diff] [blame] | 150 | * |
Georgios Pinitas | 1813422 | 2020-09-03 21:00:23 +0100 | [diff] [blame] | 151 | * @param[in] input1 First tensor input info. Data types supported: S32/F16/F32. |
George Wort | a1e7e28 | 2019-01-15 11:00:29 +0000 | [diff] [blame] | 152 | * @param[in] input2 Second tensor input info. Data types supported: Same as @p input1. |
| 153 | * @param[in] output Output tensor info. Data types supported: Same as @p input1. |
| 154 | * |
| 155 | * @return a Status |
| 156 | */ |
| 157 | static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output); |
| 158 | |
| 159 | protected: |
| 160 | // Inherited methods overridden: |
| 161 | static Status validate_arguments(const ITensorInfo &input1, const ITensorInfo &input2, const ITensorInfo &output); |
| 162 | }; |
| 163 | |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 164 | class CpuPowerKernel : public CpuArithmeticKernel |
Usama Arif | 81e671e | 2019-05-13 13:33:14 +0100 | [diff] [blame] | 165 | { |
| 166 | public: |
| 167 | /** Default constructor */ |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 168 | CpuPowerKernel() = default; |
Usama Arif | 81e671e | 2019-05-13 13:33:14 +0100 | [diff] [blame] | 169 | |
Georgios Pinitas | 1813422 | 2020-09-03 21:00:23 +0100 | [diff] [blame] | 170 | /** Configure kernel |
Usama Arif | 81e671e | 2019-05-13 13:33:14 +0100 | [diff] [blame] | 171 | * |
Michalis Spyrou | ce0c675 | 2020-06-18 10:14:57 +0100 | [diff] [blame] | 172 | * @param[in] input1 First tensor input info. Data types supported: F16/F32. |
| 173 | * @param[in] input2 Second tensor input info. Data types supported: Same as @p input1. |
| 174 | * @param[out] output Output tensor info. Data types supported: Same as @p input1. |
Usama Arif | 81e671e | 2019-05-13 13:33:14 +0100 | [diff] [blame] | 175 | */ |
Michalis Spyrou | ce0c675 | 2020-06-18 10:14:57 +0100 | [diff] [blame] | 176 | void configure(const ITensorInfo *input1, const ITensorInfo *input2, ITensorInfo *output); |
Usama Arif | 81e671e | 2019-05-13 13:33:14 +0100 | [diff] [blame] | 177 | |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 178 | /** Static function to check if given info will lead to a valid configuration of @ref CpuPowerKernel |
Usama Arif | 81e671e | 2019-05-13 13:33:14 +0100 | [diff] [blame] | 179 | * |
Michele Di Giorgio | f9b595a | 2020-07-03 13:34:52 +0100 | [diff] [blame] | 180 | * @param[in] input1 First tensor input info. Data types supported: F16/F32. |
| 181 | * @param[in] input2 Second tensor input info. Data types supported: Same as @p input1. |
| 182 | * @param[in] output Output tensor info. Data types supported: Same as @p input1. |
Usama Arif | 81e671e | 2019-05-13 13:33:14 +0100 | [diff] [blame] | 183 | * |
| 184 | * @return a Status |
| 185 | */ |
| 186 | static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output); |
| 187 | |
| 188 | protected: |
| 189 | // Inherited methods overridden: |
| 190 | static Status validate_arguments(const ITensorInfo &input1, const ITensorInfo &input2, const ITensorInfo &output); |
| 191 | }; |
| 192 | |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 193 | class CpuComparisonKernel : public CpuElementwiseKernel |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 194 | { |
| 195 | public: |
George Wort | a1e7e28 | 2019-01-15 11:00:29 +0000 | [diff] [blame] | 196 | /** Default constructor */ |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 197 | CpuComparisonKernel() = default; |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 198 | |
Georgios Pinitas | 1813422 | 2020-09-03 21:00:23 +0100 | [diff] [blame] | 199 | /** Configure kernel |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 200 | * |
Michele Di Giorgio | f9b595a | 2020-07-03 13:34:52 +0100 | [diff] [blame] | 201 | * @param[in] op Comparison operation to be executed. |
| 202 | * @param[in] input1 First tensor input info. Data types supported: QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32. |
| 203 | * @param[in] input2 Second tensor input info. Data types supported: Same as @p input1. |
| 204 | * @param[out] output Output tensor info. Data types supported: U8. |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 205 | */ |
Michalis Spyrou | ce0c675 | 2020-06-18 10:14:57 +0100 | [diff] [blame] | 206 | void configure(ComparisonOperation op, const ITensorInfo *input1, const ITensorInfo *input2, ITensorInfo *output); |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 207 | |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 208 | /** Static function to check if given info will lead to a valid configuration of @ref cpu::kernels::CpuComparisonKernel |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 209 | * |
| 210 | * @param[in] op Comparison operation to be executed. |
morgolock | 74a1696 | 2020-01-15 11:40:49 +0000 | [diff] [blame] | 211 | * @param[in] input1 First tensor input info. Data types supported: QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32. |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 212 | * @param[in] input2 Second tensor input info. Data types supported: Same as @p input1. |
Michele Di Giorgio | f9b595a | 2020-07-03 13:34:52 +0100 | [diff] [blame] | 213 | * @param[in] output Output tensor info. Data types supported: U8. |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 214 | * |
| 215 | * @return a Status |
| 216 | */ |
| 217 | static Status validate(ComparisonOperation op, const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output); |
| 218 | |
| 219 | protected: |
| 220 | // Inherited methods overridden: |
| 221 | static Status validate_arguments(const ITensorInfo &input1, const ITensorInfo &input2, const ITensorInfo &output); |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 222 | |
| 223 | private: |
| 224 | /** Function to get the micro kernel implementation |
| 225 | * |
| 226 | * @param[in] input1 First input tensor information |
| 227 | * @param[in] input2 Second input tensor information |
| 228 | * @param[in] output Output tensor information |
| 229 | * |
| 230 | * @return the function instance for the micro kernel |
| 231 | */ |
| 232 | std::function<ElementwiseFunction> get_implementation(const ITensorInfo *input1, const ITensorInfo *input2, ITensorInfo *output) override; |
| 233 | |
| 234 | ComparisonOperation _op{}; |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 235 | }; |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 236 | } // namespace kernels |
| 237 | } // namespace cpu |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 238 | } // namespace arm_compute |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 239 | #endif /* ARM_COMPUTE_CPU_ELEMENTWISE_KERNEL_H */ |