xref: /aosp_15_r20/external/ComputeLibrary/src/core/NEON/kernels/NEReductionOperationKernel.h (revision c217d954acce2dbc11938adb493fc0abd69584f3)
1 /*
2  * Copyright (c) 2017-2021 Arm Limited.
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  */
24 #ifndef ARM_COMPUTE_NEREDUCTIONOPERATIONKERNEL_H
25 #define ARM_COMPUTE_NEREDUCTIONOPERATIONKERNEL_H
26 
27 #include "src/core/NEON/INEKernel.h"
28 
29 namespace arm_compute
30 {
31 class ITensor;
32 
33 /** Kernel to perform a reduction operation
34  *
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).
39  */
40 class NEReductionOperationKernel : public INEKernel
41 {
42 public:
name()43     const char *name() const override
44     {
45         return "NEReductionOperationKernel";
46     }
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;
59 
60     /** Set the source, destination of the kernel
61      *
62      * @param[in]  input  Source tensor. Data type supported: QASYMM8_SIGNED/QASYMM8/F16/F32/S32.
63      * @param[out] output Destination tensor.Data types and data layouts supported: same as @p input, S32 for ARG_MIX/ARG_MAX.
64      *                    Output will have the same number of dimensions as input.
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);
69 
70     /** Static function to check if given info will lead to a valid configuration of @ref NEReductionOperationKernel.
71      *
72      * @param[in] input  Source tensor info. Data type supported: QASYMM8_SIGNED/QASYMM8/F16/F32/S32.
73      * @param[in] output Destination tensor info.Data types and data layouts supported: same as @p input, S32 for ARG_MIX/ARG_MAX.
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 
82     // Inherited methods overridden:
83     void run(const Window &window, const ThreadInfo &info) override;
84 
85 private:
86     const ITensor     *_input;
87     ITensor           *_output;
88     unsigned int       _reduction_axis;
89     ReductionOperation _op;
90 };
91 } // namespace arm_compute
92 #endif /*ARM_COMPUTE_NEREDUCTIONOPERATIONKERNEL_H */
93