Georgios Pinitas | 7900a9e | 2018-11-23 11:44:58 +0000 | [diff] [blame] | 1 | /* |
Sheri Zhang | 6124ce6 | 2021-05-04 14:03:13 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018-2021 Arm Limited. |
Georgios Pinitas | 7900a9e | 2018-11-23 11:44:58 +0000 | [diff] [blame] | 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 | */ |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 24 | #ifndef ARM_COMPUTE_CLCOMPARISON_H |
| 25 | #define ARM_COMPUTE_CLCOMPARISON_H |
Georgios Pinitas | 7900a9e | 2018-11-23 11:44:58 +0000 | [diff] [blame] | 26 | |
| 27 | #include "arm_compute/core/Types.h" |
| 28 | #include "arm_compute/runtime/CL/ICLSimpleFunction.h" |
| 29 | |
| 30 | namespace arm_compute |
| 31 | { |
| 32 | // Forward declarations |
Sang-Hoon Park | bef7fa2 | 2020-10-21 15:58:54 +0100 | [diff] [blame] | 33 | class CLCompileContext; |
Georgios Pinitas | 7900a9e | 2018-11-23 11:44:58 +0000 | [diff] [blame] | 34 | class ICLTensor; |
Sang-Hoon Park | bef7fa2 | 2020-10-21 15:58:54 +0100 | [diff] [blame] | 35 | class ITensorInfo; |
Georgios Pinitas | 7900a9e | 2018-11-23 11:44:58 +0000 | [diff] [blame] | 36 | |
| 37 | /** Basic function to run @ref CLComparisonKernel */ |
| 38 | class CLComparison : public ICLSimpleFunction |
| 39 | { |
| 40 | public: |
| 41 | /** Initialise the kernel's inputs and outputs. |
| 42 | * |
Sheri Zhang | 6124ce6 | 2021-05-04 14:03:13 +0100 | [diff] [blame] | 43 | * Valid data layouts: |
| 44 | * - All |
| 45 | * |
| 46 | * Valid data type configurations: |
| 47 | * |src0 |src1 |dst | |
| 48 | * |:--------|:--------|:--------| |
| 49 | * |All |All |U8 | |
| 50 | * |
Michele Di Giorgio | cbbed28 | 2019-12-20 13:26:08 +0000 | [diff] [blame] | 51 | * @param[in] input1 Source tensor. Data types supported: All. |
Georgios Pinitas | 7900a9e | 2018-11-23 11:44:58 +0000 | [diff] [blame] | 52 | * 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 Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 59 | /** 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 Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 69 | void configure(const CLCompileContext &compile_context, |
| 70 | ICLTensor *input1, |
| 71 | ICLTensor *input2, |
| 72 | ICLTensor *output, |
| 73 | ComparisonOperation operation); |
Georgios Pinitas | 7900a9e | 2018-11-23 11:44:58 +0000 | [diff] [blame] | 74 | /** Static function to check if given info will lead to a valid configuration of @ref CLComparison |
| 75 | * |
Michele Di Giorgio | cbbed28 | 2019-12-20 13:26:08 +0000 | [diff] [blame] | 76 | * @param[in] input1 Source tensor. Data types supported: All. |
Georgios Pinitas | 7900a9e | 2018-11-23 11:44:58 +0000 | [diff] [blame] | 77 | * @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 Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 83 | static Status validate(const ITensorInfo *input1, |
| 84 | const ITensorInfo *input2, |
| 85 | const ITensorInfo *output, |
| 86 | ComparisonOperation operation); |
Georgios Pinitas | 7900a9e | 2018-11-23 11:44:58 +0000 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | /** Basic function to run @ref CLComparisonKernel */ |
| 90 | template <ComparisonOperation COP> |
| 91 | class CLComparisonStatic : public ICLSimpleFunction |
| 92 | { |
| 93 | public: |
| 94 | static constexpr ComparisonOperation operation = COP; /** Comparison operations used by the class */ |
| 95 | |
| 96 | public: |
| 97 | /** Initialise the kernel's inputs and outputs. |
| 98 | * |
Michele Di Giorgio | f6f7876 | 2020-07-06 11:27:21 +0100 | [diff] [blame] | 99 | * @param[in] input1 Source tensor. Data types supported: All. |
Georgios Pinitas | 7900a9e | 2018-11-23 11:44:58 +0000 | [diff] [blame] | 100 | * 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 Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 106 | /** Comparison operations used by the class */ |
| 107 | |
| 108 | public: |
| 109 | /** Initialise the kernel's inputs and outputs. |
| 110 | * |
| 111 | * @param[in] compile_context The compile context to be used. |
Michele Di Giorgio | f6f7876 | 2020-07-06 11:27:21 +0100 | [diff] [blame] | 112 | * @param[in] input1 Source tensor. Data types supported: All. |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 113 | * 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 Pinitas | 7900a9e | 2018-11-23 11:44:58 +0000 | [diff] [blame] | 119 | /** Static function to check if given info will lead to a valid configuration of @ref CLComparison |
| 120 | * |
Michele Di Giorgio | f6f7876 | 2020-07-06 11:27:21 +0100 | [diff] [blame] | 121 | * @param[in] input1 Source tensor. Data types supported: All. |
Georgios Pinitas | 7900a9e | 2018-11-23 11:44:58 +0000 | [diff] [blame] | 122 | * @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. */ |
| 131 | using CLEqual = CLComparisonStatic<ComparisonOperation::Equal>; |
| 132 | /** Basic function to run not equal comparison. */ |
| 133 | using CLNotEqual = CLComparisonStatic<ComparisonOperation::NotEqual>; |
| 134 | /** Basic function to run greater comparison. */ |
| 135 | using CLGreater = CLComparisonStatic<ComparisonOperation::Greater>; |
| 136 | /** Basic function to run greater-equal comparison. */ |
| 137 | using CLGreaterEqual = CLComparisonStatic<ComparisonOperation::GreaterEqual>; |
| 138 | /** Basic function to run less comparison. */ |
| 139 | using CLLess = CLComparisonStatic<ComparisonOperation::Less>; |
| 140 | /** Basic function to run less-equal comparison. */ |
| 141 | using CLLessEqual = CLComparisonStatic<ComparisonOperation::LessEqual>; |
| 142 | } // namespace arm_compute |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 143 | #endif /* ARM_COMPUTE_CLCOMPARISON_H */ |