diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/CL/kernels/CLL2NormalizeLayerKernel.cpp | 30 | ||||
-rw-r--r-- | src/core/NEON/kernels/NEL2NormalizeLayerKernel.cpp | 26 | ||||
-rw-r--r-- | src/runtime/CL/functions/CLL2NormalizeLayer.cpp | 17 | ||||
-rw-r--r-- | src/runtime/NEON/functions/NEL2NormalizeLayer.cpp | 17 |
4 files changed, 56 insertions, 34 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 diff --git a/src/core/NEON/kernels/NEL2NormalizeLayerKernel.cpp b/src/core/NEON/kernels/NEL2NormalizeLayerKernel.cpp index efdcc44e0e..9900446218 100644 --- a/src/core/NEON/kernels/NEL2NormalizeLayerKernel.cpp +++ b/src/core/NEON/kernels/NEL2NormalizeLayerKernel.cpp @@ -40,6 +40,8 @@ namespace arm_compute { namespace { +constexpr int max_input_tensor_dim = 3; + template <typename T, int S> void l2_normalize_X(const ITensor *in, const ITensor *sum, ITensor *out, float epsilon, const Window &window) { @@ -141,19 +143,20 @@ void l2_normalize_Z(const ITensor *in, const ITensor *sum, ITensor *out, float e while(window.slide_window_slice_3D(in_slice) && window.slide_window_slice_3D(sum_slice)); } -Status validate_arguments(const ITensorInfo *input, const ITensorInfo *sum, const ITensorInfo *output, unsigned int axis, float epsilon) +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_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, "Normalization 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) @@ -167,10 +170,11 @@ Status validate_arguments(const ITensorInfo *input, const ITensorInfo *sum, cons return Status{}; } -std::tuple<Status, Window> validate_and_configure_window(ITensorInfo *input, ITensorInfo *sum, ITensorInfo *output, unsigned int axis) +std::tuple<Status, Window> validate_and_configure_window(ITensorInfo *input, ITensorInfo *sum, ITensorInfo *output, int axis) { + const uint32_t actual_axis = wrap_around(axis, max_input_tensor_dim); const unsigned int num_elems_processed_per_iteration = 16 / data_size_from_type(input->data_type()); - const unsigned int num_elems_processed_per_iteration_sum = (axis == 0) ? 1 : num_elems_processed_per_iteration; + const unsigned int num_elems_processed_per_iteration_sum = (actual_axis == 0) ? 1 : num_elems_processed_per_iteration; Window win = calculate_max_window(*input, Steps(num_elems_processed_per_iteration)); @@ -191,11 +195,11 @@ std::tuple<Status, Window> validate_and_configure_window(ITensorInfo *input, ITe } // namespace NEL2NormalizeLayerKernel::NEL2NormalizeLayerKernel() - : _input(nullptr), _sum(nullptr), _output(nullptr), _axis(0), _epsilon(1e-12) + : _input(nullptr), _sum(nullptr), _output(nullptr), _actual_axis(0), _epsilon(1e-12) { } -void NEL2NormalizeLayerKernel::configure(const ITensor *input, const ITensor *sum, ITensor *output, unsigned int axis, float epsilon) +void NEL2NormalizeLayerKernel::configure(const ITensor *input, const ITensor *sum, ITensor *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)); @@ -203,7 +207,7 @@ void NEL2NormalizeLayerKernel::configure(const ITensor *input, const ITensor *su _input = input; _sum = sum; _output = output; - _axis = axis; + _actual_axis = wrap_around(axis, max_input_tensor_dim); _epsilon = epsilon; // Configure kernel window @@ -213,7 +217,7 @@ void NEL2NormalizeLayerKernel::configure(const ITensor *input, const ITensor *su INEKernel::configure(std::get<1>(win_config)); } -Status NEL2NormalizeLayerKernel::validate(const ITensorInfo *input, const ITensorInfo *sum, const ITensorInfo *output, unsigned int axis, float epsilon) +Status NEL2NormalizeLayerKernel::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(), sum->clone().get(), output->clone().get(), axis))); @@ -227,7 +231,7 @@ void NEL2NormalizeLayerKernel::run(const Window &window, const ThreadInfo &info) ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window); - switch(_axis) + switch(_actual_axis) { case 0: switch(_input->info()->data_type()) diff --git a/src/runtime/CL/functions/CLL2NormalizeLayer.cpp b/src/runtime/CL/functions/CLL2NormalizeLayer.cpp index 136cb5edef..e76e4f601e 100644 --- a/src/runtime/CL/functions/CLL2NormalizeLayer.cpp +++ b/src/runtime/CL/functions/CLL2NormalizeLayer.cpp @@ -34,25 +34,31 @@ namespace arm_compute { +namespace +{ +constexpr int max_input_tensor_dim = 3; +} // namespace + CLL2NormalizeLayer::CLL2NormalizeLayer(std::shared_ptr<IMemoryManager> memory_manager) : _memory_group(std::move(memory_manager)), _reduce_func(), _normalize_kernel(), _sumsq() { } -void CLL2NormalizeLayer::configure(ICLTensor *input, ICLTensor *output, unsigned int axis, float epsilon) +void CLL2NormalizeLayer::configure(ICLTensor *input, ICLTensor *output, int axis, float epsilon) { // Manage intermediate buffers _memory_group.manage(&_sumsq); // Configure kernels - _reduce_func.configure(input, &_sumsq, axis, ReductionOperation::SUM_SQUARE); + const uint32_t actual_axis = wrap_around(axis, max_input_tensor_dim); + _reduce_func.configure(input, &_sumsq, actual_axis, ReductionOperation::SUM_SQUARE); _normalize_kernel.configure(input, &_sumsq, output, axis, epsilon); // Allocate intermediate tensor _sumsq.allocator()->allocate(); } -Status CLL2NormalizeLayer::validate(const ITensorInfo *input, const ITensorInfo *output, unsigned int axis, float epsilon) +Status CLL2NormalizeLayer::validate(const ITensorInfo *input, const ITensorInfo *output, int axis, float epsilon) { TensorShape shape(input->tensor_shape()); @@ -61,10 +67,11 @@ Status CLL2NormalizeLayer::validate(const ITensorInfo *input, const ITensorInfo sum_sq.set_data_type(input->data_type()); sum_sq.set_tensor_shape(shape); - ARM_COMPUTE_RETURN_ON_ERROR(CLReductionOperation::validate(input, &sum_sq, axis, ReductionOperation::SUM_SQUARE)); + const uint32_t actual_axis = wrap_around(axis, max_input_tensor_dim); + ARM_COMPUTE_RETURN_ON_ERROR(CLReductionOperation::validate(input, &sum_sq, actual_axis, ReductionOperation::SUM_SQUARE)); // Reduce shape on axis - shape.set(axis, 1); + shape.set(actual_axis, 1); sum_sq.set_tensor_shape(shape); ARM_COMPUTE_RETURN_ON_ERROR(CLL2NormalizeLayerKernel::validate(input, &sum_sq, output, axis, epsilon)); diff --git a/src/runtime/NEON/functions/NEL2NormalizeLayer.cpp b/src/runtime/NEON/functions/NEL2NormalizeLayer.cpp index c9ab5c98e2..88ffdbfd08 100644 --- a/src/runtime/NEON/functions/NEL2NormalizeLayer.cpp +++ b/src/runtime/NEON/functions/NEL2NormalizeLayer.cpp @@ -28,25 +28,31 @@ namespace arm_compute { +namespace +{ +constexpr int max_input_tensor_dim = 3; +} // namespace + NEL2NormalizeLayer::NEL2NormalizeLayer(std::shared_ptr<IMemoryManager> memory_manager) : _memory_group(std::move(memory_manager)), _reduce_func(), _normalize_kernel(), _sumsq() { } -void NEL2NormalizeLayer::configure(ITensor *input, ITensor *output, unsigned int axis, float epsilon) +void NEL2NormalizeLayer::configure(ITensor *input, ITensor *output, int axis, float epsilon) { // Manage intermediate buffers _memory_group.manage(&_sumsq); // Configure Kernels - _reduce_func.configure(input, &_sumsq, axis, ReductionOperation::SUM_SQUARE); + const uint32_t actual_axis = wrap_around(axis, max_input_tensor_dim); + _reduce_func.configure(input, &_sumsq, actual_axis, ReductionOperation::SUM_SQUARE); _normalize_kernel.configure(input, &_sumsq, output, axis, epsilon); // Allocate intermediate tensors _sumsq.allocator()->allocate(); } -Status NEL2NormalizeLayer::validate(const ITensorInfo *input, const ITensorInfo *output, unsigned int axis, float epsilon) +Status NEL2NormalizeLayer::validate(const ITensorInfo *input, const ITensorInfo *output, int axis, float epsilon) { TensorShape shape(input->tensor_shape()); @@ -55,10 +61,11 @@ Status NEL2NormalizeLayer::validate(const ITensorInfo *input, const ITensorInfo sum_sq.set_data_type(input->data_type()); sum_sq.set_tensor_shape(shape); - ARM_COMPUTE_RETURN_ON_ERROR(NEReductionOperation::validate(input, &sum_sq, axis, ReductionOperation::SUM_SQUARE)); + const uint32_t actual_axis = wrap_around(axis, max_input_tensor_dim); + ARM_COMPUTE_RETURN_ON_ERROR(NEReductionOperation::validate(input, &sum_sq, actual_axis, ReductionOperation::SUM_SQUARE)); // Reduce shape on axis - shape.set(axis, 1); + shape.set(actual_axis, 1); sum_sq.set_tensor_shape(shape); ARM_COMPUTE_RETURN_ON_ERROR(NEL2NormalizeLayerKernel::validate(input, &sum_sq, output, axis, epsilon)); |