Compute Library
 20.02.1
CLFillBorderKernel Class Reference

Interface for filling the border of a kernel. More...

#include <CLFillBorderKernel.h>

Collaboration diagram for CLFillBorderKernel:
[legend]

Public Member Functions

 CLFillBorderKernel ()
 Default constructor. More...
 
 CLFillBorderKernel (const CLFillBorderKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
CLFillBorderKerneloperator= (const CLFillBorderKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 CLFillBorderKernel (CLFillBorderKernel &&)=default
 Allow instances of this class to be moved. More...
 
CLFillBorderKerneloperator= (CLFillBorderKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~CLFillBorderKernel ()=default
 Default destructor. More...
 
void configure (ICLTensor *tensor, BorderSize border_size, BorderMode border_mode, const PixelValue &constant_border_value=PixelValue())
 Initialise the kernel's input, output and border mode. More...
 
template<class T >
void set_constant_border (unsigned int idx, const PixelValue &constant_border_value)
 Function to set the constant value on fill border kernel depending on type. 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...
 
bool is_parallelisable () const override
 Indicates whether or not the kernel is parallelisable. 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 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 filling the border of a kernel.

Definition at line 36 of file CLFillBorderKernel.h.

Constructor & Destructor Documentation

◆ CLFillBorderKernel() [1/3]

Default constructor.

Definition at line 44 of file CLFillBorderKernel.cpp.

45  : ICLKernel(), _tensor(nullptr)
46 {
47 }
ICLKernel()
Constructor.
Definition: ICLKernel.h:79

◆ CLFillBorderKernel() [2/3]

CLFillBorderKernel ( const CLFillBorderKernel )
delete

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

◆ CLFillBorderKernel() [3/3]

Allow instances of this class to be moved.

◆ ~CLFillBorderKernel()

~CLFillBorderKernel ( )
default

Default destructor.

Member Function Documentation

◆ configure()

void configure ( ICLTensor tensor,
BorderSize  border_size,
BorderMode  border_mode,
const PixelValue constant_border_value = PixelValue() 
)

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

Parameters
[in,out]tensorTensor to process Data types supported: U8/QASYMM8/S8/QASYMM8_SIGNED/U16/S16/U32/S32/F16/F32.
[in]border_sizeSize of the border to fill in elements.
[in]border_modeBorder mode to use for the convolution.
[in]constant_border_value(Optional) Constant value to use for borders if border_mode is set to CONSTANT.

Definition at line 62 of file CLFillBorderKernel.cpp.

63 {
64  ARM_COMPUTE_ERROR_ON(tensor == nullptr);
65  ARM_COMPUTE_ERROR_ON(tensor->info()->num_channels() != 1);
66 
67  border_size.limit(tensor->info()->padding());
68 
69  // If there is no border: early exit
71  {
72  return;
73  }
74 
75  // Select appropriate kernel
76  std::string kernel_name = "fill_image_borders_" + lower_string(string_from_border_mode(border_mode));
77 
78  const DataType dt = tensor->info()->data_type();
79 
80  // Define build options
81  CLBuildOptions build_opts;
82  build_opts.add_option("-DDATA_TYPE=" + get_underlying_cl_type_from_data_type(dt));
83  build_opts.add_option("-DBORDER_SIZE_TOP=" + support::cpp11::to_string(border_size.top));
84  build_opts.add_option("-DBORDER_SIZE_BOTTOM=" + support::cpp11::to_string(border_size.bottom));
85  build_opts.add_option("-DBORDER_SIZE_LEFT=" + support::cpp11::to_string(border_size.left));
86  build_opts.add_option("-DBORDER_SIZE_RIGHT=" + support::cpp11::to_string(border_size.right));
87 
88  // Create kernel
89  _kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel(kernel_name, build_opts.options()));
90  _tensor = tensor;
91 
92  // Create static kernel arguments
93  const unsigned int valid_width = tensor->info()->valid_region().shape[0];
94  const unsigned int valid_height = tensor->info()->valid_region().shape[1];
95  const cl_int2 valid_region_coords =
96  {
97  {
98  static_cast<cl_int>(tensor->info()->valid_region().anchor[0]),
99  static_cast<cl_int>(tensor->info()->valid_region().anchor[1]),
100  }
101  };
102  const unsigned int total_valid_width = border_size.left + valid_width + border_size.right;
103 
104  // Set static kernel arguments
105  unsigned int idx = num_arguments_per_3D_tensor(); //Skip the tensor parameters
106  ICLKernel::add_argument<cl_uint>(idx, valid_width);
107  ICLKernel::add_argument<cl_uint>(idx, valid_height);
108  ICLKernel::add_argument<cl_int2>(idx, valid_region_coords);
110  {
111  switch(dt)
112  {
113  case DataType::U8:
114  case DataType::QASYMM8:
115  set_constant_border<uint8_t>(idx, constant_border_value);
116  break;
117  case DataType::S8:
119  set_constant_border<int8_t>(idx, constant_border_value);
120  break;
121  case DataType::U16:
122  set_constant_border<uint16_t>(idx, constant_border_value);
123  break;
124  case DataType::S16:
125  set_constant_border<int16_t>(idx, constant_border_value);
126  break;
127  case DataType::U32:
128  set_constant_border<uint32_t>(idx, constant_border_value);
129  break;
130  case DataType::S32:
131  set_constant_border<int32_t>(idx, constant_border_value);
132  break;
133  case DataType::F32:
134  static_assert(sizeof(float) == 4, "Float must be 32 bit");
135  set_constant_border<float>(idx, constant_border_value);
136  break;
137  case DataType::F16:
138  static_assert(sizeof(cl_half) == sizeof(half), "Half must be same size as cl_half");
139  static_assert(sizeof(cl_half) == 2, "Half must be 16 bit");
140  set_constant_border<half>(idx, constant_border_value);
141  break;
142  default:
143  ARM_COMPUTE_ERROR("Not handled");
144  }
145  }
146 
147  // Configure kernel window
148  Window win;
149  win.set(Window::DimX, Window::Dimension(0, total_valid_width + valid_height));
150  win.set(Window::DimY, Window::Dimension(0, 1, 1));
152  ICLKernel::configure_internal(win);
153 
154  // Set config_id for enabling LWS tuning
155  _config_id = kernel_name;
156  _config_id += "_";
157  _config_id += lower_string(string_from_data_type(dt));
158  _config_id += "_";
159  _config_id += support::cpp11::to_string(tensor->info()->dimension(0));
160  _config_id += "_";
161  _config_id += support::cpp11::to_string(tensor->info()->dimension(1));
162  _config_id += "_";
164 }
unsigned int top
top of the border
Definition: Types.h:349
TensorShape shape
Shape of the valid region.
Definition: Types.h:257
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
const StringSet & options() const
Gets the current options list set.
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
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.
half_float::half half
16-bit floating point type
Definition: Types.h:45
1 channel, 1 F32 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
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
Describe one of the image's dimensions with a start, end and step.
Definition: Window.h:75
1 channel, 1 U16 per channel
unsigned int bottom
bottom of the border
Definition: Types.h:351
std::string lower_string(const std::string &val)
Lower a given string.
Definition: Utils.cpp:333
void use_tensor_dimensions(const TensorShape &shape, size_t first_dimension=Window::DimX)
Use the tensor's dimensions to fill the window dimensions.
Definition: Window.inl:264
1 channel, 1 F16 per channel
virtual ValidRegion valid_region() const =0
Valid region of the tensor.
const std::string & string_from_border_mode(BorderMode border_mode)
Translates a given border mode policy to a string.
Definition: Utils.cpp:231
1 channel, 1 S32 per channel
void add_option(std::string option)
Adds option to the existing build option list.
const std::string & string_from_data_type(DataType dt)
Convert a data type identity into a string.
Definition: Utils.cpp:144
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
Definition: Window.h:43
static constexpr unsigned int num_arguments_per_3D_tensor()
Returns the number of arguments enqueued per 3D tensor object.
Definition: ICLKernel.h:200
1 channel, 1 U32 per channel
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
quantized, asymmetric fixed-point 8-bit number unsigned
std::string kernel_name
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
virtual BorderSize border_size() const
The size of the border for that kernel.
Definition: IKernel.cpp:46
void set(size_t dimension, const Dimension &dim)
Set the values of a given dimension.
Definition: Window.inl:49
virtual PaddingSize padding() const =0
Padding of tensor.
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
unsigned int left
left of the border
Definition: Types.h:352
std::string get_underlying_cl_type_from_data_type(const DataType &dt)
Translates fixed point tensor data type to the underlying OpenCL type.
Definition: CLHelpers.cpp:221
unsigned int right
right of the border
Definition: Types.h:350
1 channel, 1 S16 per channel
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
Definition: Window.h:45
constexpr bool empty() const
Check if the entire border is zero.
Definition: Types.h:296
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
Definition: Window.h:47
Borders are left undefined.
quantized, asymmetric fixed-point 8-bit number signed
DataType
Available data types.
Definition: Types.h:75
signed 8-bit number
Describe a multidimensional execution window.
Definition: Window.h:39
virtual size_t num_channels() const =0
The number of channels for each tensor element.
void limit(const BorderSize &limit)
Limit this border size.
Definition: Types.h:341
Coordinates anchor
Anchor for the start of the valid region.
Definition: Types.h:256

References CLBuildOptions::add_option(), ValidRegion::anchor, ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON, arm_compute::test::validation::border_mode, IKernel::border_size(), BorderSize::bottom, arm_compute::CONSTANT, arm_compute::create_kernel(), ITensorInfo::data_type(), ITensorInfo::dimension(), Window::DimX, Window::DimY, Window::DimZ, BorderSize::empty(), arm_compute::F16, arm_compute::F32, CLKernelLibrary::get(), arm_compute::get_underlying_cl_type_from_data_type(), ITensor::info(), kernel_name, BorderSize::left, BorderSize::limit(), arm_compute::lower_string(), ICLKernel::num_arguments_per_3D_tensor(), ITensorInfo::num_channels(), CLBuildOptions::options(), ITensorInfo::padding(), arm_compute::QASYMM8, arm_compute::QASYMM8_SIGNED, BorderSize::right, arm_compute::S16, arm_compute::S32, arm_compute::S8, Window::set(), ValidRegion::shape, arm_compute::string_from_border_mode(), arm_compute::string_from_data_type(), ITensorInfo::tensor_shape(), arm_compute::support::cpp11::to_string(), BorderSize::top, arm_compute::U16, arm_compute::U32, arm_compute::U8, arm_compute::UNDEFINED, Window::use_tensor_dimensions(), and ITensorInfo::valid_region().

Referenced by CLDirectConvolutionLayer::configure(), CLMeanStdDev::configure(), CLNormalizationLayer::configure(), CLGaussian5x5::configure(), CLSobel7x7::configure(), CLSobel5x5::configure(), CLCannyEdge::configure(), CLHarrisCorners::configure(), CLSynthetizeFunctionInitOutputWithZeroAndWithZeroConstantBorder< K, bordersize >::configure(), and arm_compute::test::validation::DATA_TEST_CASE().

◆ is_parallelisable()

bool is_parallelisable ( ) const
overridevirtual

Indicates whether or not the kernel is parallelisable.

If the kernel is parallelisable then the window returned by window() can be split into sub-windows which can then be run in parallel.

If the kernel is not parallelisable then only the window returned by window() can be passed to run()

Returns
True if the kernel is parallelisable

Reimplemented from IKernel.

Definition at line 49 of file CLFillBorderKernel.cpp.

50 {
51  return false;
52 }

◆ operator=() [1/2]

CLFillBorderKernel& operator= ( const CLFillBorderKernel )
delete

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

◆ operator=() [2/2]

CLFillBorderKernel& operator= ( CLFillBorderKernel &&  )
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 166 of file CLFillBorderKernel.cpp.

167 {
168  // Border mode undefined or border width == 0
169  if(_kernel() == nullptr)
170  {
171  return;
172  }
173 
176 
178  Window slice = collapsed.first_slice_window_3D();
179 
180  do
181  {
182  unsigned int idx = 0;
183  add_3D_tensor_argument(idx, _tensor, slice);
184  enqueue(queue, *this, slice, lws_hint());
185  }
186  while(collapsed.slide_window_slice_3D(slice));
187 }
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
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.
Definition: ICLKernel.h:158
Window collapse_if_possible(const Window &full_window, size_t first, size_t last, bool *has_collapsed=nullptr) const
Collapse the dimensions between first and last if possible.
Definition: Window.inl:68
#define ARM_COMPUTE_ERROR_ON_MISMATCHING_WINDOWS(f, w)
Definition: Validate.h:183
bool slide_window_slice_3D(Window &slice) const
Slide the passed 3D window slice.
Definition: Window.h:333
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
Definition: Window.h:47
Window first_slice_window_3D() const
First 3D slice of the window.
Definition: Window.h:289
Describe a multidimensional execution window.
Definition: Window.h:39
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:941
SimpleTensor< T > slice(const SimpleTensor< T > &src, Coordinates starts, Coordinates ends)

References ICLKernel::add_3D_tensor_argument(), ARM_COMPUTE_ERROR_ON_MISMATCHING_WINDOWS, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, Window::collapse_if_possible(), Window::DimZ, arm_compute::enqueue(), Window::first_slice_window_3D(), ICLKernel::lws_hint(), arm_compute::test::validation::reference::slice(), Window::slide_window_slice_3D(), and IKernel::window().

Referenced by arm_compute::test::validation::DATA_TEST_CASE().

◆ set_constant_border()

void set_constant_border ( unsigned int  idx,
const PixelValue constant_border_value 
)

Function to set the constant value on fill border kernel depending on type.

Parameters
[in]idxIndex of the kernel argument to set.
[in]constant_border_valueConstant value to use for borders if border_mode is set to CONSTANT.

Definition at line 55 of file CLFillBorderKernel.cpp.

56 {
57  T value;
58  constant_border_value.get(value);
59  ICLKernel::add_argument<T>(idx, static_cast<T>(value));
60 }
void get(uint8_t &v) const
Interpret the pixel value as a U8.
Definition: PixelValue.h:230

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