Compute Library
 21.02
NEBox3x3Kernel Class Reference

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

#include <NEBox3x3Kernel.h>

Collaboration diagram for NEBox3x3Kernel:
[legend]

Public Member Functions

const char * name () const override
 Name of the kernel. More...
 
 NEBox3x3Kernel ()=default
 Default constructor. More...
 
 NEBox3x3Kernel (const NEBox3x3Kernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NEBox3x3Kerneloperator= (const NEBox3x3Kernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NEBox3x3Kernel (NEBox3x3Kernel &&)=default
 Allow instances of this class to be moved. More...
 
NEBox3x3Kerneloperator= (NEBox3x3Kernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~NEBox3x3Kernel ()=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 Box 3x3 filter.

Definition at line 34 of file NEBox3x3Kernel.h.

Constructor & Destructor Documentation

◆ NEBox3x3Kernel() [1/3]

NEBox3x3Kernel ( )
default

Default constructor.

Referenced by NEBox3x3Kernel::name().

◆ NEBox3x3Kernel() [2/3]

NEBox3x3Kernel ( const NEBox3x3Kernel )
delete

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

◆ NEBox3x3Kernel() [3/3]

NEBox3x3Kernel ( NEBox3x3Kernel &&  )
default

Allow instances of this class to be moved.

◆ ~NEBox3x3Kernel()

~NEBox3x3Kernel ( )
default

Default destructor.

Referenced by NEBox3x3Kernel::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 117 of file NEBox3x3Kernel.cpp.

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

118 {
119  return BorderSize(1);
120 }
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: U8.
[in]border_undefinedTrue if the border mode is undefined. False if it's replicate or constant.

Definition at line 122 of file NEBox3x3Kernel.cpp.

References ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN, ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES, ARM_COMPUTE_ERROR_ON_MISMATCHING_SHAPES, ARM_COMPUTE_ERROR_ON_NULLPTR, NEBox3x3Kernel::border_size(), arm_compute::calculate_max_window(), ITensor::info(), arm_compute::test::validation::input, num_elems_processed_per_iteration, arm_compute::set_format_if_unknown(), arm_compute::set_shape_if_empty(), ITensorInfo::tensor_shape(), arm_compute::U8, arm_compute::update_window_and_padding(), and ITensorInfo::valid_region().

Referenced by NEBox3x3Kernel::name().

123 {
124  ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
125 
126  set_shape_if_empty(*output->info(), input->info()->tensor_shape());
127 
130 
135 
136  _input = input;
137  _output = output;
138 
139  constexpr unsigned int num_elems_processed_per_iteration = 8;
140  constexpr unsigned int num_elems_read_per_iteration = 16;
141  constexpr unsigned int num_elems_written_per_iteration = 8;
142  constexpr unsigned int num_rows_read_per_iteration = 3;
143  constexpr int rect_offset_xy = -1;
144 
145  // Configure kernel window
146  Window win = calculate_max_window(*input->info(), Steps(num_elems_processed_per_iteration), border_undefined, border_size());
147  AccessWindowHorizontal output_access(output->info(), 0, num_elems_written_per_iteration);
148 
149  update_window_and_padding(win, AccessWindowRectangle(input->info(), rect_offset_xy, rect_offset_xy, num_elems_read_per_iteration, num_rows_read_per_iteration), output_access);
150 
151  output_access.set_valid_region(win, input->info()->valid_region(), border_undefined, border_size());
152 
153  INEKernel::configure(win);
154 }
bool set_format_if_unknown(ITensorInfo &info, Format format)
Set the format, data type and number of channels to the specified value if the current data type is u...
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
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
#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.
#define ARM_COMPUTE_ERROR_ON_MISMATCHING_SHAPES(...)
Definition: Validate.h:441
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor&#39;s metadata.
bool set_shape_if_empty(ITensorInfo &info, const TensorShape &shape)
Set the shape to the specified value if the current assignment is empty.
#define ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:790
unsigned int num_elems_processed_per_iteration
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
BorderSize border_size() const override
The size of the border for that kernel.
Describe a multidimensional execution window.
Definition: Window.h:39

◆ name()

const char* name ( ) const
inlineoverridevirtual

◆ operator=() [1/2]

NEBox3x3Kernel& operator= ( const NEBox3x3Kernel )
delete

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

Referenced by NEBox3x3Kernel::name().

◆ operator=() [2/2]

NEBox3x3Kernel& operator= ( NEBox3x3Kernel &&  )
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 156 of file NEBox3x3Kernel.cpp.

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

Referenced by calculate_kernel(), and NEBox3x3Kernel::name().

157 {
158  ARM_COMPUTE_UNUSED(info);
161 
162  Iterator input(_input, window);
163  Iterator output(_output, window);
164 
165  unsigned char *const input_top_ptr = _input->ptr_to_element(Coordinates(-1, -1));
166  unsigned char *const input_mid_ptr = _input->ptr_to_element(Coordinates(-1, 0));
167  unsigned char *const input_bot_ptr = _input->ptr_to_element(Coordinates(-1, +1));
168 
169  const int shift = 19;
170  int value = (1 << shift) / 9 + 1; //58255 / (2^19) ~= 1/9
171  const int32x4_t oneovernine = vdupq_n_s32(value);
172 
173  execute_window_loop(window, [&](const Coordinates &)
174  {
175  const uint8x16_t top_data = vld1q_u8(input_top_ptr + input.offset());
176  const uint8x16_t mid_data = vld1q_u8(input_mid_ptr + input.offset());
177  const uint8x16_t bot_data = vld1q_u8(input_bot_ptr + input.offset());
178 
179  int16x8_t out = calculate_kernel(top_data, mid_data, bot_data);
180 
181  int32x4_t outfloathigh = vmovl_s16(vget_high_s16(out));
182  int32x4_t outfloatlow = vmovl_s16(vget_low_s16(out));
183 
184  outfloathigh = vmulq_s32(outfloathigh, oneovernine);
185  outfloatlow = vmulq_s32(outfloatlow, oneovernine);
186  outfloathigh = vshrq_n_s32(outfloathigh, shift);
187  outfloatlow = vshrq_n_s32(outfloatlow, shift);
188  out = vcombine_s16(vqmovn_s32((outfloatlow)),
189  vqmovn_s32((outfloathigh)));
190 
191  vst1_u8(output.ptr(), vqmovun_s16(out));
192  },
193  input, output);
194 }
int16x8_t calculate_kernel(const uint8x16_t &top_data, const uint8x16_t &mid_data, const uint8x16_t &bot_data)
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: