From 1fbb8120aa4f5ea2e73393421611ffea803a05b4 Mon Sep 17 00:00:00 2001 From: Anthony Barbier Date: Mon, 19 Feb 2018 19:36:02 +0000 Subject: Revert "COMPMID-582: Add validation to channel_extract kernels." This reverts commit 9a0875951d43dda035f32d2e0728cf59d80cb4d3. Change-Id: I6af0bc64c656f91cf1e0357f8760defa08f2e78d Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/121190 Reviewed-by: Anthony Barbier Tested-by: Anthony Barbier --- arm_compute/core/Utils.h | 225 --------------------- arm_compute/core/Validate.h | 32 --- src/core/CL/kernels/CLChannelExtractKernel.cpp | 76 ++----- src/core/NEON/kernels/NEChannelExtractKernel.cpp | 231 +++++++++++++++------- src/runtime/CL/CLMultiImage.cpp | 14 +- src/runtime/MultiImage.cpp | 14 +- tests/AssetsLibrary.h | 26 ++- tests/SimpleTensor.h | 21 +- tests/Utils.h | 16 -- tests/validation/CL/ChannelExtract.cpp | 153 -------------- tests/validation/NEON/ChannelExtract.cpp | 153 -------------- tests/validation/fixtures/ChannelExtractFixture.h | 192 ------------------ tests/validation/reference/ChannelExtract.cpp | 76 ------- tests/validation/reference/ChannelExtract.h | 43 ---- utils/TypePrinter.h | 7 - 15 files changed, 202 insertions(+), 1077 deletions(-) delete mode 100644 tests/validation/CL/ChannelExtract.cpp delete mode 100644 tests/validation/NEON/ChannelExtract.cpp delete mode 100644 tests/validation/fixtures/ChannelExtractFixture.h delete mode 100644 tests/validation/reference/ChannelExtract.cpp delete mode 100644 tests/validation/reference/ChannelExtract.h diff --git a/arm_compute/core/Utils.h b/arm_compute/core/Utils.h index b3ebf5e25b..111eac0e57 100644 --- a/arm_compute/core/Utils.h +++ b/arm_compute/core/Utils.h @@ -237,25 +237,9 @@ inline int plane_idx_from_channel(Format format, Channel channel) { switch(format) { - // Single planar formats have a single plane - case Format::U8: - case Format::U16: - case Format::S16: - case Format::U32: - case Format::S32: - case Format::F16: - case Format::F32: - case Format::UV88: - case Format::RGB888: - case Format::RGBA8888: - case Format::YUYV422: - case Format::UYVY422: - return 0; - // Multi planar formats case Format::NV12: case Format::NV21: { - // Channel U and V share the same plane of format UV88 switch(channel) { case Channel::Y: @@ -290,131 +274,6 @@ inline int plane_idx_from_channel(Format format, Channel channel) } } -/** Return the channel index of a given channel given an input format. - * - * @param[in] format Input format - * @param[in] channel Input channel - * - * @return The channel index of the specific channel of the specific format - */ -inline int channel_idx_from_format(Format format, Channel channel) -{ - switch(format) - { - case Format::RGB888: - { - switch(channel) - { - case Channel::R: - return 0; - case Channel::G: - return 1; - case Channel::B: - return 2; - default: - ARM_COMPUTE_ERROR("Not supported channel"); - return 0; - } - } - case Format::RGBA8888: - { - switch(channel) - { - case Channel::R: - return 0; - case Channel::G: - return 1; - case Channel::B: - return 2; - case Channel::A: - return 3; - default: - ARM_COMPUTE_ERROR("Not supported channel"); - return 0; - } - } - case Format::YUYV422: - { - switch(channel) - { - case Channel::Y: - return 0; - case Channel::U: - return 1; - case Channel::V: - return 3; - default: - ARM_COMPUTE_ERROR("Not supported channel"); - return 0; - } - } - case Format::UYVY422: - { - switch(channel) - { - case Channel::Y: - return 1; - case Channel::U: - return 0; - case Channel::V: - return 2; - default: - ARM_COMPUTE_ERROR("Not supported channel"); - return 0; - } - } - case Format::NV12: - { - switch(channel) - { - case Channel::Y: - return 0; - case Channel::U: - return 0; - case Channel::V: - return 1; - default: - ARM_COMPUTE_ERROR("Not supported channel"); - return 0; - } - } - case Format::NV21: - { - switch(channel) - { - case Channel::Y: - return 0; - case Channel::U: - return 1; - case Channel::V: - return 0; - default: - ARM_COMPUTE_ERROR("Not supported channel"); - return 0; - } - } - case Format::YUV444: - case Format::IYUV: - { - switch(channel) - { - case Channel::Y: - return 0; - case Channel::U: - return 0; - case Channel::V: - return 0; - default: - ARM_COMPUTE_ERROR("Not supported channel"); - return 0; - } - } - default: - ARM_COMPUTE_ERROR("Not supported format"); - return 0; - } -} - /** Return the number of planes for a given format * * @param[in] format Input format @@ -525,28 +384,6 @@ inline DataType get_promoted_data_type(DataType dt) return DataType::UNKNOWN; } -/** Return true if the given format has horizontal subsampling. - * - * @param[in] format Format to determine subsampling. - * - * @return True if the format can be subsampled horizontaly. - */ -inline bool has_format_horizontal_subsampling(Format format) -{ - return (format == Format::YUYV422 || format == Format::UYVY422 || format == Format::NV12 || format == Format::NV21 || format == Format::IYUV || format == Format::UV88) ? true : false; -} - -/** Return true if the given format has vertical subsampling. - * - * @param[in] format Format to determine subsampling. - * - * @return True if the format can be subsampled verticaly. - */ -inline bool has_format_vertical_subsampling(Format format) -{ - return (format == Format::NV12 || format == Format::NV21 || format == Format::IYUV || format == Format::UV88) ? true : false; -} - /** Separate a 2D convolution into two 1D convolutions * * @param[in] conv 2D convolution @@ -654,68 +491,6 @@ TensorShape calculate_depth_concatenate_shape(const std::vector &inputs_vec return out_shape; } -/** Adjust tensor shape size if width or height are odd for a given multi-planar format. No modification is done for other formats. - * - * @note Adding here a few links discussing the issue of odd size and sharing the same solution: - * Android Source: https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/graphics/java/android/graphics/YuvImage.java - * WebM: https://groups.google.com/a/webmproject.org/forum/#!topic/webm-discuss/LaCKpqiDTXM - * libYUV: https://bugs.chromium.org/p/libyuv/issues/detail?id=198&can=1&q=odd%20width - * YUVPlayer: https://sourceforge.net/p/raw-yuvplayer/bugs/1/ - * - * @param[in, out] shape Tensor shape of 2D size - * @param[in] format Format of the tensor - * - */ -inline TensorShape adjust_odd_shape(const TensorShape &shape, Format format) -{ - TensorShape output{ shape }; - - // Force width to be even for formats which require subsampling of the U and V channels - if(has_format_horizontal_subsampling(format)) - { - output.set(0, output.x() & ~1U); - } - - // Force height to be even for formats which require subsampling of the U and V channels - if(has_format_vertical_subsampling(format)) - { - output.set(1, output.y() & ~1U); - } - - return output; -} - -/** Calculate subsampled shape for a given format and channel - * - * @param[in] shape Shape of the tensor to calculate the extracted channel. - * @param[in] format Format of the tensor. - * @param[in] channel Channel to create tensor shape to be extracted. - * - * @return The subsampled tensor shape. - */ -inline TensorShape calculate_subsampled_shape(const TensorShape &shape, Format format, Channel channel = Channel::UNKNOWN) -{ - TensorShape output{ shape }; - - // Subsample shape only for U or V channel - if(Channel::U == channel || Channel::V == channel || Channel::UNKNOWN == channel) - { - // Subsample width for the tensor shape when channel is U or V - if(has_format_horizontal_subsampling(format)) - { - output.set(0, output.x() / 2U); - } - - // Subsample height for the tensor shape when channel is U or V - if(has_format_vertical_subsampling(format)) - { - output.set(1, output.y() / 2U); - } - } - - return output; -} - /** Calculate accurary required by the horizontal and vertical convolution computations * * @param[in] conv_col Pointer to the vertical vector of the separated convolution filter diff --git a/arm_compute/core/Validate.h b/arm_compute/core/Validate.h index b04d293c4c..79e342c8ae 100644 --- a/arm_compute/core/Validate.h +++ b/arm_compute/core/Validate.h @@ -271,38 +271,6 @@ arm_compute::Status error_on_mismatching_dimensions(const char *function, const #define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DIMENSIONS(...) \ ARM_COMPUTE_RETURN_ON_ERROR(::arm_compute::error_on_mismatching_dimensions(__func__, __FILE__, __LINE__, __VA_ARGS__)) -/** Return an error if the passed tensor objects are not even. - * - * @param[in] function Function in which the error occurred. - * @param[in] file Name of the file where the error occurred. - * @param[in] line Line on which the error occurred. - * @param[in] format Format to check if odd shape is allowed - * @param[in] tensor1 The first object to be compared for odd shape. - * @param[in] tensors (Optional) Further allowed objects. - * - * @return Status - */ -template -arm_compute::Status error_on_tensors_not_even(const char *function, const char *file, int line, - const Format &format, const ITensor *tensor1, Ts... tensors) -{ - ARM_COMPUTE_RETURN_ERROR_ON_LOC(tensor1 == nullptr, function, file, line); - ARM_COMPUTE_RETURN_ON_ERROR(::arm_compute::error_on_nullptr(function, file, line, std::forward(tensors)...)); - const std::array < const ITensor *, 1 + sizeof...(Ts) > tensors_info_array{ { tensor1, std::forward(tensors)... } }; - ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG(std::any_of(tensors_info_array.cbegin(), tensors_info_array.cend(), [&](const ITensor * tensor) - { - const TensorShape correct_shape = adjust_odd_shape(tensor->info()->tensor_shape(), format); - return detail::have_different_dimensions(tensor->info()->tensor_shape(), correct_shape, 2); - }), - function, file, line, "Tensor shape has odd dimensions"); - return arm_compute::Status{}; -} - -#define ARM_COMPUTE_ERROR_ON_TENSORS_NOT_EVEN(...) \ - ARM_COMPUTE_ERROR_THROW_ON(::arm_compute::error_on_tensors_not_even(__func__, __FILE__, __LINE__, __VA_ARGS__)) -#define ARM_COMPUTE_RETURN_ERROR_ON_TENSORS_NOT_EVEN(...) \ - ARM_COMPUTE_RETURN_ON_ERROR(::arm_compute::error_on_tensors_not_even(__func__, __FILE__, __LINE__, __VA_ARGS__)) - /** Return an error if the passed two tensor infos have different shapes from the given dimension * * @param[in] function Function in which the error occurred. diff --git a/src/core/CL/kernels/CLChannelExtractKernel.cpp b/src/core/CL/kernels/CLChannelExtractKernel.cpp index 65843b8d5d..d0c633555d 100644 --- a/src/core/CL/kernels/CLChannelExtractKernel.cpp +++ b/src/core/CL/kernels/CLChannelExtractKernel.cpp @@ -49,48 +49,25 @@ 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_TENSOR_NOT_2D(output); - - // 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); + ARM_COMPUTE_ERROR_ON(static_cast(input) == static_cast(output)); _input = input; _output = output; + // Check format + const Format format = input->info()->format(); + ARM_COMPUTE_ERROR_ON_CHANNEL_NOT_IN_KNOWN_FORMAT(format, channel); + // 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); @@ -106,34 +83,17 @@ 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); - - 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()); - - // 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); + ARM_COMPUTE_ERROR_ON(static_cast(input) == static_cast(output)); + + // Get format + const Format fmt = input->info()->format(); + + // Get input plane + const ICLImage *input_plane = input->cl_plane(plane_idx_from_channel(fmt, channel)); + ARM_COMPUTE_ERROR_ON(nullptr == input_plane); _output = output; _input = input_plane; @@ -142,13 +102,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 == format || Format::YUV444 == format) + if(Channel::Y == channel || Format::IYUV == fmt || Format::YUV444 == fmt) { kernel_name = "copy_plane"; } else { - kernel_name = "channel_extract_" + string_from_format(format); + kernel_name = "channel_extract_" + string_from_format(fmt); build_opts.insert(("-DCHANNEL_" + string_from_channel(channel))); } _kernel = static_cast(CLKernelLibrary::get().create_kernel(kernel_name, build_opts)); diff --git a/src/core/NEON/kernels/NEChannelExtractKernel.cpp b/src/core/NEON/kernels/NEChannelExtractKernel.cpp index 98b2f280d4..e8375d1e6d 100644 --- a/src/core/NEON/kernels/NEChannelExtractKernel.cpp +++ b/src/core/NEON/kernels/NEChannelExtractKernel.cpp @@ -56,68 +56,106 @@ void NEChannelExtractKernel::configure(const ITensor *input, Channel channel, IT 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::UYVY422, Format::YUYV422); ARM_COMPUTE_ERROR_ON_FORMAT_NOT_IN(output, Format::U8); - ARM_COMPUTE_ERROR_ON_TENSOR_NOT_2D(input); - ARM_COMPUTE_ERROR_ON_TENSOR_NOT_2D(output); - - // 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); + unsigned int num_elems_processed_per_iteration = 8; - unsigned int subsampling = 1; + // Check format and channel + const Format format = input->info()->format(); + const unsigned int subsampling = (format == Format::YUYV422 || format == Format::UYVY422) && channel != Channel::Y ? 2 : 1; + TensorShape output_shape; - if(format == Format::YUYV422 || format == Format::UYVY422) + switch(format) { - // 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; - } + case Format::RGB888: + case Format::RGBA8888: + num_elems_processed_per_iteration = 16; + output_shape = input->info()->tensor_shape(); + + if(format == Format::RGB888) + { + _func = &NEChannelExtractKernel::extract_1C_from_3C_img; + } + else if(format == Format::RGBA8888) + { + _func = &NEChannelExtractKernel::extract_1C_from_4C_img; + } + + switch(channel) + { + case Channel::R: + _lut_index = 0; + break; + case Channel::G: + _lut_index = 1; + break; + case Channel::B: + _lut_index = 2; + break; + case Channel::A: + if(format == Format::RGBA8888) + { + _lut_index = 3; + _func = &NEChannelExtractKernel::extract_1C_from_4C_img; + break; + } + default: + ARM_COMPUTE_ERROR("Not supported channel for this format."); + break; + } + break; + case Format::YUYV422: + case Format::UYVY422: + output_shape = input->info()->tensor_shape(); + + if(channel != Channel::Y) + { + output_shape.set(0, output_shape[0] / 2); + } + + switch(channel) + { + case Channel::Y: + num_elems_processed_per_iteration = 16; + _func = &NEChannelExtractKernel::extract_1C_from_2C_img; + _lut_index = (Format::YUYV422 == format) ? 0 : 1; + break; + case Channel::U: + num_elems_processed_per_iteration = 32; + _func = &NEChannelExtractKernel::extract_YUYV_uv; + _lut_index = (Format::YUYV422 == format) ? 1 : 0; + break; + case Channel::V: + num_elems_processed_per_iteration = 32; + _func = &NEChannelExtractKernel::extract_YUYV_uv; + _lut_index = (Format::YUYV422 == format) ? 3 : 2; + break; + default: + ARM_COMPUTE_ERROR("Not supported channel for this format."); + break; + } + break; + default: + ARM_COMPUTE_ERROR("Not supported format."); + break; } - 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_shape, output->info()->tensor_shape()); + ARM_COMPUTE_ERROR_ON_MISMATCHING_DIMENSIONS(output->info()->tensor_shape(), output_shape); - _input = input; - _output = output; - _lut_index = channel_idx_from_format(format, channel); - - unsigned int num_elems_processed_per_iteration = 16; - - if(format == Format::YUYV422 || format == Format::UYVY422) - { - _func = &NEChannelExtractKernel::extract_1C_from_2C_img; - - if(channel != Channel::Y) // Channel::U or Channel::V - { - num_elems_processed_per_iteration = 32; - _func = &NEChannelExtractKernel::extract_YUYV_uv; - } - } - else // Format::RGB888 or Format::RGBA8888 - { - _func = &NEChannelExtractKernel::extract_1C_from_3C_img; - - if(format == Format::RGBA8888) - { - _func = &NEChannelExtractKernel::extract_1C_from_4C_img; - } - } - - Window win = calculate_max_window(*input->info(), Steps(num_elems_processed_per_iteration)); + _input = input; + _output = output; + Window win = calculate_max_window(*input->info(), Steps(num_elems_processed_per_iteration)); AccessWindowHorizontal input_access(input->info(), 0, num_elems_processed_per_iteration); AccessWindowRectangle output_access(output->info(), 0, 0, num_elems_processed_per_iteration, 1, 1.f / subsampling, 1.f / subsampling); + update_window_and_padding(win, input_access, output_access); ValidRegion input_valid_region = input->info()->valid_region(); + output_access.set_valid_region(win, ValidRegion(input_valid_region.anchor, output->info()->tensor_shape())); INEKernel::configure(win); @@ -130,45 +168,94 @@ void NEChannelExtractKernel::configure(const IMultiImage *input, Channel channel set_format_if_unknown(*output->info(), Format::U8); - const Format format = input->info()->format(); - ARM_COMPUTE_ERROR_ON_CHANNEL_NOT_IN_KNOWN_FORMAT(format, channel); - - // Get input plane - const IImage *input_plane = input->plane(plane_idx_from_channel(format, channel)); - ARM_COMPUTE_ERROR_ON_NULLPTR(input_plane); - - if(Channel::Y == channel && format != Format::YUV444) + switch(input->info()->format()) { - // 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); + case Format::NV12: + case Format::NV21: + case Format::IYUV: + switch(channel) + { + case Channel::Y: + set_shape_if_empty(*output->info(), input->plane(0)->info()->tensor_shape()); + ARM_COMPUTE_ERROR_ON_MISMATCHING_SHAPES(input->plane(0), output); + break; + case Channel::U: + case Channel::V: + set_shape_if_empty(*output->info(), input->plane(1)->info()->tensor_shape()); + ARM_COMPUTE_ERROR_ON_MISMATCHING_SHAPES(input->plane(1), output); + break; + default: + ARM_COMPUTE_ERROR("Unsupported channel for selected format"); + } + break; + case Format::YUV444: + set_shape_if_empty(*output->info(), input->plane(0)->info()->tensor_shape()); + ARM_COMPUTE_ERROR_ON_MISMATCHING_SHAPES(input->plane(0), output); + break; + default: + ARM_COMPUTE_ERROR("Unsupported format"); } - // Calculate 2x2 subsampled tensor shape - TensorShape output_shape = calculate_subsampled_shape(input->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()); - - // 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); - _input = input_plane; - _output = output; - _lut_index = channel_idx_from_format(format, channel); - unsigned int num_elems_processed_per_iteration = 32; - _func = &NEChannelExtractKernel::copy_plane; + const Format &format = input->info()->format(); - if((format == Format::NV12 || format == Format::NV21) && channel != Channel::Y) + switch(format) { - num_elems_processed_per_iteration = 16; - _func = &NEChannelExtractKernel::extract_1C_from_2C_img; + case Format::NV12: + case Format::NV21: + switch(channel) + { + case Channel::Y: + _input = input->plane(0); + _func = &NEChannelExtractKernel::copy_plane; + break; + case Channel::U: + _input = input->plane(1); + num_elems_processed_per_iteration = 16; + _func = &NEChannelExtractKernel::extract_1C_from_2C_img; + _lut_index = (Format::NV12 == format) ? 0 : 1; + break; + case Channel::V: + _input = input->plane(1); + num_elems_processed_per_iteration = 16; + _func = &NEChannelExtractKernel::extract_1C_from_2C_img; + _lut_index = (Format::NV12 == format) ? 1 : 0; + break; + default: + ARM_COMPUTE_ERROR("Not supported channel for this format."); + break; + } + break; + case Format::IYUV: + case Format::YUV444: + _func = &NEChannelExtractKernel::copy_plane; + switch(channel) + { + case Channel::Y: + _input = input->plane(0); + break; + case Channel::U: + _input = input->plane(1); + break; + case Channel::V: + _input = input->plane(2); + break; + default: + ARM_COMPUTE_ERROR("Not supported channel for this format."); + break; + } + break; + default: + ARM_COMPUTE_ERROR("Not supported format."); + break; } - Window win = calculate_max_window(*_input->info(), Steps(num_elems_processed_per_iteration)); - + _output = output; + Window win = calculate_max_window(*_input->info(), Steps(num_elems_processed_per_iteration)); AccessWindowHorizontal input_access(_input->info(), 0, num_elems_processed_per_iteration); AccessWindowHorizontal output_access(output->info(), 0, num_elems_processed_per_iteration); update_window_and_padding(win, input_access, output_access); diff --git a/src/runtime/CL/CLMultiImage.cpp b/src/runtime/CL/CLMultiImage.cpp index 92254f3531..aa09c7a67b 100644 --- a/src/runtime/CL/CLMultiImage.cpp +++ b/src/runtime/CL/CLMultiImage.cpp @@ -25,7 +25,6 @@ #include "arm_compute/core/Error.h" #include "arm_compute/core/TensorInfo.h" -#include "arm_compute/core/Utils.h" #include "arm_compute/runtime/ITensorAllocator.h" using namespace arm_compute; @@ -52,8 +51,7 @@ void CLMultiImage::init_auto_padding(unsigned int width, unsigned int height, Fo void CLMultiImage::internal_init(unsigned int width, unsigned int height, Format format, bool auto_padding) { - TensorShape shape = adjust_odd_shape(TensorShape{ width, height }, format); - TensorInfo info(shape, Format::U8); + TensorInfo info(width, height, Format::U8); if(auto_padding) { @@ -74,7 +72,7 @@ void CLMultiImage::internal_init(unsigned int width, unsigned int height, Format case Format::YUYV422: case Format::UYVY422: { - TensorInfo info_full(shape, format); + TensorInfo info_full(width, height, format); if(auto_padding) { @@ -87,8 +85,7 @@ void CLMultiImage::internal_init(unsigned int width, unsigned int height, Format case Format::NV12: case Format::NV21: { - const TensorShape shape_uv88 = calculate_subsampled_shape(shape, Format::UV88); - TensorInfo info_uv88(shape_uv88, Format::UV88); + TensorInfo info_uv88(width / 2, height / 2, Format::UV88); if(auto_padding) { @@ -101,8 +98,7 @@ void CLMultiImage::internal_init(unsigned int width, unsigned int height, Format } case Format::IYUV: { - const TensorShape shape_sub2 = calculate_subsampled_shape(shape, Format::IYUV); - TensorInfo info_sub2(shape_sub2, Format::U8); + TensorInfo info_sub2(width / 2, height / 2, Format::U8); if(auto_padding) { @@ -124,7 +120,7 @@ void CLMultiImage::internal_init(unsigned int width, unsigned int height, Format break; } - _info.init(shape.x(), shape.y(), format); + _info.init(width, height, format); } void CLMultiImage::allocate() diff --git a/src/runtime/MultiImage.cpp b/src/runtime/MultiImage.cpp index 6eba71bf1d..bdafe4c9a2 100644 --- a/src/runtime/MultiImage.cpp +++ b/src/runtime/MultiImage.cpp @@ -25,7 +25,6 @@ #include "arm_compute/core/Error.h" #include "arm_compute/core/TensorInfo.h" -#include "arm_compute/core/Utils.h" #include "arm_compute/runtime/TensorAllocator.h" using namespace arm_compute; @@ -52,8 +51,7 @@ void MultiImage::init_auto_padding(unsigned int width, unsigned int height, Form void MultiImage::internal_init(unsigned int width, unsigned int height, Format format, bool auto_padding) { - TensorShape shape = adjust_odd_shape(TensorShape{ width, height }, format); - TensorInfo info(shape, Format::U8); + TensorInfo info(width, height, Format::U8); if(auto_padding) { @@ -74,7 +72,7 @@ void MultiImage::internal_init(unsigned int width, unsigned int height, Format f case Format::YUYV422: case Format::UYVY422: { - TensorInfo info_full(shape, format); + TensorInfo info_full(width, height, format); if(auto_padding) { @@ -87,8 +85,7 @@ void MultiImage::internal_init(unsigned int width, unsigned int height, Format f case Format::NV12: case Format::NV21: { - const TensorShape shape_uv88 = calculate_subsampled_shape(shape, Format::UV88); - TensorInfo info_uv88(shape_uv88, Format::UV88); + TensorInfo info_uv88(width / 2, height / 2, Format::UV88); if(auto_padding) { @@ -101,8 +98,7 @@ void MultiImage::internal_init(unsigned int width, unsigned int height, Format f } case Format::IYUV: { - const TensorShape shape_sub2 = calculate_subsampled_shape(shape, Format::IYUV); - TensorInfo info_sub2(shape_sub2, Format::U8); + TensorInfo info_sub2(width / 2, height / 2, Format::U8); if(auto_padding) { @@ -124,7 +120,7 @@ void MultiImage::internal_init(unsigned int width, unsigned int height, Format f break; } - _info.init(shape.x(), shape.y(), format); + _info.init(width, height, format); } void MultiImage::allocate() diff --git a/tests/AssetsLibrary.h b/tests/AssetsLibrary.h index afdf714ff1..c9bd427845 100644 --- a/tests/AssetsLibrary.h +++ b/tests/AssetsLibrary.h @@ -416,24 +416,22 @@ void AssetsLibrary::fill_borders_with_garbage(T &&tensor, D &&distribution, std: template void AssetsLibrary::fill(T &&tensor, D &&distribution, std::random_device::result_type seed_offset) const { - using ResultType = typename std::remove_reference::type::result_type; + Window window; + for(unsigned int d = 0; d < tensor.shape().num_dimensions(); ++d) + { + window.set(d, Window::Dimension(0, tensor.shape()[d], 1)); + } std::mt19937 gen(_seed + seed_offset); - // Iterate over all elements - for(int element_idx = 0; element_idx < tensor.num_elements(); ++element_idx) + //FIXME: Replace with normal loop + execute_window_loop(window, [&](const Coordinates & id) { - const Coordinates id = index2coord(tensor.shape(), element_idx); - - // Iterate over all channels - for(int channel = 0; channel < tensor.num_channels(); ++channel) - { - const ResultType value = distribution(gen); - ResultType &target_value = reinterpret_cast(tensor(id))[channel]; - - store_value_with_data_type(&target_value, value, tensor.data_type()); - } - } + using ResultType = typename std::remove_reference::type::result_type; + const ResultType value = distribution(gen); + void *const out_ptr = tensor(id); + store_value_with_data_type(out_ptr, value, tensor.data_type()); + }); fill_borders_with_garbage(tensor, distribution, seed_offset); } diff --git a/tests/SimpleTensor.h b/tests/SimpleTensor.h index f3155ffeab..3dbb4862f8 100644 --- a/tests/SimpleTensor.h +++ b/tests/SimpleTensor.h @@ -297,33 +297,18 @@ int SimpleTensor::num_channels() const switch(_format) { case Format::U8: - case Format::U16: case Format::S16: - case Format::U32: + case Format::U16: case Format::S32: - case Format::F16: + case Format::U32: case Format::F32: return 1; - // Because the U and V channels are subsampled - // these formats appear like having only 2 channels: - case Format::YUYV422: - case Format::UYVY422: - return 2; - case Format::UV88: - return 2; case Format::RGB888: return 3; - case Format::RGBA8888: - return 4; case Format::UNKNOWN: return _num_channels; - //Doesn't make sense for planar formats: - case Format::NV12: - case Format::NV21: - case Format::IYUV: - case Format::YUV444: default: - return 0; + ARM_COMPUTE_ERROR("NOT SUPPORTED!"); } } diff --git a/tests/Utils.h b/tests/Utils.h index 27e0397b6b..893cb3ebb4 100644 --- a/tests/Utils.h +++ b/tests/Utils.h @@ -500,22 +500,6 @@ inline T create_tensor(const TensorShape &shape, Format format) return tensor; } -/** Create and initialize a multi-image of the given type. - * - * @param[in] shape Tensor shape. - * @param[in] format Format type. - * - * @return Initialized tensor of given type. - */ -template -inline T create_multi_image(const TensorShape &shape, Format format) -{ - T multi_image; - multi_image.init(shape.x(), shape.y(), format); - - return multi_image; -} - /** Create and initialize a HOG (Histogram of Oriented Gradients) of the given type. * * @param[in] cell_size Cell size in pixels diff --git a/tests/validation/CL/ChannelExtract.cpp b/tests/validation/CL/ChannelExtract.cpp deleted file mode 100644 index 1248a2072d..0000000000 --- a/tests/validation/CL/ChannelExtract.cpp +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Copyright (c) 2017-2018 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "arm_compute/core/Types.h" -#include "arm_compute/runtime/CL/CLMultiImage.h" -#include "arm_compute/runtime/CL/CLTensor.h" -#include "arm_compute/runtime/CL/CLTensorAllocator.h" -#include "arm_compute/runtime/CL/functions/CLChannelExtract.h" -#include "tests/CL/CLAccessor.h" -#include "tests/PaddingCalculator.h" -#include "tests/datasets/ConvertPolicyDataset.h" -#include "tests/datasets/ShapeDatasets.h" -#include "tests/framework/Asserts.h" -#include "tests/framework/Macros.h" -#include "tests/framework/datasets/Datasets.h" -#include "tests/validation/Validation.h" -#include "tests/validation/fixtures/ChannelExtractFixture.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace -{ -// Input data sets -const auto ChannelExtractRGBADataset = combine(framework::dataset::make("FormatType", { Format::RGBA8888 }), - framework::dataset::make("ChannelType", { Channel::R, Channel::G, Channel::B, Channel::A })); -const auto ChannelExtractYUVDataset = combine(framework::dataset::make("FormatType", { Format::YUYV422, Format::UYVY422 }), - framework::dataset::make("ChannelType", { Channel::Y, Channel::U, Channel::V })); -const auto ChannelExtractYUVPlanarDataset = combine(framework::dataset::make("FormatType", { Format::IYUV, Format::YUV444, Format::NV12, Format::NV21 }), - framework::dataset::make("ChannelType", { Channel::Y, Channel::U, Channel::V })); - -inline void validate_configuration(const TensorShape &shape, Format format, Channel channel) -{ - const unsigned int num_planes = num_planes_from_format(format); - - TensorShape dst_shape = adjust_odd_shape(shape, format); - dst_shape = calculate_subsampled_shape(dst_shape, format, channel); - - // Create tensors - CLMultiImage ref_src = create_multi_image(shape, format); - CLTensor dst = create_tensor(dst_shape, Format::U8); - - // Create and Configure function - CLChannelExtract channel_extract; - - if(1U == num_planes) - { - const CLTensor *plane_src = ref_src.cl_plane(0); - - channel_extract.configure(plane_src, channel, &dst); - } - else - { - channel_extract.configure(&ref_src, channel, &dst); - } - - // TODO(bsgcomp): Add validation for padding and shape (COMPMID-659) -} -} // namespace - -TEST_SUITE(CL) -TEST_SUITE(ChannelExtract) - -template -using CLChannelExtractFixture = ChannelExtractValidationFixture; - -TEST_SUITE(Configuration) -DATA_TEST_CASE(RGBA, framework::DatasetMode::ALL, combine(concat(datasets::Small2DShapes(), datasets::Large2DShapes()), ChannelExtractRGBADataset), - shape, format, channel) -{ - validate_configuration(shape, format, channel); -} -DATA_TEST_CASE(YUV, framework::DatasetMode::ALL, combine(concat(datasets::Small2DShapes(), datasets::Large2DShapes()), ChannelExtractYUVDataset), - shape, format, channel) -{ - validate_configuration(shape, format, channel); -} - -DATA_TEST_CASE(YUVPlanar, framework::DatasetMode::ALL, combine(concat(datasets::Small2DShapes(), datasets::Large2DShapes()), ChannelExtractYUVPlanarDataset), - shape, format, channel) -{ - validate_configuration(shape, format, channel); -} -TEST_SUITE_END() - -TEST_SUITE(RGBA) -FIXTURE_DATA_TEST_CASE(RunSmall, CLChannelExtractFixture, framework::DatasetMode::PRECOMMIT, combine(datasets::Small2DShapes(), ChannelExtractRGBADataset)) -{ - // Validate output - validate(CLAccessor(_target), _reference); -} -FIXTURE_DATA_TEST_CASE(RunLarge, CLChannelExtractFixture, framework::DatasetMode::NIGHTLY, combine(datasets::Large2DShapes(), ChannelExtractRGBADataset)) -{ - // Validate output - validate(CLAccessor(_target), _reference); -} -TEST_SUITE_END() - -TEST_SUITE(YUV) -FIXTURE_DATA_TEST_CASE(RunSmall, CLChannelExtractFixture, framework::DatasetMode::PRECOMMIT, combine(datasets::Small2DShapes(), ChannelExtractYUVDataset)) -{ - // Validate output - validate(CLAccessor(_target), _reference); -} -FIXTURE_DATA_TEST_CASE(RunLarge, CLChannelExtractFixture, framework::DatasetMode::NIGHTLY, combine(datasets::Large2DShapes(), ChannelExtractYUVDataset)) -{ - // Validate output - validate(CLAccessor(_target), _reference); -} -TEST_SUITE_END() - -TEST_SUITE(YUVPlanar) -FIXTURE_DATA_TEST_CASE(RunSmall, CLChannelExtractFixture, framework::DatasetMode::PRECOMMIT, combine(datasets::Small2DShapes(), ChannelExtractYUVPlanarDataset)) -{ - // Validate output - validate(CLAccessor(_target), _reference); -} -FIXTURE_DATA_TEST_CASE(RunLarge, CLChannelExtractFixture, framework::DatasetMode::NIGHTLY, combine(datasets::Large2DShapes(), ChannelExtractYUVPlanarDataset)) -{ - // Validate output - validate(CLAccessor(_target), _reference); -} -TEST_SUITE_END() - -TEST_SUITE_END() -TEST_SUITE_END() - -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/NEON/ChannelExtract.cpp b/tests/validation/NEON/ChannelExtract.cpp deleted file mode 100644 index 4d8599a21d..0000000000 --- a/tests/validation/NEON/ChannelExtract.cpp +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Copyright (c) 2017-2018 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "arm_compute/core/Types.h" -#include "arm_compute/runtime/MultiImage.h" -#include "arm_compute/runtime/NEON/functions/NEChannelExtract.h" -#include "arm_compute/runtime/Tensor.h" -#include "arm_compute/runtime/TensorAllocator.h" -#include "tests/NEON/Accessor.h" -#include "tests/PaddingCalculator.h" -#include "tests/datasets/ConvertPolicyDataset.h" -#include "tests/datasets/ShapeDatasets.h" -#include "tests/framework/Asserts.h" -#include "tests/framework/Macros.h" -#include "tests/framework/datasets/Datasets.h" -#include "tests/validation/Validation.h" -#include "tests/validation/fixtures/ChannelExtractFixture.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace -{ -// Input data sets -const auto ChannelExtractRGBADataset = combine(framework::dataset::make("FormatType", { Format::RGBA8888 }), - framework::dataset::make("ChannelType", { Channel::R, Channel::G, Channel::B, Channel::A })); -const auto ChannelExtractYUVDataset = combine(framework::dataset::make("FormatType", { Format::YUYV422, Format::UYVY422 }), - framework::dataset::make("ChannelType", { Channel::Y, Channel::U, Channel::V })); -const auto ChannelExtractYUVPlanarDataset = combine(framework::dataset::make("FormatType", { Format::IYUV, Format::YUV444, Format::NV12, Format::NV21 }), - framework::dataset::make("ChannelType", { Channel::Y, Channel::U, Channel::V })); - -inline void validate_configuration(const TensorShape &shape, Format format, Channel channel) -{ - const unsigned int num_planes = num_planes_from_format(format); - - TensorShape dst_shape = adjust_odd_shape(shape, format); - dst_shape = calculate_subsampled_shape(dst_shape, format, channel); - - // Create tensors - MultiImage ref_src = create_multi_image(shape, format); - Tensor dst = create_tensor(dst_shape, Format::U8); - - // Create and Configure function - NEChannelExtract channel_extract; - - if(1U == num_planes) - { - const Tensor *plane_src = ref_src.plane(0); - - channel_extract.configure(plane_src, channel, &dst); - } - else - { - channel_extract.configure(&ref_src, channel, &dst); - } - - // TODO(bsgcomp): Add validation for padding and shape (COMPMID-659) -} -} // namespace - -TEST_SUITE(NEON) -TEST_SUITE(ChannelExtract) - -template -using NEChannelExtractFixture = ChannelExtractValidationFixture; - -TEST_SUITE(Configuration) -DATA_TEST_CASE(RGBA, framework::DatasetMode::ALL, combine(concat(datasets::Small2DShapes(), datasets::Large2DShapes()), ChannelExtractRGBADataset), - shape, format, channel) -{ - validate_configuration(shape, format, channel); -} -DATA_TEST_CASE(YUV, framework::DatasetMode::ALL, combine(concat(datasets::Small2DShapes(), datasets::Large2DShapes()), ChannelExtractYUVDataset), - shape, format, channel) -{ - validate_configuration(shape, format, channel); -} - -DATA_TEST_CASE(YUVPlanar, framework::DatasetMode::ALL, combine(concat(datasets::Small2DShapes(), datasets::Large2DShapes()), ChannelExtractYUVPlanarDataset), - shape, format, channel) -{ - validate_configuration(shape, format, channel); -} -TEST_SUITE_END() - -TEST_SUITE(RGBA) -FIXTURE_DATA_TEST_CASE(RunSmall, NEChannelExtractFixture, framework::DatasetMode::PRECOMMIT, combine(datasets::Small2DShapes(), ChannelExtractRGBADataset)) -{ - // Validate output - validate(Accessor(_target), _reference); -} -FIXTURE_DATA_TEST_CASE(RunLarge, NEChannelExtractFixture, framework::DatasetMode::NIGHTLY, combine(datasets::Large2DShapes(), ChannelExtractRGBADataset)) -{ - // Validate output - validate(Accessor(_target), _reference); -} -TEST_SUITE_END() - -TEST_SUITE(YUV) -FIXTURE_DATA_TEST_CASE(RunSmall, NEChannelExtractFixture, framework::DatasetMode::PRECOMMIT, combine(datasets::Small2DShapes(), ChannelExtractYUVDataset)) -{ - // Validate output - validate(Accessor(_target), _reference); -} -FIXTURE_DATA_TEST_CASE(RunLarge, NEChannelExtractFixture, framework::DatasetMode::NIGHTLY, combine(datasets::Large2DShapes(), ChannelExtractYUVDataset)) -{ - // Validate output - validate(Accessor(_target), _reference); -} -TEST_SUITE_END() - -TEST_SUITE(YUVPlanar) -FIXTURE_DATA_TEST_CASE(RunSmall, NEChannelExtractFixture, framework::DatasetMode::PRECOMMIT, combine(datasets::Small2DShapes(), ChannelExtractYUVPlanarDataset)) -{ - // Validate output - validate(Accessor(_target), _reference); -} -FIXTURE_DATA_TEST_CASE(RunLarge, NEChannelExtractFixture, framework::DatasetMode::NIGHTLY, combine(datasets::Large2DShapes(), ChannelExtractYUVPlanarDataset)) -{ - // Validate output - validate(Accessor(_target), _reference); -} -TEST_SUITE_END() - -TEST_SUITE_END() -TEST_SUITE_END() - -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/fixtures/ChannelExtractFixture.h b/tests/validation/fixtures/ChannelExtractFixture.h deleted file mode 100644 index c3c2e17d09..0000000000 --- a/tests/validation/fixtures/ChannelExtractFixture.h +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Copyright (c) 2017-2018 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef ARM_COMPUTE_TEST_CHANNEL_EXTRACT_FIXTURE -#define ARM_COMPUTE_TEST_CHANNEL_EXTRACT_FIXTURE - -#include "arm_compute/core/TensorShape.h" -#include "arm_compute/core/Types.h" -#include "tests/AssetsLibrary.h" -#include "tests/Globals.h" -#include "tests/IAccessor.h" -#include "tests/framework/Asserts.h" -#include "tests/framework/Fixture.h" -#include "tests/validation/Helpers.h" -#include "tests/validation/reference/ChannelExtract.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -template -class ChannelExtractValidationFixture : public framework::Fixture -{ -public: - template - void setup(TensorShape shape, Format format, Channel channel) - { - shape = adjust_odd_shape(shape, format); - - _target = compute_target(shape, format, channel); - _reference = compute_reference(shape, format, channel); - } - -protected: - template - void fill(U &&tensor, int i) - { - library->fill_tensor_uniform(tensor, i); - } - - std::vector> create_tensor_planes_reference(const TensorShape &shape, Format format) - { - TensorShape input = adjust_odd_shape(shape, format); - - std::vector> tensor_planes; - - switch(format) - { - case Format::RGB888: - case Format::RGBA8888: - case Format::YUYV422: - case Format::UYVY422: - { - tensor_planes.emplace_back(input, format); - break; - } - case Format::NV12: - case Format::NV21: - { - const TensorShape shape_uv88 = calculate_subsampled_shape(shape, Format::UV88); - - tensor_planes.emplace_back(input, Format::U8); - tensor_planes.emplace_back(shape_uv88, Format::UV88); - break; - } - case Format::IYUV: - { - const TensorShape shape_sub2 = calculate_subsampled_shape(shape, Format::IYUV); - - tensor_planes.emplace_back(input, Format::U8); - tensor_planes.emplace_back(shape_sub2, Format::U8); - tensor_planes.emplace_back(shape_sub2, Format::U8); - break; - } - case Format::YUV444: - tensor_planes.emplace_back(input, Format::U8); - tensor_planes.emplace_back(input, Format::U8); - tensor_planes.emplace_back(input, Format::U8); - break; - default: - ARM_COMPUTE_ERROR("Not supported"); - break; - } - - return tensor_planes; - } - - TensorType compute_target(const TensorShape &shape, Format format, Channel channel) - { - const unsigned int num_planes = num_planes_from_format(format); - - TensorShape dst_shape = calculate_subsampled_shape(shape, format, channel); - - // Create tensors - MultiImageType ref_src = create_multi_image(shape, format); - TensorType dst = create_tensor(dst_shape, Format::U8); - - // Create and configure function - FunctionType channel_extract; - - if(1U == num_planes) - { - const TensorType *plane_src = static_cast(ref_src.plane(0)); - - channel_extract.configure(plane_src, channel, &dst); - } - else - { - channel_extract.configure(&ref_src, channel, &dst); - } - - for(unsigned int plane_idx = 0; plane_idx < num_planes; ++plane_idx) - { - const TensorType *src_plane = static_cast(ref_src.plane(plane_idx)); - - ARM_COMPUTE_EXPECT(src_plane->info()->is_resizable(), framework::LogLevel::ERRORS); - } - - ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); - - // Allocate tensors - ref_src.allocate(); - dst.allocator()->allocate(); - - for(unsigned int plane_idx = 0; plane_idx < num_planes; ++plane_idx) - { - const TensorType *src_plane = static_cast(ref_src.plane(plane_idx)); - - ARM_COMPUTE_EXPECT(!src_plane->info()->is_resizable(), framework::LogLevel::ERRORS); - } - - ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS); - - // Fill tensor planes - for(unsigned int plane_idx = 0; plane_idx < num_planes; ++plane_idx) - { - TensorType *src_plane = static_cast(ref_src.plane(plane_idx)); - - fill(AccessorType(*src_plane), plane_idx); - } - - // Compute function - channel_extract.run(); - - return dst; - } - - SimpleTensor compute_reference(const TensorShape &shape, Format format, Channel channel) - { - const unsigned int num_planes = num_planes_from_format(format); - - // Create reference - std::vector> ref_src = create_tensor_planes_reference(shape, format); - - // Fill references - for(unsigned int plane_idx = 0; plane_idx < num_planes; ++plane_idx) - { - fill(ref_src[plane_idx], plane_idx); - } - - return reference::channel_extract(shape, ref_src, format, channel); - } - - TensorType _target{}; - SimpleTensor _reference{}; -}; -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_CHANNEL_EXTRACT_FIXTURE */ diff --git a/tests/validation/reference/ChannelExtract.cpp b/tests/validation/reference/ChannelExtract.cpp deleted file mode 100644 index 595bb13098..0000000000 --- a/tests/validation/reference/ChannelExtract.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2017-2018 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "ChannelExtract.h" - -#include "arm_compute/core/Types.h" -#include "tests/validation/FixedPoint.h" -#include "tests/validation/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor channel_extract(const TensorShape &shape, const std::vector> &tensor_planes, Format format, Channel channel) -{ - // Find plane and channel index - const unsigned int plane_idx = plane_idx_from_channel(format, channel); - const unsigned int channel_idx = channel_idx_from_format(format, channel); - - // Create dst and get src tensor - SimpleTensor src = tensor_planes[plane_idx]; - SimpleTensor dst{ calculate_subsampled_shape(shape, format, channel), Format::U8 }; - - // Single planar formats with subsampling require a double horizontal step - const int step_x = ((Format::YUYV422 == format || Format::UYVY422 == format) && Channel::Y != channel) ? 2 : 1; - const int width = dst.shape().x(); - const int height = dst.shape().y(); - - // Loop over each pixel and extract channel - for(int y = 0; y < height; ++y) - { - for(int x = 0; x < width; ++x) - { - const Coordinates src_coord{ x * step_x, y }; - const Coordinates dst_coord{ x, y }; - - const auto *src_pixel = reinterpret_cast(src(src_coord)); - auto *dst_pixel = reinterpret_cast(dst(dst_coord)); - - dst_pixel[0] = src_pixel[channel_idx]; - } - } - - return dst; -} - -template SimpleTensor channel_extract(const TensorShape &shape, const std::vector> &tensor_planes, Format format, Channel channel); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/ChannelExtract.h b/tests/validation/reference/ChannelExtract.h deleted file mode 100644 index ac7aefbdee..0000000000 --- a/tests/validation/reference/ChannelExtract.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017-2018 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef __ARM_COMPUTE_TEST_CHANNEL_EXTRACT_H__ -#define __ARM_COMPUTE_TEST_CHANNEL_EXTRACT_H__ - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor channel_extract(const TensorShape &shape, const std::vector> &tensor_planes, Format format, Channel channel); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_CHANNEL_EXTRACT_H__ */ diff --git a/utils/TypePrinter.h b/utils/TypePrinter.h index 63fba35052..e1a561749e 100644 --- a/utils/TypePrinter.h +++ b/utils/TypePrinter.h @@ -523,13 +523,6 @@ inline ::std::ostream &operator<<(::std::ostream &os, const Channel &channel) return os; } -inline std::string to_string(const Channel &channel) -{ - std::stringstream str; - str << channel; - return str.str(); -} - /** Formatted output of the BorderMode type. */ inline ::std::ostream &operator<<(::std::ostream &os, const BorderMode &mode) { -- cgit v1.2.1