Compute Library
 19.08
CLColorConvertKernel Class Reference

Interface for the color convert kernel. More...

#include <CLColorConvertKernel.h>

Collaboration diagram for CLColorConvertKernel:
[legend]

Public Member Functions

 CLColorConvertKernel ()
 Default constructor. More...
 
 CLColorConvertKernel (const CLColorConvertKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
CLColorConvertKerneloperator= (const CLColorConvertKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 CLColorConvertKernel (CLColorConvertKernel &&)=default
 Allow instances of this class to be moved. More...
 
CLColorConvertKerneloperator= (CLColorConvertKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~CLColorConvertKernel ()=default
 Default destructor. More...
 
void configure (const ICLTensor *input, ICLTensor *output)
 Set the input and output of the kernel. More...
 
void configure (const ICLMultiImage *input, ICLImage *output)
 Set the input and output of the kernel. More...
 
void configure (const ICLImage *input, ICLMultiImage *output)
 Set the input and output of the kernel. More...
 
void configure (const ICLMultiImage *input, ICLMultiImage *output)
 Set the input and output of the kernel. More...
 
void run (const Window &window, cl::CommandQueue &queue) override
 Enqueue the OpenCL kernel to process the given window on the passed OpenCL command queue. More...
 
- Public Member Functions inherited from ICLKernel
 ICLKernel ()
 Constructor. More...
 
cl::Kernel & kernel ()
 Returns a reference to the OpenCL kernel of this object. More...
 
template<typename T >
void add_1D_array_argument (unsigned int &idx, const ICLArray< T > *array, const Strides &strides, unsigned int num_dimensions, const Window &window)
 Add the passed 1D array's parameters to the object's kernel's arguments starting from the index idx. More...
 
void add_1D_tensor_argument (unsigned int &idx, const ICLTensor *tensor, const Window &window)
 Add the passed 1D tensor's parameters to the object's kernel's arguments starting from the index idx. More...
 
void add_1D_tensor_argument_if (bool cond, unsigned int &idx, const ICLTensor *tensor, const Window &window)
 Add the passed 1D tensor's parameters to the object's kernel's arguments starting from the index idx if the condition is true. More...
 
void add_2D_tensor_argument (unsigned int &idx, const ICLTensor *tensor, const Window &window)
 Add the passed 2D tensor's parameters to the object's kernel's arguments starting from the index idx. More...
 
void add_2D_tensor_argument_if (bool cond, unsigned int &idx, const ICLTensor *tensor, const Window &window)
 Add the passed 2D tensor's parameters to the object's kernel's arguments starting from the index idx if the condition is true. More...
 
void add_3D_tensor_argument (unsigned int &idx, const ICLTensor *tensor, const Window &window)
 Add the passed 3D tensor's parameters to the object's kernel's arguments starting from the index idx. More...
 
void add_4D_tensor_argument (unsigned int &idx, const ICLTensor *tensor, const Window &window)
 Add the passed 4D tensor's parameters to the object's kernel's arguments starting from the index idx. More...
 
template<typename T >
void add_argument (unsigned int &idx, T value)
 Add the passed parameters to the object's kernel's arguments starting from the index idx. More...
 
void set_lws_hint (const cl::NDRange &lws_hint)
 Set the Local-Workgroup-Size hint. More...
 
cl::NDRange lws_hint () const
 Return the Local-Workgroup-Size hint. More...
 
const std::string & config_id () const
 Get the configuration ID. More...
 
void set_target (GPUTarget target)
 Set the targeted GPU architecture. More...
 
void set_target (cl::Device &device)
 Set the targeted GPU architecture according to the CL device. More...
 
GPUTarget get_target () const
 Get the targeted GPU architecture. More...
 
size_t get_max_workgroup_size ()
 Get the maximum workgroup size for the device the CLKernelLibrary uses. More...
 
template<typename T , unsigned int dimension_size>
void add_array_argument (unsigned &idx, const ICLArray< T > *array, const Strides &strides, unsigned int num_dimensions, const Window &window)
 Add the passed array's parameters to the object's kernel's arguments starting from the index idx. More...
 
template<unsigned int dimension_size>
void add_tensor_argument (unsigned &idx, const ICLTensor *tensor, const Window &window)
 
- 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...
 

Additional Inherited Members

- Static Public Member Functions inherited from ICLKernel
static constexpr unsigned int num_arguments_per_1D_array ()
 Returns the number of arguments enqueued per 1D array object. More...
 
static constexpr unsigned int num_arguments_per_1D_tensor ()
 Returns the number of arguments enqueued per 1D tensor object. More...
 
static constexpr unsigned int num_arguments_per_2D_tensor ()
 Returns the number of arguments enqueued per 2D tensor object. More...
 
static constexpr unsigned int num_arguments_per_3D_tensor ()
 Returns the number of arguments enqueued per 3D tensor object. More...
 
static constexpr unsigned int num_arguments_per_4D_tensor ()
 Returns the number of arguments enqueued per 4D tensor object. More...
 
static cl::NDRange gws_from_window (const Window &window)
 Get the global work size given an execution window. More...
 

Detailed Description

Interface for the color convert kernel.

Definition at line 38 of file CLColorConvertKernel.h.

Constructor & Destructor Documentation

◆ CLColorConvertKernel() [1/3]

Default constructor.

Definition at line 43 of file CLColorConvertKernel.cpp.

44  : _input(nullptr), _output(nullptr), _multi_input(nullptr), _multi_output(nullptr)
45 {
46 }

◆ CLColorConvertKernel() [2/3]

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

◆ CLColorConvertKernel() [3/3]

Allow instances of this class to be moved.

◆ ~CLColorConvertKernel()

~CLColorConvertKernel ( )
default

Default destructor.

Member Function Documentation

◆ configure() [1/4]

void configure ( const ICLTensor input,
ICLTensor output 
)

Set the input and output of the kernel.

Parameters
[in]inputSource tensor. Formats supported: RGBA8888/UYVY422/YUYV422/RGB888
[out]outputDestination tensor. Formats supported: RGB888 (if the formats of input are RGBA8888/UYVY422/YUYV422), RGBA8888 (if the formats of input are UYVY422/YUYV422/RGB888/), U8 (if the formats of input is RGB888)

Definition at line 48 of file CLColorConvertKernel.cpp.

49 {
50  ARM_COMPUTE_ERROR_ON(input == nullptr);
51  ARM_COMPUTE_ERROR_ON(output == nullptr);
52 
53  unsigned int num_elems_processed_per_iteration = 0;
54  switch(input->info()->format())
55  {
56  case Format::RGBA8888:
57  {
58  switch(output->info()->format())
59  {
60  case Format::RGB888:
61  num_elems_processed_per_iteration = 16;
62  break;
63  default:
64  ARM_COMPUTE_ERROR("Not supported");
65  break;
66  }
67  break;
68  }
69  case Format::UYVY422:
70  case Format::YUYV422:
71  {
72  switch(output->info()->format())
73  {
74  case Format::RGB888:
75  case Format::RGBA8888:
76  num_elems_processed_per_iteration = 8;
77  break;
78  default:
79  ARM_COMPUTE_ERROR("Not supported");
80  break;
81  }
82  break;
83  }
84  case Format::RGB888:
85  {
86  switch(output->info()->format())
87  {
88  case Format::RGBA8888:
89  case Format::U8:
90  num_elems_processed_per_iteration = 16;
91  break;
92  default:
93  ARM_COMPUTE_ERROR("Not supported");
94  break;
95  }
96  break;
97  }
98  default:
99  break;
100  }
101  ARM_COMPUTE_ERROR_ON_MSG(num_elems_processed_per_iteration == 0, "Conversion from %s to %s not supported",
102  string_from_format(input->info()->format()).c_str(),
103  string_from_format(output->info()->format()).c_str());
104 
105  std::stringstream kernel_name;
106 
107  kernel_name << string_from_format(input->info()->format());
108  kernel_name << "_to_";
109  kernel_name << string_from_format(output->info()->format());
110  kernel_name << "_bt709";
111 
112  _input = input;
113  _output = output;
114 
115  // Create kernel
116  _kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel(kernel_name.str()));
117 
118  // Configure kernel window
119  Window win = calculate_max_window(*input->info(), Steps(num_elems_processed_per_iteration));
120  AccessWindowHorizontal input_access(input->info(), 0, num_elems_processed_per_iteration);
121  AccessWindowHorizontal output_access(output->info(), 0, num_elems_processed_per_iteration);
122 
123  update_window_and_padding(win, input_access, output_access);
124 
125  output_access.set_valid_region(win, input->info()->valid_region());
126 
127  ICLKernel::configure_internal(win);
128 
129  // Set config_id for enabling LWS tuning
130  _config_id = kernel_name.str();
131  _config_id += "_";
132  _config_id += lower_string(string_from_data_type(input->info()->data_type()));
133  _config_id += "_";
134  _config_id += support::cpp11::to_string(input->info()->dimension(0));
135  _config_id += "_";
136  _config_id += support::cpp11::to_string(input->info()->dimension(1));
137 }
#define ARM_COMPUTE_ERROR(...)
Print the given message then throw an std::runtime_error.
Definition: Error.h:261
A single plane of 32-bit macro pixel of U0, Y0, V0, Y1 byte.
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
1 channel, 1 U8 per channel
std::string to_string(T &&value)
Convert integer and float values to string.
virtual DataType data_type() const =0
Data type used for each element of the tensor.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:337
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
std::string lower_string(const std::string &val)
Lower a given string.
Definition: Utils.cpp:327
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps=Steps(), bool skip_border=false, BorderSize border_size=BorderSize())
Calculate the maximum window for a given tensor shape and border setting.
Definition: Helpers.cpp:28
virtual ValidRegion valid_region() const =0
Valid region of the tensor.
3 channels, 1 U8 per channel
virtual Format format() const =0
Colour format of the image.
const std::string & string_from_data_type(DataType dt)
Convert a data type identity into a string.
Definition: Utils.cpp:144
bool update_window_and_padding(Window &win, Ts &&... patterns)
Update window and padding size for each of the access patterns.
Definition: Helpers.h:402
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's metadata.
std::unique_ptr< Kernel > create_kernel()
Helper function to create and return a unique_ptr pointed to a CL/GLES kernel object.
Definition: Helpers.h:86
4 channels, 1 U8 per channel
A single plane of 32-bit macro pixel of Y0, U0, Y1, V0 bytes.
Describe a multidimensional execution window.
Definition: Window.h:39
#define ARM_COMPUTE_ERROR_ON_MSG(cond,...)
Definition: Error.h:328
const std::string & string_from_format(Format format)
Convert a tensor format into a string.
Definition: Utils.cpp:85

References ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_MSG, arm_compute::calculate_max_window(), arm_compute::create_kernel(), ITensorInfo::data_type(), ITensorInfo::dimension(), ITensorInfo::format(), CLKernelLibrary::get(), ITensor::info(), arm_compute::lower_string(), arm_compute::RGB888, arm_compute::RGBA8888, arm_compute::string_from_data_type(), arm_compute::string_from_format(), arm_compute::support::cpp11::to_string(), arm_compute::U8, arm_compute::update_window_and_padding(), arm_compute::UYVY422, ITensorInfo::valid_region(), and arm_compute::YUYV422.

◆ configure() [2/4]

void configure ( const ICLMultiImage input,
ICLImage output 
)

Set the input and output of the kernel.

Parameters
[in]inputMulti-planar source image. Formats supported: NV12/NV21/IYUV
[out]outputSingle-planar destination image. Formats supported: RGB888/RGBA8888

Definition at line 139 of file CLColorConvertKernel.cpp.

140 {
142  ARM_COMPUTE_ERROR_ON(output == nullptr);
143 
144  unsigned int num_elems_processed_per_iteration = 0;
145 
146  switch(input->info()->format())
147  {
148  case Format::NV12:
149  case Format::NV21:
150  case Format::IYUV:
151  {
152  switch(output->info()->format())
153  {
154  case Format::RGB888:
155  case Format::RGBA8888:
156  num_elems_processed_per_iteration = 4;
157  break;
158  default:
159  ARM_COMPUTE_ERROR("Not supported");
160  break;
161  }
162  break;
163  }
164  default:
165  break;
166  }
167  ARM_COMPUTE_ERROR_ON_MSG(num_elems_processed_per_iteration == 0, "Conversion from %s to %s not supported",
168  string_from_format(input->info()->format()).c_str(),
169  string_from_format(output->info()->format()).c_str());
170 
171  std::stringstream kernel_name;
172 
173  kernel_name << string_from_format(input->info()->format());
174  kernel_name << "_to_";
175  kernel_name << string_from_format(output->info()->format());
176  kernel_name << "_bt709";
177 
178  _multi_input = input;
179  _output = output;
180 
181  // Create kernel
182  _kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel(kernel_name.str()));
183 
184  // Configure kernel window
185  const bool has_two_planes = (input->info()->format() == Format::NV12) || (input->info()->format() == Format::NV21);
186  const float sub_sampling = (has_two_planes || (input->info()->format() == Format::IYUV)) ? 0.5f : 1;
187 
188  Window win = calculate_max_window(*output->info(), Steps(num_elems_processed_per_iteration));
190 
191  AccessWindowHorizontal plane0_access(input->plane(0)->info(), 0, num_elems_processed_per_iteration);
192  AccessWindowRectangle plane1_access(input->plane(1)->info(), 0, 0, num_elems_processed_per_iteration, 1,
193  sub_sampling, sub_sampling);
194  AccessWindowRectangle plane2_access(has_two_planes ? nullptr : input->plane(2)->info(), 0, 0, num_elems_processed_per_iteration, 1,
195  sub_sampling, sub_sampling);
196  AccessWindowHorizontal output_access(output->info(), 0, num_elems_processed_per_iteration);
197 
199  plane0_access, plane1_access, plane2_access,
200  output_access);
201 
202  ValidRegion intersect_region = intersect_valid_regions(input->plane(0)->info()->valid_region(), input->plane(1)->info()->valid_region(),
203  input->plane(2)->info()->valid_region());
204  output_access.set_valid_region(win, ValidRegion(intersect_region.anchor, output->info()->tensor_shape()));
205 
206  ICLKernel::configure_internal(win);
207 
208  // Set config_id for enabling LWS tuning
209  _config_id = kernel_name.str();
210  _config_id += "_";
211  _config_id += lower_string(string_from_data_type(input->plane(0)->info()->data_type()));
212  _config_id += "_";
213  _config_id += support::cpp11::to_string(input->plane(0)->info()->dimension(0));
214  _config_id += "_";
215  _config_id += support::cpp11::to_string(input->plane(0)->info()->dimension(1));
216  _config_id += "_";
217  _config_id += lower_string(string_from_data_type(input->plane(1)->info()->data_type()));
218  _config_id += "_";
219  _config_id += support::cpp11::to_string(input->plane(1)->info()->dimension(0));
220  _config_id += "_";
221  _config_id += support::cpp11::to_string(input->plane(1)->info()->dimension(1));
222 }
#define ARM_COMPUTE_ERROR(...)
Print the given message then throw an std::runtime_error.
Definition: Error.h:261
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
std::string to_string(T &&value)
Convert integer and float values to string.
virtual DataType data_type() const =0
Data type used for each element of the tensor.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:337
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
A 2 plane YUV format of Luma (Y) and interleaved UV data at 4:2:0 sampling.
std::string lower_string(const std::string &val)
Lower a given string.
Definition: Utils.cpp:327
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps=Steps(), bool skip_border=false, BorderSize border_size=BorderSize())
Calculate the maximum window for a given tensor shape and border setting.
Definition: Helpers.cpp:28
A 2 plane YUV format of Luma (Y) and interleaved VU data at 4:2:0 sampling.
virtual ValidRegion valid_region() const =0
Valid region of the tensor.
3 channels, 1 U8 per channel
#define ARM_COMPUTE_ERROR_ON_TENSOR_NOT_2D(t)
Definition: Validate.h:855
Implementation of a rectangular access pattern.
virtual Format format() const =0
Colour format of the image.
const std::string & string_from_data_type(DataType dt)
Convert a data type identity into a string.
Definition: Utils.cpp:144
bool update_window_and_padding(Window &win, Ts &&... patterns)
Update window and padding size for each of the access patterns.
Definition: Helpers.h:402
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
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's metadata.
ValidRegion intersect_valid_regions(const Ts &... regions)
Intersect multiple valid regions.
Definition: Helpers.h:503
IImage * plane(unsigned int index) override
Return a pointer to the requested plane of the image.
std::unique_ptr< Kernel > create_kernel()
Helper function to create and return a unique_ptr pointed to a CL/GLES kernel object.
Definition: Helpers.h:86
virtual const MultiImageInfo * info() const =0
Interface to be implemented by the child class to return the multi-planar image's metadata.
A 3 plane of 8-bit 4:2:0 sampled Y, U, V planes.
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
Definition: Window.h:45
4 channels, 1 U8 per channel
void set_dimension_step(size_t dimension, int step)
Set the step of a given dimension.
Definition: Window.inl:153
Container for valid region of a window.
Definition: Types.h:174
Format format() const
Colour format of the image.
Describe a multidimensional execution window.
Definition: Window.h:39
Coordinates anchor
Anchor for the start of the valid region.
Definition: Types.h:246
#define ARM_COMPUTE_ERROR_ON_MSG(cond,...)
Definition: Error.h:328
const std::string & string_from_format(Format format)
Convert a tensor format into a string.
Definition: Utils.cpp:85

References ValidRegion::anchor, ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_MSG, ARM_COMPUTE_ERROR_ON_TENSOR_NOT_2D, arm_compute::calculate_max_window(), arm_compute::create_kernel(), ITensorInfo::data_type(), ITensorInfo::dimension(), Window::DimY, MultiImageInfo::format(), ITensorInfo::format(), CLKernelLibrary::get(), ITensor::info(), IMultiImage::info(), arm_compute::intersect_valid_regions(), arm_compute::IYUV, arm_compute::lower_string(), arm_compute::NV12, arm_compute::NV21, ICLMultiImage::plane(), arm_compute::RGB888, arm_compute::RGBA8888, Window::set_dimension_step(), arm_compute::string_from_data_type(), arm_compute::string_from_format(), ITensorInfo::tensor_shape(), arm_compute::support::cpp11::to_string(), arm_compute::update_window_and_padding(), and ITensorInfo::valid_region().

◆ configure() [3/4]

void configure ( const ICLImage input,
ICLMultiImage output 
)

Set the input and output of the kernel.

Parameters
[in]inputSingle-planar source image. Formats supported: RGB888/RGBA8888/UYVY422/YUYV422
[out]outputMulti-planar destination image. Formats supported: NV12/IYUV/YUV444 (if the formats of input are RGB888/RGB8888)

Definition at line 224 of file CLColorConvertKernel.cpp.

225 {
227  ARM_COMPUTE_ERROR_ON(output == nullptr);
228 
229  unsigned int num_elems_processed_per_iteration = 0;
230  unsigned int num_elems_read_per_iteration_x = 0;
231 
232  bool has_two_planes = (output->info()->format() == Format::NV12) || (output->info()->format() == Format::NV21);
233  float sub_sampling = (has_two_planes || (output->info()->format() == Format::IYUV)) ? 0.5f : 1;
234 
235  switch(input->info()->format())
236  {
237  case Format::RGB888:
238  case Format::RGBA8888:
239  {
240  switch(output->info()->format())
241  {
242  case Format::NV12:
243  case Format::IYUV:
244  num_elems_processed_per_iteration = 2;
245  num_elems_read_per_iteration_x = 8;
246  break;
247  case Format::YUV444:
248  num_elems_processed_per_iteration = 4;
249  num_elems_read_per_iteration_x = 16;
250  break;
251  default:
252  ARM_COMPUTE_ERROR("Not supported");
253  break;
254  }
255  break;
256  }
257  case Format::UYVY422:
258  case Format::YUYV422:
259  {
260  switch(output->info()->format())
261  {
262  case Format::NV12:
263  case Format::IYUV:
264  num_elems_processed_per_iteration = 8;
265  num_elems_read_per_iteration_x = 8;
266  break;
267  default:
268  ARM_COMPUTE_ERROR("Not supported");
269  break;
270  }
271  break;
272  }
273  default:
274  break;
275  }
276 
277  ARM_COMPUTE_ERROR_ON_MSG(num_elems_processed_per_iteration == 0, "Conversion from %s to %s not supported",
278  string_from_format(input->info()->format()).c_str(),
279  string_from_format(output->info()->format()).c_str());
280 
281  std::stringstream kernel_name;
282 
283  kernel_name << string_from_format(input->info()->format());
284  kernel_name << "_to_";
285  kernel_name << string_from_format(output->info()->format());
286  kernel_name << "_bt709";
287  _input = input;
288  _multi_output = output;
289 
290  // Create kernel
291  _kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel(kernel_name.str()));
292 
293  // Configure kernel window
294  Window win = calculate_max_window(*input->info(), Steps(num_elems_processed_per_iteration));
295  if((input->info()->format() != Format::RGB888 || output->info()->format() != Format::YUV444) && (input->info()->format() != Format::RGBA8888 || output->info()->format() != Format::YUV444))
296  {
298  }
299 
300  AccessWindowHorizontal output_plane0_access(output->plane(0)->info(), 0, num_elems_processed_per_iteration);
301  AccessWindowRectangle output_plane1_access(output->plane(1)->info(), 0, 0, num_elems_processed_per_iteration, 1, sub_sampling, sub_sampling);
302  AccessWindowRectangle output_plane2_access(has_two_planes ? nullptr : output->plane(2)->info(), 0, 0,
303  num_elems_processed_per_iteration, 1, sub_sampling, sub_sampling);
304 
305  AccessWindowHorizontal input_access(input->info(), 0, num_elems_read_per_iteration_x);
306 
308  input_access,
309  output_plane0_access,
310  output_plane1_access,
311  output_plane2_access);
312 
313  ValidRegion input_region = input->info()->valid_region();
314 
315  output_plane0_access.set_valid_region(win, ValidRegion(input_region.anchor, output->plane(0)->info()->tensor_shape()));
316  output_plane1_access.set_valid_region(win, ValidRegion(input_region.anchor, output->plane(1)->info()->tensor_shape()));
317  output_plane2_access.set_valid_region(win, ValidRegion(input_region.anchor, output->plane(2)->info()->tensor_shape()));
318 
319  ICLKernel::configure_internal(win);
320 
321  // Set config_id for enabling LWS tuning
322  _config_id = kernel_name.str();
323  _config_id += "_";
324  _config_id += lower_string(string_from_data_type(input->info()->data_type()));
325  _config_id += "_";
326  _config_id += support::cpp11::to_string(input->info()->dimension(0));
327  _config_id += "_";
328  _config_id += support::cpp11::to_string(input->info()->dimension(1));
329 }
#define ARM_COMPUTE_ERROR(...)
Print the given message then throw an std::runtime_error.
Definition: Error.h:261
A single plane of 32-bit macro pixel of U0, Y0, V0, Y1 byte.
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
std::string to_string(T &&value)
Convert integer and float values to string.
virtual DataType data_type() const =0
Data type used for each element of the tensor.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:337
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
A 2 plane YUV format of Luma (Y) and interleaved UV data at 4:2:0 sampling.
std::string lower_string(const std::string &val)
Lower a given string.
Definition: Utils.cpp:327
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps=Steps(), bool skip_border=false, BorderSize border_size=BorderSize())
Calculate the maximum window for a given tensor shape and border setting.
Definition: Helpers.cpp:28
A 2 plane YUV format of Luma (Y) and interleaved VU data at 4:2:0 sampling.
virtual ValidRegion valid_region() const =0
Valid region of the tensor.
3 channels, 1 U8 per channel
#define ARM_COMPUTE_ERROR_ON_TENSOR_NOT_2D(t)
Definition: Validate.h:855
Implementation of a rectangular access pattern.
virtual Format format() const =0
Colour format of the image.
const std::string & string_from_data_type(DataType dt)
Convert a data type identity into a string.
Definition: Utils.cpp:144
bool update_window_and_padding(Window &win, Ts &&... patterns)
Update window and padding size for each of the access patterns.
Definition: Helpers.h:402
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
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's metadata.
IImage * plane(unsigned int index) override
Return a pointer to the requested plane of the image.
std::unique_ptr< Kernel > create_kernel()
Helper function to create and return a unique_ptr pointed to a CL/GLES kernel object.
Definition: Helpers.h:86
virtual const MultiImageInfo * info() const =0
Interface to be implemented by the child class to return the multi-planar image's metadata.
A 3 plane of 8-bit 4:2:0 sampled Y, U, V planes.
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
Definition: Window.h:45
4 channels, 1 U8 per channel
void set_dimension_step(size_t dimension, int step)
Set the step of a given dimension.
Definition: Window.inl:153
Container for valid region of a window.
Definition: Types.h:174
A single plane of 32-bit macro pixel of Y0, U0, Y1, V0 bytes.
Format format() const
Colour format of the image.
Describe a multidimensional execution window.
Definition: Window.h:39
Coordinates anchor
Anchor for the start of the valid region.
Definition: Types.h:246
#define ARM_COMPUTE_ERROR_ON_MSG(cond,...)
Definition: Error.h:328
const std::string & string_from_format(Format format)
Convert a tensor format into a string.
Definition: Utils.cpp:85

References ValidRegion::anchor, ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_MSG, ARM_COMPUTE_ERROR_ON_TENSOR_NOT_2D, arm_compute::calculate_max_window(), arm_compute::create_kernel(), ITensorInfo::data_type(), ITensorInfo::dimension(), Window::DimY, MultiImageInfo::format(), ITensorInfo::format(), CLKernelLibrary::get(), ITensor::info(), IMultiImage::info(), arm_compute::IYUV, arm_compute::lower_string(), arm_compute::NV12, arm_compute::NV21, ICLMultiImage::plane(), arm_compute::RGB888, arm_compute::RGBA8888, Window::set_dimension_step(), arm_compute::string_from_data_type(), arm_compute::string_from_format(), ITensorInfo::tensor_shape(), arm_compute::support::cpp11::to_string(), arm_compute::update_window_and_padding(), arm_compute::UYVY422, ITensorInfo::valid_region(), arm_compute::YUV444, and arm_compute::YUYV422.

◆ configure() [4/4]

void configure ( const ICLMultiImage input,
ICLMultiImage output 
)

Set the input and output of the kernel.

Parameters
[in]inputMulti-planar source image. Formats supported: NV12/NV21/IYUV
[out]outputMulti-planar destination image. Formats supported: YUV444/IYUV (if the formats of input are NV12/NV21)/NV12 (if the format of input is IYUV)

Definition at line 331 of file CLColorConvertKernel.cpp.

332 {
333  unsigned int num_elems_processed_per_iteration = 0;
334  switch(input->info()->format())
335  {
336  case Format::NV12:
337  case Format::NV21:
338  {
339  switch(output->info()->format())
340  {
341  case Format::IYUV:
342  case Format::YUV444:
343  num_elems_processed_per_iteration = 16;
344  break;
345  default:
346  ARM_COMPUTE_ERROR("Not supported");
347  break;
348  }
349  break;
350  }
351  case Format::IYUV:
352  {
353  switch(output->info()->format())
354  {
355  case Format::YUV444:
356  case Format::NV12:
357  num_elems_processed_per_iteration = 16;
358  break;
359  default:
360  ARM_COMPUTE_ERROR("Not supported");
361  break;
362  }
363  break;
364  }
365  default:
366  break;
367  }
368  ARM_COMPUTE_ERROR_ON_MSG(num_elems_processed_per_iteration == 0, "Conversion from %s to %s not supported",
369  string_from_format(input->info()->format()).c_str(),
370  string_from_format(output->info()->format()).c_str());
371 
372  std::stringstream kernel_name;
373 
374  kernel_name << string_from_format(input->info()->format());
375  kernel_name << "_to_";
376  kernel_name << string_from_format(output->info()->format());
377  kernel_name << "_bt709";
378 
379  _multi_input = input;
380  _multi_output = output;
381 
382  // Create kernel
383  bool has_two_input_planars = (input->info()->format() == Format::NV12) || (input->info()->format() == Format::NV21);
384  bool has_two_output_planars = (output->info()->format() == Format::NV12) || (output->info()->format() == Format::NV21);
385 
386  float sub_sampling_input = (has_two_input_planars || (input->info()->format() == Format::IYUV)) ? 0.5f : 1;
387  float sub_sampling_output = (has_two_output_planars || (output->info()->format() == Format::IYUV)) ? 0.5f : 1;
388 
389  _kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel(kernel_name.str()));
390 
391  Window win = calculate_max_window(*input->cl_plane(0)->info(), Steps(num_elems_processed_per_iteration));
393 
394  AccessWindowHorizontal input_plane0_access(input->plane(0)->info(), 0, num_elems_processed_per_iteration);
395  AccessWindowRectangle input_plane1_access(input->plane(1)->info(), 0, 0, num_elems_processed_per_iteration, 1,
396  sub_sampling_input, sub_sampling_input);
397  AccessWindowRectangle input_plane2_access(has_two_input_planars ? nullptr : input->plane(2)->info(), 0, 0, num_elems_processed_per_iteration, 1,
398  sub_sampling_input, sub_sampling_input);
399  AccessWindowHorizontal output_plane0_access(output->plane(0)->info(), 0, num_elems_processed_per_iteration);
400  AccessWindowRectangle output_plane1_access(output->plane(1)->info(), 0, 0, num_elems_processed_per_iteration, 1, sub_sampling_output, sub_sampling_output);
401  AccessWindowRectangle output_plane2_access(has_two_output_planars ? nullptr : output->plane(2)->info(), 0, 0,
402  num_elems_processed_per_iteration, 1, sub_sampling_output, sub_sampling_output);
403 
405  input_plane0_access, input_plane1_access, input_plane2_access,
406  output_plane0_access, output_plane1_access, output_plane2_access);
407 
408  ValidRegion intersect_region = intersect_valid_regions(input->plane(0)->info()->valid_region(), input->plane(1)->info()->valid_region(),
409  input->plane(2)->info()->valid_region());
410  output_plane0_access.set_valid_region(win, ValidRegion(intersect_region.anchor, output->plane(0)->info()->tensor_shape()));
411  output_plane1_access.set_valid_region(win, ValidRegion(intersect_region.anchor, output->plane(1)->info()->tensor_shape()));
412  output_plane2_access.set_valid_region(win, ValidRegion(intersect_region.anchor, output->plane(2)->info()->tensor_shape()));
413 
414  ICLKernel::configure_internal(win);
415 
416  // Set config_id for enabling LWS tuning
417  _config_id = kernel_name.str();
418  _config_id += "_";
419  _config_id += lower_string(string_from_data_type(input->plane(0)->info()->data_type()));
420  _config_id += "_";
421  _config_id += support::cpp11::to_string(input->plane(0)->info()->dimension(0));
422  _config_id += "_";
423  _config_id += support::cpp11::to_string(input->plane(0)->info()->dimension(1));
424  _config_id += "_";
425  _config_id += lower_string(string_from_data_type(input->plane(1)->info()->data_type()));
426  _config_id += "_";
427  _config_id += support::cpp11::to_string(input->plane(1)->info()->dimension(0));
428  _config_id += "_";
429  _config_id += support::cpp11::to_string(input->plane(1)->info()->dimension(1));
430 }
#define ARM_COMPUTE_ERROR(...)
Print the given message then throw an std::runtime_error.
Definition: Error.h:261
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
std::string to_string(T &&value)
Convert integer and float values to string.
virtual DataType data_type() const =0
Data type used for each element of the tensor.
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
A 2 plane YUV format of Luma (Y) and interleaved UV data at 4:2:0 sampling.
virtual ICLImage * cl_plane(unsigned int index)=0
Return a pointer to the requested OpenCL plane of the image.
std::string lower_string(const std::string &val)
Lower a given string.
Definition: Utils.cpp:327
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps=Steps(), bool skip_border=false, BorderSize border_size=BorderSize())
Calculate the maximum window for a given tensor shape and border setting.
Definition: Helpers.cpp:28
A 2 plane YUV format of Luma (Y) and interleaved VU data at 4:2:0 sampling.
virtual ValidRegion valid_region() const =0
Valid region of the tensor.
Implementation of a rectangular access pattern.
const std::string & string_from_data_type(DataType dt)
Convert a data type identity into a string.
Definition: Utils.cpp:144
bool update_window_and_padding(Window &win, Ts &&... patterns)
Update window and padding size for each of the access patterns.
Definition: Helpers.h:402
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
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's metadata.
ValidRegion intersect_valid_regions(const Ts &... regions)
Intersect multiple valid regions.
Definition: Helpers.h:503
IImage * plane(unsigned int index) override
Return a pointer to the requested plane of the image.
std::unique_ptr< Kernel > create_kernel()
Helper function to create and return a unique_ptr pointed to a CL/GLES kernel object.
Definition: Helpers.h:86
virtual const MultiImageInfo * info() const =0
Interface to be implemented by the child class to return the multi-planar image's metadata.
A 3 plane of 8-bit 4:2:0 sampled Y, U, V planes.
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
Definition: Window.h:45
void set_dimension_step(size_t dimension, int step)
Set the step of a given dimension.
Definition: Window.inl:153
Container for valid region of a window.
Definition: Types.h:174
Format format() const
Colour format of the image.
Describe a multidimensional execution window.
Definition: Window.h:39
Coordinates anchor
Anchor for the start of the valid region.
Definition: Types.h:246
#define ARM_COMPUTE_ERROR_ON_MSG(cond,...)
Definition: Error.h:328
const std::string & string_from_format(Format format)
Convert a tensor format into a string.
Definition: Utils.cpp:85

References ValidRegion::anchor, ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON_MSG, arm_compute::calculate_max_window(), ICLMultiImage::cl_plane(), arm_compute::create_kernel(), ITensorInfo::data_type(), ITensorInfo::dimension(), Window::DimY, MultiImageInfo::format(), CLKernelLibrary::get(), IMultiImage::info(), ITensor::info(), arm_compute::intersect_valid_regions(), arm_compute::IYUV, arm_compute::lower_string(), arm_compute::NV12, arm_compute::NV21, ICLMultiImage::plane(), Window::set_dimension_step(), arm_compute::string_from_data_type(), arm_compute::string_from_format(), ITensorInfo::tensor_shape(), arm_compute::support::cpp11::to_string(), arm_compute::update_window_and_padding(), ITensorInfo::valid_region(), and arm_compute::YUV444.

◆ operator=() [1/2]

CLColorConvertKernel& operator= ( const CLColorConvertKernel )
delete

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

◆ operator=() [2/2]

CLColorConvertKernel& operator= ( CLColorConvertKernel &&  )
default

Allow instances of this class to be moved.

◆ run()

void run ( const Window window,
cl::CommandQueue &  queue 
)
overridevirtual

Enqueue the OpenCL kernel to process the given window on the passed OpenCL command queue.

Note
The queue is not flushed by this method, and therefore the kernel will not have been executed by the time this method returns.
Parameters
[in]windowRegion on which to execute the kernel. (Must be a valid region of the window returned by window()).
[in,out]queueCommand queue on which to enqueue the kernel.

Implements ICLKernel.

Definition at line 432 of file CLColorConvertKernel.cpp.

433 {
436 
438 
439  if(nullptr != _input && nullptr != _output)
440  {
441  do
442  {
443  unsigned int idx = 0;
444  add_2D_tensor_argument(idx, _input, slice);
445  add_2D_tensor_argument(idx, _output, slice);
446  enqueue(queue, *this, slice, lws_hint());
447  }
449  }
450  else if(nullptr != _input && nullptr != _multi_output)
451  {
452  Format format = _multi_output->info()->format();
453  do
454  {
455  Window win_uv(slice);
456 
457  if((Format::NV12 == format) || (Format::NV21 == format) || (Format::IYUV == format))
458  {
459  win_uv.set(Window::DimX, Window::Dimension(win_uv.x().start() / 2, win_uv.x().end() / 2, win_uv.x().step() / 2));
460  win_uv.set(Window::DimY, Window::Dimension(win_uv.y().start() / 2, win_uv.y().end() / 2, 1));
461  }
462  unsigned int idx = 0;
463  add_2D_tensor_argument(idx, _input, slice);
464  add_2D_tensor_argument(idx, _multi_output->cl_plane(0), slice);
465  for(int i = 1; i < 3 && (0 != _multi_output->cl_plane(i)->info()->num_dimensions()); ++i)
466  {
467  add_2D_tensor_argument(idx, _multi_output->cl_plane(i), win_uv);
468  }
469  enqueue(queue, *this, slice, lws_hint());
470  }
472  }
473  else if(nullptr != _multi_input && nullptr != _output)
474  {
475  Format format = _multi_input->info()->format();
476  do
477  {
478  Window win_uv(slice);
479 
480  if((Format::NV12 == format) || (Format::NV21 == format) || (Format::IYUV == format))
481  {
482  win_uv.set(Window::DimX, Window::Dimension(win_uv.x().start() / 2, win_uv.x().end() / 2, win_uv.x().step() / 2));
483  win_uv.set(Window::DimY, Window::Dimension(win_uv.y().start() / 2, win_uv.y().end() / 2, 1));
484  }
485 
486  unsigned int idx = 0;
487  add_2D_tensor_argument(idx, _multi_input->cl_plane(0), slice);
488 
489  for(int i = 1; i < 3 && (0 != _multi_input->cl_plane(i)->info()->num_dimensions()); ++i)
490  {
491  add_2D_tensor_argument(idx, _multi_input->cl_plane(i), win_uv);
492  }
493  add_2D_tensor_argument(idx, _output, slice);
494  enqueue(queue, *this, slice, lws_hint());
495  }
497  }
498  else if(nullptr != _multi_input && nullptr != _multi_output)
499  {
500  Format in_format = _multi_input->info()->format();
501  Format out_format = _multi_output->info()->format();
502  do
503  {
504  Window win_in_uv(slice);
505  if((Format::NV12 == in_format) || (Format::NV21 == in_format) || (Format::IYUV == in_format))
506  {
507  win_in_uv.set(Window::DimX, Window::Dimension(win_in_uv.x().start() / 2,
508  win_in_uv.x().end() / 2, win_in_uv.x().step() / 2));
509  win_in_uv.set(Window::DimY, Window::Dimension(win_in_uv.y().start() / 2, win_in_uv.y().end() / 2, 1));
510  }
511  unsigned int idx = 0;
512  add_2D_tensor_argument(idx, _multi_input->cl_plane(0), slice);
513  for(int i = 1; i < 3 && (0 != _multi_input->cl_plane(i)->info()->num_dimensions()); ++i)
514  {
515  add_2D_tensor_argument(idx, _multi_input->cl_plane(i), win_in_uv);
516  }
517 
518  Window win_out_uv(slice);
519  if((Format::NV12 == out_format) || (Format::NV21 == out_format) || (Format::IYUV == out_format))
520  {
521  win_out_uv.set(Window::DimX, Window::Dimension(win_out_uv.x().start() / 2,
522  win_out_uv.x().end() / 2, win_out_uv.x().step() / 2));
523  win_out_uv.set(Window::DimY, Window::Dimension(win_out_uv.y().start() / 2, win_out_uv.y().end() / 2, 1));
524  }
525 
526  add_2D_tensor_argument(idx, _multi_output->cl_plane(0), slice);
527  for(int i = 1; i < 3 && (0 != _multi_output->cl_plane(i)->info()->num_dimensions()); ++i)
528  {
529  add_2D_tensor_argument(idx, _multi_output->cl_plane(i), win_out_uv);
530  }
531  enqueue(queue, *this, slice, lws_hint());
532  }
534  }
535  else
536  {
537  ARM_COMPUTE_ERROR("Not supported");
538  }
539 }
Window first_slice_window_2D() const
First 2D slice of the window.
Definition: Window.h:267
#define ARM_COMPUTE_ERROR(...)
Print the given message then throw an std::runtime_error.
Definition: Error.h:261
virtual size_t num_dimensions() const =0
The number of dimensions of the tensor (rank)
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
void enqueue(cl::CommandQueue &queue, ICLKernel &kernel, const Window &window, const cl::NDRange &lws_hint=CLKernelLibrary::get().default_ndrange(), bool use_dummy_work_items=false)
Add the kernel to the command queue with the given window.
Definition: ICLKernel.cpp:39
cl::NDRange lws_hint() const
Return the Local-Workgroup-Size hint.
Definition: ICLKernel.h:247
A 2 plane YUV format of Luma (Y) and interleaved UV data at 4:2:0 sampling.
Describe one of the image's dimensions with a start, end and step.
Definition: Window.h:75
virtual ICLImage * cl_plane(unsigned int index)=0
Return a pointer to the requested OpenCL plane of the image.
A 2 plane YUV format of Luma (Y) and interleaved VU data at 4:2:0 sampling.
bool slide_window_slice_2D(Window &slice) const
Slide the passed 2D window slice.
Definition: Window.h:307
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
Definition: Window.h:43
Format
Image colour formats.
Definition: Types.h:52
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
virtual const MultiImageInfo * info() const =0
Interface to be implemented by the child class to return the multi-planar image's metadata.
A 3 plane of 8-bit 4:2:0 sampled Y, U, V planes.
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
Definition: Window.h:45
void add_2D_tensor_argument(unsigned int &idx, const ICLTensor *tensor, const Window &window)
Add the passed 2D tensor's parameters to the object's kernel's arguments starting from the index idx.
Definition: ICLKernel.h:134
Format format() const
Colour format of the image.
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205
Describe a multidimensional execution window.
Definition: Window.h:39
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:940
SimpleTensor< T > slice(const SimpleTensor< T > &src, Coordinates starts, Coordinates ends)

References ICLKernel::add_2D_tensor_argument(), ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ICLMultiImage::cl_plane(), Window::DimX, Window::DimY, Window::Dimension::end(), arm_compute::enqueue(), Window::first_slice_window_2D(), MultiImageInfo::format(), IMultiImage::info(), ITensor::info(), arm_compute::IYUV, ICLKernel::lws_hint(), ITensorInfo::num_dimensions(), arm_compute::NV12, arm_compute::NV21, Window::set(), arm_compute::test::validation::reference::slice(), Window::slide_window_slice_2D(), Window::Dimension::start(), Window::Dimension::step(), IKernel::window(), Window::x(), and Window::y().


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