Compute Library
 21.02
NEDepthToSpaceLayerKernel Class Reference

Interface for the depth to space kernel. More...

#include <NEDepthToSpaceLayerKernel.h>

Collaboration diagram for NEDepthToSpaceLayerKernel:
[legend]

Public Member Functions

const char * name () const override
 Name of the kernel. More...
 
 NEDepthToSpaceLayerKernel ()
 Default constructor. More...
 
 NEDepthToSpaceLayerKernel (const NEDepthToSpaceLayerKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NEDepthToSpaceLayerKerneloperator= (const NEDepthToSpaceLayerKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NEDepthToSpaceLayerKernel (NEDepthToSpaceLayerKernel &&)=default
 Allow instances of this class to be moved. More...
 
NEDepthToSpaceLayerKerneloperator= (NEDepthToSpaceLayerKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~NEDepthToSpaceLayerKernel ()=default
 Default destructor. More...
 
void configure (const ITensor *input, ITensor *output, int32_t block_shape)
 Initialise the kernel's inputs and output. 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...
 
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 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...
 

Static Public Member Functions

static Status validate (const ITensorInfo *input, const ITensorInfo *output, int32_t block_shape)
 Static function to check if given info will lead to a valid configuration of NEDepthToSpaceLayerKernel. More...
 

Detailed Description

Interface for the depth to space kernel.

Definition at line 35 of file NEDepthToSpaceLayerKernel.h.

Constructor & Destructor Documentation

◆ NEDepthToSpaceLayerKernel() [1/3]

Default constructor.

Definition at line 69 of file NEDepthToSpaceLayerKernel.cpp.

Referenced by NEDepthToSpaceLayerKernel::name().

70  : _input(nullptr), _output(nullptr), _block_shape(), _data_layout(DataLayout::UNKNOWN)
71 {
72 }

◆ NEDepthToSpaceLayerKernel() [2/3]

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

◆ NEDepthToSpaceLayerKernel() [3/3]

Allow instances of this class to be moved.

◆ ~NEDepthToSpaceLayerKernel()

Default destructor.

Referenced by NEDepthToSpaceLayerKernel::name().

Member Function Documentation

◆ configure()

void configure ( const ITensor input,
ITensor output,
int32_t  block_shape 
)

Initialise the kernel's inputs and output.

Parameters
[in]inputTensor input. Supported tensor rank: 4. Data types supported: All
[out]outputTensor output. Data types supported: same as input
[in]block_shapeBlock shape x value.

Definition at line 74 of file NEDepthToSpaceLayerKernel.cpp.

References ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, arm_compute::auto_init_if_empty(), arm_compute::calculate_max_window(), ICloneable< T >::clone(), arm_compute::misc::shape_calculator::compute_depth_to_space_shape(), ITensorInfo::data_layout(), ITensor::info(), arm_compute::test::validation::input, arm_compute::test::validation::output_shape, ITensorInfo::tensor_shape(), and arm_compute::validate_arguments().

Referenced by NEDepthToSpaceLayerKernel::name().

75 {
77  TensorShape output_shape = compute_depth_to_space_shape(input->info()->tensor_shape(), input->info()->data_layout(), block_shape);
78  // Output auto inizialitation if not yet initialized
79  auto_init_if_empty(*output->info(), input->info()->clone()->set_tensor_shape(output_shape));
80 
81  // Perform validation step
82  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info(), block_shape));
83 
84  _input = input;
85  _output = output;
86  _block_shape = block_shape;
87  _data_layout = input->info()->data_layout();
88 
89  // Configure kernel window
90  Window win = calculate_max_window(*input->info(), Steps());
91  ICPPKernel::configure(win);
92 }
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
TensorShape compute_depth_to_space_shape(const TensorShape &input_shape, DataLayout data_layout, int block)
Calculate the depth to space output shape of a tensor.
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:455
bool auto_init_if_empty(ITensorInfo &info, const TensorShape &shape, int num_channels, DataType data_type, QuantizationInfo quantization_info=QuantizationInfo())
Auto initialize the tensor info (shape, number of channels and data type) if the current assignment i...
Status validate_arguments(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const GEMMLowpOutputStageInfo *output_stage)
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161

◆ name()

◆ operator=() [1/2]

NEDepthToSpaceLayerKernel& operator= ( const NEDepthToSpaceLayerKernel )
delete

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

Referenced by NEDepthToSpaceLayerKernel::name().

◆ operator=() [2/2]

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 101 of file NEDepthToSpaceLayerKernel.cpp.

References ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, arm_compute::CHANNEL, ITensorInfo::dimension(), Window::DimX, Window::DimY, Window::DimZ, ITensorInfo::element_size(), arm_compute::execute_window_loop(), Window::first_slice_window_2D(), Window::first_slice_window_3D(), arm_compute::get_data_layout_dimension_index(), ITensor::info(), arm_compute::NCHW, Iterator::ptr(), ITensor::ptr_to_element(), Window::set(), Window::slide_window_slice_2D(), Window::slide_window_slice_3D(), IKernel::window(), Window::x(), and Window::y().

Referenced by NEDepthToSpaceLayerKernel::name().

102 {
106 
107  const int idx_channel = get_data_layout_dimension_index(_data_layout, DataLayoutDimension::CHANNEL);
108  const int depth_size = _input->info()->dimension(idx_channel);
109  const int r = (depth_size / (_block_shape * _block_shape));
110  const int element_size = _input->info()->element_size();
111 
112  Window slice_out = window.first_slice_window_3D();
113 
114  // The slice_out slice does not move
115  slice_out.set(Window::DimX, Window::Dimension(0, 0, 0));
116  slice_out.set(Window::DimY, Window::Dimension(0, 0, 0));
117  slice_out.set(Window::DimZ, Window::Dimension(0, 0, 0));
118 
119  // Main loop for NCHW and NHWC
120  if(_data_layout == DataLayout::NCHW)
121  {
122  Window slice_in = window.first_slice_window_2D();
123  do
124  {
125  Iterator in(_input, slice_in);
126  execute_window_loop(slice_in, [&](const Coordinates & id)
127  {
128  const int x = id.x();
129  const int y = id.y();
130 
131  const int z = id.z() % r;
132  const int out_x = x * _block_shape + (id.z() / r) % _block_shape;
133  const int out_y = y * _block_shape + (id.z() / r) / _block_shape;
134  Coordinates output_coords{ out_x, out_y, z, id[3] };
135  memcpy(_output->ptr_to_element(output_coords), in.ptr(), element_size);
136  },
137  in);
138  }
139  while(window.slide_window_slice_2D(slice_in));
140  }
141  else
142  {
143  Window slice_in = window.first_slice_window_3D();
144  do
145  {
146  Iterator in(_input, slice_in);
147  execute_window_loop(slice_in, [&](const Coordinates & id)
148  {
149  const int x = id.y();
150  const int y = id.z();
151 
152  const int z = id.x() % r;
153  const int out_x = x * _block_shape + (id.x() / r) % _block_shape;
154  const int out_y = y * _block_shape + (id.x() / r) / _block_shape;
155  Coordinates output_coords{ z, out_x, out_y, id[3] };
156  memcpy(_output->ptr_to_element(output_coords), in.ptr(), element_size);
157  },
158  in);
159  }
160  while(window.slide_window_slice_3D(slice_in));
161  }
162 }
Window first_slice_window_2D() const
First 2D slice of the window.
Definition: Window.h:283
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
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
bool slide_window_slice_2D(Window &slice) const
Slide the passed 2D window slice.
Definition: Window.h:323
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
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor&#39;s metadata.
virtual size_t element_size() const =0
Element size in bytes calculated as data_size() * num_channels()
void set(size_t dimension, const Dimension &dim)
Set the values of a given dimension.
Definition: Window.inl:49
bool slide_window_slice_3D(Window &slice) const
Slide the passed 3D window slice.
Definition: Window.h:335
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:941
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)
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
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
Window first_slice_window_3D() const
First 3D slice of the window.
Definition: Window.h:291
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205

◆ validate()

Status validate ( const ITensorInfo input,
const ITensorInfo output,
int32_t  block_shape 
)
static

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

Parameters
[in]inputTensor input info. Supported tensor rank: 4. Data types supported: All
[in]outputTensor output info. Data types supported: same as input
[in]block_shapeBlock shape value.
Returns
a status

Definition at line 94 of file NEDepthToSpaceLayerKernel.cpp.

References ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR, ARM_COMPUTE_RETURN_ON_ERROR, and arm_compute::validate_arguments().

Referenced by NEDepthToSpaceLayerKernel::name(), and NEDepthToSpaceLayer::validate().

95 {
98  return Status{};
99 }
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
Definition: Validate.h:163
Status validate_arguments(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const GEMMLowpOutputStageInfo *output_stage)

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