Georgios Pinitas | d976958 | 2017-08-03 10:19:40 +0100 | [diff] [blame] | 1 | /* |
Ramy Elgammal | 21fb2ad | 2024-05-13 11:12:11 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2021, 2024 Arm Limited. |
Georgios Pinitas | d976958 | 2017-08-03 10:19:40 +0100 | [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 |
| 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 | */ |
Ramy Elgammal | 21fb2ad | 2024-05-13 11:12:11 +0100 | [diff] [blame] | 24 | #ifndef ACL_SRC_CORE_NEON_KERNELS_NEREDUCTIONOPERATIONKERNEL_H |
| 25 | #define ACL_SRC_CORE_NEON_KERNELS_NEREDUCTIONOPERATIONKERNEL_H |
Georgios Pinitas | d976958 | 2017-08-03 10:19:40 +0100 | [diff] [blame] | 26 | |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 27 | #include "src/core/NEON/INEKernel.h" |
Georgios Pinitas | d976958 | 2017-08-03 10:19:40 +0100 | [diff] [blame] | 28 | |
| 29 | namespace arm_compute |
| 30 | { |
| 31 | class ITensor; |
| 32 | |
Michele Di Giorgio | 33f41fa | 2021-03-09 14:09:08 +0000 | [diff] [blame] | 33 | /** Kernel to perform a reduction operation |
Michele Di Giorgio | 9637b2e | 2019-09-23 16:49:49 +0100 | [diff] [blame] | 34 | * |
Sang-Hoon Park | eaa01ab | 2019-11-11 17:33:28 +0000 | [diff] [blame] | 35 | * @note For ARG_MIN/ARG_MAX reduction, the default data type for an uninitialized |
| 36 | * output tensor is signed 32-bit integer (S32). It is the user's responsibility |
| 37 | * to check that the results do not overflow because the indices are computed |
| 38 | * in unsigned 32-bit (U32). |
Michele Di Giorgio | 9637b2e | 2019-09-23 16:49:49 +0100 | [diff] [blame] | 39 | */ |
Georgios Pinitas | d976958 | 2017-08-03 10:19:40 +0100 | [diff] [blame] | 40 | class NEReductionOperationKernel : public INEKernel |
| 41 | { |
| 42 | public: |
Anthony Barbier | e8a4983 | 2018-01-18 10:04:05 +0000 | [diff] [blame] | 43 | const char *name() const override |
| 44 | { |
| 45 | return "NEReductionOperationKernel"; |
| 46 | } |
Georgios Pinitas | d976958 | 2017-08-03 10:19:40 +0100 | [diff] [blame] | 47 | /** Default constructor */ |
| 48 | NEReductionOperationKernel(); |
| 49 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 50 | NEReductionOperationKernel(const NEReductionOperationKernel &) = delete; |
| 51 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 52 | NEReductionOperationKernel &operator=(const NEReductionOperationKernel &) = delete; |
| 53 | /** Allow instances of this class to be moved */ |
| 54 | NEReductionOperationKernel(NEReductionOperationKernel &&) = default; |
| 55 | /** Allow instances of this class to be moved */ |
| 56 | NEReductionOperationKernel &operator=(NEReductionOperationKernel &&) = default; |
| 57 | /** Default destructor */ |
| 58 | ~NEReductionOperationKernel() = default; |
John Richardson | 73d4aef | 2018-05-08 14:34:33 +0100 | [diff] [blame] | 59 | |
Georgios Pinitas | d976958 | 2017-08-03 10:19:40 +0100 | [diff] [blame] | 60 | /** Set the source, destination of the kernel |
| 61 | * |
Teresa Charlin | 6268742 | 2021-04-28 10:58:49 +0100 | [diff] [blame] | 62 | * @param[in] input Source tensor. Data type supported: QASYMM8_SIGNED/QASYMM8/F16/F32/S32. |
Michele Di Giorgio | 9637b2e | 2019-09-23 16:49:49 +0100 | [diff] [blame] | 63 | * @param[out] output Destination tensor.Data types and data layouts supported: same as @p input, S32 for ARG_MIX/ARG_MAX. |
John Richardson | 73d4aef | 2018-05-08 14:34:33 +0100 | [diff] [blame] | 64 | * Output will have the same number of dimensions as input. |
Georgios Pinitas | d976958 | 2017-08-03 10:19:40 +0100 | [diff] [blame] | 65 | * @param[in] axis Axis along which to reduce. Supported reduction axis : 0 |
| 66 | * @param[in] op Reduction operation to perform. |
| 67 | */ |
| 68 | void configure(const ITensor *input, ITensor *output, unsigned int axis, ReductionOperation op); |
John Richardson | 73d4aef | 2018-05-08 14:34:33 +0100 | [diff] [blame] | 69 | |
| 70 | /** Static function to check if given info will lead to a valid configuration of @ref NEReductionOperationKernel. |
| 71 | * |
Teresa Charlin | 6268742 | 2021-04-28 10:58:49 +0100 | [diff] [blame] | 72 | * @param[in] input Source tensor info. Data type supported: QASYMM8_SIGNED/QASYMM8/F16/F32/S32. |
Michele Di Giorgio | 9637b2e | 2019-09-23 16:49:49 +0100 | [diff] [blame] | 73 | * @param[in] output Destination tensor info.Data types and data layouts supported: same as @p input, S32 for ARG_MIX/ARG_MAX. |
John Richardson | 73d4aef | 2018-05-08 14:34:33 +0100 | [diff] [blame] | 74 | * Output will have the same number of dimensions as input. |
| 75 | * @param[in] axis Axis along which to reduce. Supported reduction axis : 0 |
| 76 | * @param[in] op Reduction operation to perform. |
| 77 | * |
| 78 | * @return a status |
| 79 | */ |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 80 | static Status |
| 81 | validate(const ITensorInfo *input, const ITensorInfo *output, unsigned int axis, ReductionOperation op); |
John Richardson | 73d4aef | 2018-05-08 14:34:33 +0100 | [diff] [blame] | 82 | |
Ramy Elgammal | 21fb2ad | 2024-05-13 11:12:11 +0100 | [diff] [blame] | 83 | private: |
Georgios Pinitas | d976958 | 2017-08-03 10:19:40 +0100 | [diff] [blame] | 84 | // Inherited methods overridden: |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 85 | void run(const Window &window, const ThreadInfo &info) override; |
Ramy Elgammal | 21fb2ad | 2024-05-13 11:12:11 +0100 | [diff] [blame] | 86 | /** Common signature for all the specialized Reduction functions |
| 87 | * |
| 88 | * @param[in] window Region on which to execute the kernel. |
| 89 | */ |
| 90 | using ReductionFunction = void (*)(const Window &window, const ITensor *in, ITensor *out, ReductionOperation op); |
Georgios Pinitas | d976958 | 2017-08-03 10:19:40 +0100 | [diff] [blame] | 91 | |
Ramy Elgammal | 21fb2ad | 2024-05-13 11:12:11 +0100 | [diff] [blame] | 92 | /** Populate the _func with the right reduction operation handler |
| 93 | */ |
| 94 | void reduce_op(); |
| 95 | |
| 96 | ReductionFunction _func; |
Georgios Pinitas | d976958 | 2017-08-03 10:19:40 +0100 | [diff] [blame] | 97 | const ITensor *_input; |
| 98 | ITensor *_output; |
| 99 | unsigned int _reduction_axis; |
| 100 | ReductionOperation _op; |
Georgios Pinitas | d976958 | 2017-08-03 10:19:40 +0100 | [diff] [blame] | 101 | }; |
Gian Marco Iodice | 356f643 | 2017-09-22 11:32:21 +0100 | [diff] [blame] | 102 | } // namespace arm_compute |
Ramy Elgammal | 21fb2ad | 2024-05-13 11:12:11 +0100 | [diff] [blame] | 103 | #endif // ACL_SRC_CORE_NEON_KERNELS_NEREDUCTIONOPERATIONKERNEL_H |