Compute Library
 21.02
NESobel5x5HorKernel Class Reference

Interface for the kernel to run the horizontal pass of 5x5 Sobel filter on a tensor. More...

#include <NESobel5x5Kernel.h>

Collaboration diagram for NESobel5x5HorKernel:
[legend]

Public Member Functions

const char * name () const override
 Name of the kernel. More...
 
 NESobel5x5HorKernel ()
 Default constructor. More...
 
 NESobel5x5HorKernel (const NESobel5x5HorKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NESobel5x5HorKerneloperator= (const NESobel5x5HorKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NESobel5x5HorKernel (NESobel5x5HorKernel &&)=default
 Allow instances of this class to be moved. More...
 
NESobel5x5HorKerneloperator= (NESobel5x5HorKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~NESobel5x5HorKernel ()=default
 Default destructor. More...
 
void configure (const ITensor *input, ITensor *output_x, ITensor *output_y, bool border_undefined)
 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 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

Interface for the kernel to run the horizontal pass of 5x5 Sobel filter on a tensor.

Definition at line 36 of file NESobel5x5Kernel.h.

Constructor & Destructor Documentation

◆ NESobel5x5HorKernel() [1/3]

Default constructor.

Definition at line 42 of file NESobel5x5Kernel.cpp.

Referenced by NESobel5x5HorKernel::name().

43  : _input(nullptr), _output_x(nullptr), _output_y(nullptr), _run_sobel_x(false), _run_sobel_y(false), _border_size(0)
44 {
45 }

◆ NESobel5x5HorKernel() [2/3]

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

◆ NESobel5x5HorKernel() [3/3]

Allow instances of this class to be moved.

◆ ~NESobel5x5HorKernel()

~NESobel5x5HorKernel ( )
default

Default destructor.

Referenced by NESobel5x5HorKernel::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 47 of file NESobel5x5Kernel.cpp.

Referenced by NESobel5x5HorKernel::configure(), NESobel5x5HorKernel::name(), and NESobel5x5VertKernel::name().

48 {
49  return _border_size;
50 }

◆ configure()

void configure ( const ITensor input,
ITensor output_x,
ITensor output_y,
bool  border_undefined 
)

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

Note
At least one of output_x or output_y must be set
Parameters
[in]inputSource tensor. Data type supported: U8.
[out]output_x(Optional) Destination tensor for the X gradient. Data type supported: S16.
[out]output_y(Optional) Destination tensor for the Y gradient. Data type supported: S16.
[in]border_undefinedTrue if the border mode is undefined. False if it's replicate or constant.

Definition at line 52 of file NESobel5x5Kernel.cpp.

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN, NESobel5x5HorKernel::border_size(), arm_compute::calculate_max_window_horizontal(), ITensor::info(), arm_compute::test::validation::input, BorderSize::left, num_elems_processed_per_iteration, arm_compute::S16, arm_compute::U8, arm_compute::update_window_and_padding(), and ITensorInfo::valid_region().

Referenced by NESobel5x5HorKernel::name(), and NESobel5x5VertKernel::name().

53 {
55  ARM_COMPUTE_ERROR_ON((output_x == nullptr) && (output_y == nullptr));
56 
57  _run_sobel_x = output_x != nullptr;
58  _run_sobel_y = output_y != nullptr;
59 
60  if(_run_sobel_x)
61  {
63  }
64 
65  if(_run_sobel_y)
66  {
68  }
69 
70  _input = input;
71  _output_x = output_x;
72  _output_y = output_y;
73  _border_size = BorderSize(border_undefined ? 0 : 2, 2);
74 
75  // Configure kernel window
76  constexpr unsigned int num_elems_processed_per_iteration = 8;
77  constexpr unsigned int num_elems_read_per_iteration = 16;
78  constexpr unsigned int num_elems_written_per_iteration = 8;
79 
80  Window win = calculate_max_window_horizontal(*input->info(), Steps(num_elems_processed_per_iteration), border_undefined, border_size());
81  AccessWindowHorizontal output_x_access(output_x == nullptr ? nullptr : output_x->info(), 0, num_elems_written_per_iteration);
82  AccessWindowHorizontal output_y_access(output_y == nullptr ? nullptr : output_y->info(), 0, num_elems_written_per_iteration);
83 
85  AccessWindowHorizontal(input->info(), -border_size().left, num_elems_read_per_iteration),
86  output_x_access,
87  output_y_access);
88 
89  output_x_access.set_valid_region(win, input->info()->valid_region(), border_undefined, border_size());
90  output_y_access.set_valid_region(win, input->info()->valid_region(), border_undefined, border_size());
91 
92  INEKernel::configure(win);
93 }
Container for 2D border size.
Definition: Types.h:273
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 ValidRegion valid_region() const =0
Valid region of the tensor.
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
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
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]

NESobel5x5HorKernel& operator= ( const NESobel5x5HorKernel )
delete

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

Referenced by NESobel5x5HorKernel::name(), and NESobel5x5VertKernel::name().

◆ operator=() [2/2]

NESobel5x5HorKernel& operator= ( NESobel5x5HorKernel &&  )
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 95 of file NESobel5x5Kernel.cpp.

References 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::input, Iterator::ptr(), Window::shift(), and IKernel::window().

Referenced by NESobel5x5HorKernel::name(), and NESobel5x5VertKernel::name().

96 {
97  ARM_COMPUTE_UNUSED(info);
100 
101  Window win_in(window);
102  win_in.shift(Window::DimX, -2);
103 
104  Iterator input(_input, win_in);
105  Iterator output_x;
106  Iterator output_y;
107 
108  if(_run_sobel_x)
109  {
110  output_x = Iterator(_output_x, window);
111  }
112 
113  if(_run_sobel_y)
114  {
115  output_y = Iterator(_output_y, window);
116  }
117 
118  if(_run_sobel_y && _run_sobel_x)
119  {
120  static const int16x8_t six = vdupq_n_s16(6);
121  static const int16x8_t four = vdupq_n_s16(4);
122  static const int16x8_t two = vdupq_n_s16(2);
123  static const int16x8_t minustwo = vdupq_n_s16(-2);
124 
125  execute_window_loop(window, [&](const Coordinates &)
126  {
127  const uint8x16_t data = vld1q_u8(input.ptr());
128 
129  const int16x8x2_t data_s16 =
130  {
131  {
132  vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(data))),
133  vreinterpretq_s16_u16(vmovl_u8(vget_high_u8(data)))
134  }
135  };
136 
137  int16x8_t out_y = data_s16.val[0];
138  out_y = vmlaq_s16(out_y, vextq_s16(data_s16.val[0], data_s16.val[1], 1), four);
139  out_y = vmlaq_s16(out_y, vextq_s16(data_s16.val[0], data_s16.val[1], 2), six);
140  out_y = vmlaq_s16(out_y, vextq_s16(data_s16.val[0], data_s16.val[1], 3), four);
141  out_y = vaddq_s16(out_y, vextq_s16(data_s16.val[0], data_s16.val[1], 4));
142 
143  vst1q_s16(reinterpret_cast<int16_t *>(output_y.ptr()), out_y);
144 
145  int16x8_t out_x = vnegq_s16(data_s16.val[0]);
146  out_x = vmlaq_s16(out_x, vextq_s16(data_s16.val[0], data_s16.val[1], 1), minustwo);
147  out_x = vmlaq_s16(out_x, vextq_s16(data_s16.val[0], data_s16.val[1], 3), two);
148  out_x = vaddq_s16(out_x, vextq_s16(data_s16.val[0], data_s16.val[1], 4));
149 
150  vst1q_s16(reinterpret_cast<int16_t *>(output_x.ptr()), out_x);
151  },
152  input, output_x, output_y);
153  }
154  else if(_run_sobel_x)
155  {
156  static const int16x8_t two = vdupq_n_s16(2);
157  static const int16x8_t minustwo = vdupq_n_s16(-2);
158 
159  execute_window_loop(window, [&](const Coordinates &)
160  {
161  const uint8x16_t data = vld1q_u8(input.ptr());
162 
163  const int16x8x2_t data_s16 =
164  {
165  {
166  vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(data))),
167  vreinterpretq_s16_u16(vmovl_u8(vget_high_u8(data)))
168  }
169  };
170 
171  int16x8_t out = vnegq_s16(data_s16.val[0]);
172  out = vmlaq_s16(out, vextq_s16(data_s16.val[0], data_s16.val[1], 1), minustwo);
173  out = vmlaq_s16(out, vextq_s16(data_s16.val[0], data_s16.val[1], 3), two);
174  out = vaddq_s16(out, vextq_s16(data_s16.val[0], data_s16.val[1], 4));
175 
176  vst1q_s16(reinterpret_cast<int16_t *>(output_x.ptr()), out);
177  },
178  input, output_x);
179  }
180  else if(_run_sobel_y)
181  {
182  static const int16x8_t six = vdupq_n_s16(6);
183  static const int16x8_t four = vdupq_n_s16(4);
184 
185  execute_window_loop(window, [&](const Coordinates &)
186  {
187  const uint8x16_t data = vld1q_u8(input.ptr());
188 
189  const int16x8x2_t data_s16 =
190  {
191  {
192  vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(data))),
193  vreinterpretq_s16_u16(vmovl_u8(vget_high_u8(data)))
194  }
195  };
196 
197  int16x8_t out = data_s16.val[0];
198  out = vmlaq_s16(out, vextq_s16(data_s16.val[0], data_s16.val[1], 1), four);
199  out = vmlaq_s16(out, vextq_s16(data_s16.val[0], data_s16.val[1], 2), six);
200  out = vmlaq_s16(out, vextq_s16(data_s16.val[0], data_s16.val[1], 3), four);
201  out = vaddq_s16(out, vextq_s16(data_s16.val[0], data_s16.val[1], 4));
202 
203  vst1q_s16(reinterpret_cast<int16_t *>(output_y.ptr()), out);
204  },
205  input, output_y);
206  }
207 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
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
constexpr uint8_t * ptr() const
Return a pointer to the current pixel.
Definition: Helpers.inl:139
#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

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