1 /* 2 * Copyright (c) 2018-2020 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, 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_CLCOMPARISON_H 25 #define ARM_COMPUTE_CLCOMPARISON_H 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 33 class CLCompileContext; 34 class ICLTensor; 35 class ITensorInfo; 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 * 43 * @param[in] input1 Source tensor. Data types supported: All. 44 * The input1 tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0. 45 * @param[in] input2 Source tensor. Data types supported: Same as @p input1. 46 * The input2 tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0. 47 * @param[out] output Destination tensor. Data types supported: U8. 48 * @param[out] operation Comparison operation to be used. 49 */ 50 void configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output, ComparisonOperation operation); 51 /** Initialise the kernel's inputs and outputs. 52 * 53 * @param[in] compile_context The compile context to be used. 54 * @param[in] input1 Source tensor. Data types supported: All. 55 * The input1 tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0. 56 * @param[in] input2 Source tensor. Data types supported: Same as @p input1. 57 * The input2 tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0. 58 * @param[out] output Destination tensor. Data types supported: U8. 59 * @param[out] operation Comparison operation to be used. 60 */ 61 void configure(const CLCompileContext &compile_context, ICLTensor *input1, ICLTensor *input2, ICLTensor *output, ComparisonOperation operation); 62 /** Static function to check if given info will lead to a valid configuration of @ref CLComparison 63 * 64 * @param[in] input1 Source tensor. Data types supported: All. 65 * @param[in] input2 Source tensor. Data types supported: Same as @p input1. 66 * @param[in] output Destination tensor. Data types supported: U8. 67 * @param[out] operation Comparison operation to be used. 68 * 69 * @return a status 70 */ 71 static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, ComparisonOperation operation); 72 }; 73 74 /** Basic function to run @ref CLComparisonKernel */ 75 template <ComparisonOperation COP> 76 class CLComparisonStatic : public ICLSimpleFunction 77 { 78 public: 79 static constexpr ComparisonOperation operation = COP; /** Comparison operations used by the class */ 80 81 public: 82 /** Initialise the kernel's inputs and outputs. 83 * 84 * @param[in] input1 Source tensor. Data types supported: All. 85 * The input1 tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0. 86 * @param[in] input2 Source tensor. Data types supported: Same as @p input1. 87 * The input2 tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0. 88 * @param[out] output Destination tensor. Data types supported: U8. 89 */ 90 void configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output); 91 /** Comparison operations used by the class */ 92 93 public: 94 /** Initialise the kernel's inputs and outputs. 95 * 96 * @param[in] compile_context The compile context to be used. 97 * @param[in] input1 Source tensor. Data types supported: All. 98 * The input1 tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0. 99 * @param[in] input2 Source tensor. Data types supported: Same as @p input1. 100 * The input2 tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0. 101 * @param[out] output Destination tensor. Data types supported: U8. 102 */ 103 void configure(const CLCompileContext &compile_context, ICLTensor *input1, ICLTensor *input2, ICLTensor *output); 104 /** Static function to check if given info will lead to a valid configuration of @ref CLComparison 105 * 106 * @param[in] input1 Source tensor. Data types supported: All. 107 * @param[in] input2 Source tensor. Data types supported: Same as @p input1. 108 * @param[in] output Destination tensor. Data types supported: U8. 109 * 110 * @return a status 111 */ 112 static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output); 113 }; 114 115 /** Basic function to run equal comparison. */ 116 using CLEqual = CLComparisonStatic<ComparisonOperation::Equal>; 117 /** Basic function to run not equal comparison. */ 118 using CLNotEqual = CLComparisonStatic<ComparisonOperation::NotEqual>; 119 /** Basic function to run greater comparison. */ 120 using CLGreater = CLComparisonStatic<ComparisonOperation::Greater>; 121 /** Basic function to run greater-equal comparison. */ 122 using CLGreaterEqual = CLComparisonStatic<ComparisonOperation::GreaterEqual>; 123 /** Basic function to run less comparison. */ 124 using CLLess = CLComparisonStatic<ComparisonOperation::Less>; 125 /** Basic function to run less-equal comparison. */ 126 using CLLessEqual = CLComparisonStatic<ComparisonOperation::LessEqual>; 127 } // namespace arm_compute 128 #endif /* ARM_COMPUTE_CLCOMPARISON_H */ 129