Compute Library
 19.08
CLHOGBlockNormalizationKernel Class Reference

OpenCL kernel to perform HOG block normalization. More...

#include <CLHOGDescriptorKernel.h>

Collaboration diagram for CLHOGBlockNormalizationKernel:
[legend]

Public Member Functions

 CLHOGBlockNormalizationKernel ()
 Default constructor. More...
 
 CLHOGBlockNormalizationKernel (const CLHOGBlockNormalizationKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
CLHOGBlockNormalizationKerneloperator= (const CLHOGBlockNormalizationKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 CLHOGBlockNormalizationKernel (CLHOGBlockNormalizationKernel &&)=default
 Allow instances of this class to be moved. More...
 
CLHOGBlockNormalizationKerneloperator= (CLHOGBlockNormalizationKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~CLHOGBlockNormalizationKernel ()=default
 Default destructor. More...
 
void configure (const ICLTensor *input, ICLTensor *output, const HOGInfo *hog_info)
 Initialise the kernel's input, output and HOG's metadata. 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...
 
- 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...
 
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

OpenCL kernel to perform HOG block normalization.

Definition at line 72 of file CLHOGDescriptorKernel.h.

Constructor & Destructor Documentation

◆ CLHOGBlockNormalizationKernel() [1/3]

Default constructor.

Definition at line 134 of file CLHOGDescriptorKernel.cpp.

135  : _input(nullptr), _output(nullptr), _num_cells_per_block_stride()
136 {
137 }

◆ CLHOGBlockNormalizationKernel() [2/3]

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

◆ CLHOGBlockNormalizationKernel() [3/3]

Allow instances of this class to be moved.

◆ ~CLHOGBlockNormalizationKernel()

Default destructor.

Member Function Documentation

◆ configure()

void configure ( const ICLTensor input,
ICLTensor output,
const HOGInfo hog_info 
)

Initialise the kernel's input, output and HOG's metadata.

Parameters
[in]inputInput tensor which stores the local HOG for each cell. Data type supported: F32. Number of channels supported: equal to the number of histogram bins per cell
[out]outputOutput tensor which stores the normalised blocks. Data type supported: F32. Number of channels supported: equal to the number of histogram bins per block
[in]hog_infoHOG's metadata

Definition at line 139 of file CLHOGDescriptorKernel.cpp.

140 {
141  ARM_COMPUTE_ERROR_ON(hog_info == nullptr);
144 
145  // Number of cells per block
146  const Size2D num_cells_per_block(hog_info->block_size().width / hog_info->cell_size().width,
147  hog_info->block_size().height / hog_info->cell_size().height);
148 
149  ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(output, hog_info->num_bins() * num_cells_per_block.area(), DataType::F32);
150 
151  // Number of cells per block stride
152  const Size2D num_cells_per_block_stride(hog_info->block_stride().width / hog_info->cell_size().width,
153  hog_info->block_stride().height / hog_info->cell_size().height);
154 
155  _input = input;
156  _output = output;
157  _num_cells_per_block_stride = num_cells_per_block_stride;
158 
159  std::stringstream args_str;
160  args_str << "-DL2_HYST_THRESHOLD=" << hog_info->l2_hyst_threshold() << " ";
161  args_str << "-DNUM_CELLS_PER_BLOCK_HEIGHT=" << num_cells_per_block.height << " ";
162  args_str << "-DNUM_BINS_PER_BLOCK_X=" << num_cells_per_block.width *hog_info->num_bins() << " ";
163  args_str << "-DNUM_BINS_PER_BLOCK=" << _output->info()->num_channels() << " ";
164  args_str << "-DL2_NORM=" << static_cast<int>(HOGNormType::L2_NORM) << " ";
165  args_str << "-DL1_NORM=" << static_cast<int>(HOGNormType::L1_NORM) << " ";
166  args_str << "-DL2HYS_NORM=" << static_cast<int>(HOGNormType::L2HYS_NORM) << " ";
167  args_str << "-DHOG_NORM_TYPE=" << static_cast<int>(hog_info->normalization_type()) << " ";
168 
169  // Construct kernel name
170  std::set<std::string> build_opts = {};
171  build_opts.insert(args_str.str());
172 
173  const std::string kernel_name = std::string("hog_block_normalization");
174  _kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel(kernel_name, build_opts));
175 
176  constexpr unsigned int num_elems_processed_per_iteration = 1;
177  constexpr unsigned int num_elems_read_per_iteration = 1;
178  const unsigned int num_rows_read_per_iteration = num_cells_per_block.height;
179  constexpr unsigned int num_elems_written_per_iteration = 1;
180  const unsigned int num_rows_written_per_iteration = num_cells_per_block.height;
181 
182  // Configure kernel window
183  Window win = calculate_max_window(*output->info(), Steps(num_elems_processed_per_iteration));
184  AccessWindowRectangle output_access(output->info(), 0, 0, num_elems_written_per_iteration, num_rows_written_per_iteration);
185 
187  AccessWindowRectangle(input->info(), 0, 0, num_elems_read_per_iteration, num_rows_read_per_iteration),
188  output_access);
189 
190  output_access.set_valid_region(win, ValidRegion(Coordinates(), output->info()->tensor_shape()));
191 
192  ICLKernel::configure_internal(win);
193 
194  // Set config_id for enabling LWS tuning
195  _config_id = kernel_name;
196  _config_id += "_";
197  _config_id += lower_string(string_from_data_type(input->info()->data_type()));
198  _config_id += "_";
199  _config_id += support::cpp11::to_string(input->info()->dimension(0));
200  _config_id += "_";
201  _config_id += support::cpp11::to_string(input->info()->dimension(1));
202  _config_id += "_";
203  _config_id += support::cpp11::to_string(output->info()->dimension(0));
204  _config_id += "_";
205  _config_id += support::cpp11::to_string(output->info()->dimension(1));
206 }
L2-norm followed by clipping.
size_t num_bins() const
The number of histogram bins for each cell.
Definition: HOGInfo.cpp:111
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
const Size2D & cell_size() const
The cell size in pixels.
Definition: HOGInfo.cpp:91
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
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
std::string lower_string(const std::string &val)
Lower a given string.
Definition: Utils.cpp:327
const Size2D & block_stride() const
The block stride in pixels.
Definition: HOGInfo.cpp:106
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
HOGNormType normalization_type() const
The normalization type.
Definition: HOGInfo.cpp:116
size_t height
Height of the image region or rectangle.
Definition: Size2D.h:93
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
const Size2D & block_size() const
The block size in pixels.
Definition: HOGInfo.cpp:96
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.
float l2_hyst_threshold() const
Threshold used for L2HYS_NORM normalization type.
Definition: HOGInfo.cpp:121
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
size_t width
Width of the image region or rectangle.
Definition: Size2D.h:92
Class for specifying the size of an image or rectangle.
Definition: Size2D.h:34
Container for valid region of a window.
Definition: Types.h:174
Describe a multidimensional execution window.
Definition: Window.h:39
virtual size_t num_channels() const =0
The number of channels for each tensor element.
#define ARM_COMPUTE_ERROR_ON_DATA_TYPE_NOT_IN(t,...)
Definition: Validate.h:691

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN, ARM_COMPUTE_ERROR_ON_DATA_TYPE_NOT_IN, HOGInfo::block_size(), HOGInfo::block_stride(), arm_compute::calculate_max_window(), HOGInfo::cell_size(), arm_compute::create_kernel(), ITensorInfo::data_type(), ITensorInfo::dimension(), arm_compute::F32, CLKernelLibrary::get(), Size2D::height, ITensor::info(), arm_compute::L1_NORM, HOGInfo::l2_hyst_threshold(), arm_compute::L2_NORM, arm_compute::L2HYS_NORM, arm_compute::lower_string(), HOGInfo::normalization_type(), HOGInfo::num_bins(), ITensorInfo::num_channels(), arm_compute::string_from_data_type(), ITensorInfo::tensor_shape(), arm_compute::support::cpp11::to_string(), arm_compute::update_window_and_padding(), and Size2D::width.

Referenced by CLHOGDescriptor::configure().

◆ 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 208 of file CLHOGDescriptorKernel.cpp.

209 {
212 
214  do
215  {
216  // Compute slice for the magnitude and phase tensors
217  Window slice_in = window.first_slice_window_2D();
218  slice_in.set_dimension_step(Window::DimX, _num_cells_per_block_stride.width);
219  slice_in.set_dimension_step(Window::DimY, _num_cells_per_block_stride.height);
220 
221  unsigned int idx = 0;
222  add_2D_tensor_argument(idx, _input, slice_in);
223  add_2D_tensor_argument(idx, _output, slice);
224 
225  enqueue(queue, *this, slice, lws_hint());
226  }
228 }
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
cl::NDRange lws_hint() const
Return the Local-Workgroup-Size hint.
Definition: ICLKernel.h:247
bool slide_window_slice_2D(Window &slice) const
Slide the passed 2D window slice.
Definition: Window.h:307
size_t height
Height of the image region or rectangle.
Definition: Size2D.h:93
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
Definition: Window.h:43
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
Definition: Window.h:45
void set_dimension_step(size_t dimension, int step)
Set the step of a given dimension.
Definition: Window.inl:153
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
size_t width
Width of the image region or rectangle.
Definition: Size2D.h:92
#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
SimpleTensor< T > slice(const SimpleTensor< T > &src, Coordinates starts, Coordinates ends)

References ICLKernel::add_2D_tensor_argument(), ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, Window::DimX, Window::DimY, arm_compute::enqueue(), Window::first_slice_window_2D(), Size2D::height, ICLKernel::lws_hint(), Window::set_dimension_step(), arm_compute::test::validation::reference::slice(), Window::slide_window_slice_2D(), Size2D::width, and IKernel::window().


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