Compute Library
 21.02
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 configure (const CLCompileContext &compile_context, 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...
 
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

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

Definition at line 73 of file CLGaussianPyramidKernel.h.

Constructor & Destructor Documentation

◆ CLGaussianPyramidVertKernel() [1/3]

Default constructor.

Definition at line 147 of file CLGaussianPyramidKernel.cpp.

148  : _t2_load_offset(0)
149 {
150 }

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

Referenced by CLGaussianPyramidVertKernel::configure().

153 {
154  return BorderSize{ 2, 0 };
155 }
Container for 2D border size.
Definition: Types.h:273

◆ configure() [1/2]

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

References CLKernelLibrary::get().

158 {
159  configure(CLKernelLibrary::get().get_compile_context(), input, output);
160 }
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
void configure(const ICLTensor *input, ICLTensor *output)
Initialise the kernel&#39;s source, destination and border mode.

◆ configure() [2/2]

void configure ( const CLCompileContext compile_context,
const ICLTensor input,
ICLTensor output 
)

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

Parameters
[in]compile_contextThe compile context to be used.
[in]inputSource tensor. Data types supported: U16.
[out]outputDestination tensor. Output should have half the input height. Data types supported: U8.

Definition at line 162 of file CLGaussianPyramidKernel.cpp.

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(), ITensor::info(), arm_compute::test::validation::input, kernel_name, arm_compute::lower_string(), num_elems_processed_per_iteration, Dimensions< int >::num_max_dimensions, arm_compute::test::validation::scale_y, 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().

163 {
166  ARM_COMPUTE_ERROR_ON(input->info()->dimension(0) != output->info()->dimension(0));
167 
168  for(size_t i = 2; i < Coordinates::num_max_dimensions; ++i)
169  {
170  ARM_COMPUTE_ERROR_ON(input->info()->dimension(i) != output->info()->dimension(i));
171  }
172 
173  _input = input;
174  _output = output;
175 
176  // Create kernel
177  const std::string kernel_name = std::string("gaussian5x1_sub_y");
178  _kernel = create_kernel(compile_context, "gaussian5x1_sub_y");
179 
180  // Configure kernel window
181  constexpr unsigned int num_elems_processed_per_iteration = 8;
182  constexpr unsigned int num_rows_processed_per_iteration = 2;
183  constexpr unsigned int num_elems_written_per_iteration = 8;
184  constexpr unsigned int num_elems_read_per_iteration = 8;
185  constexpr unsigned int num_rows_per_iteration = 5;
186 
187  const float scale_y = static_cast<float>(output->info()->dimension(1)) / input->info()->dimension(1);
188 
189  Window win = calculate_max_window(*input->info(), Steps(num_elems_processed_per_iteration, num_rows_processed_per_iteration));
190  AccessWindowRectangle output_access(output->info(), 0, 0, num_elems_written_per_iteration, num_rows_per_iteration, 1.f, scale_y);
191 
192  // Determine whether we need to load even or odd rows. See above for a
193  // detailed explanation.
194  _t2_load_offset = -border_size().top;
195 
196  if((_input->info()->valid_region().anchor[1] + _input->info()->valid_region().shape[1]) % 2 == 0)
197  {
198  _t2_load_offset += 1;
199  }
200 
202  AccessWindowRectangle(input->info(), 0, _t2_load_offset, num_elems_read_per_iteration, num_rows_per_iteration),
203  output_access);
204 
205  output->info()->set_valid_region(ValidRegion(Coordinates(), output->info()->tensor_shape()));
206 
207  ICLKernel::configure_internal(win);
208 
209  // Set config_id for enabling LWS tuning
210  _config_id = kernel_name;
211  _config_id += "_";
212  _config_id += lower_string(string_from_data_type(input->info()->data_type()));
213  _config_id += "_";
214  _config_id += support::cpp11::to_string(input->info()->dimension(0));
215  _config_id += "_";
216  _config_id += support::cpp11::to_string(input->info()->dimension(1));
217  _config_id += "_";
218  _config_id += support::cpp11::to_string(output->info()->dimension(0));
219  _config_id += "_";
220  _config_id += support::cpp11::to_string(output->info()->dimension(1));
221 }
BorderSize border_size() const override
The size of the border for that kernel.
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)
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:466
1 channel, 1 U16 per channel
std::string lower_string(const std::string &val)
Lower a given string.
Definition: Utils.cpp:350
virtual void set_valid_region(const ValidRegion &valid_region)=0
Set the valid region of the tensor.
Implementation of a rectangular access pattern.
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
const std::string & string_from_data_type(DataType dt)
Convert a data type identity into a string.
Definition: Utils.cpp:135
bool update_window_and_padding(Window &win, Ts &&... patterns)
Update window and padding size for each of the access patterns.
Definition: WindowHelpers.h:46
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
std::string kernel_name
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor&#39;s metadata.
#define ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:790
unsigned int num_elems_processed_per_iteration
Container for valid region of a window.
Definition: Types.h:188
static constexpr size_t num_max_dimensions
Number of dimensions the tensor has.
Definition: Dimensions.h:46
Describe a multidimensional execution window.
Definition: Window.h:39

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

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().

224 {
227  ARM_COMPUTE_ERROR_ON(window.x().step() != 8);
228  ARM_COMPUTE_ERROR_ON(window.y().step() % 2);
229 
230  Window win_in(window);
231  win_in.shift(Window::DimY, _t2_load_offset);
232 
233  Window win_out(window);
234  win_out.scale(Window::DimY, 0.5f);
235 
236  Window slice_in = win_in.first_slice_window_2D();
237  Window slice_out = win_out.first_slice_window_2D();
238 
239  do
240  {
241  unsigned int idx = 0;
242  add_2D_tensor_argument(idx, _input, slice_in);
243  add_2D_tensor_argument(idx, _output, slice_out);
244  enqueue(queue, *this, slice_out, lws_hint());
245  }
246  while(win_in.slide_window_slice_2D(slice_in) && win_out.slide_window_slice_2D(slice_out));
247 }
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
constexpr int step() const
Return the step of the dimension.
Definition: Window.h:104
cl::NDRange lws_hint() const
Return the Local-Workgroup-Size hint.
Definition: ICLKernel.h:276
#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
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:941
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&#39;s parameters to the object&#39;s kernel&#39;s arguments starting from the index idx...
Definition: ICLKernel.h:148
constexpr const Dimension & y() const
Alias to access the second dimension of the window.
Definition: Window.h:154
Describe a multidimensional execution window.
Definition: Window.h:39
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205
constexpr const Dimension & x() const
Alias to access the first dimension of the window.
Definition: Window.h:145

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