Compute Library
 21.02
CLConvolutionRectangleKernel Class Reference

Kernel for the running convolution on a rectangle matrix. More...

#include <CLConvolutionKernel.h>

Collaboration diagram for CLConvolutionRectangleKernel:
[legend]

Public Member Functions

 CLConvolutionRectangleKernel ()
 Default constructor. More...
 
 CLConvolutionRectangleKernel (const CLConvolutionRectangleKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
CLConvolutionRectangleKerneloperator= (const CLConvolutionRectangleKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 CLConvolutionRectangleKernel (CLConvolutionRectangleKernel &&)=default
 Allow instances of this class to be moved. More...
 
CLConvolutionRectangleKerneloperator= (CLConvolutionRectangleKernel &&)=default
 Allow instances of this class to be moved. More...
 
void configure (const ICLTensor *input, ICLTensor *output, const int16_t *conv, uint32_t width, uint32_t height, uint32_t scale, bool border_undefined)
 Initialise the kernel's input, output and border mode. More...
 
void configure (const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output, const int16_t *conv, uint32_t width, uint32_t height, uint32_t scale, bool border_undefined)
 Initialise the kernel's input, output and border mode. 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...
 
BorderSize border_size () const override
 The size of the border for that kernel. 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...
 
virtual void run_op (ITensorPack &tensors, const Window &window, cl::CommandQueue &queue)
 Enqueue the OpenCL kernel to process the given window on the passed OpenCL command queue. 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...
 
void set_wbsm_hint (const cl_int &wbsm_hint)
 Set the workgroup batch size modifier hint. More...
 
cl_int wbsm_hint () const
 Return the workgroup batch size modifier 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<unsigned int dimension_size>
void add_tensor_argument (unsigned &idx, const ICLTensor *tensor, const Window &window)
 
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...
 
- 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...
 
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

Kernel for the running convolution on a rectangle matrix.

Note
Supports combinations of 3,5,7 and 9.

Definition at line 177 of file CLConvolutionKernel.h.

Constructor & Destructor Documentation

◆ CLConvolutionRectangleKernel() [1/3]

Default constructor.

Definition at line 291 of file CLConvolutionKernel.cpp.

292  : _border_size(0), _input(nullptr), _output(nullptr)
293 {
294 }

◆ CLConvolutionRectangleKernel() [2/3]

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

◆ CLConvolutionRectangleKernel() [3/3]

Allow instances of this class to be moved.

Member Function Documentation

◆ border_size()

BorderSize border_size ( ) const
overridevirtual

The size of the border for that kernel.

Returns
The width in number of elements of the border.

Reimplemented from IKernel.

Definition at line 296 of file CLConvolutionKernel.cpp.

Referenced by CLConvolutionRectangleKernel::configure().

297 {
298  return _border_size;
299 }

◆ configure() [1/2]

void configure ( const ICLTensor input,
ICLTensor output,
const int16_t *  conv,
uint32_t  width,
uint32_t  height,
uint32_t  scale,
bool  border_undefined 
)

Initialise the kernel's input, output and border mode.

Parameters
[in]inputSource tensor. Data types supported: U8.
[out]outputDestination tensor, Data types supported: U8, S16.
[in]convConvolution matrix to apply to the input tensor.
[in]widthWidth of convolution matrix (Number of columns)
[in]heightHeight of convolution matrix (Number of rows)
[in]scaleScale of the convolution matrix. If 0 is passed, it will be set to the sum of the coefficients of the convolution or 1 if they add up to 0.
[in]border_undefinedTrue if the border mode is undefined. False if it's replicate or constant.

Definition at line 301 of file CLConvolutionKernel.cpp.

References CLKernelLibrary::get().

302 {
303  configure(CLKernelLibrary::get().get_compile_context(), input, output, conv, width, height, scale, border_undefined);
304 }
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
void configure(const ICLTensor *input, ICLTensor *output, const int16_t *conv, uint32_t width, uint32_t height, uint32_t scale, bool border_undefined)
Initialise the kernel&#39;s input, output and border mode.

◆ configure() [2/2]

void configure ( const CLCompileContext compile_context,
const ICLTensor input,
ICLTensor output,
const int16_t *  conv,
uint32_t  width,
uint32_t  height,
uint32_t  scale,
bool  border_undefined 
)

Initialise the kernel's input, output and border mode.

Parameters
[in]compile_contextThe compile context to be used.
[in]inputSource tensor. Data types supported: U8.
[out]outputDestination tensor, Data types supported: U8, S16.
[in]convConvolution matrix to apply to the input tensor.
[in]widthWidth of convolution matrix (Number of columns)
[in]heightHeight of convolution matrix (Number of rows)
[in]scaleScale of the convolution matrix. If 0 is passed, it will be set to the sum of the coefficients of the convolution or 1 if they add up to 0.
[in]border_undefinedTrue if the border mode is undefined. False if it's replicate or constant.

Definition at line 306 of file CLConvolutionKernel.cpp.

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN, CLConvolutionRectangleKernel::border_size(), arm_compute::calculate_max_window(), arm_compute::create_kernel(), arm_compute::test::validation::data_type, ITensorInfo::data_type(), arm_compute::data_type_for_convolution_matrix(), arm_compute::get_cl_type_from_data_type(), ITensor::info(), arm_compute::test::validation::input, BorderSize::left, num_elems_processed_per_iteration, arm_compute::S16, arm_compute::support::cpp11::to_string(), BorderSize::top, arm_compute::U8, arm_compute::update_window_and_padding(), and ITensorInfo::valid_region().

308 {
311  ARM_COMPUTE_ERROR_ON(nullptr == conv);
312  ARM_COMPUTE_ERROR_ON(3 != width && 5 != width && 7 != width && 9 != width);
313  ARM_COMPUTE_ERROR_ON(3 != height && 5 != height && 7 != height && 9 != height);
315 
316  _input = input;
317  _output = output;
318  _border_size = BorderSize(height / 2, width / 2);
319 
320  std::set<std::string> options;
321 
322  std::stringstream output_type;
323  output_type << "-DDATA_TYPE_OUT=" << get_cl_type_from_data_type(output->info()->data_type());
324  options.insert(output_type.str());
325 
326  uint32_t matrix_size = width * height;
327 
328  std::array<int16_t, max_matrix_size> mat = { 0 };
329 
330  memcpy(mat.data(), conv, matrix_size * sizeof(int16_t));
331 
332  for(unsigned int j = 0; j < max_matrix_size; j++)
333  {
334  options.insert("-DMAT" + support::cpp11::to_string(j) + "=" + support::cpp11::to_string(mat[j]));
335  }
336 
337  options.insert("-DSCALE=" + support::cpp11::to_string(scale));
338 
340  options.insert("-DDATA_TYPE=" + get_cl_type_from_data_type(data_type));
341 
342  options.insert("-DMATRIX_WIDTH=" + support::cpp11::to_string(width));
343  options.insert("-DMATRIX_HEIGHT=" + support::cpp11::to_string(height));
344 
345  _kernel = create_kernel(compile_context, "convolution_rectangle", options);
346 
347  // Configure kernel window
348  constexpr unsigned int num_elems_processed_per_iteration = 8;
349  constexpr unsigned int num_elems_read_per_iteration = 16;
350  constexpr unsigned int num_elems_written_per_iteration = 8;
351  const unsigned int num_rows_read_per_iteration = height;
352 
353  Window win = calculate_max_window(*input->info(), Steps(num_elems_processed_per_iteration), border_undefined, border_size());
354 
355  AccessWindowRectangle input_access(input->info(), -border_size().left, -border_size().top, num_elems_read_per_iteration, num_rows_read_per_iteration);
356  AccessWindowHorizontal output_access(output->info(), 0, num_elems_written_per_iteration);
357 
358  update_window_and_padding(win, input_access, output_access);
359 
360  output_access.set_valid_region(win, input->info()->valid_region(), border_undefined, border_size());
361 
362  ICLKernel::configure_internal(win);
363 }
unsigned int top
top of the border
Definition: Types.h:375
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
1 channel, 1 U8 per channel
std::string to_string(T &&value)
Convert integer and float values to string.
#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
const DataType data_type
Definition: Im2Col.cpp:150
cl::Kernel create_kernel(const CLCompileContext &ctx, const std::string &kernel_name, const std::set< std::string > &build_opts=std::set< std::string >())
Creates an opencl kernel using a compile context.
Definition: CLHelpers.cpp:403
bool update_window_and_padding(Window &win, Ts &&... patterns)
Update window and padding size for each of the access patterns.
Definition: WindowHelpers.h:46
std::string get_cl_type_from_data_type(const DataType &dt)
Translates a tensor data type to the appropriate OpenCL type.
Definition: CLHelpers.cpp:37
unsigned int left
left of the border
Definition: Types.h:378
BorderSize border_size() const override
The size of the border for that kernel.
1 channel, 1 S16 per channel
#define ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:790
unsigned int num_elems_processed_per_iteration
DataType
Available data types.
Definition: Types.h:77
DataType data_type_for_convolution_matrix(const int16_t *conv, size_t size)
Calculate the accuracy required by the squared convolution calculation.
Definition: Utils.h:862

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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.

Reimplemented from ICLKernel.

Definition at line 365 of file CLConvolutionKernel.cpp.

References ICLKernel::add_2D_tensor_argument(), ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, arm_compute::enqueue(), Window::first_slice_window_2D(), ICLKernel::lws_hint(), arm_compute::test::validation::reference::slice(), Window::slide_window_slice_2D(), and IKernel::window().

366 {
369 
371 
372  do
373  {
374  unsigned int idx = 0;
375  add_2D_tensor_argument(idx, _input, slice);
376  add_2D_tensor_argument(idx, _output, slice);
377  enqueue(queue, *this, slice, lws_hint());
378  }
379  while(window.slide_window_slice_2D(slice));
380 }
Window first_slice_window_2D() const
First 2D slice of the window.
Definition: Window.h:283
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
void enqueue(IGCKernel &kernel, const Window &window, const gles::NDRange &lws=gles::NDRange(1U, 1U, 1U))
Add the kernel to the command queue with the given window.
Definition: IGCKernel.cpp:41
cl::NDRange lws_hint() const
Return the Local-Workgroup-Size hint.
Definition: ICLKernel.h:276
bool slide_window_slice_2D(Window &slice) const
Slide the passed 2D window slice.
Definition: Window.h:323
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:941
void add_2D_tensor_argument(unsigned int &idx, const ICLTensor *tensor, const Window &window)
Add the passed 2D tensor&#39;s parameters to the object&#39;s kernel&#39;s arguments starting from the index idx...
Definition: ICLKernel.h:148
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205
SimpleTensor< T > slice(const SimpleTensor< T > &src, Coordinates starts, Coordinates ends)

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