aboutsummaryrefslogtreecommitdiff
path: root/src/core/CL/kernels/CLL2NormalizeLayerKernel.cpp
diff options
context:
space:
mode:
authorManuel Bottini <manuel.bottini@arm.com>2019-05-14 10:38:30 +0100
committerManuel Bottini <manuel.bottini@arm.com>2019-05-14 16:13:58 +0000
commit4b5c588ed5bbf635bfb4d20b662db417caa4558f (patch)
tree25d33b5020ebfa6b19b9a9870f682df51b17ebc3 /src/core/CL/kernels/CLL2NormalizeLayerKernel.cpp
parent2388de12aa5e71f4e295179b4ea344e3e306556a (diff)
downloadComputeLibrary-4b5c588ed5bbf635bfb4d20b662db417caa4558f.tar.gz
COMPMID-2248
L2NormalizeLayer: negative axis Change-Id: Ic164d7a9ddf1615a2e3b0e10430c34194a70f221 Signed-off-by: Manuel Bottini <manuel.bottini@arm.com> Reviewed-on: https://review.mlplatform.org/c/1127 Tested-by: Arm Jenkins <bsgcomp@arm.com> Reviewed-by: Michalis Spyrou <michalis.spyrou@arm.com> Comments-Addressed: Arm Jenkins <bsgcomp@arm.com>
Diffstat (limited to 'src/core/CL/kernels/CLL2NormalizeLayerKernel.cpp')
-rw-r--r--src/core/CL/kernels/CLL2NormalizeLayerKernel.cpp30
1 files changed, 17 insertions, 13 deletions
diff --git a/src/core/CL/kernels/CLL2NormalizeLayerKernel.cpp b/src/core/CL/kernels/CLL2NormalizeLayerKernel.cpp
index cb2e29449c..00af590104 100644
--- a/src/core/CL/kernels/CLL2NormalizeLayerKernel.cpp
+++ b/src/core/CL/kernels/CLL2NormalizeLayerKernel.cpp
@@ -35,29 +35,32 @@
#include "support/ToolchainSupport.h"
-using namespace arm_compute;
-
+namespace arm_compute
+{
CLL2NormalizeLayerKernel::CLL2NormalizeLayerKernel()
- : _input(nullptr), _sum(nullptr), _output(nullptr), _axis(0), _epsilon(1e-12)
+ : _input(nullptr), _sum(nullptr), _output(nullptr), _actual_axis(0), _epsilon(1e-12)
{
}
namespace
{
-Status validate_arguments(const ITensorInfo *input, const ITensorInfo *sum, const ITensorInfo *output, unsigned int axis, float epsilon)
+constexpr int max_input_tensor_dim = 3;
+
+Status validate_arguments(const ITensorInfo *input, const ITensorInfo *sum, const ITensorInfo *output, int axis, float epsilon)
{
ARM_COMPUTE_UNUSED(epsilon);
+ const uint32_t actual_axis = wrap_around(axis, max_input_tensor_dim);
ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input, sum, output);
ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, sum);
ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED(input);
ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::F16, DataType::F32);
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(axis > 2, "Axis greater than 2 is not supported");
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(axis >= TensorShape::num_max_dimensions, "Reduction axis greater than max number of dimensions");
+ ARM_COMPUTE_RETURN_ERROR_ON_MSG(actual_axis > 2, "Actual axis greater than 2 is not supported");
+ ARM_COMPUTE_RETURN_ERROR_ON_MSG(actual_axis >= TensorShape::num_max_dimensions, "Actual normalization axis greater than max number of dimensions");
// Reduce shape on axis
TensorShape sum_shape = input->tensor_shape();
- sum_shape.set(axis, 1);
+ sum_shape.set(actual_axis, 1);
ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DIMENSIONS(sum->tensor_shape(), sum_shape);
if(output->total_size() != 0)
@@ -92,7 +95,7 @@ std::tuple<Status, Window> validate_and_configure_window(ITensorInfo *input, ITe
}
} // namespace
-void CLL2NormalizeLayerKernel::configure(const ICLTensor *input, const ICLTensor *sum, ICLTensor *output, unsigned int axis, float epsilon)
+void CLL2NormalizeLayerKernel::configure(const ICLTensor *input, const ICLTensor *sum, ICLTensor *output, int axis, float epsilon)
{
ARM_COMPUTE_ERROR_ON_NULLPTR(input, sum, output);
ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), sum->info(), output->info(), axis, epsilon));
@@ -100,7 +103,7 @@ void CLL2NormalizeLayerKernel::configure(const ICLTensor *input, const ICLTensor
_input = input;
_sum = sum;
_output = output;
- _axis = axis;
+ _actual_axis = wrap_around(axis, max_input_tensor_dim);
_epsilon = epsilon;
const unsigned int num_elems_processed_per_iteration = 16;
@@ -113,7 +116,7 @@ void CLL2NormalizeLayerKernel::configure(const ICLTensor *input, const ICLTensor
// Create kernel
std::string kernel_name;
unsigned int idx = 0;
- switch(axis)
+ switch(_actual_axis)
{
case 0:
kernel_name = "x";
@@ -128,7 +131,7 @@ void CLL2NormalizeLayerKernel::configure(const ICLTensor *input, const ICLTensor
idx = num_arguments_per_3D_tensor() * 3;
break;
default:
- ARM_COMPUTE_ERROR("Not supported");
+ ARM_COMPUTE_ERROR("Axis not supported");
}
_kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel("l2_normalize_" + kernel_name, build_opts));
@@ -149,7 +152,7 @@ void CLL2NormalizeLayerKernel::configure(const ICLTensor *input, const ICLTensor
ICLKernel::configure_internal(std::get<1>(win_config));
}
-Status CLL2NormalizeLayerKernel::validate(const ITensorInfo *input, const ITensorInfo *sum, const ITensorInfo *output, unsigned int axis, float epsilon)
+Status CLL2NormalizeLayerKernel::validate(const ITensorInfo *input, const ITensorInfo *sum, const ITensorInfo *output, int axis, float epsilon)
{
ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, sum, output, axis, epsilon));
ARM_COMPUTE_RETURN_ON_ERROR(std::get<0>(validate_and_configure_window(input->clone().get(), output->clone().get())));
@@ -164,7 +167,7 @@ void CLL2NormalizeLayerKernel::run(const Window &window, cl::CommandQueue &queue
Window window_sum(window);
- switch(_axis)
+ switch(_actual_axis)
{
case 0:
{
@@ -218,3 +221,4 @@ void CLL2NormalizeLayerKernel::run(const Window &window, cl::CommandQueue &queue
ARM_COMPUTE_ERROR("Not supported");
}
}
+} // namespace arm_compute \ No newline at end of file