blob: fca4b168b02379372b3eaf92beb36b29f9c61e2a [file] [log] [blame]
Georgios Pinitas7900a9e2018-11-23 11:44:58 +00001/*
Sheri Zhang6124ce62021-05-04 14:03:13 +01002 * Copyright (c) 2018-2021 Arm Limited.
Georgios Pinitas7900a9e2018-11-23 11:44:58 +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_CLCOMPARISON_H
25#define ARM_COMPUTE_CLCOMPARISON_H
Georgios Pinitas7900a9e2018-11-23 11:44:58 +000026
27#include "arm_compute/core/Types.h"
28#include "arm_compute/runtime/CL/ICLSimpleFunction.h"
29
30namespace arm_compute
31{
32// Forward declarations
Sang-Hoon Parkbef7fa22020-10-21 15:58:54 +010033class CLCompileContext;
Georgios Pinitas7900a9e2018-11-23 11:44:58 +000034class ICLTensor;
Sang-Hoon Parkbef7fa22020-10-21 15:58:54 +010035class ITensorInfo;
Georgios Pinitas7900a9e2018-11-23 11:44:58 +000036
37/** Basic function to run @ref CLComparisonKernel */
38class CLComparison : public ICLSimpleFunction
39{
40public:
41 /** Initialise the kernel's inputs and outputs.
42 *
Sheri Zhang6124ce62021-05-04 14:03:13 +010043 * Valid data layouts:
44 * - All
45 *
46 * Valid data type configurations:
47 * |src0 |src1 |dst |
48 * |:--------|:--------|:--------|
49 * |All |All |U8 |
50 *
Michele Di Giorgiocbbed282019-12-20 13:26:08 +000051 * @param[in] input1 Source tensor. Data types supported: All.
Georgios Pinitas7900a9e2018-11-23 11:44:58 +000052 * The input1 tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0.
53 * @param[in] input2 Source tensor. Data types supported: Same as @p input1.
54 * The input2 tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0.
55 * @param[out] output Destination tensor. Data types supported: U8.
56 * @param[out] operation Comparison operation to be used.
57 */
58 void configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output, ComparisonOperation operation);
Manuel Bottini2b84be52020-04-08 10:15:51 +010059 /** Initialise the kernel's inputs and outputs.
60 *
61 * @param[in] compile_context The compile context to be used.
62 * @param[in] input1 Source tensor. Data types supported: All.
63 * The input1 tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0.
64 * @param[in] input2 Source tensor. Data types supported: Same as @p input1.
65 * The input2 tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0.
66 * @param[out] output Destination tensor. Data types supported: U8.
67 * @param[out] operation Comparison operation to be used.
68 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010069 void configure(const CLCompileContext &compile_context,
70 ICLTensor *input1,
71 ICLTensor *input2,
72 ICLTensor *output,
73 ComparisonOperation operation);
Georgios Pinitas7900a9e2018-11-23 11:44:58 +000074 /** Static function to check if given info will lead to a valid configuration of @ref CLComparison
75 *
Michele Di Giorgiocbbed282019-12-20 13:26:08 +000076 * @param[in] input1 Source tensor. Data types supported: All.
Georgios Pinitas7900a9e2018-11-23 11:44:58 +000077 * @param[in] input2 Source tensor. Data types supported: Same as @p input1.
78 * @param[in] output Destination tensor. Data types supported: U8.
79 * @param[out] operation Comparison operation to be used.
80 *
81 * @return a status
82 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010083 static Status validate(const ITensorInfo *input1,
84 const ITensorInfo *input2,
85 const ITensorInfo *output,
86 ComparisonOperation operation);
Georgios Pinitas7900a9e2018-11-23 11:44:58 +000087};
88
89/** Basic function to run @ref CLComparisonKernel */
90template <ComparisonOperation COP>
91class CLComparisonStatic : public ICLSimpleFunction
92{
93public:
94 static constexpr ComparisonOperation operation = COP; /** Comparison operations used by the class */
95
96public:
97 /** Initialise the kernel's inputs and outputs.
98 *
Michele Di Giorgiof6f78762020-07-06 11:27:21 +010099 * @param[in] input1 Source tensor. Data types supported: All.
Georgios Pinitas7900a9e2018-11-23 11:44:58 +0000100 * The input1 tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0.
101 * @param[in] input2 Source tensor. Data types supported: Same as @p input1.
102 * The input2 tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0.
103 * @param[out] output Destination tensor. Data types supported: U8.
104 */
105 void configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output);
Manuel Bottini2b84be52020-04-08 10:15:51 +0100106 /** Comparison operations used by the class */
107
108public:
109 /** Initialise the kernel's inputs and outputs.
110 *
111 * @param[in] compile_context The compile context to be used.
Michele Di Giorgiof6f78762020-07-06 11:27:21 +0100112 * @param[in] input1 Source tensor. Data types supported: All.
Manuel Bottini2b84be52020-04-08 10:15:51 +0100113 * The input1 tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0.
114 * @param[in] input2 Source tensor. Data types supported: Same as @p input1.
115 * The input2 tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0.
116 * @param[out] output Destination tensor. Data types supported: U8.
117 */
118 void configure(const CLCompileContext &compile_context, ICLTensor *input1, ICLTensor *input2, ICLTensor *output);
Georgios Pinitas7900a9e2018-11-23 11:44:58 +0000119 /** Static function to check if given info will lead to a valid configuration of @ref CLComparison
120 *
Michele Di Giorgiof6f78762020-07-06 11:27:21 +0100121 * @param[in] input1 Source tensor. Data types supported: All.
Georgios Pinitas7900a9e2018-11-23 11:44:58 +0000122 * @param[in] input2 Source tensor. Data types supported: Same as @p input1.
123 * @param[in] output Destination tensor. Data types supported: U8.
124 *
125 * @return a status
126 */
127 static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output);
128};
129
130/** Basic function to run equal comparison. */
131using CLEqual = CLComparisonStatic<ComparisonOperation::Equal>;
132/** Basic function to run not equal comparison. */
133using CLNotEqual = CLComparisonStatic<ComparisonOperation::NotEqual>;
134/** Basic function to run greater comparison. */
135using CLGreater = CLComparisonStatic<ComparisonOperation::Greater>;
136/** Basic function to run greater-equal comparison. */
137using CLGreaterEqual = CLComparisonStatic<ComparisonOperation::GreaterEqual>;
138/** Basic function to run less comparison. */
139using CLLess = CLComparisonStatic<ComparisonOperation::Less>;
140/** Basic function to run less-equal comparison. */
141using CLLessEqual = CLComparisonStatic<ComparisonOperation::LessEqual>;
142} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000143#endif /* ARM_COMPUTE_CLCOMPARISON_H */