Compute Library
 21.02
NEHOGBlockNormalizationKernel Class Reference

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

#include <NEHOGDescriptorKernel.h>

Collaboration diagram for NEHOGBlockNormalizationKernel:
[legend]

Public Member Functions

const char * name () const override
 Name of the kernel. More...
 
 NEHOGBlockNormalizationKernel ()
 Default constructor. More...
 
 NEHOGBlockNormalizationKernel (const NEHOGBlockNormalizationKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NEHOGBlockNormalizationKerneloperator= (const NEHOGBlockNormalizationKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NEHOGBlockNormalizationKernel (NEHOGBlockNormalizationKernel &&)=default
 Allow instances of this class to be moved. More...
 
NEHOGBlockNormalizationKerneloperator= (NEHOGBlockNormalizationKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~NEHOGBlockNormalizationKernel ()=default
 Default destructor. More...
 
void configure (const ITensor *input, ITensor *output, const HOGInfo *hog_info)
 Initialise the kernel's input, output and HOG's metadata. More...
 
void run (const Window &window, const ThreadInfo &info) override
 Execute the kernel on the passed window. More...
 
- Public Member Functions inherited from ICPPKernel
virtual ~ICPPKernel ()=default
 Default destructor. More...
 
virtual void run_nd (const Window &window, const ThreadInfo &info, const Window &thread_locator)
 legacy compatibility layer for implemantions which do not support thread_locator In these cases we simply narrow the interface down the legacy version More...
 
virtual void run_op (ITensorPack &tensors, const Window &window, const ThreadInfo &info)
 Execute the kernel on the passed window. 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...
 

Detailed Description

Neon kernel to perform HOG block normalization.

Definition at line 95 of file NEHOGDescriptorKernel.h.

Constructor & Destructor Documentation

◆ NEHOGBlockNormalizationKernel() [1/3]

Default constructor.

Definition at line 711 of file NEHOGDescriptorKernel.cpp.

712  : _func(nullptr), _input(nullptr), _output(nullptr), _num_cells_per_block(), _num_cells_per_block_stride(), _num_bins(0), _l2_hyst_threshold(0.0f)
713 {
714 }

◆ NEHOGBlockNormalizationKernel() [2/3]

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

◆ NEHOGBlockNormalizationKernel() [3/3]

Allow instances of this class to be moved.

◆ ~NEHOGBlockNormalizationKernel()

Default destructor.

Member Function Documentation

◆ configure()

void configure ( const ITensor input,
ITensor 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 716 of file NEHOGDescriptorKernel.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::F32, Size2D::height, ITensor::info(), arm_compute::test::validation::input, arm_compute::L1_NORM, HOGInfo::l2_hyst_threshold(), arm_compute::L2_NORM, arm_compute::L2HYS_NORM, HOGInfo::normalization_type(), HOGInfo::num_bins(), ITensorInfo::num_channels(), num_elems_processed_per_iteration, ITensorInfo::tensor_shape(), arm_compute::update_window_and_padding(), and Size2D::width.

717 {
718  ARM_COMPUTE_ERROR_ON(hog_info == nullptr);
721 
722  // Number of cells per block
723  const Size2D num_cells_per_block(hog_info->block_size().width / hog_info->cell_size().width,
724  hog_info->block_size().height / hog_info->cell_size().height);
725 
726  // Number of cells per block stride
727  const Size2D num_cells_per_block_stride(hog_info->block_stride().width / hog_info->cell_size().width,
728  hog_info->block_stride().height / hog_info->cell_size().height);
729 
730  _input = input;
731  _output = output;
732  _l2_hyst_threshold = hog_info->l2_hyst_threshold();
733  _num_cells_per_block = num_cells_per_block;
734  _num_cells_per_block_stride = num_cells_per_block_stride;
735  _num_bins = hog_info->num_bins();
736 
737  ARM_COMPUTE_ERROR_ON((output->info()->num_channels() != (_num_bins * num_cells_per_block.width * num_cells_per_block.height)));
738 
739  switch(hog_info->normalization_type())
740  {
742  _func = &l2_norm;
743  break;
745  _func = &l2hys_norm;
746  break;
748  _func = &l1_norm;
749  break;
750  default:
751  ARM_COMPUTE_ERROR_ON("Normalisation type not supported");
752  break;
753  }
754 
755  constexpr unsigned int num_elems_processed_per_iteration = 1;
756  const unsigned int num_elems_read_per_iteration = 1;
757  const unsigned int num_rows_read_per_iteration = _num_cells_per_block.height;
758  const unsigned int num_elems_written_per_iteration = 1;
759  const unsigned int num_rows_written_per_iteration = _num_cells_per_block.height;
760 
761  // Configure kernel window
762  Window win = calculate_max_window(*output->info(), Steps(num_elems_processed_per_iteration));
763  AccessWindowRectangle output_access(output->info(), 0, 0, num_elems_written_per_iteration, num_rows_written_per_iteration);
764 
766  AccessWindowRectangle(input->info(), 0, 0, num_elems_read_per_iteration, num_rows_read_per_iteration),
767  output_access);
768 
769  output_access.set_valid_region(win, ValidRegion(Coordinates(), output->info()->tensor_shape()));
770 
771  INEKernel::configure(win);
772 }
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)
const Size2D & cell_size() const
The cell size in pixels.
Definition: HOGInfo.cpp:91
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
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.
#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
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.

◆ name()

const char* name ( ) const
inlineoverridevirtual

◆ 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,
const ThreadInfo info 
)
overridevirtual

Execute the kernel on the passed window.

Warning
If is_parallelisable() returns false then the passed window must be equal to window()
Note
The window has to be a region within the window returned by the window() method
The width of the window has to be a multiple of num_elems_processed_per_iteration().
Parameters
[in]windowRegion on which to execute the kernel. (Must be a region of the window returned by window())
[in]infoInfo about executing thread and CPU.

Reimplemented from ICPPKernel.

Definition at line 774 of file NEHOGDescriptorKernel.cpp.

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, arm_compute::data_size_from_type(), ITensorInfo::data_type(), Window::DimX, Window::DimY, arm_compute::execute_window_loop(), Size2D::height, ITensor::info(), ITensorInfo::num_channels(), Iterator::ptr(), ITensorInfo::strides_in_bytes(), Size2D::width, and IKernel::window().

775 {
776  ARM_COMPUTE_UNUSED(info);
778  ARM_COMPUTE_ERROR_ON(_func == nullptr);
780 
781  // Get number of bins per block
782  const size_t num_bins_per_block = _output->info()->num_channels();
783 
784  // Number of bins on the same row of the block
785  const int32_t num_bins_per_block_x = _num_cells_per_block.width * _num_bins;
786 
787  const size_t input_stride = _input->info()->strides_in_bytes()[Window::DimY] / data_size_from_type(_input->info()->data_type());
788 
789  Window win_in(window);
790  win_in.set_dimension_step(Window::DimX, _num_cells_per_block_stride.width);
791  win_in.set(Window::DimY, Window::Dimension(0, 0, 0));
792 
793  Iterator in(_input, win_in);
794  Iterator out(_output, window);
795 
796  // Normalises blocks
797  execute_window_loop(window, [&](const Coordinates & id)
798  {
799  const auto input_row_ptr = reinterpret_cast<const float *>(in.ptr() + id.y() * _num_cells_per_block_stride.height * _input->info()->strides_in_bytes()[Window::DimY]);
800  const auto out_row_ptr = reinterpret_cast<float *>(out.ptr());
801 
802  // Execute normalization function
803  (*_func)(input_row_ptr, out_row_ptr, input_stride, _num_cells_per_block.height, num_bins_per_block_x, num_bins_per_block, _l2_hyst_threshold);
804  },
805  in, out);
806 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
virtual DataType data_type() const =0
Data type used for each element of the tensor.
#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
Describe one of the image&#39;s dimensions with a start, end and step.
Definition: Window.h:77
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_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
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&#39;s metadata.
size_t data_size_from_type(DataType data_type)
The size in bytes of the data type.
Definition: Utils.h:106
#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
size_t width
Width of the image region or rectangle.
Definition: Size2D.h:89
void execute_window_loop(const Window &w, L &&lambda_function, Ts &&... iterators)
Iterate through the passed window, automatically adjusting the iterators and calling the lambda_funct...
Definition: Helpers.inl:77
virtual const Strides & strides_in_bytes() const =0
The strides in bytes for accessing each dimension of the tensor.
Iterator updated by execute_window_loop for each window element.
Definition: Helpers.h:46
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_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205

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