blob: 78bec62c14ed9f2978339cfca4ed9efad728e217 [file] [log] [blame]
Georgios Pinitasd9769582017-08-03 10:19:40 +01001/*
Sheri Zhangac6499a2021-02-10 15:32:38 +00002 * Copyright (c) 2017-2021 Arm Limited.
Georgios Pinitasd9769582017-08-03 10:19:40 +01003 *
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 Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_NEREDUCTIONOPERATIONKERNEL_H
25#define ARM_COMPUTE_NEREDUCTIONOPERATIONKERNEL_H
Georgios Pinitasd9769582017-08-03 10:19:40 +010026
Michalis Spyrouebcebf12020-10-21 00:04:14 +010027#include "src/core/NEON/INEKernel.h"
Georgios Pinitasd9769582017-08-03 10:19:40 +010028
29namespace arm_compute
30{
31class ITensor;
32
Michele Di Giorgio33f41fa2021-03-09 14:09:08 +000033/** Kernel to perform a reduction operation
Michele Di Giorgio9637b2e2019-09-23 16:49:49 +010034 *
Sang-Hoon Parkeaa01ab2019-11-11 17:33:28 +000035 * @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 Giorgio9637b2e2019-09-23 16:49:49 +010039 */
Georgios Pinitasd9769582017-08-03 10:19:40 +010040class NEReductionOperationKernel : public INEKernel
41{
42public:
Anthony Barbiere8a49832018-01-18 10:04:05 +000043 const char *name() const override
44 {
45 return "NEReductionOperationKernel";
46 }
Georgios Pinitasd9769582017-08-03 10:19:40 +010047 /** 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 Richardson73d4aef2018-05-08 14:34:33 +010059
Georgios Pinitasd9769582017-08-03 10:19:40 +010060 /** Set the source, destination of the kernel
61 *
Teresa Charlin62687422021-04-28 10:58:49 +010062 * @param[in] input Source tensor. Data type supported: QASYMM8_SIGNED/QASYMM8/F16/F32/S32.
Michele Di Giorgio9637b2e2019-09-23 16:49:49 +010063 * @param[out] output Destination tensor.Data types and data layouts supported: same as @p input, S32 for ARG_MIX/ARG_MAX.
John Richardson73d4aef2018-05-08 14:34:33 +010064 * Output will have the same number of dimensions as input.
Georgios Pinitasd9769582017-08-03 10:19:40 +010065 * @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 Richardson73d4aef2018-05-08 14:34:33 +010069
70 /** Static function to check if given info will lead to a valid configuration of @ref NEReductionOperationKernel.
71 *
Teresa Charlin62687422021-04-28 10:58:49 +010072 * @param[in] input Source tensor info. Data type supported: QASYMM8_SIGNED/QASYMM8/F16/F32/S32.
Michele Di Giorgio9637b2e2019-09-23 16:49:49 +010073 * @param[in] output Destination tensor info.Data types and data layouts supported: same as @p input, S32 for ARG_MIX/ARG_MAX.
John Richardson73d4aef2018-05-08 14:34:33 +010074 * 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 Thomasmathibalanafd38f02023-09-27 17:46:17 +010080 static Status
81 validate(const ITensorInfo *input, const ITensorInfo *output, unsigned int axis, ReductionOperation op);
John Richardson73d4aef2018-05-08 14:34:33 +010082
Georgios Pinitasd9769582017-08-03 10:19:40 +010083 // Inherited methods overridden:
Moritz Pflanzerc186b572017-09-07 09:48:04 +010084 void run(const Window &window, const ThreadInfo &info) override;
Georgios Pinitasd9769582017-08-03 10:19:40 +010085
86private:
87 const ITensor *_input;
88 ITensor *_output;
89 unsigned int _reduction_axis;
90 ReductionOperation _op;
Georgios Pinitasd9769582017-08-03 10:19:40 +010091};
Gian Marco Iodice356f6432017-09-22 11:32:21 +010092} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +000093#endif /*ARM_COMPUTE_NEREDUCTIONOPERATIONKERNEL_H */