aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSang-Hoon Park <sang-hoon.park@arm.com>2020-11-13 13:44:13 +0000
committerSang-Hoon Park <sang-hoon.park@arm.com>2020-11-18 12:25:16 +0000
commit75eea338eb232ebdafa2fb84d22e711b5f964785 (patch)
treed069d26864c3ae180ff526262a1436af839a5bb0
parent10a73f5c0cc15ffba532bc923c6471f67af0959a (diff)
downloadComputeLibrary-75eea338eb232ebdafa2fb84d22e711b5f964785.tar.gz
COMPMID-3961: Add Logical OR/AND/NOT operator on CL
Change-Id: I612aeed6affa17624fb9044964dd59c41a5c9888 Signed-off-by: Sang-Hoon Park <sang-hoon.park@arm.com> Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/4448 Reviewed-by: Pablo Marquez Tello <pablo.tello@arm.com> Tested-by: Arm Jenkins <bsgcomp@arm.com> Comments-Addressed: Arm Jenkins <bsgcomp@arm.com>
-rw-r--r--Android.bp3
-rw-r--r--arm_compute/core/Types.h15
-rw-r--r--arm_compute/runtime/CL/CLFunctions.h3
-rw-r--r--arm_compute/runtime/CL/functions/CLLogicalAnd.h121
-rw-r--r--arm_compute/runtime/CL/functions/CLLogicalNot.h112
-rw-r--r--arm_compute/runtime/CL/functions/CLLogicalOr.h121
-rw-r--r--src/core/CL/CLKernelLibrary.cpp2
-rw-r--r--src/core/CL/cl_kernels/elementwise_operation.cl5
-rw-r--r--src/core/CL/cl_kernels/elementwise_unary.cl6
-rw-r--r--src/core/CL/kernels/CLElementWiseUnaryLayerKernel.cpp27
-rw-r--r--src/core/CL/kernels/CLElementwiseOperationKernel.cpp69
-rw-r--r--src/core/CL/kernels/CLElementwiseOperationKernel.h44
-rw-r--r--src/runtime/CL/functions/CLLogicalAnd.cpp97
-rw-r--r--src/runtime/CL/functions/CLLogicalNot.cpp95
-rw-r--r--src/runtime/CL/functions/CLLogicalOr.cpp97
-rw-r--r--tests/validation/CL/Logical.cpp176
-rw-r--r--tests/validation/NEON/Logical.cpp4
-rw-r--r--tests/validation/fixtures/LogicalFixture.h37
-rw-r--r--tests/validation/reference/Logical.cpp31
-rw-r--r--tests/validation/reference/Logical.h9
20 files changed, 1017 insertions, 57 deletions
diff --git a/Android.bp b/Android.bp
index 64eedc9229..a4ca5c79e8 100644
--- a/Android.bp
+++ b/Android.bp
@@ -531,6 +531,9 @@ cc_library_static {
"src/runtime/CL/functions/CLLaplacianPyramid.cpp",
"src/runtime/CL/functions/CLLaplacianReconstruct.cpp",
"src/runtime/CL/functions/CLLocallyConnectedLayer.cpp",
+ "src/runtime/CL/functions/CLLogicalAnd.cpp",
+ "src/runtime/CL/functions/CLLogicalNot.cpp",
+ "src/runtime/CL/functions/CLLogicalOr.cpp",
"src/runtime/CL/functions/CLMagnitude.cpp",
"src/runtime/CL/functions/CLMaxUnpoolingLayer.cpp",
"src/runtime/CL/functions/CLMeanStdDev.cpp",
diff --git a/arm_compute/core/Types.h b/arm_compute/core/Types.h
index 2e639c4be4..39cc29b0da 100644
--- a/arm_compute/core/Types.h
+++ b/arm_compute/core/Types.h
@@ -546,13 +546,14 @@ enum class ArithmeticOperation
/** Available element wise unary operations */
enum class ElementWiseUnary
{
- RSQRT, /**< Reverse square root */
- EXP, /**< Exponential */
- NEG, /**< Negate */
- LOG, /**< Natural Logarithm */
- ABS, /**< Absolute value */
- SIN, /**< Sine */
- ROUND, /**< Round */
+ RSQRT, /**< Reverse square root */
+ EXP, /**< Exponential */
+ NEG, /**< Negate */
+ LOG, /**< Natural Logarithm */
+ ABS, /**< Absolute value */
+ SIN, /**< Sine */
+ ROUND, /**< Round */
+ LOGICAL_NOT, /**< Logical Not */
};
/** The normalization type used for the normalization layer */
diff --git a/arm_compute/runtime/CL/CLFunctions.h b/arm_compute/runtime/CL/CLFunctions.h
index f909cc30c5..4e32831bc6 100644
--- a/arm_compute/runtime/CL/CLFunctions.h
+++ b/arm_compute/runtime/CL/CLFunctions.h
@@ -99,6 +99,9 @@
#include "arm_compute/runtime/CL/functions/CLLaplacianPyramid.h"
#include "arm_compute/runtime/CL/functions/CLLaplacianReconstruct.h"
#include "arm_compute/runtime/CL/functions/CLLocallyConnectedLayer.h"
+#include "arm_compute/runtime/CL/functions/CLLogicalAnd.h"
+#include "arm_compute/runtime/CL/functions/CLLogicalNot.h"
+#include "arm_compute/runtime/CL/functions/CLLogicalOr.h"
#include "arm_compute/runtime/CL/functions/CLMagnitude.h"
#include "arm_compute/runtime/CL/functions/CLMaxUnpoolingLayer.h"
#include "arm_compute/runtime/CL/functions/CLMeanStdDev.h"
diff --git a/arm_compute/runtime/CL/functions/CLLogicalAnd.h b/arm_compute/runtime/CL/functions/CLLogicalAnd.h
new file mode 100644
index 0000000000..1a6ccf35a5
--- /dev/null
+++ b/arm_compute/runtime/CL/functions/CLLogicalAnd.h
@@ -0,0 +1,121 @@
+/*
+ * Copyright (c) 2020 Arm Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#ifndef ARM_COMPUTE_CLLOGICALAND_H
+#define ARM_COMPUTE_CLLOGICALAND_H
+
+#include "arm_compute/core/Error.h"
+#include "arm_compute/runtime/CL/ICLOperator.h"
+#include "arm_compute/runtime/IFunction.h"
+
+namespace arm_compute
+{
+class CLCompileContext;
+class ICLTensor;
+class ITensorInfo;
+
+namespace experimental
+{
+class CLLogicalAnd : public ICLOperator
+{
+public:
+ /** Default Constructor */
+ CLLogicalAnd() = default;
+ /** Initialise the kernel's inputs, output and conversion policy.
+ *
+ * @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.
+ * 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.
+ */
+ 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.
+ *
+ * @return a status
+ */
+ static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output);
+ // Inherited methods overridden:
+ void run(ITensorPack &tensors) override;
+};
+} // namespace experimental
+
+/** Basic function to run @ref CLLogicalBinaryKernel.
+ *
+ * @note The tensor data type for the inputs must be U8.
+ * @note The function performs a logical AND operation using the two input tensors.
+ */
+class CLLogicalAnd : public IFunction
+{
+public:
+ /** Default Constructor */
+ CLLogicalAnd();
+ /** Default Destructor */
+ ~CLLogicalAnd();
+ /** Prevent instances of this class from being copied (As this class contains pointers) */
+ CLLogicalAnd(const CLLogicalAnd &) = delete;
+ /** Default move constructor */
+ CLLogicalAnd(CLLogicalAnd &&);
+ /** Prevent instances of this class from being copied (As this class contains pointers) */
+ CLLogicalAnd &operator=(const CLLogicalAnd &) = delete;
+ /** Default move assignment operator */
+ CLLogicalAnd &operator=(CLLogicalAnd &&);
+ /** 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.
+ */
+ 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.
+ */
+ 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.
+ *
+ * @return a status
+ */
+ static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output);
+
+ // Inherited methods overridden:
+ void run() override;
+
+private:
+ struct Impl;
+ std::unique_ptr<Impl> _impl;
+};
+} // namespace arm_compute
+#endif /* ARM_COMPUTE_CLLOGICALAND_H */
diff --git a/arm_compute/runtime/CL/functions/CLLogicalNot.h b/arm_compute/runtime/CL/functions/CLLogicalNot.h
new file mode 100644
index 0000000000..4fdf39ed70
--- /dev/null
+++ b/arm_compute/runtime/CL/functions/CLLogicalNot.h
@@ -0,0 +1,112 @@
+/*
+ * Copyright (c) 2020 Arm Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#ifndef ARM_COMPUTE_CLLOGICALNOT_H
+#define ARM_COMPUTE_CLLOGICALNOT_H
+
+#include "arm_compute/core/Error.h"
+#include "arm_compute/runtime/CL/ICLOperator.h"
+#include "arm_compute/runtime/IFunction.h"
+
+namespace arm_compute
+{
+class CLCompileContext;
+class ICLTensor;
+class ITensorInfo;
+
+namespace experimental
+{
+class CLLogicalNot : public ICLOperator
+{
+public:
+ /** Default Constructor */
+ CLLogicalNot() = default;
+ /** Initialise the kernel's inputs, output and conversion policy.
+ *
+ * @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.
+ */
+ 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.
+ *
+ * @return a status
+ */
+ static Status validate(const ITensorInfo *input, const ITensorInfo *output);
+ // Inherited methods overridden:
+ void run(ITensorPack &tensors) override;
+};
+} // namespace experimental
+
+/** Basic function to do logical NOT operation
+ *
+ * @note The tensor data type for the inputs must be U8.
+ * @note The function performs a logical NOT operation on input tensor.
+ */
+class CLLogicalNot : public IFunction
+{
+public:
+ /** Default Constructor */
+ CLLogicalNot();
+ /** Default Destructor */
+ ~CLLogicalNot();
+ /** Prevent instances of this class from being copied (As this class contains pointers) */
+ CLLogicalNot(const CLLogicalNot &) = delete;
+ /** Default move constructor */
+ CLLogicalNot(CLLogicalNot &&);
+ /** Prevent instances of this class from being copied (As this class contains pointers) */
+ CLLogicalNot &operator=(const CLLogicalNot &) = delete;
+ /** Default move assignment operator */
+ CLLogicalNot &operator=(CLLogicalNot &&);
+ /** Initialize the function
+ *
+ * @param[in] input Input tensor. Data types supported: U8.
+ * @param[out] output Output tensor. Data types supported: U8.
+ */
+ 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.
+ */
+ 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.
+ *
+ * @return a status
+ */
+ static Status validate(const ITensorInfo *input, const ITensorInfo *output);
+ void run() override;
+
+private:
+ struct Impl;
+ std::unique_ptr<Impl> _impl;
+};
+} // namespace arm_compute
+#endif /* ARM_COMPUTE_CLLOGICALNOT_H */
diff --git a/arm_compute/runtime/CL/functions/CLLogicalOr.h b/arm_compute/runtime/CL/functions/CLLogicalOr.h
new file mode 100644
index 0000000000..a50551e1dd
--- /dev/null
+++ b/arm_compute/runtime/CL/functions/CLLogicalOr.h
@@ -0,0 +1,121 @@
+/*
+ * Copyright (c) 2020 Arm Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#ifndef ARM_COMPUTE_CLLOGICALOR_H
+#define ARM_COMPUTE_CLLOGICALOR_H
+
+#include "arm_compute/core/Error.h"
+#include "arm_compute/runtime/CL/ICLOperator.h"
+#include "arm_compute/runtime/IFunction.h"
+
+namespace arm_compute
+{
+class CLCompileContext;
+class ICLTensor;
+class ITensorInfo;
+
+namespace experimental
+{
+class CLLogicalOr : public ICLOperator
+{
+public:
+ /** Default Constructor */
+ CLLogicalOr() = default;
+ /** Initialise the kernel's inputs, output and conversion policy.
+ *
+ * @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.
+ * 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.
+ */
+ 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.
+ *
+ * @return a status
+ */
+ static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output);
+ // Inherited methods overridden:
+ void run(ITensorPack &tensors) override;
+};
+} // namespace experimental
+
+/** Basic function to run @ref CLLogicalBinaryKernel.
+ *
+ * @note The tensor data type for the inputs must be U8.
+ * @note The function performs a logical OR operation using the two input tensors.
+ */
+class CLLogicalOr : public IFunction
+{
+public:
+ /** Default Constructor */
+ CLLogicalOr();
+ /** Default Destructor */
+ ~CLLogicalOr();
+ /** Prevent instances of this class from being copied (As this class contains pointers) */
+ CLLogicalOr(const CLLogicalOr &) = delete;
+ /** Default move constructor */
+ CLLogicalOr(CLLogicalOr &&);
+ /** Prevent instances of this class from being copied (As this class contains pointers) */
+ CLLogicalOr &operator=(const CLLogicalOr &) = delete;
+ /** Default move assignment operator */
+ CLLogicalOr &operator=(CLLogicalOr &&);
+ /** 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.
+ */
+ 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.
+ */
+ 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.
+ *
+ * @return a status
+ */
+ static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output);
+
+ // Inherited methods overridden:
+ void run() override;
+
+private:
+ struct Impl;
+ std::unique_ptr<Impl> _impl;
+};
+} // namespace arm_compute
+#endif /* ARM_COMPUTE_CLLOGICALOR_H */
diff --git a/src/core/CL/CLKernelLibrary.cpp b/src/core/CL/CLKernelLibrary.cpp
index 33f0da0aa1..ae8b879be3 100644
--- a/src/core/CL/CLKernelLibrary.cpp
+++ b/src/core/CL/CLKernelLibrary.cpp
@@ -156,6 +156,8 @@ const std::map<std::string, std::string> CLKernelLibrary::_kernel_program_map =
{ "elementwise_operation_SQUARED_DIFF", "elementwise_operation.cl" },
{ "elementwise_operation_POWER", "elementwise_operation.cl" },
{ "elementwise_operation_PRELU", "elementwise_operation.cl" },
+ { "elementwise_operation_AND", "elementwise_operation.cl" },
+ { "elementwise_operation_OR", "elementwise_operation.cl" },
{ "elementwise_operation_ADD_quantized", "elementwise_operation_quantized.cl" },
{ "elementwise_operation_SUB_quantized", "elementwise_operation_quantized.cl" },
{ "elementwise_operation_MAX_quantized", "elementwise_operation_quantized.cl" },
diff --git a/src/core/CL/cl_kernels/elementwise_operation.cl b/src/core/CL/cl_kernels/elementwise_operation.cl
index f6c09b4ec7..ea25082a6c 100644
--- a/src/core/CL/cl_kernels/elementwise_operation.cl
+++ b/src/core/CL/cl_kernels/elementwise_operation.cl
@@ -40,6 +40,11 @@
#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)
diff --git a/src/core/CL/cl_kernels/elementwise_unary.cl b/src/core/CL/cl_kernels/elementwise_unary.cl
index 3e557c0550..54c81fb04e 100644
--- a/src/core/CL/cl_kernels/elementwise_unary.cl
+++ b/src/core/CL/cl_kernels/elementwise_unary.cl
@@ -41,9 +41,11 @@
// Calculate round (Cannot use round function as it rounds halfway cases away from zero).
#if defined(VEC_SIZE)
#define round_op(input) CONVERT(CONVERT_SAT_ROUND(input, VEC_DATA_TYPE(int, VEC_SIZE), rte), VEC_DATA_TYPE(DATA_TYPE, VEC_SIZE))
-#else // defined(VEC_SIZE
+#else // defined(VEC_SIZE)
#define round_op(input) CONVERT(CONVERT_SAT_ROUND(input, int, rte), DATA_TYPE)
-#endif // defined(VEC_SIZE
+#endif // defined(VEC_SIZE)
+// Calculate logical NOT
+#define logical_not_op(input) ((!input) & 0x1)
/** Applies element wise unary operator in a tensor.
*
diff --git a/src/core/CL/kernels/CLElementWiseUnaryLayerKernel.cpp b/src/core/CL/kernels/CLElementWiseUnaryLayerKernel.cpp
index 38a7f1bae1..0a641adcd2 100644
--- a/src/core/CL/kernels/CLElementWiseUnaryLayerKernel.cpp
+++ b/src/core/CL/kernels/CLElementWiseUnaryLayerKernel.cpp
@@ -34,16 +34,30 @@ namespace arm_compute
{
namespace
{
-Status validate_arguments(const ITensorInfo &input, const ITensorInfo &output)
+Status validate_arguments(const ITensorInfo &input, const ITensorInfo &output, const ElementWiseUnary op)
{
ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED(&input);
- ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(&input, 1, DataType::F16, DataType::F32);
+ 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(&input, 1, DataType::F16, DataType::F32);
+ }
// Validate in case of configured output
if(output.total_size() > 0)
{
ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED(&output);
- ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(&output, 1, DataType::F16, DataType::F32);
+ 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);
}
@@ -63,7 +77,7 @@ void CLElementWiseUnaryLayerKernel::configure(const CLCompileContext &compile_co
auto padding_info = get_padding_info({ input, output });
- ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(*input, *output));
+ ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(*input, *output, op));
const std::string kernel_name = "elementwise_unary";
const int vec_size_x = 16 / output->element_size();
@@ -98,6 +112,9 @@ void CLElementWiseUnaryLayerKernel::configure(const CLCompileContext &compile_co
case ElementWiseUnary::ROUND:
build_opts.add_option("-DOPERATION=round_op");
break;
+ case ElementWiseUnary::LOGICAL_NOT:
+ build_opts.add_option("-DOPERATION=logical_not_op");
+ break;
default:
ARM_COMPUTE_ERROR("Not implemented");
}
@@ -121,7 +138,7 @@ Status CLElementWiseUnaryLayerKernel::validate(const ITensorInfo *input, const I
{
ARM_COMPUTE_UNUSED(op);
ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input, output);
- ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(*input, *output));
+ ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(*input, *output, op));
return Status{};
}
diff --git a/src/core/CL/kernels/CLElementwiseOperationKernel.cpp b/src/core/CL/kernels/CLElementwiseOperationKernel.cpp
index efb3fe79e3..47439e15ab 100644
--- a/src/core/CL/kernels/CLElementwiseOperationKernel.cpp
+++ b/src/core/CL/kernels/CLElementwiseOperationKernel.cpp
@@ -26,6 +26,7 @@
#include "arm_compute/core/CL/CLHelpers.h"
#include "arm_compute/core/CL/ICLTensor.h"
#include "src/core/CL/CLValidate.h"
+#include "src/core/common/Validate.h"
#include "src/core/helpers/AutoConfiguration.h"
#include "src/core/helpers/WindowHelpers.h"
#include "support/Cast.h"
@@ -220,6 +221,18 @@ std::pair<Status, Window> validate_and_configure_window_for_arithmetic_operators
return configure_window_arithmetic_common(output);
}
+std::pair<Status, Window> validate_and_configure_window_for_logical_binary_operators(ITensorInfo &input1, ITensorInfo &input2, ITensorInfo &output)
+{
+ const std::pair<TensorShape, ValidRegion> broadcast_pair = ITensorInfo::broadcast_shape_and_valid_region(input1, input2);
+ const TensorShape &out_shape = broadcast_pair.first;
+
+ set_shape_if_empty(output, out_shape);
+ set_data_type_if_unknown(output, DataType::U8);
+
+ // The arithmetic utility functions can be share
+ return configure_window_arithmetic_common(output);
+}
+
std::pair<Status, Window> validate_and_configure_window_for_division(ITensorInfo &input1, ITensorInfo &input2, ITensorInfo &output)
{
const std::pair<TensorShape, ValidRegion> broadcast_pair = ITensorInfo::broadcast_shape_and_valid_region(input1, input2);
@@ -319,6 +332,62 @@ void CLElementwiseOperationKernel::run_op(ITensorPack &tensors, const Window &wi
while(collapsed.slide_window_slice_3D(slice));
}
+/** 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);
+ ARM_COMPUTE_ERROR_THROW_ON(CLLogicalBinaryKernel::validate(op, input1, input2, output));
+ _op = op;
+ configure_common(compile_context, input1, input2, output);
+}
+
+Status CLLogicalBinaryKernel::validate(kernels::LogicalOperation op, const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output)
+{
+ ARM_COMPUTE_UNUSED(op);
+ ARM_COMPUTE_ASSERT(op != kernels::LogicalOperation::Unknown && op != kernels::LogicalOperation::Not);
+ ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input1, input2, output);
+
+ ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input1, 1, DataType::U8);
+ ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input1, input2);
+
+ ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments_with_arithmetic_rules(*input1, *input2, *output));
+ ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window_for_logical_binary_operators(*input1->clone(), *input2->clone(), *output->clone()).first);
+
+ return Status{};
+}
+
+std::string CLLogicalBinaryKernel::name()
+{
+ switch(_op)
+ {
+ case kernels::LogicalOperation::And:
+ return "AND";
+ case kernels::LogicalOperation::Or:
+ return "OR";
+ case kernels::LogicalOperation::Not:
+ /* fall through */
+ default:
+ ARM_COMPUTE_ASSERT(true);
+ }
+ return "";
+}
+
+std::pair<Status, Window> CLLogicalBinaryKernel::validate_and_configure_window(ITensorInfo &input1, ITensorInfo &input2, ITensorInfo &output)
+{
+ return validate_and_configure_window_for_logical_binary_operators(input1, input2, output);
+}
+
+CLBuildOptions CLLogicalBinaryKernel::generate_build_options(const ITensorInfo &input1, const ITensorInfo &input2, const ITensorInfo &output)
+{
+ // The arithmetic utility functions can be share
+ return generate_build_options_with_arithmetic_rules(input1, input2, output, name());
+}
+
+std::string CLLogicalBinaryKernel::generate_id_for_tuning(const std::string &kernel_name, const ITensorInfo &input1, const ITensorInfo &output)
+{
+ return generate_id_for_tuning_common(kernel_name, input1, output);
+}
+
/** Arithmetic operations with saturation*/
void CLSaturatedArithmeticOperationKernel::configure(ArithmeticOperation op, ITensorInfo *input1, ITensorInfo *input2, ITensorInfo *output, const ConvertPolicy &policy,
diff --git a/src/core/CL/kernels/CLElementwiseOperationKernel.h b/src/core/CL/kernels/CLElementwiseOperationKernel.h
index 75030cf3a3..e24d1564a8 100644
--- a/src/core/CL/kernels/CLElementwiseOperationKernel.h
+++ b/src/core/CL/kernels/CLElementwiseOperationKernel.h
@@ -26,6 +26,7 @@
#include "arm_compute/core/Types.h"
#include "src/core/CL/ICLKernel.h"
+#include "src/core/KernelTypes.h"
namespace arm_compute
{
@@ -99,6 +100,49 @@ private:
ITensorInfo *_output; /**< Destination tensor info */
};
+class CLLogicalBinaryKernel : public CLElementwiseOperationKernel
+{
+public:
+ /** Default constructor */
+ CLLogicalBinaryKernel() = default;
+ /** Prevent instances of this class from being copied (As this class contains pointers) */
+ CLLogicalBinaryKernel(const CLLogicalBinaryKernel &) = delete;
+ /** Prevent instances of this class from being copied (As this class contains pointers) */
+ CLLogicalBinaryKernel &operator=(const CLLogicalBinaryKernel &) = delete;
+ /** Allow instances of this class to be moved */
+ CLLogicalBinaryKernel(CLLogicalBinaryKernel &&) = default;
+ /** Allow instances of this class to be moved */
+ CLLogicalBinaryKernel &operator=(CLLogicalBinaryKernel &&) = default;
+ /** Default destructor */
+ ~CLLogicalBinaryKernel() = default;
+ /** Function to configure kernel
+ *
+ * @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.
+ */
+ 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.
+ */
+ static Status validate(kernels::LogicalOperation op, const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output);
+
+private:
+ // Inherited methods overridden:
+ std::string name() override;
+ std::pair<Status, Window> validate_and_configure_window(ITensorInfo &input1, ITensorInfo &input2, ITensorInfo &output) override;
+ CLBuildOptions generate_build_options(const ITensorInfo &input1, const ITensorInfo &input2, const ITensorInfo &output) override;
+ std::string generate_id_for_tuning(const std::string &kernel_name, const ITensorInfo &input1, const ITensorInfo &output) override;
+
+ kernels::LogicalOperation _op{ kernels::LogicalOperation::Unknown };
+};
+
/** Addition operation */
class CLSaturatedArithmeticOperationKernel : public CLElementwiseOperationKernel
{
diff --git a/src/runtime/CL/functions/CLLogicalAnd.cpp b/src/runtime/CL/functions/CLLogicalAnd.cpp
new file mode 100644
index 0000000000..55d3dc523b
--- /dev/null
+++ b/src/runtime/CL/functions/CLLogicalAnd.cpp
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2020 Arm Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#include "arm_compute/runtime/CL/functions/CLLogicalAnd.h"
+#include "arm_compute/core/CL/ICLTensor.h"
+#include "src/core/CL/kernels/CLElementwiseOperationKernel.h"
+#include "support/MemorySupport.h"
+
+#include <utility>
+
+namespace arm_compute
+{
+namespace experimental
+{
+void CLLogicalAnd::configure(const CLCompileContext &compile_context, ITensorInfo *input1, ITensorInfo *input2, ITensorInfo *output)
+{
+ auto k = arm_compute::support::cpp14::make_unique<CLLogicalBinaryKernel>();
+ k->configure(compile_context, kernels::LogicalOperation::And, input1, input2, output);
+ _kernel = std::move(k);
+}
+
+Status CLLogicalAnd::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output)
+{
+ return CLLogicalBinaryKernel::validate(kernels::LogicalOperation::And, input1, input2, output);
+}
+
+void CLLogicalAnd::run(ITensorPack &tensors)
+{
+ ICLOperator::run(tensors);
+}
+} // namespace experimental
+
+struct CLLogicalAnd::Impl
+{
+ const ICLTensor *src0{ nullptr };
+ const ICLTensor *src1{ nullptr };
+ ICLTensor *dst{ nullptr };
+ std::unique_ptr<experimental::CLLogicalAnd> op{ nullptr };
+};
+
+CLLogicalAnd::CLLogicalAnd()
+ : _impl(support::cpp14::make_unique<Impl>())
+{
+}
+CLLogicalAnd::CLLogicalAnd(CLLogicalAnd &&) = default;
+CLLogicalAnd &CLLogicalAnd::operator=(CLLogicalAnd &&) = default;
+CLLogicalAnd::~CLLogicalAnd() = default;
+
+void CLLogicalAnd::configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output)
+{
+ configure(CLKernelLibrary::get().get_compile_context(), input1, input2, output);
+}
+
+void CLLogicalAnd::configure(const CLCompileContext &compile_context, ICLTensor *input1, ICLTensor *input2, ICLTensor *output)
+{
+ _impl->src0 = input1;
+ _impl->src1 = input2;
+ _impl->dst = output;
+ _impl->op = arm_compute::support::cpp14::make_unique<experimental::CLLogicalAnd>();
+ _impl->op->configure(compile_context, input1->info(), input2->info(), output->info());
+}
+
+Status CLLogicalAnd::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output)
+{
+ return experimental::CLLogicalAnd::validate(input1, input2, output);
+}
+
+void CLLogicalAnd::run()
+{
+ ITensorPack pack;
+ pack.add_tensor(TensorType::ACL_SRC_0, _impl->src0);
+ pack.add_tensor(TensorType::ACL_SRC_1, _impl->src1);
+ pack.add_tensor(TensorType::ACL_DST, _impl->dst);
+
+ _impl->op->run(pack);
+}
+} // namespace arm_compute
diff --git a/src/runtime/CL/functions/CLLogicalNot.cpp b/src/runtime/CL/functions/CLLogicalNot.cpp
new file mode 100644
index 0000000000..67aa3192f8
--- /dev/null
+++ b/src/runtime/CL/functions/CLLogicalNot.cpp
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2020 Arm Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#include "arm_compute/runtime/CL/functions/CLLogicalNot.h"
+#include "arm_compute/core/CL/ICLTensor.h"
+#include "src/core/CL/kernels/CLElementWiseUnaryLayerKernel.h"
+#include "support/MemorySupport.h"
+
+#include <utility>
+
+namespace arm_compute
+{
+namespace experimental
+{
+void CLLogicalNot::configure(const CLCompileContext &compile_context, const ITensorInfo *input, ITensorInfo *output)
+{
+ auto k = arm_compute::support::cpp14::make_unique<CLElementWiseUnaryLayerKernel>();
+ k->configure(compile_context, input, output, ElementWiseUnary::LOGICAL_NOT);
+ _kernel = std::move(k);
+}
+
+Status CLLogicalNot::validate(const ITensorInfo *input, const ITensorInfo *output)
+{
+ return CLElementWiseUnaryLayerKernel::validate(input, output, ElementWiseUnary::LOGICAL_NOT);
+}
+
+void CLLogicalNot::run(ITensorPack &tensors)
+{
+ ICLOperator::run(tensors);
+}
+} // namespace experimental
+
+struct CLLogicalNot::Impl
+{
+ const ICLTensor *src{ nullptr };
+ ICLTensor *dst{ nullptr };
+ std::unique_ptr<experimental::CLLogicalNot> op{ nullptr };
+};
+
+CLLogicalNot::CLLogicalNot()
+ : _impl(support::cpp14::make_unique<Impl>())
+{
+}
+CLLogicalNot::CLLogicalNot(CLLogicalNot &&) = default;
+CLLogicalNot &CLLogicalNot::operator=(CLLogicalNot &&) = default;
+CLLogicalNot::~CLLogicalNot() = default;
+
+void CLLogicalNot::configure(const ICLTensor *input, ICLTensor *output)
+{
+ configure(CLKernelLibrary::get().get_compile_context(), input, output);
+}
+
+void CLLogicalNot::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output)
+{
+ _impl->src = input;
+ _impl->dst = output;
+ _impl->op = arm_compute::support::cpp14::make_unique<experimental::CLLogicalNot>();
+ _impl->op->configure(compile_context, input->info(), output->info());
+}
+
+Status CLLogicalNot::validate(const ITensorInfo *input, const ITensorInfo *output)
+{
+ return experimental::CLLogicalNot::validate(input, output);
+}
+
+void CLLogicalNot::run()
+{
+ ITensorPack pack;
+ pack.add_tensor(TensorType::ACL_SRC, _impl->src);
+ pack.add_tensor(TensorType::ACL_DST, _impl->dst);
+
+ _impl->op->run(pack);
+}
+
+} // namespace arm_compute \ No newline at end of file
diff --git a/src/runtime/CL/functions/CLLogicalOr.cpp b/src/runtime/CL/functions/CLLogicalOr.cpp
new file mode 100644
index 0000000000..4681083fd5
--- /dev/null
+++ b/src/runtime/CL/functions/CLLogicalOr.cpp
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2020 Arm Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#include "arm_compute/runtime/CL/functions/CLLogicalOr.h"
+#include "arm_compute/core/CL/ICLTensor.h"
+#include "src/core/CL/kernels/CLElementwiseOperationKernel.h"
+#include "support/MemorySupport.h"
+
+#include <utility>
+
+namespace arm_compute
+{
+namespace experimental
+{
+void CLLogicalOr::configure(const CLCompileContext &compile_context, ITensorInfo *input1, ITensorInfo *input2, ITensorInfo *output)
+{
+ auto k = arm_compute::support::cpp14::make_unique<CLLogicalBinaryKernel>();
+ k->configure(compile_context, kernels::LogicalOperation::Or, input1, input2, output);
+ _kernel = std::move(k);
+}
+
+Status CLLogicalOr::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output)
+{
+ return CLLogicalBinaryKernel::validate(kernels::LogicalOperation::Or, input1, input2, output);
+}
+
+void CLLogicalOr::run(ITensorPack &tensors)
+{
+ ICLOperator::run(tensors);
+}
+} /* namespace experimental */
+
+struct CLLogicalOr::Impl
+{
+ const ICLTensor *src0{ nullptr };
+ const ICLTensor *src1{ nullptr };
+ ICLTensor *dst{ nullptr };
+ std::unique_ptr<experimental::CLLogicalOr> op{ nullptr };
+};
+
+CLLogicalOr::CLLogicalOr()
+ : _impl(support::cpp14::make_unique<Impl>())
+{
+}
+CLLogicalOr::CLLogicalOr(CLLogicalOr &&) = default;
+CLLogicalOr &CLLogicalOr::operator=(CLLogicalOr &&) = default;
+CLLogicalOr::~CLLogicalOr() = default;
+
+void CLLogicalOr::configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output)
+{
+ configure(CLKernelLibrary::get().get_compile_context(), input1, input2, output);
+}
+
+void CLLogicalOr::configure(const CLCompileContext &compile_context, ICLTensor *input1, ICLTensor *input2, ICLTensor *output)
+{
+ _impl->src0 = input1;
+ _impl->src1 = input2;
+ _impl->dst = output;
+ _impl->op = arm_compute::support::cpp14::make_unique<experimental::CLLogicalOr>();
+ _impl->op->configure(compile_context, input1->info(), input2->info(), output->info());
+}
+
+Status CLLogicalOr::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output)
+{
+ return experimental::CLLogicalOr::validate(input1, input2, output);
+}
+
+void CLLogicalOr::run()
+{
+ ITensorPack pack;
+ pack.add_tensor(TensorType::ACL_SRC_0, _impl->src0);
+ pack.add_tensor(TensorType::ACL_SRC_1, _impl->src1);
+ pack.add_tensor(TensorType::ACL_DST, _impl->dst);
+
+ _impl->op->run(pack);
+}
+} // namespace arm_compute
diff --git a/tests/validation/CL/Logical.cpp b/tests/validation/CL/Logical.cpp
new file mode 100644
index 0000000000..ecdb7c8f53
--- /dev/null
+++ b/tests/validation/CL/Logical.cpp
@@ -0,0 +1,176 @@
+/*
+ * Copyright (c) 2020 Arm Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#include "arm_compute/core/Types.h"
+#include "arm_compute/runtime/CL/functions/CLLogicalAnd.h"
+#include "arm_compute/runtime/CL/functions/CLLogicalNot.h"
+#include "arm_compute/runtime/CL/functions/CLLogicalOr.h"
+#include "arm_compute/runtime/Tensor.h"
+#include "arm_compute/runtime/TensorAllocator.h"
+#include "tests/CL/CLAccessor.h"
+#include "tests/PaddingCalculator.h"
+#include "tests/datasets/ShapeDatasets.h"
+#include "tests/framework/Asserts.h"
+#include "tests/framework/Macros.h"
+#include "tests/framework/datasets/Datasets.h"
+#include "tests/validation/Validation.h"
+#include "tests/validation/fixtures/LogicalFixture.h"
+
+namespace
+{
+using namespace arm_compute;
+
+const auto correct_shape = TensorShape(1, 2, 3, 4); // target shape to check against
+const auto wrong_shape = TensorShape(1, 2, 2, 4); // wrong shape to check validate logic
+const auto correct_dt = DataType::U8; // correct data type to check against
+const auto wrong_dt = DataType::F32; // wrong data type to check validate logic
+}
+
+namespace arm_compute
+{
+namespace test
+{
+namespace validation
+{
+TEST_SUITE(CL)
+TEST_SUITE(LogicalOr)
+TEST_SUITE(Validate)
+TEST_CASE(NullPtr, framework::DatasetMode::ALL)
+{
+ Status s = CLLogicalOr::validate(nullptr, nullptr, nullptr);
+ ARM_COMPUTE_EXPECT((bool)s == false, framework::LogLevel::ERRORS);
+}
+
+TEST_CASE(WrongDataType, framework::DatasetMode::ALL)
+{
+ TensorInfo in1{ correct_shape, 1, correct_dt };
+ TensorInfo in2{ correct_shape, 1, wrong_dt };
+ TensorInfo out{ correct_shape, 1, correct_dt };
+
+ Status s = CLLogicalOr::validate(&in1, &in2, &out);
+ ARM_COMPUTE_EXPECT((bool)s == false, framework::LogLevel::ERRORS);
+}
+TEST_SUITE_END() // Validate
+template <typename T>
+using CLLogicalOrFixture = LogicalOrValidationFixture<CLTensor, CLAccessor, CLLogicalOr, T>;
+
+FIXTURE_DATA_TEST_CASE(RunSmall, CLLogicalOrFixture<uint8_t>, framework::DatasetMode::ALL, zip(datasets::SmallShapes(), datasets::SmallShapes()))
+{
+ // Validate output
+ validate(CLAccessor(_target), _reference);
+}
+
+FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, CLLogicalOrFixture<uint8_t>, framework::DatasetMode::ALL, datasets::SmallShapesBroadcast())
+{
+ // Validate output
+ validate(CLAccessor(_target), _reference);
+}
+TEST_SUITE_END() // LogicalOr
+
+TEST_SUITE(LogicalAnd)
+TEST_SUITE(Validate)
+TEST_CASE(NullPtr, framework::DatasetMode::ALL)
+{
+ Status s = CLLogicalAnd::validate(nullptr, nullptr, nullptr);
+ ARM_COMPUTE_EXPECT((bool)s == false, framework::LogLevel::ERRORS);
+}
+
+TEST_CASE(WrongDataType, framework::DatasetMode::ALL)
+{
+ TensorInfo in1{ correct_shape, 1, correct_dt };
+ TensorInfo in2{ correct_shape, 1, wrong_dt };
+ TensorInfo out{ correct_shape, 1, correct_dt };
+
+ Status s = CLLogicalAnd::validate(&in1, &in2, &out);
+ ARM_COMPUTE_EXPECT((bool)s == false, framework::LogLevel::ERRORS);
+}
+TEST_SUITE_END() // Validate
+template <typename T>
+using CLLogicalAndFixture = LogicalAndValidationFixture<CLTensor, CLAccessor, CLLogicalAnd, T>;
+
+FIXTURE_DATA_TEST_CASE(RunSmall, CLLogicalAndFixture<uint8_t>, framework::DatasetMode::ALL, zip(datasets::SmallShapes(), datasets::SmallShapes()))
+{
+ // Validate output
+ validate(CLAccessor(_target), _reference);
+}
+
+FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, CLLogicalAndFixture<uint8_t>, framework::DatasetMode::ALL, datasets::SmallShapesBroadcast())
+{
+ // Validate output
+ validate(CLAccessor(_target), _reference);
+}
+TEST_SUITE_END() // LogicalAnd
+TEST_SUITE(LogicalNot)
+
+TEST_SUITE(Validate)
+TEST_CASE(NullPtr, framework::DatasetMode::ALL)
+{
+ Status s = CLLogicalNot::validate(nullptr, nullptr);
+ ARM_COMPUTE_EXPECT((bool)s == false, framework::LogLevel::ERRORS);
+}
+
+TEST_CASE(WrongDataType, framework::DatasetMode::ALL)
+{
+ TensorInfo in{ correct_shape, 1, correct_dt };
+ TensorInfo out{ correct_shape, 1, wrong_dt };
+
+ Status s = CLLogicalNot::validate(&in, &out);
+ ARM_COMPUTE_EXPECT((bool)s == false, framework::LogLevel::ERRORS);
+
+ in = TensorInfo{ correct_shape, 1, wrong_dt };
+ out = TensorInfo{ correct_shape, 1, correct_dt };
+
+ s = CLLogicalNot::validate(&in, &out);
+ ARM_COMPUTE_EXPECT((bool)s == false, framework::LogLevel::ERRORS);
+
+ in = TensorInfo{ correct_shape, 1, wrong_dt };
+ out = TensorInfo{ correct_shape, 1, wrong_dt };
+
+ s = CLLogicalNot::validate(&in, &out);
+ ARM_COMPUTE_EXPECT((bool)s == false, framework::LogLevel::ERRORS);
+}
+
+TEST_CASE(WrongShape, framework::DatasetMode::ALL)
+{
+ TensorInfo in{ correct_shape, 1, correct_dt };
+ TensorInfo out{ wrong_shape, 1, correct_dt };
+
+ Status s = CLLogicalNot::validate(&in, &out);
+ ARM_COMPUTE_EXPECT((bool)s == false, framework::LogLevel::ERRORS);
+}
+TEST_SUITE_END() // Validate
+
+template <typename T>
+using CLLogicalNotFixture = LogicalNotValidationFixture<CLTensor, CLAccessor, CLLogicalNot, T>;
+
+FIXTURE_DATA_TEST_CASE(RunSmall, CLLogicalNotFixture<uint8_t>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), framework::dataset::make("DataType",
+ DataType::U8)))
+{
+ // Validate output
+ validate(CLAccessor(_target), _reference);
+}
+TEST_SUITE_END() // LogicalNot
+TEST_SUITE_END() // CL
+} // namespace validation
+} // namespace test
+} // namespace arm_compute
diff --git a/tests/validation/NEON/Logical.cpp b/tests/validation/NEON/Logical.cpp
index f721e3cbc5..6f1c55b33c 100644
--- a/tests/validation/NEON/Logical.cpp
+++ b/tests/validation/NEON/Logical.cpp
@@ -41,7 +41,7 @@ TEST_SUITE(NEON)
TEST_SUITE(LogicalAnd)
template <typename T>
-using NELogicalAndFixture = LogicalBinaryOperationValidationFixture<Tensor, Accessor, NELogicalAnd, reference::LogicalBinaryOperation::AND, T>;
+using NELogicalAndFixture = LogicalAndValidationFixture<Tensor, Accessor, NELogicalAnd, T>;
FIXTURE_DATA_TEST_CASE(RunSmall, NELogicalAndFixture<uint8_t>, framework::DatasetMode::ALL, zip(datasets::SmallShapes(), datasets::SmallShapes()))
{
@@ -58,7 +58,7 @@ TEST_SUITE_END() // LogicalAnd
TEST_SUITE(LogicalOr)
template <typename T>
-using NELogicalOrFixture = LogicalBinaryOperationValidationFixture<Tensor, Accessor, NELogicalOr, reference::LogicalBinaryOperation::OR, T>;
+using NELogicalOrFixture = LogicalOrValidationFixture<Tensor, Accessor, NELogicalOr, T>;
FIXTURE_DATA_TEST_CASE(RunSmall, NELogicalOrFixture<uint8_t>, framework::DatasetMode::ALL, zip(datasets::SmallShapes(), datasets::SmallShapes()))
{
diff --git a/tests/validation/fixtures/LogicalFixture.h b/tests/validation/fixtures/LogicalFixture.h
index a4817cf785..4bedb378bb 100644
--- a/tests/validation/fixtures/LogicalFixture.h
+++ b/tests/validation/fixtures/LogicalFixture.h
@@ -46,10 +46,10 @@ protected:
template <typename U>
void fill(U &&tensor, int i)
{
- constexpr uint8_t zero = 0;
- constexpr uint8_t one = 0x1;
- constexpr uint8_t mixed = 0xAA;
- constexpr uint8_t mixed_bitwise_not = ~(0xAA);
+ 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);
library->fill_static_values(tensor, i == 0 ?
std::vector<uint8_t> { zero, one, zero, one, mixed, zero, mixed } :
@@ -70,7 +70,10 @@ protected:
SimpleTensor<T> _reference{};
};
-template <typename TensorType, typename AccessorType, typename FunctionType, reference::LogicalBinaryOperation Op, typename T>
+template <typename T>
+using LogicalBinaryRefFunctionPtrType = SimpleTensor<T>(const SimpleTensor<T> &, const SimpleTensor<T> &);
+
+template <typename TensorType, typename AccessorType, typename FunctionType, typename T, LogicalBinaryRefFunctionPtrType<T> RefFunction>
class LogicalBinaryOperationValidationFixture : public LogicalOperationValidationFixtureBase<TensorType, AccessorType, FunctionType, T>
{
using Parent = LogicalOperationValidationFixtureBase<TensorType, AccessorType, FunctionType, T>;
@@ -114,25 +117,19 @@ private:
Parent::fill(src0, 0);
Parent::fill(src1, 1);
- switch(Op)
- {
- case reference::LogicalBinaryOperation::OR:
- return reference::logical_or<T>(src0, src1);
- case reference::LogicalBinaryOperation::AND:
- return reference::logical_and<T>(src0, src1);
- case reference::LogicalBinaryOperation::UNKNOWN:
- /* fall-through */
- default:
- ARM_COMPUTE_ASSERT_FAIL("unknown logical binary operator is given");
- }
-
- return SimpleTensor<T> {};
+ return RefFunction(src0, src1);
}
- static constexpr auto _data_type{ DataType::U8 };
+ static constexpr auto _data_type = DataType::U8;
};
template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
+using LogicalOrValidationFixture = LogicalBinaryOperationValidationFixture<TensorType, AccessorType, FunctionType, T, &reference::logical_or<T>>;
+
+template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
+using LogicalAndValidationFixture = LogicalBinaryOperationValidationFixture<TensorType, AccessorType, FunctionType, T, &reference::logical_and<T>>;
+
+template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
class LogicalNotValidationFixture : public LogicalOperationValidationFixtureBase<TensorType, AccessorType, FunctionType, T>
{
using Parent = LogicalOperationValidationFixtureBase<TensorType, AccessorType, FunctionType, T>;
@@ -178,4 +175,4 @@ private:
} // namespace validation
} // namespace test
} // namespace arm_compute
-#endif /* ARM_COMPUTE_TEST_LOGICAL_FIXTURE */ \ No newline at end of file
+#endif /* ARM_COMPUTE_TEST_LOGICAL_FIXTURE */
diff --git a/tests/validation/reference/Logical.cpp b/tests/validation/reference/Logical.cpp
index 394525c392..9989ec841e 100644
--- a/tests/validation/reference/Logical.cpp
+++ b/tests/validation/reference/Logical.cpp
@@ -22,6 +22,8 @@
* SOFTWARE.
*/
#include "tests/validation/reference/Logical.h"
+#include "src/core/KernelTypes.h"
+#include "tests/framework/Asserts.h"
namespace arm_compute
{
@@ -32,27 +34,30 @@ namespace validation
namespace reference
{
template <typename T>
-T logical_op(LogicalBinaryOperation op, T src1, T src2)
+T logical_binary_op(arm_compute::kernels::LogicalOperation op, T src1, T src2)
{
switch(op)
{
- case LogicalBinaryOperation::AND:
+ case arm_compute::kernels::LogicalOperation::And:
return src1 && src2;
- case LogicalBinaryOperation::OR:
+ case arm_compute::kernels::LogicalOperation::Or:
return src1 || src2;
- case LogicalBinaryOperation::UNKNOWN:
+ // The following operators are either invalid or not binary operator
+ case arm_compute::kernels::LogicalOperation::Not:
+ /* fall through */
+ case arm_compute::kernels::LogicalOperation::Unknown:
+ /* fall through */
default:
- ARM_COMPUTE_ERROR_ON_MSG(true, "unknown logical binary operation is given");
+ ARM_COMPUTE_ASSERT(true);
}
- return false;
+ return T{};
}
template <size_t dim>
struct BroadcastUnroll
{
template <typename T>
- static void unroll(LogicalBinaryOperation op,
- const SimpleTensor<T> &src1, const SimpleTensor<T> &src2, SimpleTensor<T> &dst,
+ static void unroll(arm_compute::kernels::LogicalOperation op, const SimpleTensor<T> &src1, const SimpleTensor<T> &src2, SimpleTensor<T> &dst,
Coordinates &id_src1, Coordinates &id_src2, Coordinates &id_dst)
{
const bool src1_is_broadcast = (src1.shape()[dim - 1] != dst.shape()[dim - 1]);
@@ -79,10 +84,10 @@ template <>
struct BroadcastUnroll<0>
{
template <typename T>
- static void unroll(LogicalBinaryOperation op, const SimpleTensor<T> &src1, const SimpleTensor<T> &src2, SimpleTensor<T> &dst,
+ static void unroll(arm_compute::kernels::LogicalOperation op, const SimpleTensor<T> &src1, const SimpleTensor<T> &src2, SimpleTensor<T> &dst,
Coordinates &id_src1, Coordinates &id_src2, Coordinates &id_dst)
{
- dst[coord2index(dst.shape(), id_dst)] = logical_op(op, src1[coord2index(src1.shape(), id_src1)], src2[coord2index(src2.shape(), id_src2)]);
+ dst[coord2index(dst.shape(), id_dst)] = logical_binary_op(op, src1[coord2index(src1.shape(), id_src1)], src2[coord2index(src2.shape(), id_src2)]);
}
};
@@ -94,7 +99,7 @@ SimpleTensor<T> logical_or(const SimpleTensor<T> &src1, const SimpleTensor<T> &s
Coordinates id_dst{};
SimpleTensor<T> dst{ TensorShape::broadcast_shape(src1.shape(), src2.shape()), src1.data_type() };
- BroadcastUnroll<Coordinates::num_max_dimensions>::unroll(LogicalBinaryOperation::OR, src1, src2, dst, id_src1, id_src2, id_dst);
+ BroadcastUnroll<Coordinates::num_max_dimensions>::unroll(arm_compute::kernels::LogicalOperation::Or, src1, src2, dst, id_src1, id_src2, id_dst);
return dst;
}
@@ -107,7 +112,7 @@ SimpleTensor<T> logical_and(const SimpleTensor<T> &src1, const SimpleTensor<T> &
Coordinates id_dst{};
SimpleTensor<T> dst{ TensorShape::broadcast_shape(src1.shape(), src2.shape()), src1.data_type() };
- BroadcastUnroll<Coordinates::num_max_dimensions>::unroll(LogicalBinaryOperation::AND, src1, src2, dst, id_src1, id_src2, id_dst);
+ BroadcastUnroll<Coordinates::num_max_dimensions>::unroll(arm_compute::kernels::LogicalOperation::And, src1, src2, dst, id_src1, id_src2, id_dst);
return dst;
}
@@ -133,4 +138,4 @@ template SimpleTensor<uint8_t> logical_not(const SimpleTensor<uint8_t> &src1);
} // namespace reference
} // namespace validation
} // namespace test
-} // namespace arm_compute \ No newline at end of file
+} // namespace arm_compute
diff --git a/tests/validation/reference/Logical.h b/tests/validation/reference/Logical.h
index fb906b70b6..0d2bef9a43 100644
--- a/tests/validation/reference/Logical.h
+++ b/tests/validation/reference/Logical.h
@@ -34,13 +34,6 @@ namespace validation
{
namespace reference
{
-enum class LogicalBinaryOperation
-{
- UNKNOWN = 0,
- AND = 1,
- OR = 2
-};
-
template <typename T>
SimpleTensor<T> logical_or(const SimpleTensor<T> &src1, const SimpleTensor<T> &src2);
template <typename T>
@@ -51,4 +44,4 @@ SimpleTensor<T> logical_not(const SimpleTensor<T> &src1);
} // namespace validation
} // namespace test
} // namespace arm_compute
-#endif /* ARM_COMPUTE_TEST_LOGICAL_H */ \ No newline at end of file
+#endif /* ARM_COMPUTE_TEST_LOGICAL_H */