Compute Library
 21.02
NESobel7x7HorKernel Class Reference

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

#include <NESobel7x7Kernel.h>

Collaboration diagram for NESobel7x7HorKernel:
[legend]

Public Member Functions

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

Definition at line 36 of file NESobel7x7Kernel.h.

Constructor & Destructor Documentation

◆ NESobel7x7HorKernel() [1/3]

Default constructor.

Definition at line 145 of file NESobel7x7Kernel.cpp.

Referenced by NESobel7x7HorKernel::name().

146  : _input(nullptr), _output_x(nullptr), _output_y(nullptr), _run_sobel_x(false), _run_sobel_y(false), _border_size(0)
147 {
148 }

◆ NESobel7x7HorKernel() [2/3]

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

◆ NESobel7x7HorKernel() [3/3]

Allow instances of this class to be moved.

◆ ~NESobel7x7HorKernel()

~NESobel7x7HorKernel ( )
default

Default destructor.

Referenced by NESobel7x7HorKernel::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 150 of file NESobel7x7Kernel.cpp.

Referenced by NESobel7x7HorKernel::configure(), NESobel7x7HorKernel::name(), and NESobel7x7VertKernel::name().

151 {
152  return _border_size;
153 }

◆ 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: S32.
[out]output_y(Optional) Destination tensor for the Y gradient. Data type supported: S32.
[in]border_undefinedTrue if the border mode is undefined. False if it's replicate or constant.

Definition at line 155 of file NESobel7x7Kernel.cpp.

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_FORMAT_NOT_IN, NESobel7x7HorKernel::border_size(), arm_compute::calculate_max_window_horizontal(), ITensor::info(), arm_compute::test::validation::input, BorderSize::left, num_elems_processed_per_iteration, arm_compute::S32, arm_compute::U8, arm_compute::update_window_and_padding(), and ITensorInfo::valid_region().

Referenced by NESobel7x7HorKernel::name(), and NESobel7x7VertKernel::name().

156 {
158  ARM_COMPUTE_ERROR_ON((output_x == nullptr) && (output_y == nullptr));
159 
160  _run_sobel_x = output_x != nullptr;
161  _run_sobel_y = output_y != nullptr;
162 
163  if(_run_sobel_x)
164  {
166  }
167 
168  if(_run_sobel_y)
169  {
171  }
172 
173  _input = input;
174  _output_x = output_x;
175  _output_y = output_y;
176  _border_size = BorderSize(border_undefined ? 0 : 3, 3);
177 
178  // Configure kernel window
179  constexpr unsigned int num_elems_processed_per_iteration = 8;
180  constexpr unsigned int num_elems_read_per_iteration = 16;
181  constexpr unsigned int num_elems_written_per_iteration = 8;
182 
183  Window win = calculate_max_window_horizontal(*input->info(), Steps(num_elems_processed_per_iteration), border_undefined, border_size());
184  AccessWindowHorizontal output_x_access(output_x == nullptr ? nullptr : output_x->info(), 0, num_elems_written_per_iteration);
185  AccessWindowHorizontal output_y_access(output_y == nullptr ? nullptr : output_y->info(), 0, num_elems_written_per_iteration);
186 
188  AccessWindowHorizontal(input->info(), -border_size().left, num_elems_read_per_iteration),
189  output_x_access,
190  output_y_access);
191 
192  output_x_access.set_valid_region(win, input->info()->valid_region(), border_undefined, border_size());
193  output_y_access.set_valid_region(win, input->info()->valid_region(), border_undefined, border_size());
194 
195  INEKernel::configure(win);
196 }
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
#define ARM_COMPUTE_ERROR_ON_FORMAT_NOT_IN(t,...)
Definition: Validate.h:643
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.
1 channel, 1 S32 per channel
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
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]

NESobel7x7HorKernel& operator= ( const NESobel7x7HorKernel )
delete

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

Referenced by NESobel7x7HorKernel::name(), and NESobel7x7VertKernel::name().

◆ operator=() [2/2]

NESobel7x7HorKernel& operator= ( NESobel7x7HorKernel &&  )
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 198 of file NESobel7x7Kernel.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::ptr(), and IKernel::window().

Referenced by NESobel7x7HorKernel::name(), and NESobel7x7VertKernel::name().

199 {
200  ARM_COMPUTE_UNUSED(info);
203 
204  Iterator input(_input, window);
205  Iterator output_x;
206  Iterator output_y;
207 
208  if(_run_sobel_x)
209  {
210  output_x = Iterator(_output_x, window);
211  }
212 
213  if(_run_sobel_y)
214  {
215  output_y = Iterator(_output_y, window);
216  }
217 
218  if(_run_sobel_y && _run_sobel_x)
219  {
220  execute_window_loop(window, [&](const Coordinates &)
221  {
222  const uint8x16_t data = vld1q_u8(input.ptr() - 3);
223 
224  const uint16x8_t tmp_low_u16 = vmovl_u8(vget_low_u8(data));
225  const uint16x8_t tmp_high_u16 = vmovl_u8(vget_high_u8(data));
226 
227  const int32x4x4_t data_s32 =
228  {
229  {
230  vreinterpretq_s32_u32(vmovl_u16(vget_low_u16(tmp_low_u16))),
231  vreinterpretq_s32_u32(vmovl_u16(vget_high_u16(tmp_low_u16))),
232  vreinterpretq_s32_u32(vmovl_u16(vget_low_u16(tmp_high_u16))),
233  vreinterpretq_s32_u32(vmovl_u16(vget_high_u16(tmp_high_u16)))
234  }
235  };
236 
237  const int32x4x2_t out_y = compute_hor_sobel_y(data_s32);
238  vst1q_s32(reinterpret_cast<int32_t *>(output_y.ptr()), out_y.val[0]);
239  vst1q_s32(reinterpret_cast<int32_t *>(output_y.ptr()) + 4, out_y.val[1]);
240 
241  const int32x4x2_t out_x = compute_hor_sobel_x(data_s32);
242  vst1q_s32(reinterpret_cast<int32_t *>(output_x.ptr()), out_x.val[0]);
243  vst1q_s32(reinterpret_cast<int32_t *>(output_x.ptr()) + 4, out_x.val[1]);
244  },
245  input, output_x, output_y);
246  }
247  else if(_run_sobel_x)
248  {
249  execute_window_loop(window, [&](const Coordinates &)
250  {
251  const uint8x16_t data = vld1q_u8(input.ptr() - 3);
252 
253  const uint16x8_t tmp_low_u16 = vmovl_u8(vget_low_u8(data));
254  const uint16x8_t tmp_high_u16 = vmovl_u8(vget_high_u8(data));
255 
256  const int32x4x4_t data_s32 =
257  {
258  {
259  vreinterpretq_s32_u32(vmovl_u16(vget_low_u16(tmp_low_u16))),
260  vreinterpretq_s32_u32(vmovl_u16(vget_high_u16(tmp_low_u16))),
261  vreinterpretq_s32_u32(vmovl_u16(vget_low_u16(tmp_high_u16))),
262  vreinterpretq_s32_u32(vmovl_u16(vget_high_u16(tmp_high_u16)))
263  }
264  };
265 
266  const int32x4x2_t out = compute_hor_sobel_x(data_s32);
267  vst1q_s32(reinterpret_cast<int32_t *>(output_x.ptr()), out.val[0]);
268  vst1q_s32(reinterpret_cast<int32_t *>(output_x.ptr()) + 4, out.val[1]);
269  },
270  input, output_x);
271  }
272  else if(_run_sobel_y)
273  {
274  execute_window_loop(window, [&](const Coordinates &)
275  {
276  const uint8x16_t data = vld1q_u8(input.ptr() - 3);
277 
278  const uint16x8_t tmp_low_u16 = vmovl_u8(vget_low_u8(data));
279  const uint16x8_t tmp_high_u16 = vmovl_u8(vget_high_u8(data));
280 
281  const int32x4x4_t data_s32 =
282  {
283  {
284  vreinterpretq_s32_u32(vmovl_u16(vget_low_u16(tmp_low_u16))),
285  vreinterpretq_s32_u32(vmovl_u16(vget_high_u16(tmp_low_u16))),
286  vreinterpretq_s32_u32(vmovl_u16(vget_low_u16(tmp_high_u16))),
287  vreinterpretq_s32_u32(vmovl_u16(vget_high_u16(tmp_high_u16)))
288  }
289  };
290 
291  const int32x4x2_t out = compute_hor_sobel_y(data_s32);
292  vst1q_s32(reinterpret_cast<int32_t *>(output_y.ptr()), out.val[0]);
293  vst1q_s32(reinterpret_cast<int32_t *>(output_y.ptr()) + 4, out.val[1]);
294  },
295  input, output_y);
296  }
297 }
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
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: