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" |
Georgios Pinitas | 7891a73 | 2021-08-20 21:39:25 +0100 | [diff] [blame] | 28 | #include "src/cpu/ICpuKernel.h" |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 29 | |
| 30 | namespace arm_compute |
| 31 | { |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 32 | namespace cpu |
| 33 | { |
| 34 | namespace kernels |
| 35 | { |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 36 | /** Interface for an element-wise operation kernel |
| 37 | * |
| 38 | * Element-wise operation is computed by: |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 39 | * @f[ dst(x,y) = OP(src0(x,y), src1(x,y))@f] |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 40 | * |
| 41 | */ |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 42 | class CpuElementwiseKernel : public ICpuKernel |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 43 | { |
| 44 | public: |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 45 | CpuElementwiseKernel() = default; |
| 46 | ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE(CpuElementwiseKernel); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 47 | |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 48 | using ElementwiseFunction = void(const ITensor *, const ITensor *, ITensor *, const Window &); |
Georgios Pinitas | 5fdde99 | 2021-06-25 05:42:57 +0100 | [diff] [blame] | 49 | struct UKernelInfo |
| 50 | { |
| 51 | std::string name; |
| 52 | std::function<ElementwiseFunction> ukernel; |
| 53 | }; |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 54 | |
Michalis Spyrou | ce0c675 | 2020-06-18 10:14:57 +0100 | [diff] [blame] | 55 | // Inherited methods overridden: |
Georgios Pinitas | 0499dff | 2020-07-31 22:21:38 +0100 | [diff] [blame] | 56 | void run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) override; |
Georgios Pinitas | 5fdde99 | 2021-06-25 05:42:57 +0100 | [diff] [blame] | 57 | const char *name() const override; |
Michalis Spyrou | ce0c675 | 2020-06-18 10:14:57 +0100 | [diff] [blame] | 58 | |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 59 | protected: |
| 60 | /** Validate the argument passed to the kernel |
| 61 | * |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 62 | * @param[in] src0 First tensor input. Data types supported: QASYMM8/S16/F16/S32/F32. |
| 63 | * @param[in] src1 Second tensor input. Data types supported: Same as @p src0. |
| 64 | * @param[in] dst Output tensor. Data types supported: Dependent on subclass. |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 65 | */ |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 66 | static Status validate_arguments_common(const ITensorInfo &src0, const ITensorInfo &src1, const ITensorInfo &dst); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 67 | |
| 68 | /** Commmon configure function for element-wise operators with no additional options (e.g. Min, Max, SquaredDiff) |
| 69 | * |
| 70 | */ |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 71 | void configure_common(const ITensorInfo *src0, const ITensorInfo *src1, ITensorInfo *dst); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 72 | |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 73 | /** Function to get the micro kernel implementation |
| 74 | * |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 75 | * @param[in] src0 First input tensor information |
| 76 | * @param[in] src1 Second input tensor information |
| 77 | * @param[in] dst Output tensor information |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 78 | * |
| 79 | * @return the function instance for the micro kernel |
| 80 | */ |
Georgios Pinitas | 5fdde99 | 2021-06-25 05:42:57 +0100 | [diff] [blame] | 81 | virtual UKernelInfo get_implementation(const ITensorInfo *src0, const ITensorInfo *src1, ITensorInfo *dst) = 0; |
| 82 | |
| 83 | protected: |
| 84 | std::function<ElementwiseFunction> _run_method{ nullptr }; |
| 85 | std::string _name{}; |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 86 | }; |
| 87 | |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 88 | class CpuArithmeticKernel : public CpuElementwiseKernel |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 89 | { |
| 90 | public: |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 91 | CpuArithmeticKernel() = default; |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 92 | |
Georgios Pinitas | 1813422 | 2020-09-03 21:00:23 +0100 | [diff] [blame] | 93 | /** Configure kernel |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 94 | * |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 95 | * @param[in] op Arithmetic operation to be executed. |
| 96 | * @param[in] src0 First tensor input info. Data types supported: QASYMM8/S16/F16/S32/F32. |
| 97 | * @param[in] src1 Second tensor input info. Data types supported: Same as @p src0. |
| 98 | * @param[out] dst Output tensor info. Data types supported: Same as @p src0. |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 99 | */ |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 100 | void configure(ArithmeticOperation op, const ITensorInfo *src0, const ITensorInfo *src1, ITensorInfo *dst); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 101 | |
Georgios Pinitas | 5fdde99 | 2021-06-25 05:42:57 +0100 | [diff] [blame] | 102 | /** Static function to check if given info will lead to a valid configuration |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 103 | * |
Georgios Pinitas | 5fdde99 | 2021-06-25 05:42:57 +0100 | [diff] [blame] | 104 | * Similar to CpuArithmeticKernel::configure() |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 105 | * |
Georgios Pinitas | 5fdde99 | 2021-06-25 05:42:57 +0100 | [diff] [blame] | 106 | * @return a status |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 107 | */ |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 108 | static Status validate(ArithmeticOperation op, const ITensorInfo *src0, const ITensorInfo *src1, const ITensorInfo *dst); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 109 | |
| 110 | protected: |
| 111 | // Inherited methods overridden: |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 112 | static Status validate_arguments(const ITensorInfo &src0, const ITensorInfo &src1, const ITensorInfo &dst); |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 113 | |
| 114 | ArithmeticOperation _op{}; |
| 115 | |
| 116 | private: |
| 117 | /** Function to get the micro kernel implementation |
| 118 | * |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 119 | * @param[in] src0 First input tensor information |
| 120 | * @param[in] src1 Second input tensor information |
| 121 | * @param[in] dst Output tensor information |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 122 | * |
| 123 | * @return the function instance for the micro kernel |
| 124 | */ |
Georgios Pinitas | 5fdde99 | 2021-06-25 05:42:57 +0100 | [diff] [blame] | 125 | UKernelInfo get_implementation(const ITensorInfo *src0, const ITensorInfo *src1, ITensorInfo *dst) override; |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 126 | }; |
| 127 | |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 128 | class CpuDivisionKernel : public CpuArithmeticKernel |
George Wort | a1e7e28 | 2019-01-15 11:00:29 +0000 | [diff] [blame] | 129 | { |
| 130 | public: |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 131 | CpuDivisionKernel() = default; |
George Wort | a1e7e28 | 2019-01-15 11:00:29 +0000 | [diff] [blame] | 132 | |
Georgios Pinitas | 1813422 | 2020-09-03 21:00:23 +0100 | [diff] [blame] | 133 | /** Configure kernel |
George Wort | a1e7e28 | 2019-01-15 11:00:29 +0000 | [diff] [blame] | 134 | * |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 135 | * @param[in] src0 First tensor input info. Data types supported: S32/F16/F32. |
| 136 | * @param[in] src1 Second tensor input info. Data types supported: Same as @p src0. |
| 137 | * @param[out] dst Output tensor info. Data types supported: Same as @p src0. |
George Wort | a1e7e28 | 2019-01-15 11:00:29 +0000 | [diff] [blame] | 138 | */ |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 139 | void configure(const ITensorInfo *src0, const ITensorInfo *src1, ITensorInfo *dst); |
George Wort | a1e7e28 | 2019-01-15 11:00:29 +0000 | [diff] [blame] | 140 | |
Georgios Pinitas | 5fdde99 | 2021-06-25 05:42:57 +0100 | [diff] [blame] | 141 | /** Static function to check if given info will lead to a valid configuration |
George Wort | a1e7e28 | 2019-01-15 11:00:29 +0000 | [diff] [blame] | 142 | * |
Georgios Pinitas | 5fdde99 | 2021-06-25 05:42:57 +0100 | [diff] [blame] | 143 | * Similar to CpuDivisionKernel::configure() |
George Wort | a1e7e28 | 2019-01-15 11:00:29 +0000 | [diff] [blame] | 144 | * |
Georgios Pinitas | 5fdde99 | 2021-06-25 05:42:57 +0100 | [diff] [blame] | 145 | * @return a status |
George Wort | a1e7e28 | 2019-01-15 11:00:29 +0000 | [diff] [blame] | 146 | */ |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 147 | static Status validate(const ITensorInfo *src0, const ITensorInfo *src1, const ITensorInfo *dst); |
George Wort | a1e7e28 | 2019-01-15 11:00:29 +0000 | [diff] [blame] | 148 | |
| 149 | protected: |
| 150 | // Inherited methods overridden: |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 151 | static Status validate_arguments(const ITensorInfo &src0, const ITensorInfo &src1, const ITensorInfo &dst); |
George Wort | a1e7e28 | 2019-01-15 11:00:29 +0000 | [diff] [blame] | 152 | }; |
| 153 | |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 154 | class CpuPowerKernel : public CpuArithmeticKernel |
Usama Arif | 81e671e | 2019-05-13 13:33:14 +0100 | [diff] [blame] | 155 | { |
| 156 | public: |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 157 | CpuPowerKernel() = default; |
Usama Arif | 81e671e | 2019-05-13 13:33:14 +0100 | [diff] [blame] | 158 | |
Georgios Pinitas | 1813422 | 2020-09-03 21:00:23 +0100 | [diff] [blame] | 159 | /** Configure kernel |
Usama Arif | 81e671e | 2019-05-13 13:33:14 +0100 | [diff] [blame] | 160 | * |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 161 | * @param[in] src0 First tensor input info. Data types supported: F16/F32. |
| 162 | * @param[in] src1 Second tensor input info. Data types supported: Same as @p src0. |
| 163 | * @param[out] dst Output tensor info. Data types supported: Same as @p src0. |
Usama Arif | 81e671e | 2019-05-13 13:33:14 +0100 | [diff] [blame] | 164 | */ |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 165 | void configure(const ITensorInfo *src0, const ITensorInfo *src1, ITensorInfo *dst); |
Usama Arif | 81e671e | 2019-05-13 13:33:14 +0100 | [diff] [blame] | 166 | |
Georgios Pinitas | 5fdde99 | 2021-06-25 05:42:57 +0100 | [diff] [blame] | 167 | /** Static function to check if given info will lead to a valid configuration |
Usama Arif | 81e671e | 2019-05-13 13:33:14 +0100 | [diff] [blame] | 168 | * |
Georgios Pinitas | 5fdde99 | 2021-06-25 05:42:57 +0100 | [diff] [blame] | 169 | * Similar to CpuPowerKernel::configure() |
Usama Arif | 81e671e | 2019-05-13 13:33:14 +0100 | [diff] [blame] | 170 | * |
Georgios Pinitas | 5fdde99 | 2021-06-25 05:42:57 +0100 | [diff] [blame] | 171 | * @return a status |
Usama Arif | 81e671e | 2019-05-13 13:33:14 +0100 | [diff] [blame] | 172 | */ |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 173 | static Status validate(const ITensorInfo *src0, const ITensorInfo *src1, const ITensorInfo *dst); |
Usama Arif | 81e671e | 2019-05-13 13:33:14 +0100 | [diff] [blame] | 174 | |
| 175 | protected: |
| 176 | // Inherited methods overridden: |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 177 | static Status validate_arguments(const ITensorInfo &src0, const ITensorInfo &src1, const ITensorInfo &dst); |
Usama Arif | 81e671e | 2019-05-13 13:33:14 +0100 | [diff] [blame] | 178 | }; |
| 179 | |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 180 | class CpuComparisonKernel : public CpuElementwiseKernel |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 181 | { |
| 182 | public: |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 183 | CpuComparisonKernel() = default; |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 184 | |
Georgios Pinitas | 1813422 | 2020-09-03 21:00:23 +0100 | [diff] [blame] | 185 | /** Configure kernel |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 186 | * |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 187 | * @param[in] op Comparison operation to be executed. |
| 188 | * @param[in] src0 First tensor input info. Data types supported: QASYMM8/QASYMM8_SIGNED/S16/F16/S32/F32. |
| 189 | * @param[in] src1 Second tensor input info. Data types supported: Same as @p src0. |
| 190 | * @param[out] dst Output tensor info. Data types supported: U8. |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 191 | */ |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 192 | void configure(ComparisonOperation op, const ITensorInfo *src0, const ITensorInfo *src1, ITensorInfo *dst); |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 193 | |
Georgios Pinitas | 5fdde99 | 2021-06-25 05:42:57 +0100 | [diff] [blame] | 194 | /** Static function to check if given info will lead to a valid configuration |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 195 | * |
Georgios Pinitas | 5fdde99 | 2021-06-25 05:42:57 +0100 | [diff] [blame] | 196 | * Similar to CpuComparisonKernel::configure() |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 197 | * |
Georgios Pinitas | 5fdde99 | 2021-06-25 05:42:57 +0100 | [diff] [blame] | 198 | * @return a status |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 199 | */ |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 200 | static Status validate(ComparisonOperation op, const ITensorInfo *src0, const ITensorInfo *src1, const ITensorInfo *dst); |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 201 | |
| 202 | protected: |
| 203 | // Inherited methods overridden: |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 204 | static Status validate_arguments(const ITensorInfo &src0, const ITensorInfo &src1, const ITensorInfo &dst); |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 205 | |
| 206 | private: |
| 207 | /** Function to get the micro kernel implementation |
| 208 | * |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 209 | * @param[in] src0 First input tensor information |
| 210 | * @param[in] src1 Second input tensor information |
| 211 | * @param[in] dst Output tensor information |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 212 | * |
| 213 | * @return the function instance for the micro kernel |
| 214 | */ |
Georgios Pinitas | 5fdde99 | 2021-06-25 05:42:57 +0100 | [diff] [blame] | 215 | UKernelInfo get_implementation(const ITensorInfo *src0, const ITensorInfo *src1, ITensorInfo *dst) override; |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 216 | |
| 217 | ComparisonOperation _op{}; |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 218 | }; |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 219 | } // namespace kernels |
| 220 | } // namespace cpu |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 221 | } // namespace arm_compute |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 222 | #endif /* ARM_COMPUTE_CPU_ELEMENTWISE_KERNEL_H */ |