Compute Library
 19.08
CLGaussianPyramidVertKernel Class Reference

OpenCL kernel to perform a Gaussian filter and half scaling across height (vertical pass) More...

#include <CLGaussianPyramidKernel.h>

Collaboration diagram for CLGaussianPyramidVertKernel:
[legend]

Public Member Functions

 CLGaussianPyramidVertKernel ()
 Default constructor. More...
 
 CLGaussianPyramidVertKernel (const CLGaussianPyramidVertKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
CLGaussianPyramidVertKerneloperator= (const CLGaussianPyramidVertKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 CLGaussianPyramidVertKernel (CLGaussianPyramidVertKernel &&)=default
 Allow instances of this class to be moved. More...
 
CLGaussianPyramidVertKerneloperator= (CLGaussianPyramidVertKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~CLGaussianPyramidVertKernel ()=default
 Default destructor. More...
 
void configure (const ICLTensor *input, ICLTensor *output)
 Initialise the kernel's source, destination 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 ICLSimpleKernel
 ICLSimpleKernel ()
 Constructor. More...
 
 ICLSimpleKernel (const ICLSimpleKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
ICLSimpleKerneloperator= (const ICLSimpleKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 ICLSimpleKernel (ICLSimpleKernel &&)=default
 Allow instances of this class to be moved. More...
 
ICLSimpleKerneloperator= (ICLSimpleKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~ICLSimpleKernel ()=default
 Default destructor. More...
 
void configure (const ICLTensor *input, ICLTensor *output, unsigned int num_elems_processed_per_iteration, bool border_undefined=false, const BorderSize &border_size=BorderSize())
 Configure the 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...
 
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...
 
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

OpenCL kernel to perform a Gaussian filter and half scaling across height (vertical pass)

Definition at line 66 of file CLGaussianPyramidKernel.h.

Constructor & Destructor Documentation

◆ CLGaussianPyramidVertKernel() [1/3]

Default constructor.

Definition at line 140 of file CLGaussianPyramidKernel.cpp.

141  : _t2_load_offset(0)
142 {
143 }

◆ CLGaussianPyramidVertKernel() [2/3]

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

◆ CLGaussianPyramidVertKernel() [3/3]

Allow instances of this class to be moved.

◆ ~CLGaussianPyramidVertKernel()

Default destructor.

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 145 of file CLGaussianPyramidKernel.cpp.

146 {
147  return BorderSize{ 2, 0 };
148 }
Container for 2D border size.
Definition: Types.h:259

Referenced by CLGaussianPyramidVertKernel::configure().

◆ configure()

void configure ( const ICLTensor input,
ICLTensor output 
)

Initialise the kernel's source, destination and border mode.

Parameters
[in]inputSource tensor. Data types supported: U16.
[out]outputDestination tensor. Output should have half the input height. Data types supported: U8.

Definition at line 150 of file CLGaussianPyramidKernel.cpp.

151 {
154  ARM_COMPUTE_ERROR_ON(input->info()->dimension(0) != output->info()->dimension(0));
155 
156  for(size_t i = 2; i < Coordinates::num_max_dimensions; ++i)
157  {
158  ARM_COMPUTE_ERROR_ON(input->info()->dimension(i) != output->info()->dimension(i));
159  }
160 
161  _input = input;
162  _output = output;
163 
164  // Create kernel
165  const std::string kernel_name = std::string("gaussian5x1_sub_y");
166  _kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel("gaussian5x1_sub_y"));
167 
168  // Configure kernel window
169  constexpr unsigned int num_elems_processed_per_iteration = 8;
170  constexpr unsigned int num_rows_processed_per_iteration = 2;
171  constexpr unsigned int num_elems_written_per_iteration = 8;
172  constexpr unsigned int num_elems_read_per_iteration = 8;
173  constexpr unsigned int num_rows_per_iteration = 5;
174 
175  const float scale_y = static_cast<float>(output->info()->dimension(1)) / input->info()->dimension(1);
176 
177  Window win = calculate_max_window(*input->info(), Steps(num_elems_processed_per_iteration, num_rows_processed_per_iteration));
178  AccessWindowRectangle output_access(output->info(), 0, 0, num_elems_written_per_iteration, num_rows_per_iteration, 1.f, scale_y);
179 
180  // Determine whether we need to load even or odd rows. See above for a
181  // detailed explanation.
182  _t2_load_offset = -border_size().top;
183 
184  if((_input->info()->valid_region().anchor[1] + _input->info()->valid_region().shape[1]) % 2 == 0)
185  {
186  _t2_load_offset += 1;
187  }
188 
190  AccessWindowRectangle(input->info(), 0, _t2_load_offset, num_elems_read_per_iteration, num_rows_per_iteration),
191  output_access);
192 
193  output->info()->set_valid_region(ValidRegion(Coordinates(), output->info()->tensor_shape()));
194 
195  ICLKernel::configure_internal(win);
196 
197  // Set config_id for enabling LWS tuning
198  _config_id = kernel_name;
199  _config_id += "_";
200  _config_id += lower_string(string_from_data_type(input->info()->data_type()));
201  _config_id += "_";
202  _config_id += support::cpp11::to_string(input->info()->dimension(0));
203  _config_id += "_";
204  _config_id += support::cpp11::to_string(input->info()->dimension(1));
205  _config_id += "_";
206  _config_id += support::cpp11::to_string(output->info()->dimension(0));
207  _config_id += "_";
208  _config_id += support::cpp11::to_string(output->info()->dimension(1));
209 }
BorderSize border_size() const override
The size of the border for that kernel.
unsigned int top
top of the border
Definition: Types.h:339
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.
1 channel, 1 U16 per channel
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 void set_valid_region(const ValidRegion &valid_region)=0
Set the 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
Coordinates of an item.
Definition: Coordinates.h:37
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
#define ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:789
Container for valid region of a window.
Definition: Types.h:174
static constexpr size_t num_max_dimensions
Number of dimensions the tensor has.
Definition: Dimensions.h:45
Describe a multidimensional execution window.
Definition: Window.h:39

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN, CLGaussianPyramidVertKernel::border_size(), arm_compute::calculate_max_window(), arm_compute::create_kernel(), ITensorInfo::data_type(), ITensorInfo::dimension(), CLKernelLibrary::get(), ITensor::info(), arm_compute::lower_string(), Dimensions< int >::num_max_dimensions, ITensorInfo::set_valid_region(), arm_compute::string_from_data_type(), ITensorInfo::tensor_shape(), arm_compute::support::cpp11::to_string(), BorderSize::top, arm_compute::U16, arm_compute::U8, and arm_compute::update_window_and_padding().

◆ 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.

Implements ICLKernel.

Definition at line 211 of file CLGaussianPyramidKernel.cpp.

212 {
215  ARM_COMPUTE_ERROR_ON(window.x().step() != 8);
217 
218  Window win_in(window);
219  win_in.shift(Window::DimY, _t2_load_offset);
220 
221  Window win_out(window);
222  win_out.scale(Window::DimY, 0.5f);
223 
224  Window slice_in = win_in.first_slice_window_2D();
225  Window slice_out = win_out.first_slice_window_2D();
226 
227  do
228  {
229  unsigned int idx = 0;
230  add_2D_tensor_argument(idx, _input, slice_in);
231  add_2D_tensor_argument(idx, _output, slice_out);
232  enqueue(queue, *this, slice_out, lws_hint());
233  }
234  while(win_in.slide_window_slice_2D(slice_in) && win_out.slide_window_slice_2D(slice_out));
235 }
Window first_slice_window_2D() const
First 2D slice of the window.
Definition: Window.h:267
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
constexpr int step() const
Return the step of the dimension.
Definition: Window.h:102
cl::NDRange lws_hint() const
Return the Local-Workgroup-Size hint.
Definition: ICLKernel.h:247
#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 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
constexpr const Dimension & y() const
Alias to access the second dimension of the window.
Definition: Window.h:152
#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
constexpr const Dimension & x() const
Alias to access the first dimension of the window.
Definition: Window.h:143

References ICLKernel::add_2D_tensor_argument(), ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, Window::DimY, arm_compute::enqueue(), Window::first_slice_window_2D(), ICLKernel::lws_hint(), Window::scale(), Window::slide_window_slice_2D(), Window::Dimension::step(), IKernel::window(), Window::x(), and Window::y().


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