Compute Library
 21.02
NEGaussian3x3Kernel Class Reference

Neon kernel to perform a Gaussian 3x3 filter. More...

#include <NEGaussian3x3Kernel.h>

Collaboration diagram for NEGaussian3x3Kernel:
[legend]

Public Member Functions

const char * name () const override
 Name of the kernel. More...
 
 NEGaussian3x3Kernel ()=default
 Constructor. More...
 
 NEGaussian3x3Kernel (const NEGaussian3x3Kernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NEGaussian3x3Kerneloperator= (const NEGaussian3x3Kernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NEGaussian3x3Kernel (NEGaussian3x3Kernel &&)=default
 Allow instances of this class to be moved. More...
 
NEGaussian3x3Kerneloperator= (NEGaussian3x3Kernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~NEGaussian3x3Kernel ()=default
 Default destructor. More...
 
void configure (const ITensor *input, ITensor *output, bool border_undefined)
 Set the source, destination and border mode of the kernel. 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 Gaussian 3x3 filter.

Definition at line 34 of file NEGaussian3x3Kernel.h.

Constructor & Destructor Documentation

◆ NEGaussian3x3Kernel() [1/3]

NEGaussian3x3Kernel ( )
default

Constructor.

Referenced by NEGaussian3x3Kernel::name().

◆ NEGaussian3x3Kernel() [2/3]

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

◆ NEGaussian3x3Kernel() [3/3]

Allow instances of this class to be moved.

◆ ~NEGaussian3x3Kernel()

~NEGaussian3x3Kernel ( )
default

Default destructor.

Referenced by NEGaussian3x3Kernel::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 38 of file NEGaussian3x3Kernel.cpp.

Referenced by NEGaussian3x3Kernel::configure(), and NEGaussian3x3Kernel::name().

39 {
40  return BorderSize(1);
41 }
Container for 2D border size.
Definition: Types.h:273

◆ configure()

void configure ( const ITensor input,
ITensor output,
bool  border_undefined 
)

Set the source, destination and border mode of the kernel.

Parameters
[in]inputSource tensor. Data type supported: U8
[out]outputDestination tensor. Data type supported: same as input
[in]border_undefinedTrue if the border mode is undefined. False if it's replicate or constant.

Definition at line 43 of file NEGaussian3x3Kernel.cpp.

References ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN, NEGaussian3x3Kernel::border_size(), arm_compute::calculate_max_window(), ITensor::info(), arm_compute::test::validation::input, BorderSize::left, num_elems_processed_per_iteration, BorderSize::top, arm_compute::U8, arm_compute::update_window_and_padding(), and ITensorInfo::valid_region().

Referenced by NEGaussian3x3Kernel::name().

44 {
47 
48  _input = input;
49  _output = output;
50 
51  // Configure kernel window
52  constexpr unsigned int num_elems_processed_per_iteration = 8;
53  constexpr unsigned int num_elems_read_per_iteration = 16;
54  constexpr unsigned int num_elems_written_per_iteration = 8;
55  constexpr unsigned int num_rows_read_per_iteration = 3;
56 
57  Window win = calculate_max_window(*input->info(), Steps(num_elems_processed_per_iteration), border_undefined, border_size());
58  AccessWindowHorizontal output_access(output->info(), 0, num_elems_written_per_iteration);
59 
61  AccessWindowRectangle(input->info(), -border_size().left, -border_size().top, num_elems_read_per_iteration, num_rows_read_per_iteration),
62  output_access);
63 
64  output_access.set_valid_region(win, input->info()->valid_region(), border_undefined, border_size());
65 
66  INEKernel::configure(win);
67 }
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)
1 channel, 1 U8 per channel
virtual ValidRegion valid_region() const =0
Valid region of the tensor.
Implementation of a rectangular access pattern.
bool update_window_and_padding(Window &win, Ts &&... patterns)
Update window and padding size for each of the access patterns.
Definition: WindowHelpers.h:46
Class to describe a number of elements in each dimension.
Definition: Steps.h:40
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
#define ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:790
unsigned int num_elems_processed_per_iteration
BorderSize border_size() const override
The size of the border for that kernel.
Describe a multidimensional execution window.
Definition: Window.h:39

◆ name()

◆ operator=() [1/2]

NEGaussian3x3Kernel& operator= ( const NEGaussian3x3Kernel )
delete

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

Referenced by NEGaussian3x3Kernel::name().

◆ operator=() [2/2]

NEGaussian3x3Kernel& operator= ( NEGaussian3x3Kernel &&  )
default

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 69 of file NEGaussian3x3Kernel.cpp.

References ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, arm_compute::execute_window_loop(), arm_compute::test::validation::input, Iterator::offset(), Iterator::ptr(), and IKernel::window().

Referenced by NEGaussian3x3Kernel::name().

70 {
71  ARM_COMPUTE_UNUSED(info);
74 
75  Iterator input(_input, window);
76  Iterator output(_output, window);
77 
78  const uint8_t *input_bot_ptr = _input->ptr_to_element(Coordinates(-1, -1));
79  const uint8_t *input_mid_ptr = _input->ptr_to_element(Coordinates(-1, 0));
80  const uint8_t *input_top_ptr = _input->ptr_to_element(Coordinates(-1, +1));
81 
82  static const int16x8_t two = vdupq_n_s16(2);
83  static const int16x8_t four = vdupq_n_s16(4);
84 
85  execute_window_loop(window, [&](const Coordinates &)
86  {
87  uint8x16_t top_data = vld1q_u8(input_top_ptr + input.offset());
88  uint8x16_t mid_data = vld1q_u8(input_mid_ptr + input.offset());
89  uint8x16_t bot_data = vld1q_u8(input_bot_ptr + input.offset());
90 
91  const int16x8x2_t top_s16 =
92  {
93  {
94  vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(top_data))),
95  vreinterpretq_s16_u16(vmovl_u8(vget_high_u8(top_data)))
96  }
97  };
98  const int16x8x2_t mid_s16 =
99  {
100  {
101  vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(mid_data))),
102  vreinterpretq_s16_u16(vmovl_u8(vget_high_u8(mid_data)))
103  }
104  };
105  const int16x8x2_t bot_s16 =
106  {
107  {
108  vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(bot_data))),
109  vreinterpretq_s16_u16(vmovl_u8(vget_high_u8(bot_data)))
110  }
111  };
112 
113  //top left
114  int16x8_t out = top_s16.val[0];
115  //top mid
116  out = vmlaq_s16(out, vextq_s16(top_s16.val[0], top_s16.val[1], 1), two);
117  //top right
118  out = vaddq_s16(out, vextq_s16(top_s16.val[0], top_s16.val[1], 2));
119  //mid left
120  out = vmlaq_s16(out, mid_s16.val[0], two);
121  //mid mid
122  out = vmlaq_s16(out, vextq_s16(mid_s16.val[0], mid_s16.val[1], 1), four);
123  //mid right
124  out = vmlaq_s16(out, vextq_s16(mid_s16.val[0], mid_s16.val[1], 2), two);
125  //bot left
126  out = vaddq_s16(out, bot_s16.val[0]);
127  //bot mid
128  out = vmlaq_s16(out, vextq_s16(bot_s16.val[0], bot_s16.val[1], 1), two);
129  //bot right
130  out = vaddq_s16(out, vextq_s16(bot_s16.val[0], bot_s16.val[1], 2));
131 
132  vst1_u8(output.ptr(), vqshrun_n_s16(out, 4));
133  },
134  input, output);
135 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
#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
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205

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