Compute Library
 19.08
GCFillBorderKernel Class Reference

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

#include <GCFillBorderKernel.h>

Collaboration diagram for GCFillBorderKernel:
[legend]

Public Member Functions

 GCFillBorderKernel ()
 Default constructor. More...
 
 GCFillBorderKernel (const GCFillBorderKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
GCFillBorderKerneloperator= (const GCFillBorderKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 GCFillBorderKernel (GCFillBorderKernel &&)=default
 Allow instances of this class to be moved. More...
 
GCFillBorderKerneloperator= (GCFillBorderKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~GCFillBorderKernel ()=default
 Default destructor. More...
 
void configure (const IGCTensor *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) override
 Enqueue the OpenGL ES shader to process the given window. More...
 
bool is_parallelisable () const override
 Indicates whether or not the kernel is parallelisable. More...
 
- Public Member Functions inherited from IGCKernel
 IGCKernel ()
 Constructor. More...
 
GCKernelkernel ()
 Returns a reference to the GLES kernel of this object. More...
 
void add_1D_tensor_argument (unsigned int &idx, const IGCTensor *tensor, const unsigned int binding_point, 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_2D_tensor_argument (unsigned int &idx, const IGCTensor *tensor, const unsigned int binding_point, 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_3D_tensor_argument (unsigned int &idx, const IGCTensor *tensor, const unsigned int binding_point, const Window &window)
 Add the passed 3D tensor's parameters to the object's kernel's arguments starting from the index idx. More...
 
unsigned int num_arguments_per_1D_tensor () const
 Returns the number of arguments enqueued per 1D tensor object. More...
 
unsigned int num_arguments_per_2D_tensor () const
 Returns the number of arguments enqueued per 2D tensor object. More...
 
unsigned int num_arguments_per_3D_tensor () const
 Returns the number of arguments enqueued per 3D tensor object. More...
 
void set_lws_hint (gles::NDRange &lws_hint)
 Set the Local-Workgroup-Size hint. More...
 
void set_target (GPUTarget target)
 Set the targeted GPU architecture. More...
 
GPUTarget get_target () const
 Get the targeted GPU architecture. More...
 
- 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...
 

Detailed Description

Interface for filling the border of a kernel.

Definition at line 36 of file GCFillBorderKernel.h.

Constructor & Destructor Documentation

◆ GCFillBorderKernel() [1/3]

Default constructor.

Definition at line 42 of file GCFillBorderKernel.cpp.

43  : IGCKernel(), _tensor(nullptr)
44 {
45 }
IGCKernel()
Constructor.
Definition: IGCKernel.cpp:64

◆ GCFillBorderKernel() [2/3]

GCFillBorderKernel ( const GCFillBorderKernel )
delete

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

◆ GCFillBorderKernel() [3/3]

Allow instances of this class to be moved.

◆ ~GCFillBorderKernel()

~GCFillBorderKernel ( )
default

Default destructor.

Member Function Documentation

◆ configure()

void configure ( const IGCTensor 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: 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 60 of file GCFillBorderKernel.cpp.

61 {
62  ARM_COMPUTE_ERROR_ON(tensor == nullptr);
64  ARM_COMPUTE_ERROR_ON(tensor->info()->num_channels() != 1);
65 
66  border_size.limit(tensor->info()->padding());
67 
68  // If there is no border: early exit
70  {
71  return;
72  }
73 
74  // Select appropriate kernel
75  std::string kernel_name = "fill_image_borders_" + lower_string(string_from_border_mode(border_mode));
76 
77  // Define build options
78  std::set<std::string> build_opts;
79  build_opts.emplace("#define LOCAL_SIZE_X " + support::cpp11::to_string(1));
80  build_opts.emplace("#define LOCAL_SIZE_Y " + support::cpp11::to_string(1));
81  build_opts.emplace("#define LOCAL_SIZE_Z " + support::cpp11::to_string(1));
82  build_opts.emplace("#define BORDER_SIZE_TOP " + support::cpp11::to_string(border_size.top));
83  build_opts.emplace("#define BORDER_SIZE_BOTTOM " + support::cpp11::to_string(border_size.bottom));
84  build_opts.emplace("#define BORDER_SIZE_LEFT " + support::cpp11::to_string(border_size.left));
85  build_opts.emplace("#define BORDER_SIZE_RIGHT " + support::cpp11::to_string(border_size.right));
86 
88  {
89  build_opts.emplace("#define FILL_IMAGE_BORDERS_REPLICATE\n");
90  }
91  else
92  {
93  build_opts.emplace("#define FILL_IMAGE_BORDERS_CONSTANT\n");
94  }
95 
96  switch(tensor->info()->data_type())
97  {
98  case DataType::F16:
99  build_opts.emplace("#define DATA_TYPE_FP16");
100  break;
101 
102  case DataType::F32:
103  build_opts.emplace("#define DATA_TYPE_FP32");
104  break;
105 
106  default:
107  ARM_COMPUTE_ERROR("Current data type is not supported");
108  break;
109  }
110 
111  // Create kernel
112  _kernel = static_cast<GCKernel>(GCKernelLibrary::get().create_kernel(kernel_name, build_opts));
113  _tensor = tensor;
114 
115  // Create static kernel arguments
116  const unsigned int valid_width = tensor->info()->valid_region().shape[0];
117  const unsigned int valid_height = tensor->info()->valid_region().shape[1];
118  const unsigned int total_valid_width = border_size.left + valid_width + border_size.right;
119 
120  // Set static kernel arguments
121  unsigned int idx = num_arguments_per_3D_tensor(); //Skip the tensor parameters
122  _kernel.set_argument(idx++, valid_width);
123  _kernel.set_argument(idx++, valid_height);
124  _kernel.set_argument(idx++, tensor->info()->valid_region().anchor[0]);
125  _kernel.set_argument(idx++, tensor->info()->valid_region().anchor[1]);
126 
128  {
129  set_constant_border<float>(idx++, constant_border_value);
130  }
131 
132  // Configure kernel window
133  Window win;
134  win.set(Window::DimX, Window::Dimension(0, total_valid_width + valid_height));
135  win.set(Window::DimY, Window::Dimension(0, 1, 1));
137 
138  IGCKernel::configure(win);
139 }
#define ARM_COMPUTE_ERROR(...)
Print the given message then throw an std::runtime_error.
Definition: Error.h:261
unsigned int top
top of the border
Definition: Types.h:339
TensorShape shape
Shape of the valid region.
Definition: Types.h:247
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.
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:337
Describe one of the image's dimensions with a start, end and step.
Definition: Window.h:75
unsigned int bottom
bottom of the border
Definition: Types.h:341
unsigned int num_arguments_per_3D_tensor() const
Returns the number of arguments enqueued per 3D tensor object.
Definition: IGCKernel.cpp:147
std::string lower_string(const std::string &val)
Lower a given string.
Definition: Utils.cpp:327
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:250
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:228
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
Definition: Window.h:43
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
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:48
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:342
unsigned int right
right of the border
Definition: Types.h:340
#define ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:789
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
Definition: Window.h:45
static GCKernelLibrary & get()
Get the static instance of GCKernelLibrary.
constexpr bool empty() const
Check if the entire border is zero.
Definition: Types.h:286
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
Definition: Window.h:47
Borders are left undefined.
Pixels outside the image are assumed to have the same value as the closest image pixel.
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:331
Coordinates anchor
Anchor for the start of the valid region.
Definition: Types.h:246

References ValidRegion::anchor, ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN, arm_compute::test::validation::border_mode, IKernel::border_size(), BorderSize::bottom, arm_compute::CONSTANT, arm_compute::create_kernel(), ITensorInfo::data_type(), Window::DimX, Window::DimY, Window::DimZ, BorderSize::empty(), arm_compute::F16, arm_compute::F32, GCKernelLibrary::get(), ITensor::info(), BorderSize::left, BorderSize::limit(), arm_compute::lower_string(), IGCKernel::num_arguments_per_3D_tensor(), ITensorInfo::num_channels(), ITensorInfo::padding(), arm_compute::REPLICATE, BorderSize::right, Window::set(), ValidRegion::shape, arm_compute::string_from_border_mode(), ITensorInfo::tensor_shape(), arm_compute::support::cpp11::to_string(), BorderSize::top, arm_compute::UNDEFINED, Window::use_tensor_dimensions(), and ITensorInfo::valid_region().

Referenced by GCPoolingLayer::configure(), GCNormalizationLayer::configure(), GCDepthwiseConvolutionLayer3x3::configure(), GCDirectConvolutionLayer::configure(), and GCConvolutionLayer::configure().

◆ 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 47 of file GCFillBorderKernel.cpp.

48 {
49  return false;
50 }

◆ operator=() [1/2]

GCFillBorderKernel& operator= ( const GCFillBorderKernel )
delete

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

◆ operator=() [2/2]

GCFillBorderKernel& operator= ( GCFillBorderKernel &&  )
default

Allow instances of this class to be moved.

◆ run()

void run ( const Window window)
overridevirtual

Enqueue the OpenGL ES shader to process the given window.

Parameters
[in]windowRegion on which to execute the kernel. (Must be a valid region of the window returned by window()).

Implements IGCKernel.

Definition at line 141 of file GCFillBorderKernel.cpp.

142 {
143  // Border mode undefined or border width == 0
144  if(_kernel.get_program() == 0)
145  {
146  return;
147  }
148 
151 
152  _kernel.use();
154 
155  do
156  {
157  unsigned int idx = 0;
158  add_3D_tensor_argument(idx, _tensor, 1, slice);
159 
160  _kernel.update_shader_params();
161 
162  enqueue(*this, slice);
163  }
165 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
void add_3D_tensor_argument(unsigned int &idx, const IGCTensor *tensor, const unsigned int binding_point, const Window &window)
Add the passed 3D tensor's parameters to the object's kernel's arguments starting from the index idx.
Definition: IGCKernel.cpp:132
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
#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:319
Window first_slice_window_3D() const
First 3D slice of the window.
Definition: Window.h:275
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 IGCKernel::add_3D_tensor_argument(), ARM_COMPUTE_ERROR_ON_MISMATCHING_WINDOWS, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, arm_compute::enqueue(), Window::first_slice_window_3D(), arm_compute::test::validation::reference::slice(), Window::slide_window_slice_3D(), and IKernel::window().

◆ 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 53 of file GCFillBorderKernel.cpp.

54 {
55  T value;
56  constant_border_value.get(value);
57  _kernel.set_argument(idx, static_cast<T>(value));
58 }
void get(uint8_t &v) const
Interpret the pixel value as a U8.
Definition: PixelValue.h:215

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