Compute Library
 21.02
NEIntegralImageKernel Class Reference

Kernel to perform an image integral on an image. More...

#include <NEIntegralImageKernel.h>

Collaboration diagram for NEIntegralImageKernel:
[legend]

Public Member Functions

const char * name () const override
 Name of the kernel. More...
 
 NEIntegralImageKernel ()=default
 Default constructor. More...
 
 NEIntegralImageKernel (const NEIntegralImageKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NEIntegralImageKerneloperator= (const NEIntegralImageKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NEIntegralImageKernel (NEIntegralImageKernel &&)=delete
 Prevent instances of this class from being moved (As this class contains non movable objects) More...
 
NEIntegralImageKerneloperator= (NEIntegralImageKernel &&)=delete
 Prevent instances of this class from being moved (As this class contains non movable objects) More...
 
 ~NEIntegralImageKernel ()=default
 Default destructor. More...
 
void configure (const ITensor *input, ITensor *output)
 Set the source, destination and border mode of the kernel. 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...
 
bool is_parallelisable () const override
 Indicates whether or not the kernel is parallelisable. More...
 
- Public Member Functions inherited from ICPPSimpleKernel
 ICPPSimpleKernel ()
 Constructor. More...
 
 ICPPSimpleKernel (const ICPPSimpleKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
ICPPSimpleKerneloperator= (const ICPPSimpleKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 ICPPSimpleKernel (ICPPSimpleKernel &&)=default
 Allow instances of this class to be moved. More...
 
ICPPSimpleKerneloperator= (ICPPSimpleKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~ICPPSimpleKernel ()=default
 Default destructor. 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...
 
const Windowwindow () const
 The maximum window the kernel can be executed on. More...
 

Detailed Description

Kernel to perform an image integral on an image.

Definition at line 34 of file NEIntegralImageKernel.h.

Constructor & Destructor Documentation

◆ NEIntegralImageKernel() [1/3]

NEIntegralImageKernel ( )
default

Default constructor.

Referenced by NEIntegralImageKernel::name().

◆ NEIntegralImageKernel() [2/3]

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

◆ NEIntegralImageKernel() [3/3]

Prevent instances of this class from being moved (As this class contains non movable objects)

◆ ~NEIntegralImageKernel()

~NEIntegralImageKernel ( )
default

Default destructor.

Referenced by NEIntegralImageKernel::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 66 of file NEIntegralImageKernel.cpp.

Referenced by NEIntegralImageKernel::name().

67 {
68  return BorderSize{ 1, 0, 0, 1 };
69 }
Container for 2D border size.
Definition: Types.h:273

◆ configure()

void configure ( const ITensor input,
ITensor output 
)

Set the source, destination and border mode of the kernel.

Parameters
[in]inputSource tensor. Data type supported: U8
[out]outputDestination tensor. Data type supported: U32

Definition at line 40 of file NEIntegralImageKernel.cpp.

References ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN, arm_compute::calculate_max_window(), ITensor::info(), arm_compute::test::validation::input, num_elems_processed_per_iteration, arm_compute::U32, arm_compute::U8, arm_compute::update_window_and_padding(), and ITensorInfo::valid_region().

Referenced by NEIntegralImageKernel::name().

41 {
44 
45  _input = input;
46  _output = output;
47 
48  constexpr unsigned int num_elems_processed_per_iteration = 16;
49 
50  // Configure kernel window
51  Window win = calculate_max_window(*input->info(), Steps(num_elems_processed_per_iteration));
52  // The kernel is effectively reading 17 values from -1 as it loads 16
53  // starting at -1 and also 16 starting at 0
54  AccessWindowRectangle output_read_access(output->info(), -1, -1, num_elems_processed_per_iteration + 1, 1);
55  AccessWindowHorizontal output_write_access(output->info(), 0, num_elems_processed_per_iteration);
56 
59  output_read_access, output_write_access);
60 
61  output_write_access.set_valid_region(win, input->info()->valid_region());
62 
63  IKernel::configure(win);
64 }
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
1 channel, 1 U8 per channel
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
1 channel, 1 U32 per channel
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.
#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

◆ is_parallelisable()

bool is_parallelisable ( ) const
overridevirtual

Indicates whether or not the kernel is parallelisable.

If the kernel is parallelisable then the window returned by window() can be split into sub-windows which can then be run in parallel.

If the kernel is not parallelisable then only the window returned by window() can be passed to run()

Returns
True if the kernel is parallelisable

Reimplemented from IKernel.

Definition at line 71 of file NEIntegralImageKernel.cpp.

Referenced by NEIntegralImageKernel::name().

72 {
73  return false;
74 }

◆ name()

◆ operator=() [1/2]

NEIntegralImageKernel& operator= ( const NEIntegralImageKernel )
delete

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

Referenced by NEIntegralImageKernel::name().

◆ operator=() [2/2]

NEIntegralImageKernel& operator= ( NEIntegralImageKernel &&  )
delete

Prevent instances of this class from being moved (As this class contains non movable objects)

◆ 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 76 of file NEIntegralImageKernel.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::offset(), Iterator::ptr(), ITensor::ptr_to_element(), and IKernel::window().

Referenced by NEIntegralImageKernel::name().

77 {
78  ARM_COMPUTE_UNUSED(info);
81 
82  Iterator input(_input, window);
83  Iterator output(_output, window);
84 
85  const auto output_top_left = reinterpret_cast<const uint32_t *>(_output->ptr_to_element(Coordinates(-1, -1)));
86  const auto output_top_mid = reinterpret_cast<const uint32_t *>(_output->ptr_to_element(Coordinates(0, -1)));
87 
88  execute_window_loop(window, [&](const Coordinates &)
89  {
90  const uint8x16_t input_pixels = vld1q_u8(input.ptr());
91 
92  const uint16x8x2_t tmp =
93  {
94  {
95  vmovl_u8(vget_low_u8(input_pixels)),
96  vmovl_u8(vget_high_u8(input_pixels))
97  }
98  };
99 
100  uint32x4x4_t pixels =
101  {
102  {
103  vmovl_u16(vget_low_u16(tmp.val[0])),
104  vmovl_u16(vget_high_u16(tmp.val[0])),
105  vmovl_u16(vget_low_u16(tmp.val[1])),
106  vmovl_u16(vget_high_u16(tmp.val[1]))
107  }
108  };
109 
110  // Divide by four as pointer is now uint32 instead of uint8!
111  const size_t off = output.offset() / 4;
112 
113  // Add top mid pixel values
114  const uint32_t *const top_mid_ptr = output_top_mid + off;
115 
116  pixels.val[0] = vaddq_u32(vld1q_u32(top_mid_ptr), pixels.val[0]);
117  pixels.val[1] = vaddq_u32(vld1q_u32(top_mid_ptr + 4), pixels.val[1]);
118  pixels.val[2] = vaddq_u32(vld1q_u32(top_mid_ptr + 8), pixels.val[2]);
119  pixels.val[3] = vaddq_u32(vld1q_u32(top_mid_ptr + 12), pixels.val[3]);
120 
121  // Subtract top left diagonal values
122  const auto outptr = reinterpret_cast<uint32_t *>(output.ptr());
123  const uint32_t *const top_left_ptr = output_top_left + off;
124 
125  pixels.val[0] = vsubq_u32(pixels.val[0], vld1q_u32(top_left_ptr));
126  vst1q_u32(outptr, pixels.val[0]);
127 
128  pixels.val[1] = vsubq_u32(pixels.val[1], vld1q_u32(top_left_ptr + 4));
129  vst1q_u32(outptr + 4, pixels.val[1]);
130 
131  pixels.val[2] = vsubq_u32(pixels.val[2], vld1q_u32(top_left_ptr + 8));
132  vst1q_u32(outptr + 8, pixels.val[2]);
133 
134  pixels.val[3] = vsubq_u32(pixels.val[3], vld1q_u32(top_left_ptr + 12));
135  vst1q_u32(outptr + 12, pixels.val[3]);
136 
137  // Perform prefix summation
138  for(auto i = 0; i < 16; ++i)
139  {
140  outptr[i] += outptr[i - 1];
141  }
142  },
143  input, output);
144 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
uint8_t * ptr_to_element(const Coordinates &id) const
Return a pointer to the element at the passed coordinates.
Definition: ITensor.h:63
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
Coordinates of an item.
Definition: Coordinates.h:37
#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: