Compute Library
 21.02
NEConvolutionRectangleKernel Class Reference

Kernel for the running convolution on a rectangle matrix. More...

#include <NEConvolutionKernel.h>

Collaboration diagram for NEConvolutionRectangleKernel:
[legend]

Public Member Functions

const char * name () const override
 Name of the kernel. More...
 
 NEConvolutionRectangleKernel ()
 Default constructor. More...
 
 NEConvolutionRectangleKernel (NEConvolutionRectangleKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NEConvolutionRectangleKerneloperator= (NEConvolutionRectangleKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NEConvolutionRectangleKernel (NEConvolutionRectangleKernel &&)=default
 Allow instances of this class to be moved. More...
 
NEConvolutionRectangleKerneloperator= (NEConvolutionRectangleKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~NEConvolutionRectangleKernel ()=default
 Default destructor. More...
 
void configure (const ITensor *input, ITensor *output, const int16_t *conv, uint32_t width, uint32_t height, uint32_t scale, bool border_undefined)
 Initialise the kernel's input, output 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

Kernel for the running convolution on a rectangle matrix.

Note
Supports combinations of 3,5,7 and 9.

Definition at line 242 of file NEConvolutionKernel.h.

Constructor & Destructor Documentation

◆ NEConvolutionRectangleKernel() [1/3]

Default constructor.

Definition at line 1419 of file NEConvolutionKernel.cpp.

1420  : _input(nullptr), _output(nullptr), _scale(0), _convolution(), _border_size(), _func_idx(0)
1421 {
1422 }

◆ NEConvolutionRectangleKernel() [2/3]

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

◆ NEConvolutionRectangleKernel() [3/3]

Allow instances of this class to be moved.

◆ ~NEConvolutionRectangleKernel()

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 1424 of file NEConvolutionKernel.cpp.

1425 {
1426  return _border_size;
1427 }

◆ configure()

void configure ( const ITensor input,
ITensor output,
const int16_t *  conv,
uint32_t  width,
uint32_t  height,
uint32_t  scale,
bool  border_undefined 
)

Initialise the kernel's input, output and border mode.

Parameters
[in]inputSource tensor. Data type supported: U8.
[out]outputDestination tensor, Data types supported: U8, S16.
[in]convConvolution matrix to apply to the input tensor.
[in]widthWidth of convolution matrix (Number of columns)
[in]heightHeight of convolution matrix (Number of rows)
[in]scaleScale of the convolution matrix. If 0 is passed, it will be set to the sum of the coefficients of the convolution or 1 if they add up to 0.
[in]border_undefinedTrue if the border mode is undefined. False if it's replicate or constant.

Definition at line 1429 of file NEConvolutionKernel.cpp.

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN, ARM_COMPUTE_ERROR_ON_MISMATCHING_SHAPES, ARM_COMPUTE_ERROR_ON_NULLPTR, arm_compute::calculate_max_window(), ITensor::info(), arm_compute::test::validation::input, BorderSize::left, num_elems_processed_per_iteration, arm_compute::S16, arm_compute::test::validation::scale, arm_compute::set_shape_if_empty(), ITensorInfo::tensor_shape(), BorderSize::top, arm_compute::U8, arm_compute::update_window_and_padding(), and ITensorInfo::valid_region().

1430 {
1431  ARM_COMPUTE_ERROR_ON_NULLPTR(input, output, conv);
1432 
1433  set_shape_if_empty(*output->info(), input->info()->tensor_shape());
1434 
1438  ARM_COMPUTE_ERROR_ON(width != 3 && width != 5 && width != 7 && width != 9);
1439  ARM_COMPUTE_ERROR_ON(height != 3 && height != 5 && height != 7 && height != 9);
1441 
1442  _input = input;
1443  _output = output;
1444  _scale = scale;
1445  _border_size = BorderSize(height / 2, width / 2);
1446 
1447  // Setup the convolution matrix
1448  const uint32_t nr_elements = width * height;
1449  _convolution.resize(nr_elements);
1450  std::copy_n(conv, nr_elements, _convolution.begin());
1451 
1452  // Set function index to help choose appropriate function in run()
1453  _func_idx = get_index(height) * 4 + get_index(width);
1454  ARM_COMPUTE_ERROR_ON(_func_idx > (_nr_supported_sizes * _nr_supported_sizes));
1455 
1456  // Configure kernel window
1457  constexpr unsigned int num_elems_processed_per_iteration = 8;
1458  constexpr unsigned int num_elems_read_per_iteration = 16;
1459  constexpr unsigned int num_elems_written_per_iteration = 8;
1460 
1461  Window win = calculate_max_window(*input->info(), Steps(num_elems_processed_per_iteration), border_undefined, _border_size);
1462  AccessWindowHorizontal output_access(output->info(), 0, num_elems_written_per_iteration);
1463 
1465  AccessWindowRectangle(input->info(), -_border_size.left, -_border_size.top, num_elems_read_per_iteration, height),
1466  output_access);
1467 
1468  output_access.set_valid_region(win, input->info()->valid_region(), border_undefined, _border_size);
1469 
1470  INEKernel::configure(win);
1471 }
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
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_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.
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
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161

◆ name()

◆ operator=() [1/2]

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

◆ 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 1473 of file NEConvolutionKernel.cpp.

References ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, ITensor::buffer(), caffe_mnist_image_extractor::cols, ITensorInfo::data_type(), arm_compute::execute_window_loop(), ITensor::info(), arm_compute::test::validation::input, ITensorInfo::offset_element_in_bytes(), Iterator::ptr(), caffe_mnist_image_extractor::rows, arm_compute::S16, arm_compute::detail::store_results(), arm_compute::U8, and IKernel::window().

1474 {
1478 
1479  using ConvolutionRectangleFunction = void (NEConvolutionRectangleKernel::*)(const Window & window);
1480 
1481  // uint8_t function table
1482  static const std::array<ConvolutionRectangleFunction, 16> func_table_u8 =
1483  {
1484  {
1485  &NEConvolutionRectangleKernel::convolution<uint8_t, 3, 3>,
1486  &NEConvolutionRectangleKernel::convolution<uint8_t, 3, 5>,
1487  &NEConvolutionRectangleKernel::convolution<uint8_t, 3, 7>,
1488  &NEConvolutionRectangleKernel::convolution<uint8_t, 3, 9>,
1489  &NEConvolutionRectangleKernel::convolution<uint8_t, 5, 3>,
1490  &NEConvolutionRectangleKernel::convolution<uint8_t, 5, 5>,
1491  &NEConvolutionRectangleKernel::convolution<uint8_t, 5, 7>,
1492  &NEConvolutionRectangleKernel::convolution<uint8_t, 5, 9>,
1493  &NEConvolutionRectangleKernel::convolution<uint8_t, 7, 3>,
1494  &NEConvolutionRectangleKernel::convolution<uint8_t, 7, 5>,
1495  &NEConvolutionRectangleKernel::convolution<uint8_t, 7, 7>,
1496  &NEConvolutionRectangleKernel::convolution<uint8_t, 7, 9>,
1497  &NEConvolutionRectangleKernel::convolution<uint8_t, 9, 3>,
1498  &NEConvolutionRectangleKernel::convolution<uint8_t, 9, 5>,
1499  &NEConvolutionRectangleKernel::convolution<uint8_t, 9, 7>,
1500  &NEConvolutionRectangleKernel::convolution<uint8_t, 9, 9>
1501  }
1502  };
1503  // int16_t function table
1504  static const std::array<ConvolutionRectangleFunction, 16> func_table_s16 =
1505  {
1506  {
1507  &NEConvolutionRectangleKernel::convolution<int16_t, 3, 3>,
1508  &NEConvolutionRectangleKernel::convolution<int16_t, 3, 5>,
1509  &NEConvolutionRectangleKernel::convolution<int16_t, 3, 7>,
1510  &NEConvolutionRectangleKernel::convolution<int16_t, 3, 9>,
1511  &NEConvolutionRectangleKernel::convolution<int16_t, 5, 3>,
1512  &NEConvolutionRectangleKernel::convolution<int16_t, 5, 5>,
1513  &NEConvolutionRectangleKernel::convolution<int16_t, 5, 7>,
1514  &NEConvolutionRectangleKernel::convolution<int16_t, 5, 9>,
1515  &NEConvolutionRectangleKernel::convolution<int16_t, 7, 3>,
1516  &NEConvolutionRectangleKernel::convolution<int16_t, 7, 5>,
1517  &NEConvolutionRectangleKernel::convolution<int16_t, 7, 7>,
1518  &NEConvolutionRectangleKernel::convolution<int16_t, 7, 9>,
1519  &NEConvolutionRectangleKernel::convolution<int16_t, 9, 3>,
1520  &NEConvolutionRectangleKernel::convolution<int16_t, 9, 5>,
1521  &NEConvolutionRectangleKernel::convolution<int16_t, 9, 7>,
1522  &NEConvolutionRectangleKernel::convolution<int16_t, 9, 9>
1523  }
1524  };
1525 
1526  // Run appropriate function
1527  switch(_output->info()->data_type())
1528  {
1529  case DataType::U8:
1530  ARM_COMPUTE_ERROR_ON(_func_idx >= func_table_u8.size());
1531  (this->*func_table_u8[_func_idx])(window);
1532  break;
1533  case DataType::S16:
1534  ARM_COMPUTE_ERROR_ON(_func_idx >= func_table_s16.size());
1535  (this->*func_table_s16[_func_idx])(window);
1536  break;
1537  default:
1538  ARM_COMPUTE_ERROR("Not supported");
1539  }
1540 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
#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
virtual DataType data_type() const =0
Data type used for each element of the tensor.
#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
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor&#39;s metadata.
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:941
1 channel, 1 S16 per channel
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: