Compute Library
CpuCopyKernel Class Reference

Kernel to perform a copy between two tensors. More...

#include <CpuCopyKernel.h>

Collaboration diagram for CpuCopyKernel:

Public Member Functions

 CpuCopyKernel ()=default
void configure (const ITensorInfo *src, ITensorInfo *dst, const PaddingList &padding=PaddingList())
 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...

Static Public Member Functions

static Status validate (const ITensorInfo *src, const ITensorInfo *dst, const PaddingList &padding=PaddingList())
 Static function to check if given info will lead to a valid configuration. More...

Detailed Description

Kernel to perform a copy between two tensors.

Definition at line 37 of file CpuCopyKernel.h.

Constructor & Destructor Documentation

◆ CpuCopyKernel()

CpuCopyKernel ( )

Member Function Documentation



◆ configure()

void configure ( const ITensorInfo src,
ITensorInfo dst,
const PaddingList padding = PaddingList() 

Configure kernel for a given list of arguments.

[in]srcSource tensor. Data types supported: All
[out]dstDestination tensor. Data types supported: same as src.
[in]padding(Optional) Padding to be applied to the input tensor

Definition at line 79 of file CpuCopyKernel.cpp.


80 {
82  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(src, dst, padding));
84  _padding = padding;
86  std::pair<Status, Window> win_config;
87  if(padding.empty())
88  {
89  win_config = validate_and_configure_window(src, dst);
90  }
91  else
92  {
93  win_config = validate_and_configure_window_with_padding(src, dst, padding);
94  }
96  ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
97  ICpuKernel::configure(win_config.second);
98 }
Definition: Error.h:455
SimpleTensor< float > src
Definition: DFT.cpp:155
Definition: Validate.h:157

◆ name()

const char * name ( ) const

Name of the kernel.

Kernel name

Implements ICPPKernel.

Definition at line 160 of file CpuCopyKernel.cpp.

161 {
162  return "CpuCopyKernel";
163 }

◆ 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 116 of file CpuCopyKernel.cpp.

References arm_compute::ACL_DST, arm_compute::ACL_SRC, ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, Window::DimX, Window::Dimension::end(), arm_compute::execute_window_loop(), Window::first_slice_window_1D(), ITensorPack::get_const_tensor(), ITensorPack::get_tensor(), Iterator::ptr(), Window::set(), IKernel::window(), and Window::x().

117 {
122  const auto src = tensors.get_const_tensor(TensorType::ACL_SRC);
123  auto dst = tensors.get_tensor(TensorType::ACL_DST);
125  if(_padding.empty())
126  {
127  Window dst_window{ window };
128  dst_window.set(Window::DimX, Window::Dimension(dst_window.x().start(), dst_window.x().end(), src->info()->dimension(0)));
129  Window out_slice = dst_window.first_slice_window_1D();
130  do
131  {
132  Iterator src_it(src, out_slice);
133  Iterator dst_it(dst, out_slice);
135  execute_window_loop(out_slice, [&](const Coordinates &)
136  {
137  memcpy(dst_it.ptr(), src_it.ptr(), dst->info()->dimension(0) * dst->info()->element_size());
138  },
139  src_it, dst_it);
140  }
141  while(dst_window.slide_window_slice_1D(out_slice));
142  }
143  else
144  {
145  Window src_window{ window };
146  src_window.set(Window::DimX, Window::Dimension(0, window.x().end() - _padding[0].first, src->info()->dimension(0)));
148  Iterator src_it(src, src_window);
149  Iterator dst_it(dst, window);
150  const size_t row_size_in_bytes = src->info()->dimension(0) * src->info()->element_size();
151  execute_window_loop(window, [&](const Coordinates &)
152  {
153  auto dst_ptr = dst_it.ptr() + _padding[0].first * dst->info()->element_size();
154  std::memcpy(dst_ptr, src_it.ptr(), row_size_in_bytes);
155  },
156  src_it, dst_it);
157  }
158 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
SimpleTensor< float > src
Definition: DFT.cpp:155
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
void set(size_t dimension, const Dimension &dim)
Set the values of a given dimension.
Definition: Window.inl:49
Definition: Validate.h:915
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
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
constexpr int end() const
Return the end of the dimension.
Definition: Window.h:99
Definition: Validate.h:201
constexpr const Dimension & x() const
Alias to access the first dimension of the window.
Definition: Window.h:145

◆ validate()

Status validate ( const ITensorInfo src,
const ITensorInfo dst,
const PaddingList padding = PaddingList() 

Static function to check if given info will lead to a valid configuration.

Similar to CpuCopyKernel::configure()

a status

Definition at line 100 of file CpuCopyKernel.cpp.

References ARM_COMPUTE_RETURN_ON_ERROR, and ICloneable< T >::clone().

Referenced by CpuCopy::validate().

101 {
102  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(src, dst, padding));
104  if(padding.empty())
105  {
106  ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(src->clone().get(), dst->clone().get()).first);
107  }
108  else
109  {
110  ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window_with_padding(src->clone().get(), dst->clone().get(), padding).first);
111  }
113  return Status{};
114 }
Checks if a status contains an error and returns it.
Definition: Error.h:204
SimpleTensor< float > src
Definition: DFT.cpp:155

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