Georgios Pinitas | d976958 | 2017-08-03 10:19:40 +0100 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2020 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 | */ |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 24 | #ifndef ARM_COMPUTE_NEREDUCTIONOPERATIONKERNEL_H |
| 25 | #define ARM_COMPUTE_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 | 9637b2e | 2019-09-23 16:49:49 +0100 | [diff] [blame] | 33 | /** NEON kernel to perform a reduction operation |
| 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 | * |
Michele Di Giorgio | f9b595a | 2020-07-03 13:34:52 +0100 | [diff] [blame] | 62 | * @param[in] input Source tensor. Data type supported: QASYMM8_SIGNED/QASYMM8/F16/F32/S32. Data layouts supported: NCHW. |
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 | * |
Michele Di Giorgio | f9b595a | 2020-07-03 13:34:52 +0100 | [diff] [blame] | 72 | * @param[in] input Source tensor info. Data type supported: QASYMM8_SIGNED/QASYMM8/F16/F32/S32. Data layouts supported: NCHW. |
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 | */ |
| 80 | static Status validate(const ITensorInfo *input, const ITensorInfo *output, unsigned int axis, ReductionOperation op); |
| 81 | |
Georgios Pinitas | d976958 | 2017-08-03 10:19:40 +0100 | [diff] [blame] | 82 | // Inherited methods overridden: |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 83 | void run(const Window &window, const ThreadInfo &info) override; |
Georgios Pinitas | d976958 | 2017-08-03 10:19:40 +0100 | [diff] [blame] | 84 | |
| 85 | private: |
| 86 | const ITensor *_input; |
| 87 | ITensor *_output; |
| 88 | unsigned int _reduction_axis; |
| 89 | ReductionOperation _op; |
Georgios Pinitas | d976958 | 2017-08-03 10:19:40 +0100 | [diff] [blame] | 90 | }; |
Gian Marco Iodice | 356f643 | 2017-09-22 11:32:21 +0100 | [diff] [blame] | 91 | } // namespace arm_compute |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 92 | #endif /*ARM_COMPUTE_NEREDUCTIONOPERATIONKERNEL_H */ |