Compute Library
 21.02
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 configure (const CLCompileContext &compile_context, 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...
 
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...
 
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 81 of file CLHOGDescriptorKernel.h.

Constructor & Destructor Documentation

◆ CLHOGBlockNormalizationKernel() [1/3]

Default constructor.

Definition at line 138 of file CLHOGDescriptorKernel.cpp.

139  : _input(nullptr), _output(nullptr), _num_cells_per_block_stride()
140 {
141 }

◆ 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() [1/2]

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

References CLKernelLibrary::get().

144 {
145  configure(CLKernelLibrary::get().get_compile_context(), input, output, hog_info);
146 }
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
void configure(const ICLTensor *input, ICLTensor *output, const HOGInfo *hog_info)
Initialise the kernel&#39;s input, output and HOG&#39;s metadata.

◆ configure() [2/2]

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

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

Parameters
[in]compile_contextThe compile context to be used.
[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 148 of file CLHOGDescriptorKernel.cpp.

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, Size2D::height, ITensor::info(), arm_compute::test::validation::input, kernel_name, 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(), num_elems_processed_per_iteration, arm_compute::string_from_data_type(), ITensorInfo::tensor_shape(), arm_compute::support::cpp11::to_string(), arm_compute::update_window_and_padding(), and Size2D::width.

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

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

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

218 {
221 
223  do
224  {
225  // Compute slice for the magnitude and phase tensors
226  Window slice_in = window.first_slice_window_2D();
227  slice_in.set_dimension_step(Window::DimX, _num_cells_per_block_stride.width);
228  slice_in.set_dimension_step(Window::DimY, _num_cells_per_block_stride.height);
229 
230  unsigned int idx = 0;
231  add_2D_tensor_argument(idx, _input, slice_in);
232  add_2D_tensor_argument(idx, _output, slice);
233 
234  enqueue(queue, *this, slice, lws_hint());
235  }
236  while(window.slide_window_slice_2D(slice));
237 }
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
cl::NDRange lws_hint() const
Return the Local-Workgroup-Size hint.
Definition: ICLKernel.h:276
bool slide_window_slice_2D(Window &slice) const
Slide the passed 2D window slice.
Definition: Window.h:323
size_t height
Height of the image region or rectangle.
Definition: Size2D.h:90
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
Definition: Window.h:43
#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 set_dimension_step(size_t dimension, int step)
Set the step of a given dimension.
Definition: Window.inl:167
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
size_t width
Width of the image region or rectangle.
Definition: Size2D.h:89
Describe a multidimensional execution window.
Definition: Window.h:39
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205
SimpleTensor< T > slice(const SimpleTensor< T > &src, Coordinates starts, Coordinates ends)

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