blob: 215dc2f5eeb238ebbe25261d7c76b6b53386d65e [file] [log] [blame]
George Wort5801a552018-12-13 17:50:26 +00001/*
2 * Copyright (c) 2018 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, INNEUDING 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 NEAIM, 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_NESELECTKERNEL_H__
25#define __ARM_COMPUTE_NESELECTKERNEL_H__
26
27#include "arm_compute/core/NEON/INEKernel.h"
28#include "arm_compute/core/Types.h"
29
30namespace arm_compute
31{
32class ITensor;
33
34/** Interface for the select kernel
35 *
36 * Select is computed by:
37 * @f[ output(i) = condition(i) ? x(i) : y(i) @f]
38 *
39 */
40class NESelectKernel : public INEKernel
41{
42public:
43 const char *name() const override
44 {
45 return "NESelectKernel";
46 }
47 /** Default constructor */
48 NESelectKernel();
49 /** Prevent instances of this class from being copied (As this class contains pointers) */
50 NESelectKernel(const NESelectKernel &) = delete;
51 /** Prevent instances of this class from being copied (As this class contains pointers) */
52 NESelectKernel &operator=(const NESelectKernel &) = delete;
53 /** Allow instances of this class to be moved */
54 NESelectKernel(NESelectKernel &&) = default;
55 /** Allow instances of this class to be moved */
56 NESelectKernel &operator=(NESelectKernel &&) = default;
57 /** Default destructor */
58 ~NESelectKernel() = default;
59
60 /** Common signature for all the specialised elementwise functions
61 *
62 * @param[in] c Condition input tensor. Data types supported: U8.
63 * @param[in] x First input tensor. Data types supported: U8/S8/U16/S16/U32/S32/F16/F32.
64 * @param[out] y Second input tensor. Data types supported: Same as @p x
65 * @param[in] output Output tensor. Data types supported: Same as @p x
66 */
67 void configure(const ITensor *c, const ITensor *x, const ITensor *y, ITensor *output);
68
69 /** Validate the argument passed to the kernel
70 *
71 * @param[in] c Condition input tensor. Data types supported: U8.
72 * @param[in] x First input tensor. Data types supported: U8/S8/U16/S16/U32/S32/F16/F32.
73 * @param[in] y Second input tensor. Data types supported: Same as @p x
74 * @param[in] output Output tensor. Data types supported: Same as @p x.
75 *
76 * @return a status
77 */
78 static Status validate(const ITensorInfo *c, const ITensorInfo *x, const ITensorInfo *y, const ITensorInfo *output);
79
80 // Inherited methods overridden:
81 void run(const Window &window, const ThreadInfo &info) override;
82
83private:
84 /** Common signature for all the specialised select functions
85 *
86 * @param[in] c Condition input tensor. Data types supported: U8.
87 * @param[in] x First input tensor. Data types supported: U8/S8/U16/S16/U32/S32/F16/F32.
88 * @param[in] y Second input tensor. Data types supported: Same as @p x
89 * @param[in] output Output tensor. Data types supported: Same as @p x.
90 */
91 using SelectFunction = void(const ITensor *c, const ITensor *x, const ITensor *y, ITensor *output, const Window &window);
92
93 /** Select function to use for the particular tensor types passed to configure() */
94 SelectFunction *_function;
95 const ITensor *_c; /**< Condition tensor */
96 const ITensor *_x; /**< Source tensor 1 */
97 const ITensor *_y; /**< Source tensor 2 */
98 ITensor *_output; /**< Destination tensor */
99 bool _has_same_rank; /**< Flag that indicates if condition tensor and other inputs have the same rank */
100};
101} // namespace arm_compute
102#endif /* __ARM_COMPUTE_NESELECTKERNEL_H__ */