blob: fb3b41b0de0aa084b2cbe94d9ca43de6b46ae1fb [file] [log] [blame]
Manuel Bottini7b9998d2019-10-21 17:59:07 +01001/*
Pablo Marquez Tello9b392d72023-06-27 15:49:50 +01002 * Copyright (c) 2019-2020, 2023 Arm Limited.
Manuel Bottini7b9998d2019-10-21 17:59:07 +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 */
24#ifndef ARM_COMPUTE_CLARGMINMAXLAYERKERNEL_H
25#define ARM_COMPUTE_CLARGMINMAXLAYERKERNEL_H
26
Manuel Bottini7b9998d2019-10-21 17:59:07 +010027#include "arm_compute/core/Types.h"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010028
Sang-Hoon Parkbef7fa22020-10-21 15:58:54 +010029#include "src/core/CL/ICLKernel.h"
Manuel Bottini7b9998d2019-10-21 17:59:07 +010030
31namespace arm_compute
32{
33class ICLTensor;
34
35/** Interface for the reduction operation kernel
36 *
37 * @note The default data type for an uninitialized output tensor is
38 * signed 32-bit integer (S32). It is the user's responsibility to check
39 * that the results do not overflow because the indices are computed
40 * in unsigned 32-bit (U32).
41 */
42class CLArgMinMaxLayerKernel : public ICLKernel
43{
44public:
45 /** Default constructor */
46 CLArgMinMaxLayerKernel();
47 /** Prevent instances of this class from being copied (As this class contains pointers) */
48 CLArgMinMaxLayerKernel(const CLArgMinMaxLayerKernel &) = delete;
49 /** Prevent instances of this class from being copied (As this class contains pointers) */
50 CLArgMinMaxLayerKernel &operator=(const CLArgMinMaxLayerKernel &) = delete;
51 /** Allow instances of this class to be moved */
52 CLArgMinMaxLayerKernel(CLArgMinMaxLayerKernel &&) = default;
53 /** Allow instances of this class to be moved */
54 CLArgMinMaxLayerKernel &operator=(CLArgMinMaxLayerKernel &&) = default;
55 /** Default destructor */
56 ~CLArgMinMaxLayerKernel() = default;
57
58 /** Set the input and output tensors.
59 *
Pablo Marquez Tello9b392d72023-06-27 15:49:50 +010060 * @param[in] input Source tensor. Data types supported: QASYMM8/QASYMM8_SIGNED/S32/F16/F32.
61 * @param[out] output Destination tensor. Data types supported: U32/S32
62 * Output will have the same number of dimensions as input.
63 * @param[in] axis Axis along which to reduce. Supported reduction axis : 0,1,2,3
64 * @param[in] op Reduction operation to perform. Only ArgMin and ArgMax are supported.
Manuel Bottini7b9998d2019-10-21 17:59:07 +010065 */
Pablo Marquez Tello9b392d72023-06-27 15:49:50 +010066 void configure(const ICLTensor *input, ICLTensor *output, unsigned int axis, ReductionOperation op);
Manuel Bottini4c6bd512020-04-08 10:15:51 +010067 /** Set the input and output tensors.
68 *
69 * @param[in] compile_context The compile context to be used.
Sheri Zhangc5b6d882020-06-26 14:46:59 +010070 * @param[in] input Source tensor. Data types supported: QASYMM8/QASYMM8_SIGNED/S32/F16/F32.
Manuel Bottini4c6bd512020-04-08 10:15:51 +010071 * @param[out] output Destination tensor. Data types supported: U32/S32
72 * Output will have the same number of dimensions as input.
73 * @param[in] axis Axis along which to reduce. Supported reduction axis : 0,1,2,3
74 * @param[in] op Reduction operation to perform. Only ArgMin and ArgMax are supported.
75 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010076 void configure(const CLCompileContext &compile_context,
77 const ICLTensor *input,
78 ICLTensor *output,
79 unsigned int axis,
80 ReductionOperation op);
Manuel Bottini7b9998d2019-10-21 17:59:07 +010081
82 /** Static function to check if given info will lead to a valid configuration of @ref CLArgMinMaxLayerKernel.
83 *
Pablo Marquez Tello9b392d72023-06-27 15:49:50 +010084 * @param[in] input Source tensor info. Data types supported: QASYMM8/QASYMM8_SIGNED/S32/F16/F32.
85 * @param[in] output Destination tensor info. Data types supported: U32/S32
86 * Output will have the same number of dimensions as input.
87 * @param[in] axis Axis along which to reduce. Supported reduction axis : 0,1,2,3
88 * @param[in] op Reduction operation to perform. Only ArgMin and ArgMax are supported.
Manuel Bottini7b9998d2019-10-21 17:59:07 +010089 *
90 * @return a status
91 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010092 static Status
93 validate(const ITensorInfo *input, const ITensorInfo *output, unsigned int axis, ReductionOperation op);
Manuel Bottini7b9998d2019-10-21 17:59:07 +010094
95 // Inherited methods overridden:
96 void run(const Window &window, cl::CommandQueue &queue) override;
97
98private:
99 const ICLTensor *_input;
Manuel Bottini7b9998d2019-10-21 17:59:07 +0100100 ICLTensor *_output;
101 unsigned int _reduction_axis;
102 ReductionOperation _op;
103};
104} // namespace arm_compute
105#endif /* ARM_COMPUTE_CLARGMINMAXLAYERKERNEL_H */