Compute Library
 21.08
CPPUpsampleKernel Class Reference

CPP kernel to perform tensor upsample. More...

#include <CPPUpsampleKernel.h>

Collaboration diagram for CPPUpsampleKernel:
[legend]

Public Member Functions

const char * name () const override
 Name of the kernel. More...
 
 CPPUpsampleKernel ()
 Default constructor. More...
 
 CPPUpsampleKernel (const CPPUpsampleKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
CPPUpsampleKerneloperator= (const CPPUpsampleKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 CPPUpsampleKernel (CPPUpsampleKernel &&)=default
 Allow instances of this class to be moved. More...
 
CPPUpsampleKerneloperator= (CPPUpsampleKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~CPPUpsampleKernel ()=default
 Default destructor. More...
 
void configure (const ITensor *input, ITensor *output, const PadStrideInfo &info)
 Set the input and output of the kernel. More...
 
void run (const Window &window, const ThreadInfo &info) override
 Execute the kernel on the passed window. More...
 
bool is_parallelisable () const override
 Indicates whether or not the kernel is parallelisable. 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 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

CPP kernel to perform tensor upsample.

Definition at line 36 of file CPPUpsampleKernel.h.

Constructor & Destructor Documentation

◆ CPPUpsampleKernel() [1/3]

Default constructor.

Definition at line 34 of file CPPUpsampleKernel.cpp.

Referenced by CPPUpsampleKernel::name().

35  : _input(nullptr), _output(nullptr), _info()
36 {
37 }

◆ CPPUpsampleKernel() [2/3]

CPPUpsampleKernel ( const CPPUpsampleKernel )
delete

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

◆ CPPUpsampleKernel() [3/3]

Allow instances of this class to be moved.

◆ ~CPPUpsampleKernel()

~CPPUpsampleKernel ( )
default

Default destructor.

Referenced by CPPUpsampleKernel::name().

Member Function Documentation

◆ configure()

void configure ( const ITensor input,
ITensor output,
const PadStrideInfo info 
)

Set the input and output of the kernel.

Parameters
[in]inputThe input tensor to upsample. Data types supported: All.
[out]outputThe output tensor. Data types supported: same as input.
[in]infoPadding info.

Definition at line 44 of file CPPUpsampleKernel.cpp.

References ARM_COMPUTE_ERROR_ON_NULLPTR, arm_compute::calculate_max_window(), ITensor::info(), arm_compute::test::validation::info, arm_compute::test::validation::input, ITensorInfo::num_dimensions(), Dimensions< T >::set_num_dimensions(), ITensorInfo::set_valid_region(), and ITensorInfo::tensor_shape().

Referenced by CPPUpsampleKernel::name().

45 {
47 
48  _input = input;
49  _output = output;
50  _info = info;
51 
52  // Configure kernel window
53  Window win = calculate_max_window(*input->info(), Steps());
54 
55  // The CPPUpsampleKernel doesn't need padding so update_window_and_padding() can be skipped
56  Coordinates coord;
57  coord.set_num_dimensions(output->info()->num_dimensions());
58  output->info()->set_valid_region(ValidRegion(coord, output->info()->tensor_shape()));
59 
60  ICPPKernel::configure(win);
61 }
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:157

◆ 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 39 of file CPPUpsampleKernel.cpp.

Referenced by CPPUpsampleKernel::name().

40 {
41  return false;
42 }

◆ name()

◆ operator=() [1/2]

CPPUpsampleKernel& operator= ( const CPPUpsampleKernel )
delete

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

Referenced by CPPUpsampleKernel::name().

◆ operator=() [2/2]

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

Reimplemented from ICPPKernel.

Definition at line 63 of file CPPUpsampleKernel.cpp.

References ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, ITensor::buffer(), arm_compute::test::validation::data_layout, ITensorInfo::data_layout(), ITensorInfo::data_type(), ITensorInfo::dimension(), Window::DimX, Window::DimY, Window::DimZ, ITensorInfo::element_size(), arm_compute::execute_window_loop(), arm_compute::get_data_layout_dimension_index(), arm_compute::HEIGHT, ITensor::info(), arm_compute::NCHW, UniformQuantizationInfo::offset, PadStrideInfo::pad_bottom(), PadStrideInfo::pad_left(), PadStrideInfo::pad_right(), PadStrideInfo::pad_top(), Iterator::ptr(), arm_compute::QASYMM8, arm_compute::QASYMM8_SIGNED, ITensorInfo::quantization_info(), PadStrideInfo::stride(), ITensorInfo::total_size(), QuantizationInfo::uniform(), arm_compute::WIDTH, and IKernel::window().

Referenced by CPPUpsampleKernel::name().

64 {
68 
69  const DataLayout data_layout = _input->info()->data_layout();
70  const size_t idx_w = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
71  const size_t idx_h = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
72 
73  // Initialize _scaled_output buffer
74  const int width_scaled = _output->info()->dimension(idx_w);
75  const int height_scaled = _output->info()->dimension(idx_h);
76  const int stride_width = _info.stride().first;
77  const int stride_height = _info.stride().second;
78  const int start_width = _info.pad_left();
79  const int start_height = _info.pad_top();
80  const int end_width = width_scaled - _info.pad_right();
81  const int end_height = height_scaled - _info.pad_bottom();
82  const size_t element_size = _input->info()->element_size();
83 
84  // The fill value is normally 0, but for quantized types '0' corresponds to the offset
85  switch(_output->info()->data_type())
86  {
87  case DataType::QASYMM8:
88  {
89  const uint8_t fill_value = _output->info()->quantization_info().uniform().offset;
90  std::fill_n(_output->buffer(), _output->info()->total_size(), fill_value);
91  }
92  break;
94  {
95  const int8_t fill_value = _output->info()->quantization_info().uniform().offset;
96  std::fill_n(_output->buffer(), _output->info()->total_size(), fill_value);
97  }
98  break;
99  default:
100  std::fill_n(_output->buffer(), _output->info()->total_size(), 0);
101  }
102 
103  // Create window
104  Window window_out(window);
105  if(data_layout == DataLayout::NCHW)
106  {
107  window_out.set(Window::DimX, Window::Dimension(start_width, end_width, stride_width));
108  window_out.set(Window::DimY, Window::Dimension(start_height, end_height, stride_height));
109  }
110  else
111  {
112  window_out.set(Window::DimY, Window::Dimension(start_width, end_width, stride_width));
113  window_out.set(Window::DimZ, Window::Dimension(start_height, end_height, stride_height));
114  }
115 
116  // Create iterators
117  Iterator in(_input, window);
118  Iterator out(_output, window_out);
119 
120  execute_window_loop(window, [&](const Coordinates &)
121  {
122  memcpy(out.ptr(), in.ptr(), element_size);
123  },
124  in, out);
125 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
virtual DataType data_type() const =0
Data type used for each element of the tensor.
const DataLayout data_layout
Definition: Im2Col.cpp:151
unsigned int pad_top() const
Get the top padding.
Definition: Types.h:731
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:152
quantized, asymmetric fixed-point 8-bit number unsigned
virtual uint8_t * buffer() const =0
Interface to be implemented by the child class to return a pointer to CPU memory. ...
std::pair< unsigned int, unsigned int > stride() const
Get the stride.
Definition: Types.h:695
UniformQuantizationInfo uniform() const
Return per layer quantization info.
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor&#39;s metadata.
unsigned int pad_right() const
Get the right padding.
Definition: Types.h:726
virtual size_t element_size() const =0
Element size in bytes calculated as data_size() * num_channels()
virtual QuantizationInfo quantization_info() const =0
Get the quantization settings (scale and offset) of the tensor.
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:915
Num samples, channels, height, width.
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
Definition: Window.h:45
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
virtual size_t total_size() const =0
Returns the total size of the tensor in bytes.
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
quantized, asymmetric fixed-point 8-bit number signed
size_t get_data_layout_dimension_index(const DataLayout data_layout, const DataLayoutDimension data_layout_dimension)
Get the index of the given dimension.
Definition: Helpers.inl:193
unsigned int pad_bottom() const
Get the bottom padding.
Definition: Types.h:736
unsigned int pad_left() const
Get the left padding.
Definition: Types.h:721
DataLayout
[DataLayout enum definition]
Definition: Types.h:111
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:201
virtual DataLayout data_layout() const =0
Get the data layout of the tensor.

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