From 52c54f61b97bcedab309bfa761e193939e12e739 Mon Sep 17 00:00:00 2001 From: Usama Arif Date: Tue, 14 May 2019 10:22:36 +0100 Subject: COMPMID-2270: Implement POW operator for CL Change-Id: Id14ecdc62439d90eb247bb75990d6593637cb42e Signed-off-by: Usama Arif Reviewed-on: https://review.mlplatform.org/c/1129 Comments-Addressed: Arm Jenkins Reviewed-by: Gian Marco Iodice Tested-by: Arm Jenkins --- src/core/CL/CLKernelLibrary.cpp | 1 + src/core/CL/cl_kernels/elementwise_operation.cl | 3 ++- src/core/CL/kernels/CLElementwiseOperationKernel.cpp | 19 ++++++++++--------- src/runtime/CL/functions/CLElementwiseOperations.cpp | 16 +++++++++++++++- 4 files changed, 28 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/core/CL/CLKernelLibrary.cpp b/src/core/CL/CLKernelLibrary.cpp index b2d7e23624..e102f44b88 100644 --- a/src/core/CL/CLKernelLibrary.cpp +++ b/src/core/CL/CLKernelLibrary.cpp @@ -252,6 +252,7 @@ const std::map CLKernelLibrary::_kernel_program_map = { "elementwise_operation_MIN", "elementwise_operation.cl" }, { "elementwise_operation_DIV", "elementwise_operation.cl" }, { "elementwise_operation_SQUARED_DIFF", "elementwise_operation.cl" }, + { "elementwise_operation_POWER", "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 00d7ed3ba1..0b660e4012 100644 --- a/src/core/CL/cl_kernels/elementwise_operation.cl +++ b/src/core/CL/cl_kernels/elementwise_operation.cl @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 ARM Limited. + * Copyright (c) 2018-2019 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -37,6 +37,7 @@ #define MIN(x, y) min(x, y) #define SQUARED_DIFF(x, y) (x - y) * (x - y) #define DIV(x, y) (x / y) +#define POWER(x, y) pow(x, y) #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/kernels/CLElementwiseOperationKernel.cpp b/src/core/CL/kernels/CLElementwiseOperationKernel.cpp index 63c9244961..ce0c51dac5 100644 --- a/src/core/CL/kernels/CLElementwiseOperationKernel.cpp +++ b/src/core/CL/kernels/CLElementwiseOperationKernel.cpp @@ -42,6 +42,7 @@ std::map supported_arithmetic_ops = { ArithmeticOperation::SQUARED_DIFF, "SQUARED_DIFF" }, { ArithmeticOperation::MIN, "MIN" }, { ArithmeticOperation::MAX, "MAX" }, + { ArithmeticOperation::POWER, "POWER" }, }; std::map supported_sat_arithmetic_ops = @@ -64,7 +65,7 @@ std::string generate_id_for_tuning_common(const std::string &kernel_name, const return config_id; } -Status validate_arguments_with_division_rules(const ITensorInfo &input1, const ITensorInfo &input2, const ITensorInfo &output) +Status validate_arguments_with_float_only_supported_rules(const ITensorInfo &input1, const ITensorInfo &input2, const ITensorInfo &output) { ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(&input1, &input2, &output); ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED(&input1); @@ -344,10 +345,10 @@ void CLArithmeticOperationKernel::configure(ArithmeticOperation op, const ICLTen Status CLArithmeticOperationKernel::validate(ArithmeticOperation op, const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output) { ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input1, input2, output); - if(op == ArithmeticOperation::DIV) + if(op == ArithmeticOperation::DIV || op == ArithmeticOperation::POWER) { - // Division doesn't support integer arithmetic - ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments_with_division_rules(*input1, *input2, *output)); + // Division and Power operators don't support integer arithmetic + ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments_with_float_only_supported_rules(*input1, *input2, *output)); ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window_for_division(*input1->clone(), *input2->clone(), *output->clone()).first); } else @@ -360,9 +361,9 @@ Status CLArithmeticOperationKernel::validate(ArithmeticOperation op, const ITens } std::pair CLArithmeticOperationKernel::validate_and_configure_window(ITensorInfo &input1, ITensorInfo &input2, ITensorInfo &output) { - if(_op == ArithmeticOperation::DIV) + if(_op == ArithmeticOperation::DIV || _op == ArithmeticOperation::POWER) { - // Division doesn't support integer arithmetic + // Division and Power operators don't support integer arithmetic return validate_and_configure_window_for_division(input1, input2, output); } else @@ -372,10 +373,10 @@ std::pair CLArithmeticOperationKernel::validate_and_configure_wi } Status CLArithmeticOperationKernel::validate_arguments(const ITensorInfo &input1, const ITensorInfo &input2, const ITensorInfo &output) { - if(_op == ArithmeticOperation::DIV) + if(_op == ArithmeticOperation::DIV || _op == ArithmeticOperation::POWER) { - // Division doesn't support integer arithmetic - return validate_arguments_with_division_rules(input1, input2, output); + // Division and Power operators don't support integer arithmetic + return validate_arguments_with_float_only_supported_rules(input1, input2, output); } else { diff --git a/src/runtime/CL/functions/CLElementwiseOperations.cpp b/src/runtime/CL/functions/CLElementwiseOperations.cpp index 28f4b13f22..15de56d24a 100644 --- a/src/runtime/CL/functions/CLElementwiseOperations.cpp +++ b/src/runtime/CL/functions/CLElementwiseOperations.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 ARM Limited. + * Copyright (c) 2018-2019 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -124,4 +124,18 @@ Status CLElementwiseSquaredDiff::validate(const ITensorInfo *input1, const ITens { return CLArithmeticOperationKernel::validate(ArithmeticOperation::SQUARED_DIFF, input1, input2, output); } + +void CLElementwisePower::configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output) +{ + auto k = arm_compute::support::cpp14::make_unique(); + k->configure(ArithmeticOperation::POWER, input1, input2, output); + _kernel = std::move(k); + configure_border_handler(_border_handler, _kernel->border_size(), input1, input2, output); +} + +Status CLElementwisePower::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output) +{ + return CLArithmeticOperationKernel::validate(ArithmeticOperation::POWER, input1, input2, output); +} + } // namespace arm_compute -- cgit v1.2.1