Compute Library
 19.08
NEBatchToSpaceLayerKernel Class Reference

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

#include <NEBatchToSpaceLayerKernel.h>

Collaboration diagram for NEBatchToSpaceLayerKernel:
[legend]

Public Member Functions

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

Static Public Member Functions

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

Detailed Description

Interface for the batch to space kernel.

Definition at line 34 of file NEBatchToSpaceLayerKernel.h.

Constructor & Destructor Documentation

◆ NEBatchToSpaceLayerKernel() [1/3]

Default constructor.

Definition at line 83 of file NEBatchToSpaceLayerKernel.cpp.

84  : _input(nullptr), _block_shape(nullptr), _output(nullptr), _block_shape_x(), _block_shape_y()
85 {
86 }

◆ NEBatchToSpaceLayerKernel() [2/3]

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

◆ NEBatchToSpaceLayerKernel() [3/3]

Allow instances of this class to be moved.

◆ ~NEBatchToSpaceLayerKernel()

Default destructor.

Member Function Documentation

◆ configure() [1/2]

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

Initialise the kernel's inputs and output.

Parameters
[in]inputTensor input. Supported tensor rank: 4. Data types supported: U8/S8/QASYMM8/U16/S16/F16/U32/S32/F32.
[in]block_shape1-D tensor with shape [M]. Data types supported: S32
[out]outputTensor output. Data types supported: same as input

Definition at line 88 of file NEBatchToSpaceLayerKernel.cpp.

89 {
90  ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
91  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), block_shape->info(), output->info()));
92 
93  _input = input;
94  _block_shape = block_shape;
95  _output = output;
96 
97  // Configure kernel window
98  Window win = calculate_max_window(*input->info(), Steps());
99  ICPPKernel::configure(win);
100 }
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:327
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_ERROR_THROW_ON, arm_compute::calculate_max_window(), and ITensor::info().

◆ configure() [2/2]

void configure ( const ITensor input,
const int32_t  block_shape_x,
const int32_t  block_shape_y,
ITensor output 
)

Initialise the kernel's inputs and output (Static block shape).

Parameters
[in]inputTensor input. Supported tensor rank: 4. Data types supported: U8/S8/QASYMM8/U16/S16/F16/U32/S32/F32.
[in]block_shape_xBlock shape x value.
[in]block_shape_yBlock shape y value.
[out]outputTensor output. Data types supported: same as input

Definition at line 102 of file NEBatchToSpaceLayerKernel.cpp.

103 {
104  ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
105  TensorShape output_shape = compute_batch_to_space_shape(input->info(), block_shape_x, block_shape_y);
106  // Output auto inizialitation if not yet initialized
107  auto_init_if_empty(*output->info(), input->info()->clone()->set_tensor_shape(output_shape));
108 
109  // Perform validation step
110  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments_static(input->info(), block_shape_x, block_shape_y, output->info()));
111 
112  _input = input;
113  _output = output;
114  _block_shape_x = block_shape_x;
115  _block_shape_y = block_shape_y;
116 
117  // Configure kernel window
118  Window win = calculate_max_window(*input->info(), Steps());
119  ICPPKernel::configure(win);
120 }
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:327
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
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...
Definition: Helpers.inl:201
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
TensorShape compute_batch_to_space_shape(const ITensorInfo *input, const int block_x, const int block_y)
Calculate the batch to space output shape of a tensor.

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_batch_to_space_shape(), ITensor::info(), and arm_compute::test::validation::output_shape.

◆ name()

const char* name ( ) const
inlineoverridevirtual

Name of the kernel.

Returns
Kernel name

Implements ICPPKernel.

Definition at line 37 of file NEBatchToSpaceLayerKernel.h.

38  {
39  return "NEBatchToSpaceLayerKernel";
40  }

◆ operator=() [1/2]

NEBatchToSpaceLayerKernel& operator= ( const NEBatchToSpaceLayerKernel )
delete

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

◆ 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.

Implements ICPPKernel.

Definition at line 136 of file NEBatchToSpaceLayerKernel.cpp.

137 {
141 
142  if(_block_shape != nullptr)
143  {
144  // Retrieve the block shapes dynamically
145  _block_shape_x = *(reinterpret_cast<const int *>(_block_shape->ptr_to_element(0)));
146  _block_shape_y = *(reinterpret_cast<const int *>(_block_shape->ptr_to_element(1)));
147  }
148 
149  const int batch_size = _input->info()->dimension(3);
150  const int r = (batch_size / (_block_shape_x * _block_shape_y));
151  const int element_size = _input->info()->element_size();
152 
153  Window slice_in = window.first_slice_window_3D();
154  Window slice_out = window.first_slice_window_4D();
155 
156  // The slice_out slice does not move
157  slice_out.set(Window::DimX, Window::Dimension(0, 0, 0));
158  slice_out.set(Window::DimY, Window::Dimension(0, 0, 0));
159  slice_out.set(Window::DimZ, Window::Dimension(0, 0, 0));
160  slice_out.set(3, Window::Dimension(0, 0, 0));
161 
162  int batch_id = 0;
163  // Main loop for NCHW and NHWC
164  if(_input->info()->data_layout() == DataLayout::NCHW)
165  {
166  do
167  {
168  Iterator in(_input, slice_in);
169  execute_window_loop(slice_in, [&](const Coordinates & id)
170  {
171 
172  const int x = id.x();
173  const int y = id.y();
174  const int z = id.z();
175 
176  const int w = batch_id % r;
177  const int out_x = x * _block_shape_x + (batch_id / r) % _block_shape_x;
178  const int out_y = y * _block_shape_y + (batch_id / r) / _block_shape_x;
179  Coordinates output_coords{ out_x, out_y, z, w };
180  memcpy(_output->ptr_to_element(output_coords), in.ptr(), element_size);
181  },
182  in);
183  ++batch_id;
184  }
185  while(window.slide_window_slice_3D(slice_in));
186  }
187  else
188  {
189  do
190  {
191  Iterator in(_input, slice_in);
192  execute_window_loop(slice_in, [&](const Coordinates & id)
193  {
194 
195  const int z = id.x();
196  const int x = id.y();
197  const int y = id.z();
198 
199  const int w = batch_id % r;
200  const int out_x = x * _block_shape_x + (batch_id / r) % _block_shape_x;
201  const int out_y = y * _block_shape_y + (batch_id / r) / _block_shape_x;
202  Coordinates output_coords{ z, out_x, out_y, w };
203  memcpy(_output->ptr_to_element(output_coords), in.ptr(), element_size);
204  },
205  in);
206  ++batch_id;
207  }
208  while(window.slide_window_slice_3D(slice_in));
209  }
210 }
SimpleTensor< float > w
Definition: DFT.cpp:156
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.
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
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()
void set(size_t dimension, const Dimension &dim)
Set the values of a given dimension.
Definition: Window.inl:48
bool slide_window_slice_3D(Window &slice) const
Slide the passed 3D window slice.
Definition: Window.h:319
Num samples, channels, height, width.
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
Definition: Window.h:45
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
Definition: Window.h:47
Window first_slice_window_4D() const
First 4D slice of the window.
Definition: Window.h:283
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
Window first_slice_window_3D() const
First 3D slice of the window.
Definition: Window.h:275
#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
virtual DataLayout data_layout() const =0
Get the data layout of the tensor.

References ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, ITensorInfo::data_layout(), ITensorInfo::dimension(), Window::DimX, Window::DimY, Window::DimZ, ITensorInfo::element_size(), arm_compute::execute_window_loop(), Window::first_slice_window_3D(), Window::first_slice_window_4D(), ITensor::info(), arm_compute::test::validation::info, arm_compute::NCHW, Iterator::ptr(), ITensor::ptr_to_element(), Window::set(), Window::slide_window_slice_3D(), arm_compute::test::validation::w, IKernel::window(), and Window::x().

◆ validate() [1/2]

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

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

Parameters
[in]inputTensor input. Supported tensor rank: 4. Data types supported: U8/S8/QASYMM8/U16/S16/F16/U32/S32/F32.
[in]block_shape1-D tensor with shape [M]. Data types supported: S32
[in]outputTensor output. Data types supported: same as input
Returns
a status

Definition at line 122 of file NEBatchToSpaceLayerKernel.cpp.

123 {
124  ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input, block_shape, output);
125  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, block_shape, output));
126  return Status{};
127 }
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:193
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
Definition: Validate.h:163

References ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR, and ARM_COMPUTE_RETURN_ON_ERROR.

Referenced by NEBatchToSpaceLayer::validate().

◆ validate() [2/2]

Status validate ( const ITensorInfo input,
const int32_t  block_shape_x,
const int32_t  block_shape_y,
const ITensorInfo output 
)
static

Static function to check if given info will lead to a valid configuration of NEBatchToSpaceLayerKernel (Static block shape).

Parameters
[in]inputTensor input. Supported tensor rank: 4. Data types supported: U8/S8/QASYMM8/U16/S16/F16/U32/S32/F32.
[in]block_shape_xBlock shape x value.
[in]block_shape_yBlock shape y value.
[in]outputTensor output. Data types supported: same as input
Returns
a status

Definition at line 129 of file NEBatchToSpaceLayerKernel.cpp.

130 {
132  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments_static(input, block_shape_x, block_shape_y, output));
133  return Status{};
134 }
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:193
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
Definition: Validate.h:163

References ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR, and ARM_COMPUTE_RETURN_ON_ERROR.


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