Compute Library
 21.02
NEChannelExtractKernel Class Reference

Interface for the channel extract kernel. More...

#include <NEChannelExtractKernel.h>

Collaboration diagram for NEChannelExtractKernel:
[legend]

Public Member Functions

const char * name () const override
 Name of the kernel. More...
 
 NEChannelExtractKernel ()
 Default constructor. More...
 
 NEChannelExtractKernel (const NEChannelExtractKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NEChannelExtractKerneloperator= (const NEChannelExtractKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NEChannelExtractKernel (NEChannelExtractKernel &&)=default
 Allow instances of this class to be moved. More...
 
NEChannelExtractKerneloperator= (NEChannelExtractKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~NEChannelExtractKernel ()=default
 Default destructor. More...
 
void configure (const ITensor *input, Channel channel, ITensor *output)
 Set the input and output of the kernel. More...
 
void configure (const IMultiImage *input, Channel channel, IImage *output)
 Set the input and output of the kernel. More...
 
void run (const Window &window, const ThreadInfo &info) override
 Execute the kernel on the passed window. More...
 
- Public Member Functions inherited from ICPPSimpleKernel
 ICPPSimpleKernel ()
 Constructor. More...
 
 ICPPSimpleKernel (const ICPPSimpleKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
ICPPSimpleKerneloperator= (const ICPPSimpleKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 ICPPSimpleKernel (ICPPSimpleKernel &&)=default
 Allow instances of this class to be moved. More...
 
ICPPSimpleKerneloperator= (ICPPSimpleKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~ICPPSimpleKernel ()=default
 Default destructor. More...
 
- Public Member Functions inherited from ICPPKernel
virtual ~ICPPKernel ()=default
 Default destructor. More...
 
virtual void run_nd (const Window &window, const ThreadInfo &info, const Window &thread_locator)
 legacy compatibility layer for implemantions which do not support thread_locator In these cases we simply narrow the interface down the legacy version More...
 
virtual void run_op (ITensorPack &tensors, const Window &window, const ThreadInfo &info)
 Execute the kernel on the passed window. More...
 
- Public Member Functions inherited from IKernel
 IKernel ()
 Constructor. More...
 
virtual ~IKernel ()=default
 Destructor. More...
 
virtual bool is_parallelisable () const
 Indicates whether or not the kernel is parallelisable. More...
 
virtual BorderSize border_size () const
 The size of the border for that kernel. More...
 
const Windowwindow () const
 The maximum window the kernel can be executed on. More...
 

Detailed Description

Interface for the channel extract kernel.

Definition at line 37 of file NEChannelExtractKernel.h.

Constructor & Destructor Documentation

◆ NEChannelExtractKernel() [1/3]

Default constructor.

Definition at line 49 of file NEChannelExtractKernel.cpp.

Referenced by NEChannelExtractKernel::name().

50  : _func(nullptr), _lut_index(0)
51 {
52 }

◆ NEChannelExtractKernel() [2/3]

Prevent instances of this class from being copied (As this class contains pointers)

◆ NEChannelExtractKernel() [3/3]

Allow instances of this class to be moved.

◆ ~NEChannelExtractKernel()

~NEChannelExtractKernel ( )
default

Default destructor.

Referenced by NEChannelExtractKernel::name().

Member Function Documentation

◆ configure() [1/2]

void configure ( const ITensor input,
Channel  channel,
ITensor output 
)

Set the input and output of the kernel.

Parameters
[in]inputSource tensor. Formats supported: RGB888/RGBA8888/YUYV422/UYVY422
[in]channelChannel to extract.
[out]outputDestination tensor. Format supported: U8

Definition at line 54 of file NEChannelExtractKernel.cpp.

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_CHANNEL_NOT_IN_KNOWN_FORMAT, ARM_COMPUTE_ERROR_ON_FORMAT_NOT_IN, ARM_COMPUTE_ERROR_ON_MISMATCHING_DIMENSIONS, ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_ON_TENSOR_NOT_2D, ARM_COMPUTE_ERROR_ON_TENSORS_NOT_EVEN, arm_compute::calculate_subsampled_shape(), ITensorInfo::format(), ITensor::info(), arm_compute::test::validation::input, arm_compute::test::validation::output_shape, arm_compute::RGB888, arm_compute::RGBA8888, arm_compute::set_format_if_unknown(), arm_compute::set_shape_if_empty(), ITensorInfo::tensor_shape(), arm_compute::U8, arm_compute::UYVY422, arm_compute::Y, and arm_compute::YUYV422.

Referenced by NEChannelExtractKernel::name().

55 {
56  ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
57  ARM_COMPUTE_ERROR_ON(input == output);
58 
60 
61  // Check if input tensor has a valid format
64 
67 
68  // Check if channel is valid for given format
69  const Format format = input->info()->format();
71 
72  unsigned int subsampling = 1;
73 
74  if(format == Format::YUYV422 || format == Format::UYVY422)
75  {
76  // Check if the width of the tensor shape is even for formats with subsampled channels (UYVY422 and YUYV422)
78 
79  if(channel != Channel::Y)
80  {
81  subsampling = 2;
82  }
83  }
84 
87 
89 
90  _input = input;
91  _output = output;
92  _lut_index = channel_idx_from_format(format, channel);
93 
94  unsigned int num_elems_processed_per_iteration = 16;
95 
96  if(format == Format::YUYV422 || format == Format::UYVY422)
97  {
98  _func = &NEChannelExtractKernel::extract_1C_from_2C_img;
99 
100  if(channel != Channel::Y) // Channel::U or Channel::V
101  {
102  num_elems_processed_per_iteration = 32;
103  _func = &NEChannelExtractKernel::extract_YUYV_uv;
104  }
105  }
106  else // Format::RGB888 or Format::RGBA8888
107  {
108  _func = &NEChannelExtractKernel::extract_1C_from_3C_img;
109 
110  if(format == Format::RGBA8888)
111  {
112  _func = &NEChannelExtractKernel::extract_1C_from_4C_img;
113  }
114  }
115 
116  Window win = calculate_max_window(*input->info(), Steps(num_elems_processed_per_iteration));
117 
119  AccessWindowRectangle output_access(output->info(), 0, 0, num_elems_processed_per_iteration, 1, 1.f / subsampling, 1.f / subsampling);
120  update_window_and_padding(win, input_access, output_access);
121 
122  ValidRegion input_valid_region = input->info()->valid_region();
123  output_access.set_valid_region(win, ValidRegion(input_valid_region.anchor, output->info()->tensor_shape()));
124 
125  INEKernel::configure(win);
126 }
bool set_format_if_unknown(ITensorInfo &info, Format format)
Set the format, data type and number of channels to the specified value if the current data type is u...
A single plane of 32-bit macro pixel of U0, Y0, V0, Y1 byte.
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
Shape of a tensor.
Definition: TensorShape.h:39
TensorShape calculate_subsampled_shape(const TensorShape &shape, Format format, Channel channel=Channel::UNKNOWN)
Calculate subsampled shape for a given format and channel.
Definition: Utils.h:774
#define ARM_COMPUTE_ERROR_ON_TENSOR_NOT_2D(t)
Definition: Validate.h:856
1 channel, 1 U8 per channel
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
#define ARM_COMPUTE_ERROR_ON_FORMAT_NOT_IN(t,...)
Definition: Validate.h:643
virtual ValidRegion valid_region() const =0
Valid region of the tensor.
3 channels, 1 U8 per channel
#define ARM_COMPUTE_ERROR_ON_TENSORS_NOT_EVEN(...)
Definition: Validate.h:318
Implementation of a rectangular access pattern.
virtual Format format() const =0
Colour format of the image.
bool update_window_and_padding(Window &win, Ts &&... patterns)
Update window and padding size for each of the access patterns.
Definition: WindowHelpers.h:46
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
Format
Image colour formats.
Definition: Types.h:54
Class to describe a number of elements in each dimension.
Definition: Steps.h:40
Implementation of a row access pattern.
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor&#39;s metadata.
bool set_shape_if_empty(ITensorInfo &info, const TensorShape &shape)
Set the shape to the specified value if the current assignment is empty.
4 channels, 1 U8 per channel
#define ARM_COMPUTE_ERROR_ON_MISMATCHING_DIMENSIONS(...)
Definition: Validate.h:286
unsigned int num_elems_processed_per_iteration
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
Container for valid region of a window.
Definition: Types.h:188
A single plane of 32-bit macro pixel of Y0, U0, Y1, V0 bytes.
Describe a multidimensional execution window.
Definition: Window.h:39
Coordinates anchor
Anchor for the start of the valid region.
Definition: Types.h:260
int channel_idx_from_format(Format format, Channel channel)
Return the channel index of a given channel given an input format.
Definition: Utils.h:327
#define ARM_COMPUTE_ERROR_ON_CHANNEL_NOT_IN_KNOWN_FORMAT(f, c)
Definition: Validate.h:903

◆ configure() [2/2]

void configure ( const IMultiImage input,
Channel  channel,
IImage output 
)

Set the input and output of the kernel.

Parameters
[in]inputMulti-planar source image. Formats supported: NV12/NV21/IYUV/YUV444
[in]channelChannel to extract.
[out]outputSingle-planar destination image. Format supported: U8

Definition at line 128 of file NEChannelExtractKernel.cpp.

References ARM_COMPUTE_ERROR_ON_CHANNEL_NOT_IN_KNOWN_FORMAT, ARM_COMPUTE_ERROR_ON_FORMAT_NOT_IN, ARM_COMPUTE_ERROR_ON_MISMATCHING_DIMENSIONS, ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_ON_TENSOR_NOT_2D, ARM_COMPUTE_ERROR_ON_TENSORS_NOT_EVEN, arm_compute::calculate_subsampled_shape(), MultiImageInfo::format(), ITensor::info(), IMultiImage::info(), arm_compute::IYUV, arm_compute::NV12, arm_compute::NV21, arm_compute::test::validation::output_shape, IMultiImage::plane(), arm_compute::plane_idx_from_channel(), arm_compute::set_format_if_unknown(), arm_compute::set_shape_if_empty(), ITensorInfo::tensor_shape(), arm_compute::U8, arm_compute::Y, and arm_compute::YUV444.

129 {
130  ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
132 
134 
135  const Format format = input->info()->format();
137 
138  // Get input plane
139  const IImage *input_plane = input->plane(plane_idx_from_channel(format, channel));
140  ARM_COMPUTE_ERROR_ON_NULLPTR(input_plane);
141 
142  if(Channel::Y == channel && format != Format::YUV444)
143  {
144  // Check if the width of the tensor shape is even for formats with subsampled channels (UYVY422 and YUYV422)
145  ARM_COMPUTE_ERROR_ON_TENSORS_NOT_EVEN(format, input_plane);
146  }
147 
148  // Calculate 2x2 subsampled tensor shape
149  TensorShape output_shape = calculate_subsampled_shape(input->plane(0)->info()->tensor_shape(), format, channel);
150  set_shape_if_empty(*output->info(), output_shape);
151 
153 
154  // Check if input tensor has a valid format
157 
158  _input = input_plane;
159  _output = output;
160  _lut_index = channel_idx_from_format(format, channel);
161 
162  unsigned int num_elems_processed_per_iteration = 32;
163 
164  _func = &NEChannelExtractKernel::copy_plane;
165 
166  if((format == Format::NV12 || format == Format::NV21) && channel != Channel::Y)
167  {
168  num_elems_processed_per_iteration = 16;
169  _func = &NEChannelExtractKernel::extract_1C_from_2C_img;
170  }
171 
172  Window win = calculate_max_window(*_input->info(), Steps(num_elems_processed_per_iteration));
173 
174  AccessWindowHorizontal input_access(_input->info(), 0, num_elems_processed_per_iteration);
176  update_window_and_padding(win, input_access, output_access);
177  output_access.set_valid_region(win, _input->info()->valid_region());
178 
179  INEKernel::configure(win);
180 }
bool set_format_if_unknown(ITensorInfo &info, Format format)
Set the format, data type and number of channels to the specified value if the current data type is u...
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
Shape of a tensor.
Definition: TensorShape.h:39
int plane_idx_from_channel(Format format, Channel channel)
Return the plane index of a given channel given an input format.
Definition: Utils.h:262
TensorShape calculate_subsampled_shape(const TensorShape &shape, Format format, Channel channel=Channel::UNKNOWN)
Calculate subsampled shape for a given format and channel.
Definition: Utils.h:774
#define ARM_COMPUTE_ERROR_ON_TENSOR_NOT_2D(t)
Definition: Validate.h:856
1 channel, 1 U8 per channel
A 2 plane YUV format of Luma (Y) and interleaved UV data at 4:2:0 sampling.
#define ARM_COMPUTE_ERROR_ON_FORMAT_NOT_IN(t,...)
Definition: Validate.h:643
Interface for Neon tensor.
Definition: ITensor.h:36
A 2 plane YUV format of Luma (Y) and interleaved VU data at 4:2:0 sampling.
#define ARM_COMPUTE_ERROR_ON_TENSORS_NOT_EVEN(...)
Definition: Validate.h:318
bool update_window_and_padding(Window &win, Ts &&... patterns)
Update window and padding size for each of the access patterns.
Definition: WindowHelpers.h:46
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
Format
Image colour formats.
Definition: Types.h:54
Class to describe a number of elements in each dimension.
Definition: Steps.h:40
Implementation of a row access pattern.
A 3 plane of 8 bit 4:4:4 sampled Y, U, V planes.
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor&#39;s metadata.
bool set_shape_if_empty(ITensorInfo &info, const TensorShape &shape)
Set the shape to the specified value if the current assignment is empty.
virtual const MultiImageInfo * info() const =0
Interface to be implemented by the child class to return the multi-planar image&#39;s metadata...
A 3 plane of 8-bit 4:2:0 sampled Y, U, V planes.
#define ARM_COMPUTE_ERROR_ON_MISMATCHING_DIMENSIONS(...)
Definition: Validate.h:286
virtual IImage * plane(unsigned int index)=0
Return a pointer to the requested plane of the image.
unsigned int num_elems_processed_per_iteration
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
Format format() const
Colour format of the image.
Describe a multidimensional execution window.
Definition: Window.h:39
int channel_idx_from_format(Format format, Channel channel)
Return the channel index of a given channel given an input format.
Definition: Utils.h:327
#define ARM_COMPUTE_ERROR_ON_CHANNEL_NOT_IN_KNOWN_FORMAT(f, c)
Definition: Validate.h:903

◆ name()

◆ operator=() [1/2]

NEChannelExtractKernel& operator= ( const NEChannelExtractKernel )
delete

Prevent instances of this class from being copied (As this class contains pointers)

Referenced by NEChannelExtractKernel::name().

◆ operator=() [2/2]

NEChannelExtractKernel& operator= ( NEChannelExtractKernel &&  )
default

Allow instances of this class to be moved.

◆ run()

void run ( const Window window,
const ThreadInfo info 
)
overridevirtual

Execute the kernel on the passed window.

Warning
If is_parallelisable() returns false then the passed window must be equal to window()
Note
The window has to be a region within the window returned by the window() method
The width of the window has to be a multiple of num_elems_processed_per_iteration().
Parameters
[in]windowRegion on which to execute the kernel. (Must be a region of the window returned by window())
[in]infoInfo about executing thread and CPU.

Reimplemented from ICPPKernel.

Definition at line 182 of file NEChannelExtractKernel.cpp.

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, and IKernel::window().

Referenced by NEChannelExtractKernel::name().

183 {
184  ARM_COMPUTE_UNUSED(info);
187  ARM_COMPUTE_ERROR_ON(_func == nullptr);
188 
189  (this->*_func)(window);
190 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:941
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205

The documentation for this class was generated from the following files: