From 60954c671ffdc3422bbdb728fc022eb6896c1e17 Mon Sep 17 00:00:00 2001 From: Alex Gilday Date: Mon, 5 Mar 2018 16:22:48 +0000 Subject: COMPMID-754: Add validation to (De)QuantizationLayers Change-Id: If8fa1277e8dc5b8e28a8bcad4ff9fc672b00ce9a Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/123275 Reviewed-by: Anthony Barbier Tested-by: Jenkins Reviewed-by: Michalis Spyrou --- src/core/CL/kernels/CLMinMaxLayerKernel.cpp | 80 ++++++++++++++++++++--------- 1 file changed, 57 insertions(+), 23 deletions(-) (limited to 'src/core/CL/kernels/CLMinMaxLayerKernel.cpp') diff --git a/src/core/CL/kernels/CLMinMaxLayerKernel.cpp b/src/core/CL/kernels/CLMinMaxLayerKernel.cpp index 8ba1f776a1..60dd5e7de3 100644 --- a/src/core/CL/kernels/CLMinMaxLayerKernel.cpp +++ b/src/core/CL/kernels/CLMinMaxLayerKernel.cpp @@ -30,38 +30,69 @@ #include "arm_compute/core/Helpers.h" #include "arm_compute/core/Validate.h" #include "arm_compute/core/Window.h" +#include "arm_compute/core/utils/misc/ShapeCalculator.h" #include using namespace arm_compute; +using namespace arm_compute::misc::shape_calculator; -CLMinMaxLayerKernel::CLMinMaxLayerKernel() - : _input(nullptr), _output(nullptr) +namespace { +Status validate_arguments(const ITensorInfo *input, const ITensorInfo *output) +{ + ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input, output); + ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::F32); + ARM_COMPUTE_RETURN_ERROR_ON(input->num_dimensions() < 3); + + if(output->tensor_shape().total_size() > 0) + { + ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output); + + TensorShape output_shape = compute_min_max_shape(input); + + ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DIMENSIONS(output->tensor_shape(), output_shape); + } + + return Status{}; } -void CLMinMaxLayerKernel::configure(const ICLTensor *input, ICLTensor *output) +std::tuple validate_and_configure_window(ITensorInfo *input, ITensorInfo *output) { - ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::F32); - ARM_COMPUTE_ERROR_ON(input->info()->num_dimensions() < 3); - ARM_COMPUTE_ERROR_ON_NULLPTR(output); - - TensorShape output_shape{ input->info()->tensor_shape() }; - output_shape.set(Window::DimX, 2); - output_shape.remove_dimension(1); - output_shape.remove_dimension(1); + TensorShape output_shape = compute_min_max_shape(input); // Output auto initialization if not yet initialized - auto_init_if_empty(*output->info(), output_shape, 1, input->info()->data_type(), input->info()->fixed_point_position()); + auto_init_if_empty(*output, output_shape, 1, input->data_type(), input->fixed_point_position()); + + const unsigned int num_elems_processed_per_iteration = 1; + + // Configure kernel window + Window win = calculate_max_window(*input, Steps(num_elems_processed_per_iteration)); + AccessWindowHorizontal input_access(input, 0, num_elems_processed_per_iteration); + AccessWindowStatic output_access(output, 0, 0, 2, output->dimension(1)); + + bool window_changed = update_window_and_padding(win, input_access, output_access); - ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(input, output); - ARM_COMPUTE_ERROR_ON_MISMATCHING_DIMENSIONS(output->info()->tensor_shape(), output_shape); + output_access.set_valid_region(win, ValidRegion(Coordinates(), output->tensor_shape())); + + Status err = (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Status{}; + return std::make_tuple(err, win); +} +} // namespace + +CLMinMaxLayerKernel::CLMinMaxLayerKernel() + : _input(nullptr), _output(nullptr) +{ +} + +void CLMinMaxLayerKernel::configure(const ICLTensor *input, ICLTensor *output) +{ + ARM_COMPUTE_ERROR_ON_NULLPTR(input, output); + ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info())); _input = input; _output = output; - const unsigned int num_elems_processed_per_iteration = 1; - std::set build_opts; build_opts.emplace("-DWIDTH=" + support::cpp11::to_string(input->info()->dimension(0))); build_opts.emplace("-DHEIGHT=" + support::cpp11::to_string(input->info()->dimension(1))); @@ -70,16 +101,19 @@ void CLMinMaxLayerKernel::configure(const ICLTensor *input, ICLTensor *output) // Create kernel _kernel = static_cast(CLKernelLibrary::get().create_kernel("minmax_layer", build_opts)); - // Configure kernel window - Window win = calculate_max_window(*input->info(), Steps(num_elems_processed_per_iteration)); - AccessWindowHorizontal input_access(input->info(), 0, num_elems_processed_per_iteration); - AccessWindowStatic output_access(output->info(), 0, 0, 2, output->info()->dimension(1)); + auto win_config = validate_and_configure_window(input->info(), output->info()); + + ARM_COMPUTE_ERROR_THROW_ON(std::get<0>(win_config)); - update_window_and_padding(win, input_access, output_access); + ICLKernel::configure(std::get<1>(win_config)); +} - output_access.set_valid_region(win, ValidRegion(Coordinates(), output->info()->tensor_shape())); +Status CLMinMaxLayerKernel::validate(const ITensorInfo *input, const ITensorInfo *output) +{ + ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output)); + ARM_COMPUTE_RETURN_ON_ERROR(std::get<0>(validate_and_configure_window(input->clone().get(), output->clone().get()))); - ICLKernel::configure(win); + return Status{}; } void CLMinMaxLayerKernel::reset(cl::CommandQueue &queue) -- cgit v1.2.1