Compute Library
 21.02
NEAbsoluteDifferenceKernel Class Reference

Interface for the absolute difference kernel. More...

#include <NEAbsoluteDifferenceKernel.h>

Collaboration diagram for NEAbsoluteDifferenceKernel:
[legend]

Public Member Functions

const char * name () const override
 Name of the kernel. More...
 
 NEAbsoluteDifferenceKernel ()
 Default constructor. More...
 
 NEAbsoluteDifferenceKernel (const NEAbsoluteDifferenceKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NEAbsoluteDifferenceKerneloperator= (const NEAbsoluteDifferenceKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NEAbsoluteDifferenceKernel (NEAbsoluteDifferenceKernel &&)=default
 Allow instances of this class to be moved. More...
 
NEAbsoluteDifferenceKerneloperator= (NEAbsoluteDifferenceKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~NEAbsoluteDifferenceKernel ()=default
 Default destructor. More...
 
void configure (const ITensor *input1, const ITensor *input2, ITensor *output)
 Set the inputs and output tensors. More...
 
void run (const Window &window, const ThreadInfo &info) override
 Execute the kernel on the passed window. 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...
 
virtual BorderSize border_size () const
 The size of the border for that kernel. More...
 
const Windowwindow () const
 The maximum window the kernel can be executed on. More...
 

Detailed Description

Interface for the absolute difference kernel.

Absolute difference is computed by:

\[ output(x,y) = | input1(x,y) - input2(x,y) | \]

Definition at line 38 of file NEAbsoluteDifferenceKernel.h.

Constructor & Destructor Documentation

◆ NEAbsoluteDifferenceKernel() [1/3]

Default constructor.

Definition at line 124 of file NEAbsoluteDifferenceKernel.cpp.

Referenced by NEAbsoluteDifferenceKernel::name().

125  : _func(nullptr), _input1(nullptr), _input2(nullptr), _output(nullptr)
126 {
127 }

◆ NEAbsoluteDifferenceKernel() [2/3]

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

◆ NEAbsoluteDifferenceKernel() [3/3]

Allow instances of this class to be moved.

◆ ~NEAbsoluteDifferenceKernel()

Default destructor.

Referenced by NEAbsoluteDifferenceKernel::name().

Member Function Documentation

◆ configure()

void configure ( const ITensor input1,
const ITensor input2,
ITensor output 
)

Set the inputs and output tensors.

Parameters
[in]input1Source tensor. Data types supported: U8/S16
[in]input2Source tensor. Data types supported: U8/S16
[out]outputDestination tensor, Data types supported: U8/S16

Definition at line 129 of file NEAbsoluteDifferenceKernel.cpp.

References ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN, ARM_COMPUTE_ERROR_ON_MISMATCHING_SHAPES, ARM_COMPUTE_ERROR_ON_MSG, ARM_COMPUTE_ERROR_ON_NULLPTR, arm_compute::calculate_max_window(), ITensorInfo::data_type(), ITensor::info(), arm_compute::intersect_valid_regions(), num_elems_processed_per_iteration, arm_compute::S16, arm_compute::set_format_if_unknown(), arm_compute::set_shape_if_empty(), ITensorInfo::tensor_shape(), arm_compute::U8, arm_compute::update_window_and_padding(), arm_compute::test::validation::valid_region, and ITensorInfo::valid_region().

Referenced by NEAbsoluteDifferenceKernel::name().

130 {
131  ARM_COMPUTE_ERROR_ON_NULLPTR(input1, input2, output);
132 
133  set_shape_if_empty(*output->info(), input1->info()->tensor_shape());
134 
135  if(input1->info()->data_type() == DataType::S16 || input2->info()->data_type() == DataType::S16)
136  {
137  set_format_if_unknown(*output->info(), Format::S16);
138  }
139  else if(input1->info()->data_type() == DataType::U8 || input2->info()->data_type() == DataType::U8)
140  {
141  set_format_if_unknown(*output->info(), Format::U8);
142  }
143 
144  ARM_COMPUTE_ERROR_ON_MISMATCHING_SHAPES(input1, input2, output);
148  ARM_COMPUTE_ERROR_ON_MSG(output->info()->data_type() == DataType::U8 && (input1->info()->data_type() != DataType::U8 || input2->info()->data_type() != DataType::U8),
149  "The output image can only be U8 if both input images are U8");
150 
151  _input1 = input1;
152  _input2 = input2;
153  _output = output;
154 
155  const DataType input1_data_type = input1->info()->data_type();
156  const DataType input2_data_type = input2->info()->data_type();
157 
158  if(input1_data_type == input2_data_type)
159  {
160  if(input1_data_type == DataType::U8)
161  {
162  _func = &abs_diff_U8_U8_U8;
163  }
164  else
165  {
166  _func = &abs_diff_S16_S16_S16;
167  }
168  }
169  else
170  {
171  if(input1_data_type == DataType::U8)
172  {
173  _func = &abs_diff_U8_S16_S16;
174  }
175  else
176  {
177  _func = &abs_diff_S16_U8_S16;
178  }
179  }
180 
181  constexpr unsigned int num_elems_processed_per_iteration = 16;
182 
183  // Configure kernel window
184  Window win = calculate_max_window(*input1->info(), Steps(num_elems_processed_per_iteration));
185  AccessWindowHorizontal output_access(output->info(), 0, num_elems_processed_per_iteration);
186 
188  AccessWindowHorizontal(input1->info(), 0, num_elems_processed_per_iteration),
189  AccessWindowHorizontal(input2->info(), 0, num_elems_processed_per_iteration),
190  output_access);
191 
192  ValidRegion valid_region = intersect_valid_regions(input1->info()->valid_region(),
193  input2->info()->valid_region());
194 
195  output_access.set_valid_region(win, valid_region);
196 
197  INEKernel::configure(win);
198 }
bool set_format_if_unknown(ITensorInfo &info, Format format)
Set the format, data type and number of channels to the specified value if the current data type is u...
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
1 channel, 1 U8 per channel
const ValidRegion valid_region
Definition: Scale.cpp:221
bool update_window_and_padding(Window &win, Ts &&... patterns)
Update window and padding size for each of the access patterns.
Definition: WindowHelpers.h:46
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
Definition: Error.h:456
#define ARM_COMPUTE_ERROR_ON_MISMATCHING_SHAPES(...)
Definition: Validate.h:441
bool set_shape_if_empty(ITensorInfo &info, const TensorShape &shape)
Set the shape to the specified value if the current assignment is empty.
ValidRegion intersect_valid_regions(const Ts &... regions)
Intersect multiple valid regions.
Definition: WindowHelpers.h:74
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
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
DataType
Available data types.
Definition: Types.h:77

◆ name()

◆ operator=() [1/2]

NEAbsoluteDifferenceKernel& operator= ( const NEAbsoluteDifferenceKernel )
delete

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

Referenced by NEAbsoluteDifferenceKernel::name().

◆ operator=() [2/2]

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 200 of file NEAbsoluteDifferenceKernel.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 NEAbsoluteDifferenceKernel::name().

201 {
205  ARM_COMPUTE_ERROR_ON(_func == nullptr);
206 
207  _func(_input1, _input2, _output, window);
208 }
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
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205

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