Compute Library
 21.02
CLHarrisScoreKernel Class Reference

Interface for the harris score kernel. More...

#include <CLHarrisCornersKernel.h>

Collaboration diagram for CLHarrisScoreKernel:
[legend]

Public Member Functions

 CLHarrisScoreKernel ()
 Default constructor. More...
 
 CLHarrisScoreKernel (const CLHarrisScoreKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
CLHarrisScoreKerneloperator= (const CLHarrisScoreKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 CLHarrisScoreKernel (CLHarrisScoreKernel &&)=default
 Allow instances of this class to be moved. More...
 
CLHarrisScoreKerneloperator= (CLHarrisScoreKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~CLHarrisScoreKernel ()=default
 Default destructor. More...
 
void configure (const ICLImage *input1, const ICLImage *input2, ICLImage *output, int32_t block_size, float norm_factor, float strength_thresh, float sensitivity, bool border_undefined)
 Setup the kernel parameters. More...
 
void configure (const CLCompileContext &compile_context, const ICLImage *input1, const ICLImage *input2, ICLImage *output, int32_t block_size, float norm_factor, float strength_thresh, float sensitivity, bool border_undefined)
 Setup the kernel parameters. 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 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

Interface for the harris score kernel.

Note
The implementation supports 3, 5, and 7 for the block_size.

Definition at line 40 of file CLHarrisCornersKernel.h.

Constructor & Destructor Documentation

◆ CLHarrisScoreKernel() [1/3]

Default constructor.

Definition at line 44 of file CLHarrisCornersKernel.cpp.

45  : _input1(nullptr), _input2(nullptr), _output(nullptr), _sensitivity(), _strength_thresh(), _norm_factor(), _border_size(0)
46 {
47 }

◆ CLHarrisScoreKernel() [2/3]

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

◆ CLHarrisScoreKernel() [3/3]

Allow instances of this class to be moved.

◆ ~CLHarrisScoreKernel()

~CLHarrisScoreKernel ( )
default

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 49 of file CLHarrisCornersKernel.cpp.

Referenced by CLHarrisScoreKernel::configure().

50 {
51  return _border_size;
52 }

◆ configure() [1/2]

void configure ( const ICLImage input1,
const ICLImage input2,
ICLImage output,
int32_t  block_size,
float  norm_factor,
float  strength_thresh,
float  sensitivity,
bool  border_undefined 
)

Setup the kernel parameters.

Parameters
[in]input1Source image (gradient X). Data types supported S16, S32. (Must be the same as input2)
[in]input2Source image (gradient Y). Data types supported S16, S32. (Must be the same as input1)
[out]outputDestination image (harris score). Data types supported F32
[in]block_sizeThe block window size used to compute the Harris Corner score. Supports: 3, 5 and 7
[in]norm_factorNormalization factor to use accordingly with the gradient size (Must be different from 0)
[in]strength_threshMinimum threshold with which to eliminate Harris Corner scores (computed using the normalized Sobel kernel).
[in]sensitivitySensitivity threshold k from the Harris-Stephens equation.
[in]border_undefinedTrue if the border mode is undefined. False if it's replicate or constant.

Definition at line 54 of file CLHarrisCornersKernel.cpp.

References CLKernelLibrary::get().

57 {
58  configure(CLKernelLibrary::get().get_compile_context(), input1, input2, output, block_size, norm_factor, strength_thresh, sensitivity, border_undefined);
59 }
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
void configure(const ICLImage *input1, const ICLImage *input2, ICLImage *output, int32_t block_size, float norm_factor, float strength_thresh, float sensitivity, bool border_undefined)
Setup the kernel parameters.

◆ configure() [2/2]

void configure ( const CLCompileContext compile_context,
const ICLImage input1,
const ICLImage input2,
ICLImage output,
int32_t  block_size,
float  norm_factor,
float  strength_thresh,
float  sensitivity,
bool  border_undefined 
)

Setup the kernel parameters.

Parameters
[in]compile_contextThe compile context to be used.
[in]input1Source image (gradient X). Data types supported S16, S32. (Must be the same as input2)
[in]input2Source image (gradient Y). Data types supported S16, S32. (Must be the same as input1)
[out]outputDestination image (harris score). Data types supported F32
[in]block_sizeThe block window size used to compute the Harris Corner score. Supports: 3, 5 and 7
[in]norm_factorNormalization factor to use accordingly with the gradient size (Must be different from 0)
[in]strength_threshMinimum threshold with which to eliminate Harris Corner scores (computed using the normalized Sobel kernel).
[in]sensitivitySensitivity threshold k from the Harris-Stephens equation.
[in]border_undefinedTrue if the border mode is undefined. False if it's replicate or constant.

Definition at line 61 of file CLHarrisCornersKernel.cpp.

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN, ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES, ARM_COMPUTE_ERROR_ON_TENSOR_NOT_2D, CLHarrisScoreKernel::border_size(), arm_compute::calculate_max_window(), arm_compute::create_kernel(), ITensorInfo::data_type(), ITensorInfo::dimension(), arm_compute::F32, arm_compute::get_cl_type_from_data_type(), ITensor::info(), arm_compute::intersect_valid_regions(), BorderSize::left, arm_compute::lower_string(), ICLKernel::num_arguments_per_2D_tensor(), num_elems_processed_per_iteration, arm_compute::S16, arm_compute::S32, arm_compute::string_from_data_type(), arm_compute::support::cpp11::to_string(), BorderSize::top, arm_compute::update_window_and_padding(), arm_compute::test::validation::valid_region, and ITensorInfo::valid_region().

64 {
72  ARM_COMPUTE_ERROR_ON(!(block_size == 3 || block_size == 5 || block_size == 7));
73  ARM_COMPUTE_ERROR_ON(0.0f == norm_factor);
74 
75  _input1 = input1;
76  _input2 = input2;
77  _output = output;
78  _sensitivity = sensitivity;
79  _strength_thresh = strength_thresh;
80  _norm_factor = norm_factor;
81  _border_size = BorderSize(block_size / 2);
82 
83  // Select kernel
84  std::stringstream harris_score_kernel_name;
85  harris_score_kernel_name << "harris_score_" << block_size << "x" << block_size;
86 
87  // Create build options
88  std::set<std::string> build_opts = { ("-DDATA_TYPE=" + get_cl_type_from_data_type(input1->info()->data_type())) };
89 
90  // Create kernel
91  _kernel = create_kernel(compile_context, harris_score_kernel_name.str(), build_opts);
92 
93  // Set static kernel arguments
94  unsigned int idx = 3 * num_arguments_per_2D_tensor(); //Skip the input and output parameters
95  _kernel.setArg(idx++, sensitivity);
96  _kernel.setArg(idx++, strength_thresh);
97  _kernel.setArg(idx++, norm_factor);
98 
99  // Configure kernel window
100  constexpr unsigned int num_elems_processed_per_iteration = 4;
101  constexpr unsigned int num_elems_written_per_iteration = 4;
102  const unsigned int num_elems_read_per_iteration = block_size == 7 ? 10 : 8;
103  const unsigned int num_rows_read_per_iteration = block_size;
104 
105  Window win = calculate_max_window(*_input1->info(), Steps(num_elems_processed_per_iteration), border_undefined, border_size());
106 
107  AccessWindowRectangle input1_access(input1->info(), -border_size().left, -border_size().top, num_elems_read_per_iteration, num_rows_read_per_iteration);
108  AccessWindowRectangle input2_access(input2->info(), -border_size().left, -border_size().top, num_elems_read_per_iteration, num_rows_read_per_iteration);
109  AccessWindowHorizontal output_access(output->info(), 0, num_elems_written_per_iteration);
110 
111  update_window_and_padding(win, input1_access, input2_access, output_access);
112 
114  output_access.set_valid_region(win, valid_region, border_undefined, border_size());
115 
116  ICLKernel::configure_internal(win);
117 
118  // Set config_id for enabling LWS tuning
119  _config_id = harris_score_kernel_name.str();
120  _config_id += "_";
121  _config_id += lower_string(string_from_data_type(input1->info()->data_type()));
122  _config_id += "_";
123  _config_id += support::cpp11::to_string(input1->info()->dimension(0));
124  _config_id += "_";
125  _config_id += support::cpp11::to_string(input1->info()->dimension(1));
126  _config_id += "_";
127  _config_id += lower_string(string_from_data_type(input2->info()->data_type()));
128  _config_id += "_";
129  _config_id += support::cpp11::to_string(input2->info()->dimension(0));
130  _config_id += "_";
131  _config_id += support::cpp11::to_string(input2->info()->dimension(1));
132 }
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.
#define ARM_COMPUTE_ERROR_ON_TENSOR_NOT_2D(t)
Definition: Validate.h:856
Container for 2D border size.
Definition: Types.h:273
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 ValidRegion valid_region
Definition: Scale.cpp:221
virtual ValidRegion valid_region() const =0
Valid region of the tensor.
1 channel, 1 S32 per channel
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
#define ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(...)
Definition: Validate.h:543
Class to describe a number of elements in each dimension.
Definition: Steps.h:40
Implementation of a row access pattern.
std::string get_cl_type_from_data_type(const DataType &dt)
Translates a tensor data type to the appropriate OpenCL type.
Definition: CLHelpers.cpp:37
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor&#39;s metadata.
ValidRegion intersect_valid_regions(const Ts &... regions)
Intersect multiple valid regions.
Definition: WindowHelpers.h:74
static constexpr unsigned int num_arguments_per_2D_tensor()
Returns the number of arguments enqueued per 2D tensor object.
Definition: ICLKernel.h:206
unsigned int left
left of the border
Definition: Types.h:378
1 channel, 1 S16 per channel
#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
Describe a multidimensional execution window.
Definition: Window.h:39
BorderSize border_size() const override
The size of the border for that kernel.

◆ operator=() [1/2]

CLHarrisScoreKernel& operator= ( const CLHarrisScoreKernel )
delete

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

◆ operator=() [2/2]

CLHarrisScoreKernel& operator= ( CLHarrisScoreKernel &&  )
default

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 134 of file CLHarrisCornersKernel.cpp.

References ICLKernel::add_2D_tensor_argument(), ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, arm_compute::enqueue(), Window::first_slice_window_2D(), ICLKernel::lws_hint(), arm_compute::test::validation::reference::slice(), Window::slide_window_slice_2D(), and IKernel::window().

135 {
138 
140  do
141  {
142  unsigned int idx = 0;
143  add_2D_tensor_argument(idx, _input1, slice);
144  add_2D_tensor_argument(idx, _input2, slice);
145  add_2D_tensor_argument(idx, _output, slice);
146  enqueue(queue, *this, slice, lws_hint());
147  }
148  while(window.slide_window_slice_2D(slice));
149 }
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
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:941
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
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: