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

Definition at line 36 of file CLHOGDescriptorKernel.h.

Constructor & Destructor Documentation

◆ CLHOGOrientationBinningKernel() [1/3]

Default constructor.

Definition at line 42 of file CLHOGDescriptorKernel.cpp.

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

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

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

References CLKernelLibrary::get().

48 {
49  configure(CLKernelLibrary::get().get_compile_context(), input_magnitude, input_phase, output, hog_info);
50 }
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
void configure(const ICLTensor *input_magnitude, const ICLTensor *input_phase, ICLTensor *output, const HOGInfo *hog_info)
Initialise the kernel&#39;s inputs, output and HOG&#39;s metadata.

◆ configure() [2/2]

void configure ( const CLCompileContext compile_context,
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]compile_contextThe compile context to be used.
[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 52 of file CLHOGDescriptorKernel.cpp.

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, Size2D::height, ITensor::info(), kernel_name, arm_compute::lower_string(), HOGInfo::num_bins(), num_elems_processed_per_iteration, 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.

53 {
56  ARM_COMPUTE_ERROR_ON(hog_info == nullptr);
58  ARM_COMPUTE_ERROR_ON(input_magnitude->info()->dimension(Window::DimX) != input_phase->info()->dimension(Window::DimX));
59  ARM_COMPUTE_ERROR_ON(input_magnitude->info()->dimension(Window::DimY) != input_phase->info()->dimension(Window::DimY));
60 
61  _input_magnitude = input_magnitude;
62  _input_phase = input_phase;
63  _output = output;
64  _cell_size = hog_info->cell_size();
65 
66  float phase_scale = (PhaseType::SIGNED == hog_info->phase_type() ? hog_info->num_bins() / 360.0f : hog_info->num_bins() / 180.0f);
67  phase_scale *= (PhaseType::SIGNED == hog_info->phase_type() ? 360.0f / 255.0f : 1.0f);
68 
69  std::stringstream args_str;
70  args_str << "-DCELL_WIDTH=" << hog_info->cell_size().width << " ";
71  args_str << "-DCELL_HEIGHT=" << hog_info->cell_size().height << " ";
72  args_str << "-DNUM_BINS=" << hog_info->num_bins() << " ";
73  args_str << "-DPHASE_SCALE=" << phase_scale << " ";
74 
75  // Construct kernel name
76  std::set<std::string> build_opts = {};
77  build_opts.insert(args_str.str());
78 
79  // Create kernel
80  const std::string kernel_name = std::string("hog_orientation_binning");
81  _kernel = create_kernel(compile_context, kernel_name, build_opts);
82 
83  constexpr unsigned int num_elems_processed_per_iteration = 1;
84  constexpr unsigned int num_elems_read_per_iteration = 1;
85  const unsigned int num_rows_read_per_iteration = hog_info->cell_size().height;
86  constexpr unsigned int num_elems_written_per_iteration = 1;
87 
88  // Configure kernel window
89  Window win = calculate_max_window(*output->info(), Steps(num_elems_processed_per_iteration));
90  AccessWindowHorizontal output_access(output->info(), 0, num_elems_written_per_iteration);
91 
93  AccessWindowRectangle(input_magnitude->info(), 0, 0, num_elems_read_per_iteration, num_rows_read_per_iteration),
94  AccessWindowRectangle(input_phase->info(), 0, 0, num_elems_read_per_iteration, num_rows_read_per_iteration),
95  output_access);
96 
97  output->info()->set_valid_region(ValidRegion(Coordinates(), output->info()->tensor_shape()));
98 
99  ICLKernel::configure_internal(win);
100 
101  // Set config_id for enabling LWS tuning
102  _config_id = kernel_name;
103  _config_id += "_";
104  _config_id += lower_string(string_from_data_type(input_magnitude->info()->data_type()));
105  _config_id += "_";
106  _config_id += support::cpp11::to_string(input_magnitude->info()->dimension(0));
107  _config_id += "_";
108  _config_id += support::cpp11::to_string(input_magnitude->info()->dimension(1));
109  _config_id += "_";
110  _config_id += support::cpp11::to_string(output->info()->dimension(0));
111  _config_id += "_";
112  _config_id += support::cpp11::to_string(output->info()->dimension(1));
113 }
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
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:466
std::string lower_string(const std::string &val)
Lower a given string.
Definition: Utils.cpp:350
PhaseType phase_type() const
The type of PhaseType.
Definition: HOGInfo.cpp:126
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: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
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: 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
Implementation of a row access pattern.
std::string kernel_name
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor&#39;s metadata.
1 channel, 1 S16 per channel
#define ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:790
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:89
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

◆ 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 115 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(), arm_compute::test::validation::reference::slice(), Window::slide_window_slice_2D(), Window::Dimension::start(), Size2D::width, IKernel::window(), Window::x(), and Window::y().

116 {
119 
121  do
122  {
123  // Compute slice for the magnitude and phase tensors
124  Window slice_mag_phase = window.first_slice_window_2D();
125  slice_mag_phase.set(Window::DimX, Window::Dimension(window.x().start() * _cell_size.width, window.x().start() * _cell_size.width, _cell_size.width));
126  slice_mag_phase.set(Window::DimY, Window::Dimension(window.y().start() * _cell_size.height, window.y().start() * _cell_size.height, _cell_size.height));
127 
128  unsigned int idx = 0;
129  add_2D_tensor_argument(idx, _input_magnitude, slice_mag_phase);
130  add_2D_tensor_argument(idx, _input_phase, slice_mag_phase);
131  add_2D_tensor_argument(idx, _output, slice);
132 
133  enqueue(queue, *this, slice, lws_hint());
134  }
135  while(window.slide_window_slice_2D(slice));
136 }
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
Describe one of the image&#39;s dimensions with a start, end and step.
Definition: Window.h:77
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
void set(size_t dimension, const Dimension &dim)
Set the values of a given dimension.
Definition: Window.inl:49
#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
size_t width
Width of the image region or rectangle.
Definition: Size2D.h:89
constexpr const Dimension & y() const
Alias to access the second dimension of the window.
Definition: Window.h:154
constexpr int start() const
Return the start of the dimension.
Definition: Window.h:94
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)
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: