Compute Library
 19.08
NEGaussianPyramidHorKernel Class Reference

NEON kernel to perform a GaussianPyramid (horizontal pass) More...

#include <NEGaussianPyramidKernel.h>

Collaboration diagram for NEGaussianPyramidHorKernel:
[legend]

Public Member Functions

const char * name () const override
 Name of the kernel. More...
 
 NEGaussianPyramidHorKernel ()
 Default constructor. More...
 
 NEGaussianPyramidHorKernel (NEGaussianPyramidHorKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NEGaussianPyramidHorKerneloperator= (NEGaussianPyramidHorKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NEGaussianPyramidHorKernel (NEGaussianPyramidHorKernel &&)=default
 Allow instances of this class to be moved. More...
 
NEGaussianPyramidHorKerneloperator= (NEGaussianPyramidHorKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~NEGaussianPyramidHorKernel ()=default
 Default destructor. More...
 
void configure (const ITensor *input, ITensor *output)
 Initialise the kernel's source, destination and border mode. More...
 
void run (const Window &window, const ThreadInfo &info) override
 Execute the kernel on the passed window. More...
 
BorderSize border_size () const override
 The size of the border for that kernel. More...
 
- Public Member Functions inherited from ICPPSimpleKernel
 ICPPSimpleKernel ()
 Constructor. More...
 
 ICPPSimpleKernel (const ICPPSimpleKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
ICPPSimpleKerneloperator= (const ICPPSimpleKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 ICPPSimpleKernel (ICPPSimpleKernel &&)=default
 Allow instances of this class to be moved. More...
 
ICPPSimpleKerneloperator= (ICPPSimpleKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~ICPPSimpleKernel ()=default
 Default destructor. More...
 
- Public Member Functions inherited from ICPPKernel
virtual ~ICPPKernel ()=default
 Default destructor. 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...
 

Detailed Description

NEON kernel to perform a GaussianPyramid (horizontal pass)

Definition at line 34 of file NEGaussianPyramidKernel.h.

Constructor & Destructor Documentation

◆ NEGaussianPyramidHorKernel() [1/3]

Default constructor.

Definition at line 43 of file NEGaussianPyramidKernel.cpp.

44  : _l2_load_offset(0)
45 {
46 }

◆ NEGaussianPyramidHorKernel() [2/3]

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

◆ NEGaussianPyramidHorKernel() [3/3]

Allow instances of this class to be moved.

◆ ~NEGaussianPyramidHorKernel()

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 48 of file NEGaussianPyramidKernel.cpp.

49 {
50  return BorderSize{ 0, 2 };
51 }
Container for 2D border size.
Definition: Types.h:259

Referenced by NEGaussianPyramidHorKernel::configure().

◆ configure()

void configure ( const ITensor input,
ITensor output 
)

Initialise the kernel's source, destination and border mode.

Parameters
[in]inputSource tensor. Data type supported: U8.
[out]outputDestination tensor. Output should have half the input width. Data type supported: S16.

Definition at line 53 of file NEGaussianPyramidKernel.cpp.

54 {
57  ARM_COMPUTE_ERROR_ON(input->info()->dimension(1) != output->info()->dimension(1));
58 
59  for(size_t i = 2; i < Coordinates::num_max_dimensions; ++i)
60  {
61  ARM_COMPUTE_ERROR_ON(input->info()->dimension(i) != output->info()->dimension(i));
62  }
63 
64  _input = input;
65  _output = output;
66 
67  // Configure kernel window
68  constexpr unsigned int num_elems_processed_per_iteration = 16;
69  constexpr unsigned int num_elems_read_per_iteration = 32;
70  constexpr unsigned int num_elems_written_per_iteration = 8;
71  const float scale_x = static_cast<float>(output->info()->dimension(0)) / input->info()->dimension(0);
72 
73  Window win = calculate_max_window_horizontal(*input->info(), Steps(num_elems_processed_per_iteration));
74  AccessWindowHorizontal output_access(output->info(), 0, num_elems_written_per_iteration, scale_x);
75 
76  // Sub sampling selects odd pixels (1, 3, 5, ...) for images with even
77  // width and even pixels (0, 2, 4, ...) for images with odd width. (Whether
78  // a pixel is even or odd is determined based on the tensor shape not the
79  // valid region!)
80  // Thus the offset from which the first pixel (L2) for the convolution is
81  // loaded depends on the anchor and shape of the valid region.
82  // In the case of an even shape (= even image width) we need to load L2
83  // from -2 if the anchor is odd and from -1 if the anchor is even. That
84  // makes sure that L2 is always loaded from an odd pixel.
85  // On the other hand, for an odd shape (= odd image width) we need to load
86  // L2 from -1 if the anchor is odd and from -2 if the anchor is even to
87  // achieve the opposite effect.
88  // The condition can be simplified to checking whether anchor + shape is
89  // odd (-2) or even (-1) as only adding an odd and an even number will have
90  // an odd result.
91  _l2_load_offset = -border_size().left;
92 
93  if((_input->info()->valid_region().anchor[0] + _input->info()->valid_region().shape[0]) % 2 == 0)
94  {
95  _l2_load_offset += 1;
96  }
97 
98  // Replace input access with static window
100  AccessWindowHorizontal(input->info(), _l2_load_offset, num_elems_read_per_iteration),
101  output_access);
102 
103  output->info()->set_valid_region(ValidRegion(Coordinates(), output->info()->tensor_shape()));
104 
105  INEKernel::configure(win);
106 }
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
1 channel, 1 U8 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
virtual void set_valid_region(const ValidRegion &valid_region)=0
Set the valid region of the tensor.
BorderSize border_size() const override
The size of the border for that kernel.
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.
unsigned int left
left of the border
Definition: Types.h:342
1 channel, 1 S16 per channel
#define ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:789
Container for valid region of a window.
Definition: Types.h:174
static constexpr size_t num_max_dimensions
Number of dimensions the tensor has.
Definition: Dimensions.h:45
Describe a multidimensional execution window.
Definition: Window.h:39
Window calculate_max_window_horizontal(const ValidRegion &valid_region, const Steps &steps=Steps(), bool skip_border=false, BorderSize border_size=BorderSize())
Calculate the maximum window used by a horizontal kernel for a given tensor shape and border setting.
Definition: Helpers.cpp:131

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN, NEGaussianPyramidHorKernel::border_size(), arm_compute::calculate_max_window_horizontal(), ITensorInfo::dimension(), ITensor::info(), BorderSize::left, Dimensions< int >::num_max_dimensions, arm_compute::S16, ITensorInfo::set_valid_region(), ITensorInfo::tensor_shape(), arm_compute::U8, and arm_compute::update_window_and_padding().

◆ name()

const char* name ( ) const
inlineoverridevirtual

Name of the kernel.

Returns
Kernel name

Implements ICPPKernel.

Definition at line 37 of file NEGaussianPyramidKernel.h.

38  {
39  return "NEGaussianPyramidHorKernel";
40  }

◆ 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.

Implements ICPPKernel.

Definition at line 108 of file NEGaussianPyramidKernel.cpp.

109 {
114 
115  static const int16x8_t six = vdupq_n_s16(6);
116  static const int16x8_t four = vdupq_n_s16(4);
117 
118  Window win_in(window);
119  win_in.shift(Window::DimX, _l2_load_offset);
120 
121  Iterator in(_input, win_in);
122 
123  // The output is half the width of the input
124  Window win_out(window);
125  win_out.scale(Window::DimX, 0.5f);
126 
127  Iterator out(_output, win_out);
128 
130  {
131  const uint8x16x2_t data_2q = vld2q_u8(in.ptr());
132  const uint8x16_t &data_even = data_2q.val[0];
133  const uint8x16_t &data_odd = data_2q.val[1];
134 
135  const int16x8_t data_l2 = vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(data_even)));
136  const int16x8_t data_l1 = vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(data_odd)));
137  const int16x8_t data_m = vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(vextq_u8(data_even, data_even, 1))));
138  const int16x8_t data_r1 = vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(vextq_u8(data_odd, data_odd, 1))));
139  const int16x8_t data_r2 = vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(vextq_u8(data_even, data_even, 2))));
140 
141  int16x8_t out_val = vaddq_s16(data_l2, data_r2);
142  out_val = vmlaq_s16(out_val, data_l1, four);
143  out_val = vmlaq_s16(out_val, data_m, six);
144  out_val = vmlaq_s16(out_val, data_r1, four);
145 
146  vst1q_s16(reinterpret_cast<int16_t *>(out.ptr()), out_val);
147  },
148  in, out);
149 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
constexpr int step() const
Return the step of the dimension.
Definition: Window.h:102
#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 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:160
Coordinates of an item.
Definition: Coordinates.h:37
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:122
Iterator updated by execute_window_loop for each window element.
Definition: Helpers.h:318
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205
Describe a multidimensional execution window.
Definition: Window.h:39
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:940
constexpr const Dimension & x() const
Alias to access the first dimension of the window.
Definition: Window.h:143

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, Window::DimX, arm_compute::execute_window_loop(), arm_compute::test::validation::info, Iterator::ptr(), Window::scale(), Window::shift(), Window::Dimension::step(), IKernel::window(), and Window::x().


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