From 2dbc586417d5a36fcc0aca97267388466f7fff6e Mon Sep 17 00:00:00 2001 From: Sang-Hoon Park Date: Wed, 18 Nov 2020 13:52:11 +0000 Subject: COMPMID-3961: Cleaning up logical operators on OpenCL Change-Id: I04cd23e9abcb1828e54cd59fee3bfa95a6dea3fb Signed-off-by: Sang-Hoon Park Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/4461 Tested-by: Arm Jenkins Comments-Addressed: Arm Jenkins Reviewed-by: Michele Di Giorgio Reviewed-by: Manuel Bottini --- arm_compute/runtime/CL/functions/CLLogicalAnd.h | 20 ++++++++++---------- arm_compute/runtime/CL/functions/CLLogicalNot.h | 10 +++++----- arm_compute/runtime/CL/functions/CLLogicalOr.h | 20 ++++++++++---------- src/core/CL/cl_kernels/elementwise_operation.cl | 6 ++---- .../CL/kernels/CLElementWiseUnaryLayerKernel.cpp | 8 -------- src/core/CL/kernels/CLElementwiseOperationKernel.cpp | 1 + src/core/CL/kernels/CLElementwiseOperationKernel.h | 8 ++++---- src/runtime/CL/functions/CLLogicalOr.cpp | 2 +- tests/validation/fixtures/LogicalFixture.h | 8 ++++---- tests/validation/reference/Logical.cpp | 4 ++-- 10 files changed, 39 insertions(+), 48 deletions(-) diff --git a/arm_compute/runtime/CL/functions/CLLogicalAnd.h b/arm_compute/runtime/CL/functions/CLLogicalAnd.h index 1a6ccf35a5..f5d834c876 100644 --- a/arm_compute/runtime/CL/functions/CLLogicalAnd.h +++ b/arm_compute/runtime/CL/functions/CLLogicalAnd.h @@ -46,16 +46,16 @@ public: * @param[in] compile_context The compile context to be used. * @param[in, out] input1 First tensor input. Data types supported: U8. * The input tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0. - * @param[in, out] input2 Second tensor input. Data types supported: U8. + * @param[in, out] input2 Second tensor input. Data types supported: same as @p input1. * The input tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0. - * @param[out] output Output tensor. Data types supported: U8. + * @param[out] output Output tensor. Data types supported: same as @p input1. */ void configure(const CLCompileContext &compile_context, ITensorInfo *input1, ITensorInfo *input2, ITensorInfo *output); /** Static function to check if given info will lead to a valid configuration of @ref CLLogicalBinaryKernel * * @param[in] input1 First tensor input info. Data types supported: U8. - * @param[in] input2 Second tensor input info. Data types supported: U8. - * @param[in] output Output tensor info. Data types supported: U8. + * @param[in] input2 Second tensor input info. Data types supported: same as @p input1. + * @param[in] output Output tensor info. Data types supported: same as @p input1. * * @return a status */ @@ -88,23 +88,23 @@ public: /** Initialize the function * * @param[in] input1 Input tensor. Data types supported: U8. - * @param[in] input2 Input tensor. Data types supported: U8. - * @param[out] output Output tensor. Data types supported: U8. + * @param[in] input2 Input tensor. Data types supported: same as @p input1. + * @param[out] output Output tensor. Data types supported: same as @p input1. */ void configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output); /** Initialize the function * * @param[in] compile_context The compile context to be used. * @param[in] input1 Input tensor. Data types supported: U8. - * @param[in] input2 Input tensor. Data types supported: U8. - * @param[out] output Output tensor. Data types supported: U8. + * @param[in] input2 Input tensor. Data types supported: same as @p input1. + * @param[out] output Output tensor. Data types supported: same as @p input1. */ void configure(const CLCompileContext &compile_context, ICLTensor *input1, ICLTensor *input2, ICLTensor *output); /** Static function to check if given info will lead to a valid configuration * * @param[in] input1 First tensor input info. Data types supported: U8. - * @param[in] input2 Second tensor input info. Data types supported: U8. - * @param[in] output Output tensor info. Data types supported: U8. + * @param[in] input2 Second tensor input info. Data types supported: same as @p input1. + * @param[in] output Output tensor info. Data types supported: same as @p input1. * * @return a status */ diff --git a/arm_compute/runtime/CL/functions/CLLogicalNot.h b/arm_compute/runtime/CL/functions/CLLogicalNot.h index 4fdf39ed70..f1f2ac1162 100644 --- a/arm_compute/runtime/CL/functions/CLLogicalNot.h +++ b/arm_compute/runtime/CL/functions/CLLogicalNot.h @@ -45,13 +45,13 @@ public: * * @param[in] compile_context The compile context to be used. * @param[in, out] input Tensor input. Data types supported: U8. - * @param[out] output Output tensor. Data types supported: U8. + * @param[out] output Output tensor. Data types supported: same as @p input. */ void configure(const CLCompileContext &compile_context, const ITensorInfo *input, ITensorInfo *output); /** Static function to check if given info will lead to a valid configuration of @ref CLElementWiseUnaryLayerKernel * * @param[in] input Tensor input info. Data types supported: U8. - * @param[in] output Output tensor info. Data types supported: U8. + * @param[in] output Output tensor info. Data types supported: same as @p input. * * @return a status */ @@ -84,20 +84,20 @@ public: /** Initialize the function * * @param[in] input Input tensor. Data types supported: U8. - * @param[out] output Output tensor. Data types supported: U8. + * @param[out] output Output tensor. Data types supported: same as @p input. */ void configure(const ICLTensor *input, ICLTensor *output); /** Initialize the function * * @param[in] compile_context The compile context to be used. * @param[in] input Input tensor. Data types supported: U8. - * @param[out] output Output tensor. Data types supported: U8. + * @param[out] output Output tensor. Data types supported: same as @p input. */ void configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output); /** Static function to check if given info will lead to a valid configuration * * @param[in] input Tensor input info. Data types supported: U8. - * @param[in] output Output tensor info. Data types supported: U8. + * @param[in] output Output tensor info. Data types supported: same as @p input. * * @return a status */ diff --git a/arm_compute/runtime/CL/functions/CLLogicalOr.h b/arm_compute/runtime/CL/functions/CLLogicalOr.h index a50551e1dd..daf7d85aef 100644 --- a/arm_compute/runtime/CL/functions/CLLogicalOr.h +++ b/arm_compute/runtime/CL/functions/CLLogicalOr.h @@ -46,16 +46,16 @@ public: * @param[in] compile_context The compile context to be used. * @param[in, out] input1 First tensor input. Data types supported: U8. * The input tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0. - * @param[in, out] input2 Second tensor input. Data types supported: U8. + * @param[in, out] input2 Second tensor input. Data types supported: same as @p input1. * The input tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0. - * @param[out] output Output tensor. Data types supported: U8. + * @param[out] output Output tensor. Data types supported: same as @p input1. */ void configure(const CLCompileContext &compile_context, ITensorInfo *input1, ITensorInfo *input2, ITensorInfo *output); /** Static function to check if given info will lead to a valid configuration of @ref CLLogicalBinaryKernel * * @param[in] input1 First tensor input info. Data types supported: U8. - * @param[in] input2 Second tensor input info. Data types supported: U8. - * @param[in] output Output tensor info. Data types supported: U8. + * @param[in] input2 Second tensor input info. Data types supported: same as @p input1. + * @param[in] output Output tensor info. Data types supported: same as @p input1. * * @return a status */ @@ -88,23 +88,23 @@ public: /** Initialize the function * * @param[in] input1 Input tensor. Data types supported: U8. - * @param[in] input2 Input tensor. Data types supported: U8. - * @param[out] output Output tensor. Data types supported: U8. + * @param[in] input2 Input tensor. Data types supported: same as @p input1. + * @param[out] output Output tensor. Data types supported: same as @p input1. */ void configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output); /** Initialize the function * * @param[in] compile_context The compile context to be used. * @param[in] input1 Input tensor. Data types supported: U8. - * @param[in] input2 Input tensor. Data types supported: U8. - * @param[out] output Output tensor. Data types supported: U8. + * @param[in] input2 Input tensor. Data types supported: same as @p input1. + * @param[out] output Output tensor. Data types supported: same as @p input1. */ void configure(const CLCompileContext &compile_context, ICLTensor *input1, ICLTensor *input2, ICLTensor *output); /** Static function to check if given info will lead to a valid configuration * * @param[in] input1 First tensor input info. Data types supported: U8. - * @param[in] input2 Second tensor input info. Data types supported: U8. - * @param[in] output Output tensor info. Data types supported: U8. + * @param[in] input2 Second tensor input info. Data types supported: same as @p input1. + * @param[in] output Output tensor info. Data types supported: same as @p input1. * * @return a status */ diff --git a/src/core/CL/cl_kernels/elementwise_operation.cl b/src/core/CL/cl_kernels/elementwise_operation.cl index ea25082a6c..f38f6202ad 100644 --- a/src/core/CL/cl_kernels/elementwise_operation.cl +++ b/src/core/CL/cl_kernels/elementwise_operation.cl @@ -23,6 +23,8 @@ */ #include "helpers.h" +#if defined(OP) && defined(VEC_SIZE_IN1) && defined(VEC_SIZE_IN2) && defined(VEC_SIZE_OUT) && defined(DATA_TYPE_IN1) && defined(DATA_TYPE_IN2) && defined(DATA_TYPE_OUT) + /** List of all the operations supported by this kernel. * @note ADD and SUB operations, when executed on integers, support saturation */ #ifdef SATURATE @@ -40,16 +42,12 @@ #define POWER(x, y) pow(x, y) #define PRELU(x, y) (select(y * x, x, CONVERT((x > (DATA_TYPE_OUT)0), SELECT_VEC_DATA_TYPE(DATA_TYPE_OUT, VEC_SIZE_OUT)))) -#if defined(VEC_SIZE_OUT) && defined(DATA_TYPE_OUT) #define AND(x, y) (CONVERT((x && y), VEC_DATA_TYPE(DATA_TYPE_OUT, VEC_SIZE_OUT)) & 1) #define OR(x, y) (CONVERT((x || y), VEC_DATA_TYPE(DATA_TYPE_OUT, VEC_SIZE_OUT)) & 1) -#endif // defined(VEC_SIZE_OUT) && defined(DATA_TYPE_OUT) #define OP_FUN_NAME_STR(op) elementwise_operation_##op #define OP_FUN_NAME(op) OP_FUN_NAME_STR(op) -#if defined(OP) && defined(VEC_SIZE_IN1) && defined(VEC_SIZE_IN2) && defined(VEC_SIZE_OUT) && defined(DATA_TYPE_IN1) && defined(DATA_TYPE_IN2) && defined(DATA_TYPE_OUT) - #if defined(ACTIVATION_TYPE) #include "activation_float_helpers.h" #endif // defined(ACTIVATION_TYPE) diff --git a/src/core/CL/kernels/CLElementWiseUnaryLayerKernel.cpp b/src/core/CL/kernels/CLElementWiseUnaryLayerKernel.cpp index 0a641adcd2..e7c95ba09e 100644 --- a/src/core/CL/kernels/CLElementWiseUnaryLayerKernel.cpp +++ b/src/core/CL/kernels/CLElementWiseUnaryLayerKernel.cpp @@ -50,14 +50,6 @@ Status validate_arguments(const ITensorInfo &input, const ITensorInfo &output, c if(output.total_size() > 0) { ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED(&output); - if(op == ElementWiseUnary::LOGICAL_NOT) - { - ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(&input, 1, DataType::U8); - } - else - { - ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(&output, 1, DataType::F16, DataType::F32); - } ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(&input, &output); ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(&input, &output); } diff --git a/src/core/CL/kernels/CLElementwiseOperationKernel.cpp b/src/core/CL/kernels/CLElementwiseOperationKernel.cpp index 47439e15ab..7c1d940494 100644 --- a/src/core/CL/kernels/CLElementwiseOperationKernel.cpp +++ b/src/core/CL/kernels/CLElementwiseOperationKernel.cpp @@ -333,6 +333,7 @@ void CLElementwiseOperationKernel::run_op(ITensorPack &tensors, const Window &wi } /** Logical binary */ + void CLLogicalBinaryKernel::configure(const CLCompileContext &compile_context, kernels::LogicalOperation op, ITensorInfo *input1, ITensorInfo *input2, ITensorInfo *output) { ARM_COMPUTE_ERROR_ON_NULLPTR(input1, input2, output); diff --git a/src/core/CL/kernels/CLElementwiseOperationKernel.h b/src/core/CL/kernels/CLElementwiseOperationKernel.h index e24d1564a8..dd04a03ead 100644 --- a/src/core/CL/kernels/CLElementwiseOperationKernel.h +++ b/src/core/CL/kernels/CLElementwiseOperationKernel.h @@ -120,16 +120,16 @@ public: * @param[in] compile_context The compile context to be used. * @param[in] op Logical binary operation to be executed. * @param[in] input1 First tensor input info. Data types supported: U8. - * @param[in] input2 Second tensor input info. Data types supported: U8. - * @param[in] output Output tensor info. Data types supported: U8. + * @param[in] input2 Second tensor input info. Data types supported: same as @p input1. + * @param[in] output Output tensor info. Data types supported: same as @p input1. */ void configure(const CLCompileContext &compile_context, kernels::LogicalOperation op, ITensorInfo *input1, ITensorInfo *input2, ITensorInfo *output); /** Static function to check if the given configuration is valid for this kernel * * @param[in] op Logical binary operation to be executed. * @param[in] input1 First tensor input info. Data types supported: U8. - * @param[in] input2 Second tensor input info. Data types supported: U8. - * @param[in] output Output tensor info. Data types supported: U8. + * @param[in] input2 Second tensor input info. Data types supported: same as @p input1. + * @param[in] output Output tensor info. Data types supported: same as @p input1. */ static Status validate(kernels::LogicalOperation op, const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output); diff --git a/src/runtime/CL/functions/CLLogicalOr.cpp b/src/runtime/CL/functions/CLLogicalOr.cpp index 4681083fd5..b5be3cf816 100644 --- a/src/runtime/CL/functions/CLLogicalOr.cpp +++ b/src/runtime/CL/functions/CLLogicalOr.cpp @@ -48,7 +48,7 @@ void CLLogicalOr::run(ITensorPack &tensors) { ICLOperator::run(tensors); } -} /* namespace experimental */ +} // namespace experimental struct CLLogicalOr::Impl { diff --git a/tests/validation/fixtures/LogicalFixture.h b/tests/validation/fixtures/LogicalFixture.h index 4bedb378bb..9f64d89d10 100644 --- a/tests/validation/fixtures/LogicalFixture.h +++ b/tests/validation/fixtures/LogicalFixture.h @@ -46,10 +46,10 @@ protected: template void fill(U &&tensor, int i) { - constexpr auto zero = (uint8_t)0; - constexpr auto one = (uint8_t)0x1; - constexpr auto mixed = (uint8_t)0xAA; - constexpr auto mixed_bitwise_not = (uint8_t) ~(0xAA); + constexpr auto zero = static_cast(0); + constexpr auto one = static_cast(0x1); + constexpr auto mixed = static_cast(0xAA); + constexpr auto mixed_bitwise_not = static_cast((~0xAA)); library->fill_static_values(tensor, i == 0 ? std::vector { zero, one, zero, one, mixed, zero, mixed } : diff --git a/tests/validation/reference/Logical.cpp b/tests/validation/reference/Logical.cpp index 9989ec841e..099abf6f96 100644 --- a/tests/validation/reference/Logical.cpp +++ b/tests/validation/reference/Logical.cpp @@ -44,9 +44,9 @@ T logical_binary_op(arm_compute::kernels::LogicalOperation op, T src1, T src2) return src1 || src2; // The following operators are either invalid or not binary operator case arm_compute::kernels::LogicalOperation::Not: - /* fall through */ + // fall through case arm_compute::kernels::LogicalOperation::Unknown: - /* fall through */ + // fall through default: ARM_COMPUTE_ASSERT(true); } -- cgit v1.2.1