aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIoan-Cristian Szabo <ioan-cristian.szabo@arm.com>2017-10-27 17:35:40 +0100
committerAnthony Barbier <anthony.barbier@arm.com>2018-11-02 16:47:18 +0000
commit91d20d95df35961d3eb5de497007d98576118d19 (patch)
tree13042e212d65fbf5bd7425079bb72b6bd1e2e84d /src
parent19835e591cb0b66a0f5000ae1505bf299e50337d (diff)
downloadComputeLibrary-91d20d95df35961d3eb5de497007d98576118d19.tar.gz
COMPMID-582: Add validation to channel_extract kernels.
Change-Id: I6413a05f6870a0d04f12d7348269b15297ae8493 Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/114696 Tested-by: Jenkins <bsgcomp@arm.com> Reviewed-by: Anthony Barbier <anthony.barbier@arm.com>
Diffstat (limited to 'src')
-rw-r--r--src/core/CL/kernels/CLChannelExtractKernel.cpp78
-rw-r--r--src/core/NEON/kernels/NEChannelExtractKernel.cpp233
-rw-r--r--src/runtime/CL/CLMultiImage.cpp16
-rw-r--r--src/runtime/MultiImage.cpp16
4 files changed, 152 insertions, 191 deletions
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<const void *>(input) == static_cast<void *>(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<std::string> build_opts = { ("-DCHANNEL_" + string_from_channel(channel)) };
_kernel = static_cast<cl::Kernel>(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<const void *>(input) == static_cast<void *>(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<std::string> 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<cl::Kernel>(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 bac24718ba..98b2f280d4 100644
--- a/src/core/NEON/kernels/NEChannelExtractKernel.cpp
+++ b/src/core/NEON/kernels/NEChannelExtractKernel.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016, 2017 ARM Limited.
+ * Copyright (c) 2016-2018 ARM Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -56,106 +56,68 @@ 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);
- unsigned int num_elems_processed_per_iteration = 8;
+ 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);
- // 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;
+ unsigned int subsampling = 1;
- switch(format)
+ if(format == Format::YUYV422 || format == Format::UYVY422)
{
- 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;
+ // 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;
+ }
}
+ 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_MISMATCHING_DIMENSIONS(output_shape, output->info()->tensor_shape());
- _input = input;
- _output = output;
+ _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));
- 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);
@@ -168,94 +130,45 @@ void NEChannelExtractKernel::configure(const IMultiImage *input, Channel channel
set_format_if_unknown(*output->info(), Format::U8);
- switch(input->info()->format())
+ 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)
{
- 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");
+ // 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->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;
- const Format &format = input->info()->format();
+ _func = &NEChannelExtractKernel::copy_plane;
- switch(format)
+ if((format == Format::NV12 || format == Format::NV21) && channel != Channel::Y)
{
- 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;
+ num_elems_processed_per_iteration = 16;
+ _func = &NEChannelExtractKernel::extract_1C_from_2C_img;
}
- _output = output;
- Window win = calculate_max_window(*_input->info(), Steps(num_elems_processed_per_iteration));
+ 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 63059cb5f4..92254f3531 100644
--- a/src/runtime/CL/CLMultiImage.cpp
+++ b/src/runtime/CL/CLMultiImage.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016, 2017 ARM Limited.
+ * Copyright (c) 2016-2018 ARM Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -25,6 +25,7 @@
#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;
@@ -51,7 +52,8 @@ 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)
{
- TensorInfo info(width, height, Format::U8);
+ TensorShape shape = adjust_odd_shape(TensorShape{ width, height }, format);
+ TensorInfo info(shape, Format::U8);
if(auto_padding)
{
@@ -72,7 +74,7 @@ void CLMultiImage::internal_init(unsigned int width, unsigned int height, Format
case Format::YUYV422:
case Format::UYVY422:
{
- TensorInfo info_full(width, height, format);
+ TensorInfo info_full(shape, format);
if(auto_padding)
{
@@ -85,7 +87,8 @@ void CLMultiImage::internal_init(unsigned int width, unsigned int height, Format
case Format::NV12:
case Format::NV21:
{
- TensorInfo info_uv88(width / 2, height / 2, Format::UV88);
+ const TensorShape shape_uv88 = calculate_subsampled_shape(shape, Format::UV88);
+ TensorInfo info_uv88(shape_uv88, Format::UV88);
if(auto_padding)
{
@@ -98,7 +101,8 @@ void CLMultiImage::internal_init(unsigned int width, unsigned int height, Format
}
case Format::IYUV:
{
- TensorInfo info_sub2(width / 2, height / 2, Format::U8);
+ const TensorShape shape_sub2 = calculate_subsampled_shape(shape, Format::IYUV);
+ TensorInfo info_sub2(shape_sub2, Format::U8);
if(auto_padding)
{
@@ -120,7 +124,7 @@ void CLMultiImage::internal_init(unsigned int width, unsigned int height, Format
break;
}
- _info.init(width, height, format);
+ _info.init(shape.x(), shape.y(), format);
}
void CLMultiImage::allocate()
diff --git a/src/runtime/MultiImage.cpp b/src/runtime/MultiImage.cpp
index def1487c5e..6eba71bf1d 100644
--- a/src/runtime/MultiImage.cpp
+++ b/src/runtime/MultiImage.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016, 2017 ARM Limited.
+ * Copyright (c) 2016-2018 ARM Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -25,6 +25,7 @@
#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;
@@ -51,7 +52,8 @@ 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)
{
- TensorInfo info(width, height, Format::U8);
+ TensorShape shape = adjust_odd_shape(TensorShape{ width, height }, format);
+ TensorInfo info(shape, Format::U8);
if(auto_padding)
{
@@ -72,7 +74,7 @@ void MultiImage::internal_init(unsigned int width, unsigned int height, Format f
case Format::YUYV422:
case Format::UYVY422:
{
- TensorInfo info_full(width, height, format);
+ TensorInfo info_full(shape, format);
if(auto_padding)
{
@@ -85,7 +87,8 @@ void MultiImage::internal_init(unsigned int width, unsigned int height, Format f
case Format::NV12:
case Format::NV21:
{
- TensorInfo info_uv88(width / 2, height / 2, Format::UV88);
+ const TensorShape shape_uv88 = calculate_subsampled_shape(shape, Format::UV88);
+ TensorInfo info_uv88(shape_uv88, Format::UV88);
if(auto_padding)
{
@@ -98,7 +101,8 @@ void MultiImage::internal_init(unsigned int width, unsigned int height, Format f
}
case Format::IYUV:
{
- TensorInfo info_sub2(width / 2, height / 2, Format::U8);
+ const TensorShape shape_sub2 = calculate_subsampled_shape(shape, Format::IYUV);
+ TensorInfo info_sub2(shape_sub2, Format::U8);
if(auto_padding)
{
@@ -120,7 +124,7 @@ void MultiImage::internal_init(unsigned int width, unsigned int height, Format f
break;
}
- _info.init(width, height, format);
+ _info.init(shape.x(), shape.y(), format);
}
void MultiImage::allocate()