From 9414f64c231a013664102e2c284b10266c6b4d4e Mon Sep 17 00:00:00 2001 From: Ioan-Cristian Szabo Date: Fri, 27 Oct 2017 17:35:40 +0100 Subject: COMPMID-582: Add validation to channel_extract kernels. Change-Id: I5022d02f06f9d849dad76e3d9b8e48632c236429 Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/121191 Reviewed-by: Anthony Barbier Tested-by: Jenkins --- src/core/CL/kernels/CLChannelExtractKernel.cpp | 76 ++++++++++++++++++++------ 1 file changed, 58 insertions(+), 18 deletions(-) (limited to 'src/core/CL/kernels/CLChannelExtractKernel.cpp') diff --git a/src/core/CL/kernels/CLChannelExtractKernel.cpp b/src/core/CL/kernels/CLChannelExtractKernel.cpp index d0c633555d..65843b8d5d 100644 --- a/src/core/CL/kernels/CLChannelExtractKernel.cpp +++ b/src/core/CL/kernels/CLChannelExtractKernel.cpp @@ -49,25 +49,48 @@ CLChannelExtractKernel::CLChannelExtractKernel() void CLChannelExtractKernel::configure(const ICLTensor *input, Channel channel, ICLTensor *output) { + ARM_COMPUTE_ERROR_ON_NULLPTR(input, output); + ARM_COMPUTE_ERROR_ON(input == output); + + set_format_if_unknown(*output->info(), Format::U8); + + // Check if input tensor has a valid format ARM_COMPUTE_ERROR_ON_FORMAT_NOT_IN(input, Format::RGB888, Format::RGBA8888, Format::YUYV422, Format::UYVY422); ARM_COMPUTE_ERROR_ON_FORMAT_NOT_IN(output, Format::U8); - ARM_COMPUTE_ERROR_ON(static_cast(input) == static_cast(output)); - - _input = input; - _output = output; + ARM_COMPUTE_ERROR_ON_TENSOR_NOT_2D(output); - // Check format + // Check if channel is valid for given format const Format format = input->info()->format(); ARM_COMPUTE_ERROR_ON_CHANNEL_NOT_IN_KNOWN_FORMAT(format, channel); + // Half the processed elements for U,V channels due to sub-sampling of 2 + _subsampling = 1; + + if(format == Format::YUYV422 || format == Format::UYVY422) + { + // Check if the width of the tensor shape is even for formats with subsampled channels (UYVY422 and YUYV422) + ARM_COMPUTE_ERROR_ON_TENSORS_NOT_EVEN(format, input); + + if(channel != Channel::Y) + { + _subsampling = 2; + } + } + + // Calculate output tensor shape using subsampling + TensorShape output_shape = calculate_subsampled_shape(input->info()->tensor_shape(), format, channel); + set_shape_if_empty(*output->info(), output_shape); + + ARM_COMPUTE_ERROR_ON_MISMATCHING_DIMENSIONS(output->info()->tensor_shape(), output_shape); + + _input = input; + _output = output; + // Create kernel std::string kernel_name = "channel_extract_" + string_from_format(format); std::set build_opts = { ("-DCHANNEL_" + string_from_channel(channel)) }; _kernel = static_cast(CLKernelLibrary::get().create_kernel(kernel_name, build_opts)); - // Half the processed elements for U,V channels due to sub-sampling of 2 - _subsampling = ((Format::YUYV422 == format || Format::UYVY422 == format) && Channel::Y != channel) ? 2 : 1; - // Configure 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); @@ -83,17 +106,34 @@ void CLChannelExtractKernel::configure(const ICLTensor *input, Channel channel, void CLChannelExtractKernel::configure(const ICLMultiImage *input, Channel channel, ICLImage *output) { + ARM_COMPUTE_ERROR_ON_NULLPTR(input, output); ARM_COMPUTE_ERROR_ON_TENSOR_NOT_2D(output); - ARM_COMPUTE_ERROR_ON_FORMAT_NOT_IN(input, Format::NV12, Format::NV21, Format::IYUV, Format::YUV444); - ARM_COMPUTE_ERROR_ON_FORMAT_NOT_IN(output, Format::U8); - ARM_COMPUTE_ERROR_ON(static_cast(input) == static_cast(output)); - // Get format - const Format fmt = input->info()->format(); + set_format_if_unknown(*output->info(), Format::U8); + + // Check if channel is valid for given format + const Format format = input->info()->format(); + ARM_COMPUTE_ERROR_ON_CHANNEL_NOT_IN_KNOWN_FORMAT(format, channel); + + // Get input plane from the given channel + const ICLImage *input_plane = input->cl_plane(plane_idx_from_channel(format, channel)); + ARM_COMPUTE_ERROR_ON_NULLPTR(input_plane); + + if(Channel::Y == channel && format != Format::YUV444) + { + // Check if the width of the tensor shape is even for formats with subsampled channels (UYVY422 and YUYV422) + ARM_COMPUTE_ERROR_ON_TENSORS_NOT_EVEN(format, input_plane); + } + + // Calculate 2x2 subsampled tensor shape + TensorShape output_shape = calculate_subsampled_shape(input->cl_plane(0)->info()->tensor_shape(), format, channel); + set_shape_if_empty(*output->info(), output_shape); + + ARM_COMPUTE_ERROR_ON_MISMATCHING_DIMENSIONS(output_shape, output->info()->tensor_shape()); - // Get input plane - const ICLImage *input_plane = input->cl_plane(plane_idx_from_channel(fmt, channel)); - ARM_COMPUTE_ERROR_ON(nullptr == input_plane); + // Check if input tensor has a valid format + ARM_COMPUTE_ERROR_ON_FORMAT_NOT_IN(input, Format::NV12, Format::NV21, Format::IYUV, Format::YUV444); + ARM_COMPUTE_ERROR_ON_FORMAT_NOT_IN(output, Format::U8); _output = output; _input = input_plane; @@ -102,13 +142,13 @@ void CLChannelExtractKernel::configure(const ICLMultiImage *input, Channel chann // Create kernel std::string kernel_name; std::set build_opts; - if(Channel::Y == channel || Format::IYUV == fmt || Format::YUV444 == fmt) + if(Channel::Y == channel || Format::IYUV == format || Format::YUV444 == format) { kernel_name = "copy_plane"; } else { - kernel_name = "channel_extract_" + string_from_format(fmt); + kernel_name = "channel_extract_" + string_from_format(format); build_opts.insert(("-DCHANNEL_" + string_from_channel(channel))); } _kernel = static_cast(CLKernelLibrary::get().create_kernel(kernel_name, build_opts)); -- cgit v1.2.1