giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018-2020 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 | */ |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 24 | #ifndef ARM_COMPUTE_NEELEMENTWISEOPERATIONKERNEL_H |
| 25 | #define ARM_COMPUTE_NEELEMENTWISEOPERATIONKERNEL_H |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 26 | |
| 27 | #include "arm_compute/core/NEON/INEKernel.h" |
| 28 | #include "arm_compute/core/Types.h" |
| 29 | |
| 30 | namespace arm_compute |
| 31 | { |
| 32 | class ITensor; |
| 33 | |
| 34 | /** Interface for an element-wise operation kernel |
| 35 | * |
| 36 | * Element-wise operation is computed by: |
| 37 | * @f[ output(x,y) = OP(input1(x,y), input2(x,y))@f] |
| 38 | * |
| 39 | */ |
| 40 | class NEElementwiseOperationKernel : public INEKernel |
| 41 | { |
| 42 | public: |
| 43 | const char *name() const override |
| 44 | { |
| 45 | return "NEElementwiseOperationKernel"; |
| 46 | } |
| 47 | /** Default constructor */ |
| 48 | NEElementwiseOperationKernel(); |
| 49 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 50 | NEElementwiseOperationKernel(const NEElementwiseOperationKernel &) = delete; |
| 51 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 52 | NEElementwiseOperationKernel &operator=(const NEElementwiseOperationKernel &) = delete; |
| 53 | /** Allow instances of this class to be moved */ |
| 54 | NEElementwiseOperationKernel(NEElementwiseOperationKernel &&) = default; |
| 55 | /** Allow instances of this class to be moved */ |
| 56 | NEElementwiseOperationKernel &operator=(NEElementwiseOperationKernel &&) = default; |
| 57 | /** Default destructor */ |
| 58 | ~NEElementwiseOperationKernel() = default; |
| 59 | |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 60 | /** Common signature for all the specialised arithmetic functions |
| 61 | * |
Michele Di Giorgio | f9b595a | 2020-07-03 13:34:52 +0100 | [diff] [blame] | 62 | * @param[in] input1 First tensor input info. Data types supported: QASYMM8/S16/F16/S32/F32. |
| 63 | * @param[in] input2 Second tensor input info. Data types supported: Same as @p input1. |
| 64 | * @param[out] output Output tensor info. Data types supported: Dependent on subclass. |
| 65 | * @param[in] window Region on which to execute the kernel. |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 66 | */ |
| 67 | using ElementwiseFunction = void(const ITensor *input1, const ITensor *input2, ITensor *output, const Window &window); |
| 68 | |
Michalis Spyrou | ce0c675 | 2020-06-18 10:14:57 +0100 | [diff] [blame] | 69 | // Inherited methods overridden: |
Georgios Pinitas | 0499dff | 2020-07-31 22:21:38 +0100 | [diff] [blame] | 70 | void run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) override; |
Michalis Spyrou | ce0c675 | 2020-06-18 10:14:57 +0100 | [diff] [blame] | 71 | |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 72 | protected: |
| 73 | /** Validate the argument passed to the kernel |
| 74 | * |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 75 | * @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] | 76 | * @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] | 77 | * @param[in] output Output tensor. Data types supported: Dependent on subclass. |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 78 | */ |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 79 | 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] | 80 | |
| 81 | /** Commmon configure function for element-wise operators with no additional options (e.g. Min, Max, SquaredDiff) |
| 82 | * |
| 83 | */ |
Michalis Spyrou | ce0c675 | 2020-06-18 10:14:57 +0100 | [diff] [blame] | 84 | void configure_common(const ITensorInfo *input1, const ITensorInfo *input2, ITensorInfo *output); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 85 | |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 86 | /** Function to use for the particular tensor types passed to configure() */ |
| 87 | std::function<void(const ITensor *input1, const ITensor *input2, ITensor *output, const Window &window)> _function; |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 88 | |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 89 | const ITensor *_input1; |
| 90 | const ITensor *_input2; |
| 91 | ITensor *_output; |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | class NEArithmeticOperationKernel : public NEElementwiseOperationKernel |
| 95 | { |
| 96 | public: |
George Wort | a1e7e28 | 2019-01-15 11:00:29 +0000 | [diff] [blame] | 97 | /** Default constructor */ |
| 98 | NEArithmeticOperationKernel() = default; |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 99 | |
| 100 | /** Static function to check if given info will lead to a valid configuration of @ref NEArithmeticOperationKernel |
| 101 | * |
Michele Di Giorgio | f9b595a | 2020-07-03 13:34:52 +0100 | [diff] [blame] | 102 | * @param[in] op Arithmetic operation to be executed. |
| 103 | * @param[in] input1 First tensor input info. Data types supported: QASYMM8/S16/F16/S32/F32. |
| 104 | * @param[in] input2 Second tensor input info. Data types supported: Same as @p input1. |
| 105 | * @param[out] output Output tensor info. Data types supported: Same as @p input1. |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 106 | */ |
Michalis Spyrou | ce0c675 | 2020-06-18 10:14:57 +0100 | [diff] [blame] | 107 | void configure(ArithmeticOperation op, const ITensorInfo *input1, const ITensorInfo *input2, ITensorInfo *output); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 108 | |
| 109 | /** Static function to check if given info will lead to a valid configuration of @ref NEArithmeticOperationKernel |
| 110 | * |
| 111 | * @param[in] op Arithmetic operation to be executed. |
| 112 | * @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] | 113 | * @param[in] input2 Second tensor input info. Data types supported: Same as @p input1. |
| 114 | * @param[in] output Output tensor info. Data types supported: Same as @p input1. |
| 115 | * |
| 116 | * @return a Status |
| 117 | */ |
| 118 | static Status validate(ArithmeticOperation op, const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output); |
| 119 | |
| 120 | protected: |
| 121 | // Inherited methods overridden: |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 122 | static Status validate_arguments(const ITensorInfo &input1, const ITensorInfo &input2, const ITensorInfo &output); |
| 123 | }; |
| 124 | |
George Wort | a1e7e28 | 2019-01-15 11:00:29 +0000 | [diff] [blame] | 125 | class NEDivisionOperationKernel : public NEArithmeticOperationKernel |
| 126 | { |
| 127 | public: |
| 128 | /** Default constructor */ |
| 129 | NEDivisionOperationKernel() = default; |
| 130 | |
| 131 | /** Static function to check if given info will lead to a valid configuration of @ref NEArithmeticOperationKernel |
| 132 | * |
Michele Di Giorgio | f9b595a | 2020-07-03 13:34:52 +0100 | [diff] [blame] | 133 | * @param[in] input1 First tensor input info. Data types supported: F16/F32. |
| 134 | * @param[in] input2 Second tensor input info. Data types supported: Same as @p input1. |
| 135 | * @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] | 136 | */ |
Michalis Spyrou | ce0c675 | 2020-06-18 10:14:57 +0100 | [diff] [blame] | 137 | void configure(const ITensorInfo *input1, const ITensorInfo *input2, ITensorInfo *output); |
George Wort | a1e7e28 | 2019-01-15 11:00:29 +0000 | [diff] [blame] | 138 | |
| 139 | /** Static function to check if given info will lead to a valid configuration of @ref NEArithmeticOperationKernel |
| 140 | * |
| 141 | * @param[in] input1 First tensor input info. Data types supported: F16/F32. |
| 142 | * @param[in] input2 Second tensor input info. Data types supported: Same as @p input1. |
| 143 | * @param[in] output Output tensor info. Data types supported: Same as @p input1. |
| 144 | * |
| 145 | * @return a Status |
| 146 | */ |
| 147 | static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output); |
| 148 | |
| 149 | protected: |
| 150 | // Inherited methods overridden: |
| 151 | static Status validate_arguments(const ITensorInfo &input1, const ITensorInfo &input2, const ITensorInfo &output); |
| 152 | }; |
| 153 | |
Usama Arif | 81e671e | 2019-05-13 13:33:14 +0100 | [diff] [blame] | 154 | class NEPowerOperationKernel : public NEArithmeticOperationKernel |
| 155 | { |
| 156 | public: |
| 157 | /** Default constructor */ |
| 158 | NEPowerOperationKernel() = default; |
| 159 | |
| 160 | /** Static function to check if given info will lead to a valid configuration of @ref NEArithmeticOperationKernel |
| 161 | * |
Michalis Spyrou | ce0c675 | 2020-06-18 10:14:57 +0100 | [diff] [blame] | 162 | * @param[in] input1 First tensor input info. Data types supported: F16/F32. |
| 163 | * @param[in] input2 Second tensor input info. Data types supported: Same as @p input1. |
| 164 | * @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] | 165 | */ |
Michalis Spyrou | ce0c675 | 2020-06-18 10:14:57 +0100 | [diff] [blame] | 166 | void configure(const ITensorInfo *input1, const ITensorInfo *input2, ITensorInfo *output); |
Usama Arif | 81e671e | 2019-05-13 13:33:14 +0100 | [diff] [blame] | 167 | |
| 168 | /** Static function to check if given info will lead to a valid configuration of @ref NEArithmeticOperationKernel |
| 169 | * |
Michele Di Giorgio | f9b595a | 2020-07-03 13:34:52 +0100 | [diff] [blame] | 170 | * @param[in] input1 First tensor input info. Data types supported: F16/F32. |
| 171 | * @param[in] input2 Second tensor input info. Data types supported: Same as @p input1. |
| 172 | * @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] | 173 | * |
| 174 | * @return a Status |
| 175 | */ |
| 176 | static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output); |
| 177 | |
| 178 | protected: |
| 179 | // Inherited methods overridden: |
| 180 | static Status validate_arguments(const ITensorInfo &input1, const ITensorInfo &input2, const ITensorInfo &output); |
| 181 | }; |
| 182 | |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 183 | class NEComparisonOperationKernel : public NEElementwiseOperationKernel |
| 184 | { |
| 185 | public: |
George Wort | a1e7e28 | 2019-01-15 11:00:29 +0000 | [diff] [blame] | 186 | /** Default constructor */ |
| 187 | NEComparisonOperationKernel() = default; |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 188 | |
| 189 | /** Static function to check if given info will lead to a valid configuration of @ref NEComparisonOperationKernel |
| 190 | * |
Michele Di Giorgio | f9b595a | 2020-07-03 13:34:52 +0100 | [diff] [blame] | 191 | * @param[in] op Comparison operation to be executed. |
| 192 | * @param[in] input1 First tensor input info. Data types supported: QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32. |
| 193 | * @param[in] input2 Second tensor input info. Data types supported: Same as @p input1. |
| 194 | * @param[out] output Output tensor info. Data types supported: U8. |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 195 | */ |
Michalis Spyrou | ce0c675 | 2020-06-18 10:14:57 +0100 | [diff] [blame] | 196 | void configure(ComparisonOperation op, const ITensorInfo *input1, const ITensorInfo *input2, ITensorInfo *output); |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 197 | |
| 198 | /** Static function to check if given info will lead to a valid configuration of @ref NEComparisonOperationKernel |
| 199 | * |
| 200 | * @param[in] op Comparison operation to be executed. |
morgolock | 74a1696 | 2020-01-15 11:40:49 +0000 | [diff] [blame] | 201 | * @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] | 202 | * @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] | 203 | * @param[in] output Output tensor info. Data types supported: U8. |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 204 | * |
| 205 | * @return a Status |
| 206 | */ |
| 207 | static Status validate(ComparisonOperation op, const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output); |
| 208 | |
| 209 | protected: |
| 210 | // Inherited methods overridden: |
| 211 | static Status validate_arguments(const ITensorInfo &input1, const ITensorInfo &input2, const ITensorInfo &output); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 212 | }; |
| 213 | } // namespace arm_compute |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 214 | #endif /* ARM_COMPUTE_NEELEMENTWISEOPERATIONKERNEL_H */ |