xref: /aosp_15_r20/external/ComputeLibrary/arm_compute/runtime/NEON/functions/NEArgMinMaxLayer.h (revision c217d954acce2dbc11938adb493fc0abd69584f3)
1 /*
2  * Copyright (c) 2018-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_NEARGMINMAXLAYER_H
25 #define ARM_COMPUTE_NEARGMINMAXLAYER_H
26 
27 #include "arm_compute/runtime/NEON/functions/NEReductionOperation.h"
28 
29 #include "arm_compute/core/Types.h"
30 #include "arm_compute/runtime/MemoryGroup.h"
31 #include "arm_compute/runtime/NEON/INESimpleFunction.h"
32 
33 namespace arm_compute
34 {
35 class ITensor;
36 
37 /** Function to calculate the index of the minimum or maximum values in a
38  *  tensor based on an axis.
39  *
40  *  This function calls the following kernels:
41  *
42  * -# @ref NEReductionOperationKernel
43  * -# @ref NEFillBorderKernel
44  *
45  * @note The default data type for an uninitialized output tensor is
46  *       signed 32-bit integer (S32). It is the user's responsibility to check
47  *       that the results do not overflow because the indices are computed
48  *       in unsigned 32-bit (U32).
49  */
50 class NEArgMinMaxLayer : public IFunction
51 {
52 public:
53     /** Constructor */
54     NEArgMinMaxLayer(std::shared_ptr<IMemoryManager> memory_manager = nullptr);
55     /** Prevent instances of this class from being copied (As this class contains pointers) */
56     NEArgMinMaxLayer(const NEArgMinMaxLayer &) = delete;
57     /** Prevent instances of this class from being copied (As this class contains pointers) */
58     NEArgMinMaxLayer &operator=(const NEArgMinMaxLayer &) = delete;
59     /** Prevent instances of this class from being moved (As this class contains non movable objects) */
60     NEArgMinMaxLayer(NEArgMinMaxLayer &&) = delete;
61     /** Prevent instances of this class from being moved (As this class contains non movable objects) */
62     NEArgMinMaxLayer &operator=(NEArgMinMaxLayer &&) = delete;
63     /** Default destructor */
64     ~NEArgMinMaxLayer();
65     /** Set the input and output tensors.
66      *
67      * Valid data layouts:
68      * - All
69      *
70      * Valid data type configurations:
71      * |src            |dst        |
72      * |:--------------|:----------|
73      * |QASYMM8        |U32, S32   |
74      * |QASYMM8_SIGNED |U32, S32   |
75      * |S32            |U32, S32   |
76      * |F16            |U32, S32   |
77      * |F32            |U32, S32   |
78      *
79      * @param[in]  input  Input source tensor. Data types supported: QASYMM8_SIGNED/QASYMM8/S32/F16/F32.
80      * @param[in]  axis   Axis to find max/min index.
81      * @param[out] output Output source tensor. Data types supported: U32/S32.
82      * @param[in]  op     Operation to perform: min or max
83      */
84     void configure(ITensor *input, int axis, ITensor *output, const ReductionOperation &op);
85     /** Static function to check if given info will lead to a valid configuration of @ref NEArgMinMaxLayer
86      *
87      * @param[in] input  Input source tensor info. Data types supported: QASYMM8_SIGNED/QASYMM8/S32/F16/F32.
88      * @param[in] axis   Axis to find max/min index.
89      * @param[in] output Output source tensor info. Data types supported: U32/S32.
90      * @param[in] op     Operation to perform: min or max
91      *
92      * @return a status
93      */
94     static Status validate(const ITensorInfo *input, int axis, const ITensorInfo *output, const ReductionOperation &op);
95 
96     // Inherited methods overridden:
97     void run() override;
98 
99 private:
100     std::unique_ptr<NEReductionOperation> _reduction_function;
101 };
102 } // namespace arm_compute
103 #endif /* ARM_COMPUTE_NEARGMINMAXLAYER_H */
104