From 91d20d95df35961d3eb5de497007d98576118d19 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: I6413a05f6870a0d04f12d7348269b15297ae8493 Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/114696 Tested-by: Jenkins Reviewed-by: Anthony Barbier --- src/core/CL/kernels/CLChannelExtractKernel.cpp | 78 +++++++++++++++++++------- 1 file changed, 59 insertions(+), 19 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 be046cf0a1..65843b8d5d 100644 --- a/src/core/CL/kernels/CLChannelExtractKernel.cpp +++ b/src/core/CL/kernels/CLChannelExtractKernel.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2017 ARM Limited. + * Copyright (c) 2016-2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -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