Compute Library
 19.08
NEMemsetKernel Class Reference

Interface for filling the planes of a tensor. More...

#include <NEMemsetKernel.h>

Collaboration diagram for NEMemsetKernel:
[legend]

Public Member Functions

const char * name () const override
 Name of the kernel. More...
 
 NEMemsetKernel ()
 Default constructor. More...
 
 ~NEMemsetKernel ()=default
 Default destructor. More...
 
 NEMemsetKernel (const NEMemsetKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NEMemsetKerneloperator= (const NEMemsetKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NEMemsetKernel (NEMemsetKernel &&)=default
 Allow instances of this class to be moved. More...
 
NEMemsetKerneloperator= (NEMemsetKernel &&)=default
 Allow instances of this class to be moved. More...
 
void configure (ITensor *tensor, const PixelValue &constant_value)
 Initialise the kernel's tensor and filling value. 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...
 
- 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 filling the planes of a tensor.

Definition at line 37 of file NEMemsetKernel.h.

Constructor & Destructor Documentation

◆ NEMemsetKernel() [1/3]

Default constructor.

Definition at line 35 of file NEMemsetKernel.cpp.

36  : _tensor(nullptr), _constant_value()
37 {
38 }

◆ ~NEMemsetKernel()

~NEMemsetKernel ( )
default

Default destructor.

◆ NEMemsetKernel() [2/3]

NEMemsetKernel ( const NEMemsetKernel )
delete

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

◆ NEMemsetKernel() [3/3]

NEMemsetKernel ( NEMemsetKernel &&  )
default

Allow instances of this class to be moved.

Member Function Documentation

◆ configure()

void configure ( ITensor tensor,
const PixelValue constant_value 
)

Initialise the kernel's tensor and filling value.

Parameters
[in,out]tensorInput tensor to fill. Supported data types: U8/S8/QASYMM8/U16/S16/F16/U32/S32/F32
[in]constant_valueThe value used to fill the planes of the tensor

Definition at line 40 of file NEMemsetKernel.cpp.

41 {
43  _tensor = tensor;
44  _constant_value = constant_value;
45 
46  // Configure kernel window
47  Window win = calculate_max_window(*tensor->info(), Steps());
48  INEKernel::configure(win);
49 }
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps=Steps(), bool skip_border=false, BorderSize border_size=BorderSize())
Calculate the maximum window for a given tensor shape and border setting.
Definition: Helpers.cpp:28
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161

References ARM_COMPUTE_ERROR_ON_NULLPTR, arm_compute::calculate_max_window(), and ITensor::info().

Referenced by NESpaceToBatchLayer::configure().

◆ name()

const char* name ( ) const
inlineoverridevirtual

Name of the kernel.

Returns
Kernel name

Implements ICPPKernel.

Definition at line 40 of file NEMemsetKernel.h.

41  {
42  return "NEMemsetKernel";
43  }

◆ operator=() [1/2]

NEMemsetKernel& operator= ( const NEMemsetKernel )
delete

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

◆ operator=() [2/2]

NEMemsetKernel& operator= ( NEMemsetKernel &&  )
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.

Implements ICPPKernel.

Definition at line 51 of file NEMemsetKernel.cpp.

52 {
56 
57  // Collapse all the batches on the third dimension
58  bool has_collapsed = true;
59  Window collapsed = window.collapse_if_possible(window, Window::DimZ, &has_collapsed);
60  ARM_COMPUTE_ERROR_ON(!has_collapsed);
61 
62  uint8_t *const start_valid_region = _tensor->ptr_to_element(_tensor->info()->valid_region().anchor);
63  const auto window_width = static_cast<int>(collapsed.x().end()) - static_cast<int>(collapsed.x().start());
64  const size_t element_size = _tensor->info()->element_size();
65 
66  // Unroll X dimension
67  collapsed.set(Window::DimX, Window::Dimension(0, 1, 1));
68 
69  Iterator tensor_it(_tensor, collapsed);
70  execute_window_loop(collapsed, [&](const Coordinates &)
71  {
72  uint8_t *base_addr = start_valid_region + tensor_it.offset();
73  // Set memory
74  for(int i = 0; i < window_width; ++i)
75  {
76  std::memcpy(base_addr + i * element_size, &_constant_value.value, element_size);
77  }
78 
79  },
80  tensor_it);
81 }
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_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:337
virtual ValidRegion valid_region() const =0
Valid region of the tensor.
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
Definition: Window.h:43
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:160
Window collapse_if_possible(const Window &full_window, size_t first, size_t last, bool *has_collapsed=nullptr) const
Collapse the dimensions between first and last if possible.
Definition: Window.inl:54
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
virtual size_t element_size() const =0
Element size in bytes calculated as data_size() * num_channels()
union arm_compute::PixelValue::@0 value
Union which describes the value of a pixel for any image format.
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
Definition: Window.h:47
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:122
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:940
Coordinates anchor
Anchor for the start of the valid region.
Definition: Types.h:246

References ValidRegion::anchor, ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, Window::collapse_if_possible(), Window::DimX, Window::DimZ, ITensorInfo::element_size(), Window::Dimension::end(), arm_compute::execute_window_loop(), ITensor::info(), arm_compute::test::validation::info, Iterator::offset(), ITensor::ptr_to_element(), Window::set(), Window::Dimension::start(), ITensorInfo::valid_region(), PixelValue::value, IKernel::window(), and Window::x().


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