Compute Library
 21.02
NESobel7x7VertKernel Class Reference

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

#include <NESobel7x7Kernel.h>

Collaboration diagram for NESobel7x7VertKernel:
[legend]

Public Member Functions

const char * name () const override
 Name of the kernel. More...
 
 NESobel7x7VertKernel ()
 Default constructor. More...
 
 NESobel7x7VertKernel (const NESobel7x7VertKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NESobel7x7VertKerneloperator= (const NESobel7x7VertKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NESobel7x7VertKernel (NESobel7x7VertKernel &&)=default
 Allow instances of this class to be moved. More...
 
NESobel7x7VertKerneloperator= (NESobel7x7VertKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~NESobel7x7VertKernel ()=default
 Default destructor. More...
 
void configure (const ITensor *input_x, const ITensor *input_y, 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 vertical pass of 7x7 Sobel Y filter on a tensor.

Definition at line 83 of file NESobel7x7Kernel.h.

Constructor & Destructor Documentation

◆ NESobel7x7VertKernel() [1/3]

Default constructor.

Definition at line 299 of file NESobel7x7Kernel.cpp.

300  : _input_x(nullptr), _input_y(nullptr), _output_x(nullptr), _output_y(nullptr), _run_sobel_x(false), _run_sobel_y(false)
301 {
302 }

◆ NESobel7x7VertKernel() [2/3]

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

◆ NESobel7x7VertKernel() [3/3]

Allow instances of this class to be moved.

◆ ~NESobel7x7VertKernel()

~NESobel7x7VertKernel ( )
default

Default destructor.

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 304 of file NESobel7x7Kernel.cpp.

Referenced by NESobel7x7VertKernel::configure().

305 {
306  return BorderSize{ 3, 0 };
307 }
Container for 2D border size.
Definition: Types.h:273

◆ configure()

void configure ( const ITensor input_x,
const ITensor input_y,
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
If output_x is set then input_x must be set too
If output_y is set then input_y must be set too
Parameters
[in]input_x(Optional) Input for X (X output of hor pass). Data type supported: S32.
[in]input_y(Optional) Input for Y (Y output of hor pass). Data type supported: S32.
[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 309 of file NESobel7x7Kernel.cpp.

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_FORMAT_NOT_IN, NESobel7x7VertKernel::border_size(), arm_compute::calculate_max_window(), ITensor::info(), arm_compute::test::validation::input, num_elems_processed_per_iteration, arm_compute::S32, BorderSize::top, arm_compute::update_window_and_padding(), and ITensorInfo::valid_region().

310 {
311  ARM_COMPUTE_ERROR_ON((output_x == nullptr) && (output_y == nullptr));
312 
313  _run_sobel_x = (output_x != nullptr);
314  _run_sobel_y = (output_y != nullptr);
315 
316  if(_run_sobel_x)
317  {
320  }
321 
322  if(_run_sobel_y)
323  {
326  }
327 
328  _input_x = input_x;
329  _input_y = input_y;
330  _output_x = output_x;
331  _output_y = output_y;
332 
333  const ITensor *const input = _run_sobel_x ? input_x : input_y;
334 
335  // Configure kernel window
336  constexpr unsigned int num_elems_processed_per_iteration = 8;
337  constexpr unsigned int num_elems_read_per_iteration = 8;
338  constexpr unsigned int num_elems_written_per_iteration = 8;
339  constexpr unsigned int num_rows_read_per_iteration = 7;
340 
341  Window win = calculate_max_window(*input->info(), Steps(num_elems_processed_per_iteration), border_undefined, border_size());
342  AccessWindowHorizontal output_x_access(output_x == nullptr ? nullptr : output_x->info(), 0, num_elems_written_per_iteration);
343  AccessWindowHorizontal output_y_access(output_y == nullptr ? nullptr : output_y->info(), 0, num_elems_written_per_iteration);
344 
346  AccessWindowRectangle(input_x == nullptr ? nullptr : input_x->info(), 0, -border_size().top, num_elems_read_per_iteration, num_rows_read_per_iteration),
347  AccessWindowRectangle(input_y == nullptr ? nullptr : input_y->info(), 0, -border_size().top, num_elems_read_per_iteration, num_rows_read_per_iteration),
348  output_x_access,
349  output_y_access);
350 
351  output_x_access.set_valid_region(win, input->info()->valid_region(), border_undefined, border_size());
352  output_y_access.set_valid_region(win, input->info()->valid_region(), border_undefined, border_size());
353 
354  INEKernel::configure(win);
355 }
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)
BorderSize border_size() const override
The size of the border for that kernel.
#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
Interface for Neon tensor.
Definition: ITensor.h:36
virtual ValidRegion valid_region() const =0
Valid region of the tensor.
1 channel, 1 S32 per channel
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 num_elems_processed_per_iteration
Describe a multidimensional execution window.
Definition: Window.h:39

◆ name()

const char* name ( ) const
inlineoverridevirtual

Name of the kernel.

Returns
Kernel name

Implements ICPPKernel.

Definition at line 86 of file NESobel7x7Kernel.h.

References NESobel7x7HorKernel::border_size(), NESobel7x7HorKernel::configure(), arm_compute::test::validation::info, NESobel7x7HorKernel::operator=(), NESobel7x7HorKernel::run(), and IKernel::window().

87  {
88  return "NESobel7x7VertKernel";
89  }

◆ operator=() [1/2]

NESobel7x7VertKernel& operator= ( const NESobel7x7VertKernel )
delete

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

◆ operator=() [2/2]

NESobel7x7VertKernel& operator= ( NESobel7x7VertKernel &&  )
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 357 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(), ITensorInfo::format(), ITensor::info(), arm_compute::pixel_size_from_format(), Iterator::ptr(), ITensorInfo::strides_in_bytes(), and IKernel::window().

358 {
359  ARM_COMPUTE_UNUSED(info);
362 
363  Iterator input_x;
364  Iterator input_y;
365  Iterator output_x;
366  Iterator output_y;
367 
368  int32_t in_x_stride = 0;
369  int32_t in_y_stride = 0;
370 
371  if(_run_sobel_x)
372  {
373  input_x = Iterator(_input_x, window);
374  output_x = Iterator(_output_x, window);
375  in_x_stride = _input_x->info()->strides_in_bytes()[1] / pixel_size_from_format(_input_x->info()->format());
376  }
377 
378  if(_run_sobel_y)
379  {
380  input_y = Iterator(_input_y, window);
381  output_y = Iterator(_output_y, window);
382  in_y_stride = _input_y->info()->strides_in_bytes()[1] / pixel_size_from_format(_input_y->info()->format());
383  }
384 
385  if(_run_sobel_x)
386  {
387  execute_window_loop(window, [&](const Coordinates &)
388  {
389  auto in_ptr = reinterpret_cast<int32_t *>(input_x.ptr()) - 3 * in_x_stride;
390 
391  //top3
392  int32x4x2_t data =
393  {
394  {
395  vld1q_s32(in_ptr),
396  vld1q_s32(in_ptr + 4)
397  }
398  };
399 
400  int32x4x2_t out = data;
401 
402  //top2
403  in_ptr += in_x_stride;
404  data.val[0] = vld1q_s32(in_ptr);
405  out.val[0] = vmlaq_s32(out.val[0], data.val[0], six);
406 
407  data.val[1] = vld1q_s32(in_ptr + 4);
408  out.val[1] = vmlaq_s32(out.val[1], data.val[1], six);
409 
410  //top
411  in_ptr += in_x_stride;
412  data.val[0] = vld1q_s32(in_ptr);
413  out.val[0] = vmlaq_s32(out.val[0], data.val[0], fifteen);
414 
415  data.val[1] = vld1q_s32(in_ptr + 4);
416  out.val[1] = vmlaq_s32(out.val[1], data.val[1], fifteen);
417 
418  //mid
419  in_ptr += in_x_stride;
420  data.val[0] = vld1q_s32(in_ptr);
421  out.val[0] = vmlaq_s32(out.val[0], data.val[0], twenty);
422 
423  data.val[1] = vld1q_s32(in_ptr + 4);
424  out.val[1] = vmlaq_s32(out.val[1], data.val[1], twenty);
425 
426  //low
427  in_ptr += in_x_stride;
428  data.val[0] = vld1q_s32(in_ptr);
429  out.val[0] = vmlaq_s32(out.val[0], data.val[0], fifteen);
430 
431  data.val[1] = vld1q_s32(in_ptr + 4);
432  out.val[1] = vmlaq_s32(out.val[1], data.val[1], fifteen);
433 
434  //low2
435  in_ptr += in_x_stride;
436  data.val[0] = vld1q_s32(in_ptr);
437  out.val[0] = vmlaq_s32(out.val[0], data.val[0], six);
438 
439  data.val[1] = vld1q_s32(in_ptr + 4);
440  out.val[1] = vmlaq_s32(out.val[1], data.val[1], six);
441 
442  //low3
443  in_ptr += in_x_stride;
444  data.val[0] = vld1q_s32(in_ptr);
445  out.val[0] = vaddq_s32(out.val[0], data.val[0]);
446 
447  data.val[1] = vld1q_s32(in_ptr + 4);
448  out.val[1] = vaddq_s32(out.val[1], data.val[1]);
449 
450  vst1q_s32(reinterpret_cast<int32_t *>(output_x.ptr()) + 0, out.val[0]);
451  vst1q_s32(reinterpret_cast<int32_t *>(output_x.ptr()) + 4, out.val[1]);
452  },
453  input_x, output_x);
454  }
455 
456  if(_run_sobel_y)
457  {
458  execute_window_loop(window, [&](const Coordinates &)
459  {
460  auto in_ptr = reinterpret_cast<int32_t *>(input_y.ptr()) - 3 * in_y_stride;
461 
462  //top3
463  int32x4x2_t data =
464  {
465  {
466  vld1q_s32(in_ptr),
467  vld1q_s32(in_ptr + 4)
468  }
469  };
470 
471  int32x4x2_t out =
472  {
473  {
474  vnegq_s32(data.val[0]),
475  vnegq_s32(data.val[1])
476  }
477  };
478 
479  //top2
480  in_ptr += in_y_stride;
481  data.val[0] = vld1q_s32(in_ptr);
482  out.val[0] = vmlaq_s32(out.val[0], data.val[0], minusfour);
483 
484  data.val[1] = vld1q_s32(in_ptr + 4);
485  out.val[1] = vmlaq_s32(out.val[1], data.val[1], minusfour);
486 
487  //top
488  in_ptr += in_y_stride;
489  data.val[0] = vld1q_s32(in_ptr);
490  out.val[0] = vmlaq_s32(out.val[0], data.val[0], minusfive);
491 
492  data.val[1] = vld1q_s32(in_ptr + 4);
493  out.val[1] = vmlaq_s32(out.val[1], data.val[1], minusfive);
494 
495  //low
496  in_ptr += (2 * in_y_stride);
497  data.val[0] = vld1q_s32(in_ptr);
498  out.val[0] = vmlaq_s32(out.val[0], data.val[0], five);
499 
500  data.val[1] = vld1q_s32(in_ptr + 4);
501  out.val[1] = vmlaq_s32(out.val[1], data.val[1], five);
502 
503  //low2
504  in_ptr += in_y_stride;
505  data.val[0] = vld1q_s32(in_ptr);
506  out.val[0] = vmlaq_s32(out.val[0], data.val[0], four);
507 
508  data.val[1] = vld1q_s32(in_ptr + 4);
509  out.val[1] = vmlaq_s32(out.val[1], data.val[1], four);
510 
511  //low3
512  in_ptr += in_y_stride;
513  data.val[0] = vld1q_s32(in_ptr);
514  out.val[0] = vaddq_s32(out.val[0], data.val[0]);
515 
516  data.val[1] = vld1q_s32(in_ptr + 4);
517  out.val[1] = vaddq_s32(out.val[1], data.val[1]);
518 
519  vst1q_s32(reinterpret_cast<int32_t *>(output_y.ptr()) + 0, out.val[0]);
520  vst1q_s32(reinterpret_cast<int32_t *>(output_y.ptr()) + 4, out.val[1]);
521  },
522  input_y, output_y);
523  }
524 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
virtual Format format() const =0
Colour format of the image.
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
Coordinates of an item.
Definition: Coordinates.h:37
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor&#39;s metadata.
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
size_t pixel_size_from_format(Format format)
The size in bytes of the pixel format.
Definition: Utils.h:146
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
virtual const Strides & strides_in_bytes() const =0
The strides in bytes for accessing each dimension of the tensor.
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: