Compute Library
 21.02
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...
 
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...
 
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 45 of file NEGaussianPyramidKernel.cpp.

Referenced by NEGaussianPyramidHorKernel::name().

46  : _l2_load_offset(0)
47 {
48 }

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

Referenced by NEGaussianPyramidHorKernel::name().

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

Referenced by NEGaussianPyramidHorKernel::configure(), NEGaussianPyramidHorKernel::name(), and NEGaussianPyramidVertKernel::name().

51 {
52  return BorderSize{ 0, 2 };
53 }
Container for 2D border size.
Definition: Types.h:273

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

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(), arm_compute::test::validation::input, BorderSize::left, num_elems_processed_per_iteration, Dimensions< int >::num_max_dimensions, arm_compute::S16, arm_compute::test::validation::scale_x, ITensorInfo::set_valid_region(), ITensorInfo::tensor_shape(), arm_compute::U8, and arm_compute::update_window_and_padding().

Referenced by NEGaussianPyramidHorKernel::name(), and NEGaussianPyramidVertKernel::name().

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

◆ name()

◆ operator=() [1/2]

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

Referenced by NEGaussianPyramidHorKernel::name(), and NEGaussianPyramidVertKernel::name().

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

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(), Iterator::ptr(), Window::scale(), Window::shift(), Window::Dimension::step(), IKernel::window(), and Window::x().

Referenced by NEGaussianPyramidHorKernel::name(), and NEGaussianPyramidVertKernel::name().

111 {
112  ARM_COMPUTE_UNUSED(info);
115  ARM_COMPUTE_ERROR_ON(window.x().step() % 2);
116 
117  static const int16x8_t six = vdupq_n_s16(6);
118  static const int16x8_t four = vdupq_n_s16(4);
119 
120  Window win_in(window);
121  win_in.shift(Window::DimX, _l2_load_offset);
122 
123  Iterator in(_input, win_in);
124 
125  // The output is half the width of the input
126  Window win_out(window);
127  win_out.scale(Window::DimX, 0.5f);
128 
129  Iterator out(_output, win_out);
130 
131  execute_window_loop(window, [&](const Coordinates &)
132  {
133  const uint8x16x2_t data_2q = vld2q_u8(in.ptr());
134  const uint8x16_t &data_even = data_2q.val[0];
135  const uint8x16_t &data_odd = data_2q.val[1];
136 
137  const int16x8_t data_l2 = vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(data_even)));
138  const int16x8_t data_l1 = vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(data_odd)));
139  const int16x8_t data_m = vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(vextq_u8(data_even, data_even, 1))));
140  const int16x8_t data_r1 = vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(vextq_u8(data_odd, data_odd, 1))));
141  const int16x8_t data_r2 = vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(vextq_u8(data_even, data_even, 2))));
142 
143  int16x8_t out_val = vaddq_s16(data_l2, data_r2);
144  out_val = vmlaq_s16(out_val, data_l1, four);
145  out_val = vmlaq_s16(out_val, data_m, six);
146  out_val = vmlaq_s16(out_val, data_r1, four);
147 
148  vst1q_s16(reinterpret_cast<int16_t *>(out.ptr()), out_val);
149  },
150  in, out);
151 }
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:104
#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
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
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:941
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
Iterator updated by execute_window_loop for each window element.
Definition: Helpers.h:46
Describe a multidimensional execution window.
Definition: Window.h:39
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205
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: