From 7c435f2e32e3441ac6c288e786f25c86b65e1453 Mon Sep 17 00:00:00 2001 From: Gian Marco Date: Tue, 5 Dec 2017 16:17:23 +0000 Subject: COMPMID-728 - Added validation for transpose - Added validation in NETranspose - Added validation in CLTranspose Change-Id: I51aa1810c957fda75bdf899f33116d96a76d89a1 Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/111999 Reviewed-by: Anthony Barbier Tested-by: BSG Visual Compute Jenkins server to access repositories on http://mpd-gerrit.cambridge.arm.com --- src/core/CL/kernels/CLTransposeKernel.cpp | 98 ++++++++++++++++++++++--------- 1 file changed, 71 insertions(+), 27 deletions(-) (limited to 'src/core/CL/kernels/CLTransposeKernel.cpp') diff --git a/src/core/CL/kernels/CLTransposeKernel.cpp b/src/core/CL/kernels/CLTransposeKernel.cpp index 81ab217923..abc9f0219c 100644 --- a/src/core/CL/kernels/CLTransposeKernel.cpp +++ b/src/core/CL/kernels/CLTransposeKernel.cpp @@ -39,25 +39,80 @@ using namespace arm_compute; -void CLTransposeKernel::configure(const ICLTensor *input, ICLTensor *output) +namespace +{ +TensorShape transposed_tensor_shape(const TensorShape &in) { - ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::U8, DataType::S8, DataType::QS8, DataType::QASYMM8, DataType::U16, DataType::S16, DataType::QS16, DataType::U32, DataType::S32, - DataType::F16, - DataType::F32); - ARM_COMPUTE_ERROR_ON_NULLPTR(output); - - TensorShape output_shape{ input->info()->tensor_shape() }; - const size_t w_out = input->info()->dimension(1); - const size_t h_out = input->info()->dimension(0); + TensorShape output_shape{ in }; + const size_t w_out = in[1]; + const size_t h_out = in[0]; output_shape.set(0, w_out); output_shape.set(1, h_out); + return output_shape; +} + +Error validate_arguments(const ITensorInfo *input, const ITensorInfo *output) +{ + ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::U8, DataType::S8, DataType::QS8, DataType::QASYMM8, DataType::U16, DataType::S16, DataType::QS16, DataType::U32, DataType::S32, + DataType::F16, + DataType::F32); + + if(output->total_size() != 0) + { + const TensorInfo tensor_info = input->clone()->set_tensor_shape(transposed_tensor_shape(input->tensor_shape())); + + ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(output, &tensor_info); + ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output); + ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_FIXED_POINT(input, output); + } + + return Error{}; +} + +std::pair validate_and_configure_window(ITensorInfo *input, ITensorInfo *output) +{ + // Configure kernel window + const unsigned int num_elems_processed_per_iteration = max_cl_vector_width / input->element_size(); + + Window win = calculate_max_window(*input, Steps(num_elems_processed_per_iteration, num_elems_processed_per_iteration)); + + AccessWindowRectangle input_access(input, 0, 0, num_elems_processed_per_iteration, num_elems_processed_per_iteration); + + bool window_changed = update_window_and_padding(win, input_access); + + if(output->total_size() != 0) + { + // TODO (COMPMID-708): Replace AccessWindowStatic with AccessWindowTranspose + AccessWindowStatic output_access(output, 0, 0, ceil_to_multiple(output->dimension(0), num_elems_processed_per_iteration), ceil_to_multiple(output->dimension(1), + num_elems_processed_per_iteration)); + + window_changed = window_changed || update_window_and_padding(win, output_access); + + output_access.set_valid_region(win, ValidRegion(Coordinates(), output->tensor_shape())); + } + + Error err = (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Error{}; + return std::make_pair(err, win); +} +} // namespace + +Error CLTransposeKernel::validate(const ITensorInfo *input, const ITensorInfo *output) +{ + ARM_COMPUTE_ERROR_ON_NULLPTR(input, output); + ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output)); + ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(), output->clone().get()).first); + return Error{}; +} + +void CLTransposeKernel::configure(const ICLTensor *input, ICLTensor *output) +{ + ARM_COMPUTE_ERROR_ON_NULLPTR(input, output); + // Output tensor auto inizialitation if not yet initialized - auto_init_if_empty(*output->info(), output_shape, 1, input->info()->data_type(), input->info()->fixed_point_position(), input->info()->quantization_info()); + auto_init_if_empty(*output->info(), input->info()->clone()->set_tensor_shape(transposed_tensor_shape(input->info()->tensor_shape()))); - ARM_COMPUTE_ERROR_ON_MISMATCHING_DIMENSIONS(output->info()->tensor_shape(), output_shape); - ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(input, output); - ARM_COMPUTE_ERROR_ON_MISMATCHING_FIXED_POINT(input, output); + ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info())); _input = input; _output = output; @@ -71,18 +126,7 @@ void CLTransposeKernel::configure(const ICLTensor *input, ICLTensor *output) _kernel = static_cast(CLKernelLibrary::get().create_kernel("transpose", build_opts)); // Configure kernel window - const unsigned int num_elems_processed_per_iteration = max_cl_vector_width / input->info()->element_size(); - - Window win = calculate_max_window(*input->info(), Steps(num_elems_processed_per_iteration, num_elems_processed_per_iteration)); - - AccessWindowRectangle input_access(input->info(), 0, 0, num_elems_processed_per_iteration, num_elems_processed_per_iteration); - // TODO (COMPMID-708): Replace AccessWindowStatic with AccessWindowTranspose - AccessWindowStatic output_access(output->info(), 0, 0, ceil_to_multiple(output->info()->dimension(0), num_elems_processed_per_iteration), ceil_to_multiple(output->info()->dimension(1), - num_elems_processed_per_iteration)); - - update_window_and_padding(win, input_access, output_access); - - output_access.set_valid_region(win, input->info()->valid_region()); - - ICLKernel::configure(win); + auto win_config = validate_and_configure_window(input->info(), output->info()); + ARM_COMPUTE_ERROR_THROW_ON(win_config.first); + ICLKernel::configure(win_config.second); } -- cgit v1.2.1