Compute Library
 21.02
NEDerivativeKernel Class Reference

Interface for the kernel to run the derivative along the X/Y directions on a tensor. More...

#include <NEDerivativeKernel.h>

Collaboration diagram for NEDerivativeKernel:
[legend]

Public Member Functions

const char * name () const override
 Name of the kernel. More...
 
 NEDerivativeKernel ()
 Default constructor. More...
 
 NEDerivativeKernel (const NEDerivativeKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NEDerivativeKerneloperator= (const NEDerivativeKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NEDerivativeKernel (NEDerivativeKernel &&)=default
 Allow instances of this class to be moved. More...
 
NEDerivativeKerneloperator= (NEDerivativeKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~NEDerivativeKernel ()=default
 Default destructor. More...
 
void configure (const ITensor *input, ITensor *output_x, ITensor *output_y, bool border_undefined)
 Initialise the kernel's sources, 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 the derivative along the X/Y directions on a tensor.

Definition at line 36 of file NEDerivativeKernel.h.

Constructor & Destructor Documentation

◆ NEDerivativeKernel() [1/3]

Default constructor.

Definition at line 46 of file NEDerivativeKernel.cpp.

Referenced by NEDerivativeKernel::name().

47  : _func(nullptr), _input(nullptr), _output_x(nullptr), _output_y(nullptr)
48 {
49 }

◆ NEDerivativeKernel() [2/3]

NEDerivativeKernel ( const NEDerivativeKernel )
delete

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

◆ NEDerivativeKernel() [3/3]

Allow instances of this class to be moved.

◆ ~NEDerivativeKernel()

~NEDerivativeKernel ( )
default

Default destructor.

Referenced by NEDerivativeKernel::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 51 of file NEDerivativeKernel.cpp.

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

52 {
53  return BorderSize(1);
54 }
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 sources, 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 56 of file NEDerivativeKernel.cpp.

References ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN, NEDerivativeKernel::border_size(), arm_compute::calculate_max_window(), arm_compute::execute_window_loop(), ITensor::info(), arm_compute::test::validation::input, BorderSize::left, num_elems_processed_per_iteration, Iterator::ptr(), arm_compute::S16, ITensorInfo::strides_in_bytes(), BorderSize::top, arm_compute::U8, arm_compute::update_window_and_padding(), ITensorInfo::valid_region(), and IKernel::window().

Referenced by NEDerivativeKernel::name().

57 {
59  ARM_COMPUTE_ERROR_ON((output_x == nullptr) && (output_y == nullptr));
60 
61  const bool run_der_x = output_x != nullptr;
62  const bool run_der_y = output_y != nullptr;
63 
64  if(run_der_x)
65  {
67  }
68 
69  if(run_der_y)
70  {
72  }
73 
74  _input = input;
75  _output_x = output_x;
76  _output_y = output_y;
77 
78  constexpr unsigned int num_elems_processed_per_iteration = 16;
79  constexpr unsigned int num_rows_read_per_iteration = 3;
80 
81  Window win = calculate_max_window(*input->info(), Steps(num_elems_processed_per_iteration), border_undefined, border_size());
82 
83  AccessWindowHorizontal out_x_access(output_x == nullptr ? nullptr : output_x->info(), 0, num_elems_processed_per_iteration);
84  AccessWindowHorizontal out_y_access(output_y == nullptr ? nullptr : output_y->info(), 0, num_elems_processed_per_iteration);
85 
86  // TODO(COMPMID-1503) Fix x-access input bug in Neon kernel instead of '+2'
87  AccessWindowHorizontal in_x_access(input->info(), -border_size().left, num_elems_processed_per_iteration + 2);
88  AccessWindowRectangle in_y_access(input->info(), 0, -border_size().left, num_elems_processed_per_iteration, num_rows_read_per_iteration);
89 
90  // TODO(COMPMID-1503) Fix x-access input bug in Neon kernel instead of '+2'
91  AccessWindowRectangle in_xy_access(input->info(), -border_size().left, -border_size().top, num_elems_processed_per_iteration + 2, num_rows_read_per_iteration);
92 
93  if(run_der_x && run_der_y)
94  {
95  _func = &NEDerivativeKernel::derivative_xy;
96  update_window_and_padding(win, in_xy_access, out_x_access, out_y_access);
97  out_y_access.set_valid_region(win, input->info()->valid_region(), border_undefined, border_size());
98  out_x_access.set_valid_region(win, input->info()->valid_region(), border_undefined, border_size());
99  }
100  else
101  {
102  if(run_der_x)
103  {
104  _func = &NEDerivativeKernel::derivative_x;
105  update_window_and_padding(win, in_x_access, out_x_access);
106  out_x_access.set_valid_region(win, input->info()->valid_region(), border_undefined, border_size());
107  }
108  else if(run_der_y)
109  {
110  _func = &NEDerivativeKernel::derivative_y;
111  update_window_and_padding(win, in_y_access, out_y_access);
112  out_y_access.set_valid_region(win, input->info()->valid_region(), border_undefined, border_size());
113  }
114  else
115  {
116  ARM_COMPUTE_ERROR("At least one output must be NOT NULL");
117  }
118  }
119 
120  INEKernel::configure(win);
121 }
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)
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
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
BorderSize border_size() const override
The size of the border for that kernel.
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

◆ name()

◆ operator=() [1/2]

NEDerivativeKernel& operator= ( const NEDerivativeKernel )
delete

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

Referenced by NEDerivativeKernel::name().

◆ operator=() [2/2]

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

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, and IKernel::window().

Referenced by NEDerivativeKernel::name().

224 {
225  ARM_COMPUTE_UNUSED(info);
228  ARM_COMPUTE_ERROR_ON(_func == nullptr);
229 
230  (this->*_func)(window);
231 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
#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_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:941
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205

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