Compute Library
 21.02
NEScharr3x3Kernel Class Reference

Interface for the kernel to run a 3x3 Scharr filter on a tensor. More...

#include <NEScharr3x3Kernel.h>

Collaboration diagram for NEScharr3x3Kernel:
[legend]

Public Member Functions

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

\[ \mathbf{G}_x=\begin{vmatrix} -3 & 0 & +3\\ -10& 0 & +10\\ -3 & 0 & +3 \end{vmatrix} \]

Definition at line 43 of file NEScharr3x3Kernel.h.

Constructor & Destructor Documentation

◆ NEScharr3x3Kernel() [1/3]

Default constructor.

Definition at line 87 of file NEScharr3x3Kernel.cpp.

Referenced by NEScharr3x3Kernel::name().

88  : _run_scharr_x(false), _run_scharr_y(false), _input(nullptr), _output_x(nullptr), _output_y(nullptr)
89 {
90 }

◆ NEScharr3x3Kernel() [2/3]

NEScharr3x3Kernel ( const NEScharr3x3Kernel )
delete

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

◆ NEScharr3x3Kernel() [3/3]

Allow instances of this class to be moved.

◆ ~NEScharr3x3Kernel()

~NEScharr3x3Kernel ( )
default

Default destructor.

Referenced by NEScharr3x3Kernel::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 135 of file NEScharr3x3Kernel.cpp.

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

136 {
137  return BorderSize(1);
138 }
Container for 2D border size.
Definition: Types.h:273

◆ configure()

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

Initialise the kernel's source, destination and border.

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 92 of file NEScharr3x3Kernel.cpp.

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

Referenced by NEScharr3x3Kernel::name().

93 {
95  ARM_COMPUTE_ERROR_ON((output_x == nullptr) && (output_y == nullptr));
96 
97  _run_scharr_x = output_x != nullptr;
98  _run_scharr_y = output_y != nullptr;
99 
100  if(_run_scharr_x)
101  {
103  }
104 
105  if(_run_scharr_y)
106  {
108  }
109 
110  _input = input;
111  _output_x = output_x;
112  _output_y = output_y;
113 
114  // Configure kernel window
115  constexpr unsigned int num_elems_processed_per_iteration = 8;
116  constexpr unsigned int num_elems_read_per_iteration = 16;
117  constexpr unsigned int num_elems_written_per_iteration = 8;
118  constexpr unsigned int num_rows_read_per_iteration = 3;
119 
120  Window win = calculate_max_window(*input->info(), Steps(num_elems_processed_per_iteration), border_undefined, border_size());
121  AccessWindowHorizontal output_x_access(output_x == nullptr ? nullptr : output_x->info(), 0, num_elems_written_per_iteration);
122  AccessWindowHorizontal output_y_access(output_y == nullptr ? nullptr : output_y->info(), 0, num_elems_written_per_iteration);
123 
125  AccessWindowRectangle(input->info(), -border_size().left, -border_size().top, num_elems_read_per_iteration, num_rows_read_per_iteration),
126  output_x_access,
127  output_y_access);
128 
129  output_x_access.set_valid_region(win, input->info()->valid_region(), border_undefined, border_size());
130  output_y_access.set_valid_region(win, input->info()->valid_region(), border_undefined, border_size());
131 
132  INEKernel::configure(win);
133 }
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
#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
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
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
Describe a multidimensional execution window.
Definition: Window.h:39
BorderSize border_size() const override
The size of the border for that kernel.

◆ name()

◆ operator=() [1/2]

NEScharr3x3Kernel& operator= ( const NEScharr3x3Kernel )
delete

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

Referenced by NEScharr3x3Kernel::name().

◆ operator=() [2/2]

NEScharr3x3Kernel& operator= ( NEScharr3x3Kernel &&  )
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 140 of file NEScharr3x3Kernel.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(), ITensor::ptr_to_element(), and IKernel::window().

Referenced by NEScharr3x3Kernel::name().

141 {
142  ARM_COMPUTE_UNUSED(info);
145 
146  const unsigned char *const input_top_ptr = _input->ptr_to_element(Coordinates(-1, -1));
147  const unsigned char *const input_mid_ptr = _input->ptr_to_element(Coordinates(-1, 0));
148  const unsigned char *const input_bot_ptr = _input->ptr_to_element(Coordinates(-1, +1));
149 
150  Iterator input(_input, window);
151  Iterator output_y;
152  Iterator output_x;
153 
154  if(_run_scharr_y)
155  {
156  output_y = Iterator(_output_y, window);
157  }
158 
159  if(_run_scharr_x)
160  {
161  output_x = Iterator(_output_x, window);
162  }
163 
164  if(_run_scharr_x && _run_scharr_y)
165  {
166  execute_window_loop(window, [&](const Coordinates &)
167  {
168 
169  const uint8x16_t top_data = vld1q_u8(input_top_ptr + input.offset());
170  const uint8x16_t mid_data = vld1q_u8(input_mid_ptr + input.offset());
171  const uint8x16_t bot_data = vld1q_u8(input_bot_ptr + input.offset());
172 
173  const int16x8x2_t top_s16 =
174  {
175  {
176  vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(top_data))),
177  vreinterpretq_s16_u16(vmovl_u8(vget_high_u8(top_data)))
178  }
179  };
180  const int16x8x2_t mid_s16 =
181  {
182  {
183  vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(mid_data))),
184  vreinterpretq_s16_u16(vmovl_u8(vget_high_u8(mid_data)))
185  }
186  };
187  const int16x8x2_t bot_s16 =
188  {
189  {
190  vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(bot_data))),
191  vreinterpretq_s16_u16(vmovl_u8(vget_high_u8(bot_data)))
192  }
193  };
194 
195  vst1q_s16(reinterpret_cast<int16_t *>(output_x.ptr()), scharr_x(top_s16, mid_s16, bot_s16));
196  vst1q_s16(reinterpret_cast<int16_t *>(output_y.ptr()), scharr_y(top_s16, bot_s16));
197  },
198  input, output_x, output_y);
199  }
200  else if(_run_scharr_x)
201  {
202  execute_window_loop(window, [&](const Coordinates &)
203  {
204 
205  const uint8x16_t top_data = vld1q_u8(input_top_ptr + input.offset());
206  const uint8x16_t mid_data = vld1q_u8(input_mid_ptr + input.offset());
207  const uint8x16_t bot_data = vld1q_u8(input_bot_ptr + input.offset());
208 
209  const int16x8x2_t top_s16 =
210  {
211  {
212  vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(top_data))),
213  vreinterpretq_s16_u16(vmovl_u8(vget_high_u8(top_data)))
214  }
215  };
216  const int16x8x2_t mid_s16 =
217  {
218  {
219  vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(mid_data))),
220  vreinterpretq_s16_u16(vmovl_u8(vget_high_u8(mid_data)))
221  }
222  };
223  const int16x8x2_t bot_s16 =
224  {
225  {
226  vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(bot_data))),
227  vreinterpretq_s16_u16(vmovl_u8(vget_high_u8(bot_data)))
228  }
229  };
230 
231  vst1q_s16(reinterpret_cast<int16_t *>(output_x.ptr()), scharr_x(top_s16, mid_s16, bot_s16));
232  },
233  input, output_x);
234  }
235  else if(_run_scharr_y)
236  {
237  execute_window_loop(window, [&](const Coordinates &)
238  {
239 
240  const uint8x16_t top_data = vld1q_u8(input_top_ptr + input.offset());
241  const uint8x16_t bot_data = vld1q_u8(input_bot_ptr + input.offset());
242 
243  const int16x8x2_t top_s16 =
244  {
245  {
246  vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(top_data))),
247  vreinterpretq_s16_u16(vmovl_u8(vget_high_u8(top_data)))
248  }
249  };
250  const int16x8x2_t bot_s16 =
251  {
252  {
253  vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(bot_data))),
254  vreinterpretq_s16_u16(vmovl_u8(vget_high_u8(bot_data)))
255  }
256  };
257 
258  vst1q_s16(reinterpret_cast<int16_t *>(output_y.ptr()), scharr_y(top_s16, bot_s16));
259  },
260  input, output_y);
261  }
262 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
uint8_t * ptr_to_element(const Coordinates &id) const
Return a pointer to the element at the passed coordinates.
Definition: ITensor.h:63
#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
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205

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