Compute Library
 19.08
CLHOGOrientationBinningKernel Class Reference

OpenCL kernel to perform HOG Orientation Binning. More...

#include <CLHOGDescriptorKernel.h>

Collaboration diagram for CLHOGOrientationBinningKernel:
[legend]

Public Member Functions

 CLHOGOrientationBinningKernel ()
 Default constructor. More...
 
 CLHOGOrientationBinningKernel (const CLHOGOrientationBinningKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
CLHOGOrientationBinningKerneloperator= (const CLHOGOrientationBinningKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 CLHOGOrientationBinningKernel (CLHOGOrientationBinningKernel &&)=default
 Allow instances of this class to be moved. More...
 
CLHOGOrientationBinningKerneloperator= (CLHOGOrientationBinningKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~CLHOGOrientationBinningKernel ()=default
 Default destructor. More...
 
void configure (const ICLTensor *input_magnitude, const ICLTensor *input_phase, ICLTensor *output, const HOGInfo *hog_info)
 Initialise the kernel's inputs, 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 Orientation Binning.

Definition at line 36 of file CLHOGDescriptorKernel.h.

Constructor & Destructor Documentation

◆ CLHOGOrientationBinningKernel() [1/3]

Default constructor.

Definition at line 43 of file CLHOGDescriptorKernel.cpp.

44  : _input_magnitude(nullptr), _input_phase(nullptr), _output(nullptr), _cell_size()
45 {
46 }

◆ CLHOGOrientationBinningKernel() [2/3]

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

◆ CLHOGOrientationBinningKernel() [3/3]

Allow instances of this class to be moved.

◆ ~CLHOGOrientationBinningKernel()

Default destructor.

Member Function Documentation

◆ configure()

void configure ( const ICLTensor input_magnitude,
const ICLTensor input_phase,
ICLTensor output,
const HOGInfo hog_info 
)

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

Parameters
[in]input_magnitudeInput tensor which stores the magnitude of the gradient for each pixel. Data type supported: S16.
[in]input_phaseInput tensor which stores the phase of the gradient for each pixel. Data type supported: U8
[out]outputOutput tensor which stores the local HOG for each cell. DataType supported: F32. Number of channels supported: equal to the number of histogram bins per cell
[in]hog_infoHOG's metadata

Definition at line 48 of file CLHOGDescriptorKernel.cpp.

49 {
52  ARM_COMPUTE_ERROR_ON(hog_info == nullptr);
54  ARM_COMPUTE_ERROR_ON(input_magnitude->info()->dimension(Window::DimX) != input_phase->info()->dimension(Window::DimX));
55  ARM_COMPUTE_ERROR_ON(input_magnitude->info()->dimension(Window::DimY) != input_phase->info()->dimension(Window::DimY));
56 
57  _input_magnitude = input_magnitude;
58  _input_phase = input_phase;
59  _output = output;
60  _cell_size = hog_info->cell_size();
61 
62  float phase_scale = (PhaseType::SIGNED == hog_info->phase_type() ? hog_info->num_bins() / 360.0f : hog_info->num_bins() / 180.0f);
63  phase_scale *= (PhaseType::SIGNED == hog_info->phase_type() ? 360.0f / 255.0f : 1.0f);
64 
65  std::stringstream args_str;
66  args_str << "-DCELL_WIDTH=" << hog_info->cell_size().width << " ";
67  args_str << "-DCELL_HEIGHT=" << hog_info->cell_size().height << " ";
68  args_str << "-DNUM_BINS=" << hog_info->num_bins() << " ";
69  args_str << "-DPHASE_SCALE=" << phase_scale << " ";
70 
71  // Construct kernel name
72  std::set<std::string> build_opts = {};
73  build_opts.insert(args_str.str());
74 
75  // Create kernel
76  const std::string kernel_name = std::string("hog_orientation_binning");
77  _kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel(kernel_name, build_opts));
78 
79  constexpr unsigned int num_elems_processed_per_iteration = 1;
80  constexpr unsigned int num_elems_read_per_iteration = 1;
81  const unsigned int num_rows_read_per_iteration = hog_info->cell_size().height;
82  constexpr unsigned int num_elems_written_per_iteration = 1;
83 
84  // Configure kernel window
85  Window win = calculate_max_window(*output->info(), Steps(num_elems_processed_per_iteration));
86  AccessWindowHorizontal output_access(output->info(), 0, num_elems_written_per_iteration);
87 
89  AccessWindowRectangle(input_magnitude->info(), 0, 0, num_elems_read_per_iteration, num_rows_read_per_iteration),
90  AccessWindowRectangle(input_phase->info(), 0, 0, num_elems_read_per_iteration, num_rows_read_per_iteration),
91  output_access);
92 
93  output->info()->set_valid_region(ValidRegion(Coordinates(), output->info()->tensor_shape()));
94 
95  ICLKernel::configure_internal(win);
96 
97  // Set config_id for enabling LWS tuning
98  _config_id = kernel_name;
99  _config_id += "_";
100  _config_id += lower_string(string_from_data_type(input_magnitude->info()->data_type()));
101  _config_id += "_";
102  _config_id += support::cpp11::to_string(input_magnitude->info()->dimension(0));
103  _config_id += "_";
104  _config_id += support::cpp11::to_string(input_magnitude->info()->dimension(1));
105  _config_id += "_";
106  _config_id += support::cpp11::to_string(output->info()->dimension(0));
107  _config_id += "_";
108  _config_id += support::cpp11::to_string(output->info()->dimension(1));
109 }
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
Angle range: [0, 360].
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.
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
PhaseType phase_type() const
The type of PhaseType.
Definition: HOGInfo.cpp:126
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.
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
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
Definition: Window.h:43
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
Implementation of a row access pattern.
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
1 channel, 1 S16 per channel
#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
size_t width
Width of the image region or rectangle.
Definition: Size2D.h:92
Container for valid region of a window.
Definition: Types.h:174
Describe a multidimensional execution window.
Definition: Window.h:39

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN, arm_compute::calculate_max_window(), HOGInfo::cell_size(), arm_compute::create_kernel(), ITensorInfo::data_type(), ITensorInfo::dimension(), Window::DimX, Window::DimY, arm_compute::F32, CLKernelLibrary::get(), Size2D::height, ITensor::info(), arm_compute::lower_string(), HOGInfo::num_bins(), HOGInfo::phase_type(), arm_compute::S16, ITensorInfo::set_valid_region(), arm_compute::SIGNED, arm_compute::string_from_data_type(), ITensorInfo::tensor_shape(), arm_compute::support::cpp11::to_string(), arm_compute::U8, 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 111 of file CLHOGDescriptorKernel.cpp.

112 {
115 
117  do
118  {
119  // Compute slice for the magnitude and phase tensors
120  Window slice_mag_phase = window.first_slice_window_2D();
121  slice_mag_phase.set(Window::DimX, Window::Dimension(window.x().start() * _cell_size.width, window.x().start() * _cell_size.width, _cell_size.width));
122  slice_mag_phase.set(Window::DimY, Window::Dimension(window.y().start() * _cell_size.height, window.y().start() * _cell_size.height, _cell_size.height));
123 
124  unsigned int idx = 0;
125  add_2D_tensor_argument(idx, _input_magnitude, slice_mag_phase);
126  add_2D_tensor_argument(idx, _input_phase, slice_mag_phase);
127  add_2D_tensor_argument(idx, _output, slice);
128 
129  enqueue(queue, *this, slice, lws_hint());
130  }
132 }
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
Describe one of the image's dimensions with a start, end and step.
Definition: Window.h:75
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
void set(size_t dimension, const Dimension &dim)
Set the values of a given dimension.
Definition: Window.inl:48
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
size_t width
Width of the image region or rectangle.
Definition: Size2D.h:92
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
constexpr int start() const
Return the start of the dimension.
Definition: Window.h:92
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)
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_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(), arm_compute::test::validation::reference::slice(), Window::slide_window_slice_2D(), Window::Dimension::start(), Size2D::width, IKernel::window(), Window::x(), and Window::y().


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