giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 1 | /* |
morgolock | a359805 | 2019-12-31 12:20:47 +0000 | [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 |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 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_NEELEMENTWISEOPERATIONS_H |
| 25 | #define ARM_COMPUTE_NEELEMENTWISEOPERATIONS_H |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 26 | |
| 27 | #include "arm_compute/core/Types.h" |
| 28 | #include "arm_compute/runtime/NEON/INESimpleFunction.h" |
| 29 | |
| 30 | namespace arm_compute |
| 31 | { |
| 32 | class ITensor; |
| 33 | |
| 34 | /** Basic function to run @ref NEArithmeticOperationKernel for max |
| 35 | * |
morgolock | 6427c82 | 2020-01-13 11:53:20 +0000 | [diff] [blame] | 36 | * @note The tensor data type for the inputs must be QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32. |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 37 | * @note The function performs a max operation between two tensors. |
| 38 | */ |
| 39 | class NEElementwiseMax : public INESimpleFunction |
| 40 | { |
| 41 | public: |
| 42 | /** Initialise the kernel's inputs, output and conversion policy. |
| 43 | * |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 44 | * @param[in, out] input1 First tensor input. Data types supported: QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32. |
| 45 | * @param[in, out] input2 Second tensor input. Data types supported: Same as @p input1. |
| 46 | * @param[out] output Output tensor. Data types supported: Same as @p input1. |
| 47 | * @param[in] act_info (Optional) Activation layer information in case of a fused activation. Currently not supported. |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 48 | */ |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 49 | void configure(ITensor *input1, ITensor *input2, ITensor *output, const ActivationLayerInfo &act_info = ActivationLayerInfo()); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 50 | /** Static function to check if given info will lead to a valid configuration of @ref NEArithmeticOperationKernel for max |
| 51 | * |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 52 | * @param[in] input1 First tensor input info. Data types supported: QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32. |
| 53 | * @param[in] input2 Second tensor input info. Data types supported: Same as @p input1. |
| 54 | * @param[in] output Output tensor info. Data types supported: Same as @p input1. |
| 55 | * @param[in] act_info (Optional) Activation layer information in case of a fused activation. Currently not supported. |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 56 | * |
| 57 | * @return a status |
| 58 | */ |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 59 | static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info = ActivationLayerInfo()); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | /** Basic function to run @ref NEArithmeticOperationKernel for min |
| 63 | * |
morgolock | 6427c82 | 2020-01-13 11:53:20 +0000 | [diff] [blame] | 64 | * @note The tensor data type for the inputs must be QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32. |
| 65 | * @note The function performs a min operation between two tensors. |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 66 | */ |
| 67 | class NEElementwiseMin : public INESimpleFunction |
| 68 | { |
| 69 | public: |
| 70 | /** Initialise the kernel's inputs, output and conversion policy. |
| 71 | * |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 72 | * @param[in, out] input1 First tensor input. Data types supported: QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32. |
| 73 | * @param[in, out] input2 Second tensor input. Data types supported: Same as @p input1. |
| 74 | * @param[out] output Output tensor. Data types supported: Same as @p input1. |
| 75 | * @param[in] act_info (Optional) Activation layer information in case of a fused activation. Currently not supported. |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 76 | */ |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 77 | void configure(ITensor *input1, ITensor *input2, ITensor *output, const ActivationLayerInfo &act_info = ActivationLayerInfo()); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 78 | /** Static function to check if given info will lead to a valid configuration of @ref NEArithmeticOperationKernel for min |
| 79 | * |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 80 | * @param[in] input1 First tensor input info. Data types supported: QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32. |
| 81 | * @param[in] input2 Second tensor input info. Data types supported: Same as @p input1. |
| 82 | * @param[in] output Output tensor info. Data types supported: Same as @p input1. |
| 83 | * @param[in] act_info (Optional) Activation layer information in case of a fused activation. Currently not supported. |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 84 | * |
| 85 | * @return a status |
| 86 | */ |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 87 | static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info = ActivationLayerInfo()); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | /** Basic function to run @ref NEArithmeticOperationKernel for squared difference |
| 91 | * |
morgolock | 6427c82 | 2020-01-13 11:53:20 +0000 | [diff] [blame] | 92 | * @note The tensor data type for the inputs must be QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32. |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 93 | * @note The function performs a squared different operation between two tensors (i.e., out[i] = (in1[i] - in2[i])^2 |
| 94 | */ |
| 95 | class NEElementwiseSquaredDiff : public INESimpleFunction |
| 96 | { |
| 97 | public: |
| 98 | /** Initialise the kernel's inputs, output and conversion policy. |
| 99 | * |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 100 | * @param[in, out] input1 First tensor input. Data types supported: QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32. |
| 101 | * @param[in, out] input2 Second tensor input. Data types supported: Same as @p input1. |
| 102 | * @param[out] output Output tensor. Data types supported: Same as @p input1. |
| 103 | * @param[in] act_info (Optional) Activation layer information in case of a fused activation. Currently not supported. |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 104 | */ |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 105 | void configure(ITensor *input1, ITensor *input2, ITensor *output, const ActivationLayerInfo &act_info = ActivationLayerInfo()); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 106 | /** Static function to check if given info will lead to a valid configuration of @ref NEArithmeticOperationKernel for squared difference |
| 107 | * |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 108 | * @param[in] input1 First tensor input info. Data types supported: QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32. |
| 109 | * @param[in] input2 Second tensor input info. Data types supported: Same as @p input1. |
| 110 | * @param[in] output Output tensor info. Data types supported: Same as @p input1. |
| 111 | * @param[in] act_info (Optional) Activation layer information in case of a fused activation. Currently not supported. |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 112 | * |
| 113 | * @return a status |
| 114 | */ |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 115 | static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info = ActivationLayerInfo()); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 116 | }; |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 117 | |
George Wort | a1e7e28 | 2019-01-15 11:00:29 +0000 | [diff] [blame] | 118 | /** Basic function to run @ref NEArithmeticOperationKernel for division |
| 119 | * |
| 120 | * @note The tensor data type for the inputs must be F16/F32. |
| 121 | * @note The function performs a squared different operation between two tensors (i.e., out[i] = in1[i] / in2[i]) |
| 122 | */ |
| 123 | class NEElementwiseDivision : public INESimpleFunction |
| 124 | { |
| 125 | public: |
| 126 | /** Initialise the kernel's inputs, output and conversion policy. |
| 127 | * |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 128 | * @param[in, out] input1 First tensor input. Data types supported: F16/F32. |
| 129 | * @param[in, out] input2 Second tensor input. Data types supported: Same as @p input1. |
| 130 | * @param[out] output Output tensor. Data types supported: Same as @p input1. |
| 131 | * @param[in] act_info (Optional) Activation layer information in case of a fused activation. Currently not supported. |
George Wort | a1e7e28 | 2019-01-15 11:00:29 +0000 | [diff] [blame] | 132 | */ |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 133 | void configure(ITensor *input1, ITensor *input2, ITensor *output, const ActivationLayerInfo &act_info = ActivationLayerInfo()); |
George Wort | a1e7e28 | 2019-01-15 11:00:29 +0000 | [diff] [blame] | 134 | /** Static function to check if given info will lead to a valid configuration of @ref NEArithmeticOperationKernel for division |
| 135 | * |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 136 | * @param[in] input1 First tensor input info. Data types supported: F16/F32. |
| 137 | * @param[in] input2 Second tensor input info. Data types supported: Same as @p input1. |
| 138 | * @param[in] output Output tensor info. Data types supported: Same as @p input1. |
| 139 | * @param[in] act_info (Optional) Activation layer information in case of a fused activation. Currently not supported. |
George Wort | a1e7e28 | 2019-01-15 11:00:29 +0000 | [diff] [blame] | 140 | * |
| 141 | * @return a status |
| 142 | */ |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 143 | static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info = ActivationLayerInfo()); |
George Wort | a1e7e28 | 2019-01-15 11:00:29 +0000 | [diff] [blame] | 144 | }; |
| 145 | |
Usama Arif | 81e671e | 2019-05-13 13:33:14 +0100 | [diff] [blame] | 146 | /** Basic function to run @ref NEArithmeticOperationKernel for power |
| 147 | * |
| 148 | * @note The tensor data type for the inputs must be F16/F32. |
| 149 | * @note The function performs a elementwise power of in1 to in2 (i.e., out[i] = in1[i] ^ in2[i]) |
| 150 | * @note For an exponent that is a float, this function will only work with a positive base. |
| 151 | */ |
| 152 | class NEElementwisePower : public INESimpleFunction |
| 153 | { |
| 154 | public: |
| 155 | /** Initialise the kernel's inputs, output and conversion policy. |
| 156 | * |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 157 | * @param[in, out] input1 First tensor input. Data types supported: F16/F32. |
| 158 | * @param[in, out] input2 Second tensor input. Data types supported: Same as @p input1. |
| 159 | * @param[out] output Output tensor. Data types supported: Same as @p input1. |
| 160 | * @param[in] act_info (Optional) Activation layer information in case of a fused activation. Currently not supported. |
Usama Arif | 81e671e | 2019-05-13 13:33:14 +0100 | [diff] [blame] | 161 | */ |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 162 | void configure(ITensor *input1, ITensor *input2, ITensor *output, const ActivationLayerInfo &act_info = ActivationLayerInfo()); |
Usama Arif | 81e671e | 2019-05-13 13:33:14 +0100 | [diff] [blame] | 163 | /** Static function to check if given info will lead to a valid configuration of @ref NEArithmeticOperationKernel for power |
| 164 | * |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 165 | * @param[in] input1 First tensor input info. Data types supported: F16/F32. |
| 166 | * @param[in] input2 Second tensor input info. Data types supported: Same as @p input1. |
| 167 | * @param[in] output Output tensor info. Data types supported: Same as @p input1. |
| 168 | * @param[in] act_info (Optional) Activation layer information in case of a fused activation. Currently not supported. |
Usama Arif | 81e671e | 2019-05-13 13:33:14 +0100 | [diff] [blame] | 169 | * |
| 170 | * @return a status |
| 171 | */ |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 172 | static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info = ActivationLayerInfo()); |
Usama Arif | 81e671e | 2019-05-13 13:33:14 +0100 | [diff] [blame] | 173 | }; |
| 174 | |
George Wort | a1e7e28 | 2019-01-15 11:00:29 +0000 | [diff] [blame] | 175 | /** Basic function to run @ref NEComparisonOperationKernel. |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 176 | * |
morgolock | 74a1696 | 2020-01-15 11:40:49 +0000 | [diff] [blame] | 177 | * @note The tensor data type for the inputs must be QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32. |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 178 | * @note The function performs a comparison operation between two tensors. |
| 179 | */ |
| 180 | class NEElementwiseComparison : public INESimpleFunction |
| 181 | { |
| 182 | public: |
| 183 | /** Initialise the kernel's inputs, output and conversion policy. |
| 184 | * |
morgolock | 74a1696 | 2020-01-15 11:40:49 +0000 | [diff] [blame] | 185 | * @param[in, out] input1 First tensor input. Data types supported: QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32. |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 186 | * @param[in, out] input2 Second tensor input. Data types supported: Same as @p input1. |
| 187 | * @param[out] output Output tensor. Data types supported: U16/U32. |
| 188 | * @param[in] op Comparison Operation to be performed. |
| 189 | */ |
| 190 | void configure(ITensor *input1, ITensor *input2, ITensor *output, ComparisonOperation op); |
| 191 | /** Static function to check if given info will lead to a valid configuration of @ref NEComparisonOperationKernel |
| 192 | * |
morgolock | 74a1696 | 2020-01-15 11:40:49 +0000 | [diff] [blame] | 193 | * @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] | 194 | * @param[in] input2 Second tensor input info. Data types supported: Same as @p input1. |
| 195 | * @param[in] output Output tensor info. Data types supported: U16/U32. |
| 196 | * @param[in] op Comparison Operation to be performed. |
| 197 | * |
| 198 | * @return a status |
| 199 | */ |
| 200 | static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, ComparisonOperation op); |
| 201 | }; |
| 202 | |
| 203 | /** Basic function to run @ref NEComparisonOperationKernel |
| 204 | * |
morgolock | 74a1696 | 2020-01-15 11:40:49 +0000 | [diff] [blame] | 205 | * @note The tensor data type for the inputs must be QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32. |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 206 | * @note The function performs a comparison operation between two tensors. |
| 207 | */ |
| 208 | template <ComparisonOperation op> |
| 209 | class NEElementwiseComparisonStatic : public INESimpleFunction |
| 210 | { |
| 211 | public: |
| 212 | /** Initialise the kernel's inputs, output and conversion policy. |
| 213 | * |
morgolock | 74a1696 | 2020-01-15 11:40:49 +0000 | [diff] [blame] | 214 | * @param[in, out] input1 First tensor input. Data types supported: QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32. |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 215 | * @param[in, out] input2 Second tensor input. Data types supported: Same as @p input1. |
| 216 | * @param[out] output Output tensor. Data types supported: U16/U32. |
| 217 | */ |
| 218 | void configure(ITensor *input1, ITensor *input2, ITensor *output); |
| 219 | /** Static function to check if given info will lead to a valid configuration of @ref NEComparisonOperationKernel |
| 220 | * |
morgolock | 74a1696 | 2020-01-15 11:40:49 +0000 | [diff] [blame] | 221 | * @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] | 222 | * @param[in] input2 Second tensor input info. Data types supported: Same as @p input1. |
| 223 | * @param[in] output Output tensor info. Data types supported: U16/U32. |
| 224 | * |
| 225 | * @return a status |
| 226 | */ |
| 227 | static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output); |
| 228 | }; |
| 229 | |
| 230 | /** Basic function to run equal comparison. */ |
| 231 | using NEEqual = NEElementwiseComparisonStatic<ComparisonOperation::Equal>; |
| 232 | /** Basic function to run not equal comparison. */ |
| 233 | using NENotEqual = NEElementwiseComparisonStatic<ComparisonOperation::NotEqual>; |
| 234 | /** Basic function to run greater comparison. */ |
| 235 | using NEGreater = NEElementwiseComparisonStatic<ComparisonOperation::Greater>; |
| 236 | /** Basic function to run greater-equal comparison. */ |
| 237 | using NEGreaterEqual = NEElementwiseComparisonStatic<ComparisonOperation::GreaterEqual>; |
| 238 | /** Basic function to run less comparison. */ |
| 239 | using NELess = NEElementwiseComparisonStatic<ComparisonOperation::Less>; |
| 240 | /** Basic function to run less-equal comparison. */ |
| 241 | using NELessEqual = NEElementwiseComparisonStatic<ComparisonOperation::LessEqual>; |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 242 | } // namespace arm_compute |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 243 | #endif /* ARM_COMPUTE_NEELEMENTWISEOPERATIONS_H */ |