blob: 4392de7b28890549abd5aeb6d246ff209dab7730 [file] [log] [blame]
Michalis Spyrouaea14c62019-01-03 11:10:25 +00001/*
Sheri Zhangac6499a2021-02-10 15:32:38 +00002 * Copyright (c) 2018-2021 Arm Limited.
Michalis Spyrouaea14c62019-01-03 11:10:25 +00003 *
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_NEARGMINMAXLAYER_H
25#define ARM_COMPUTE_NEARGMINMAXLAYER_H
Michalis Spyrouaea14c62019-01-03 11:10:25 +000026
Sang-Hoon Park0fc2d7a2019-11-01 18:50:08 +000027#include "arm_compute/runtime/NEON/functions/NEReductionOperation.h"
28
Michalis Spyrouaea14c62019-01-03 11:10:25 +000029#include "arm_compute/core/Types.h"
30#include "arm_compute/runtime/MemoryGroup.h"
31#include "arm_compute/runtime/NEON/INESimpleFunction.h"
32
33namespace arm_compute
34{
Michele Di Giorgio9637b2e2019-09-23 16:49:49 +010035class ITensor;
Michalis Spyrouaea14c62019-01-03 11:10:25 +000036
Michele Di Giorgio9637b2e2019-09-23 16:49:49 +010037/** Function to calculate the index of the minimum or maximum values in a
38 * tensor based on an axis.
39 *
Michele Di Giorgio33f41fa2021-03-09 14:09:08 +000040 * This function calls the following kernels:
Michalis Spyrouaea14c62019-01-03 11:10:25 +000041 *
42 * -# @ref NEReductionOperationKernel
43 * -# @ref NEFillBorderKernel
44 *
Sang-Hoon Parkeaa01ab2019-11-11 17:33:28 +000045 * @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).
Michalis Spyrouaea14c62019-01-03 11:10:25 +000049 */
50class NEArgMinMaxLayer : public IFunction
51{
52public:
53 /** Constructor */
54 NEArgMinMaxLayer(std::shared_ptr<IMemoryManager> memory_manager = nullptr);
Michalis Spyrouebcebf12020-10-21 00:04:14 +010055 /** 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();
Michalis Spyrouaea14c62019-01-03 11:10:25 +000065 /** Set the input and output tensors.
66 *
Teresa Charlin62687422021-04-28 10:58:49 +010067 * 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 *
Luca Foschianiee939fb2020-01-28 10:38:07 +000079 * @param[in] input Input source tensor. Data types supported: QASYMM8_SIGNED/QASYMM8/S32/F16/F32.
Michalis Spyrouaea14c62019-01-03 11:10:25 +000080 * @param[in] axis Axis to find max/min index.
Michele Di Giorgio9637b2e2019-09-23 16:49:49 +010081 * @param[out] output Output source tensor. Data types supported: U32/S32.
Michalis Spyrouaea14c62019-01-03 11:10:25 +000082 * @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 *
Luca Foschianiee939fb2020-01-28 10:38:07 +000087 * @param[in] input Input source tensor info. Data types supported: QASYMM8_SIGNED/QASYMM8/S32/F16/F32.
Michalis Spyrouaea14c62019-01-03 11:10:25 +000088 * @param[in] axis Axis to find max/min index.
Michele Di Giorgio9637b2e2019-09-23 16:49:49 +010089 * @param[in] output Output source tensor info. Data types supported: U32/S32.
Michalis Spyrouaea14c62019-01-03 11:10:25 +000090 * @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
99private:
Sang-Hoon Park2697fd82019-10-15 16:49:24 +0100100 std::unique_ptr<NEReductionOperation> _reduction_function;
Michalis Spyrouaea14c62019-01-03 11:10:25 +0000101};
102} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000103#endif /* ARM_COMPUTE_NEARGMINMAXLAYER_H */