Compute Library
CpuFillKernel Class Reference

Kernel for filling a tensor with a given constant value. More...

#include <CpuFillKernel.h>

Collaboration diagram for CpuFillKernel:

Public Member Functions

 CpuFillKernel ()=default
void configure (const ITensorInfo *tensor, const PixelValue &constant_value)
 Configure kernel for a given list of arguments. More...
void run_op (ITensorPack &tensors, const Window &window, const ThreadInfo &info) override
 Execute the kernel on the passed window. More...
const char * name () const override
 Name of the kernel. More...
- Public Member Functions inherited from ICPPKernel
virtual ~ICPPKernel ()=default
 Default destructor. More...
virtual void run (const Window &window, const ThreadInfo &info)
 Execute the kernel on the passed window. 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...
- 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...
bool is_window_configured () const
 Function to check if the embedded window of this kernel has been configured. More...

Detailed Description

Kernel for filling a tensor with a given constant value.

Definition at line 38 of file CpuFillKernel.h.

Constructor & Destructor Documentation

◆ CpuFillKernel()

CpuFillKernel ( )

Member Function Documentation



◆ configure()

void configure ( const ITensorInfo tensor,
const PixelValue constant_value 

Configure kernel for a given list of arguments.

[in,out]tensorTensor to fill. Supported data types: All
[in]constant_valueThe value used to fill the planes of the tensor

Definition at line 40 of file CpuFillKernel.cpp.

References ARM_COMPUTE_ERROR_ON_NULLPTR, and arm_compute::calculate_max_window().

41 {
43  _constant_value = constant_value;
45  // Configure kernel window
46  Window win = calculate_max_window(*tensor, Steps());
47  ICpuKernel::configure(win);
48 }
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
Definition: Validate.h:157

◆ name()

const char * name ( ) const

Name of the kernel.

Kernel name

Implements ICPPKernel.

Definition at line 84 of file CpuFillKernel.cpp.

85 {
86  return "CpuFillKernel";
87 }

◆ run_op()

void run_op ( ITensorPack tensors,
const Window window,
const ThreadInfo info 

Execute the kernel on the passed window.

If is_parallelisable() returns false then the passed window must be equal to window()
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().
[in]tensorsA vector containing the tensors to operate on.
[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 50 of file CpuFillKernel.cpp.

References arm_compute::ACL_SRC_DST, 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, Window::Dimension::end(), arm_compute::execute_window_loop(), ITensorPack::get_tensor(), Iterator::offset(), Window::set(), Window::Dimension::start(), PixelValue::value, IKernel::window(), and Window::x().

51 {
56  auto inout = tensors.get_tensor(TensorType::ACL_SRC_DST);
58  // Collapse all the batches on the third dimension
59  bool has_collapsed = true;
60  Window collapsed = window.collapse_if_possible(window, Window::DimZ, &has_collapsed);
61  ARM_COMPUTE_ERROR_ON(!has_collapsed);
63  uint8_t *const start_valid_region = inout->ptr_to_element(inout->info()->valid_region().anchor);
64  const auto window_width = static_cast<int>(collapsed.x().end()) - static_cast<int>(collapsed.x().start());
65  const size_t element_size = inout->info()->element_size();
67  // Unroll X dimension
68  collapsed.set(Window::DimX, Window::Dimension(0, 1, 1));
70  Iterator tensor_it(inout, collapsed);
71  execute_window_loop(collapsed, [&](const Coordinates &)
72  {
73  uint8_t *base_addr = start_valid_region + tensor_it.offset();
74  // Set memory
75  for(int i = 0; i < window_width; ++i)
76  {
77  std::memcpy(base_addr + i * element_size, &_constant_value.value, element_size);
78  }
80  },
81  tensor_it);
82 }
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
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
Definition: Window.h:43
To avoid unused variables warnings.
Definition: Error.h:152
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:68
union arm_compute::PixelValue::@0 value
Union which describes the value of a pixel for any image format.
Definition: Validate.h:915
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
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:77
Definition: Validate.h:201

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