Compute Library
 19.08
NESpaceToBatchLayer Class Reference

Basic function to spatial divide a tensor. More...

#include <NESpaceToBatchLayer.h>

Collaboration diagram for NESpaceToBatchLayer:
[legend]

Public Member Functions

 NESpaceToBatchLayer ()
 Default constructor. More...
 
 NESpaceToBatchLayer (const NESpaceToBatchLayer &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NESpaceToBatchLayeroperator= (const NESpaceToBatchLayer &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NESpaceToBatchLayer (NESpaceToBatchLayer &&)=default
 Allow instances of this class to be moved. More...
 
NESpaceToBatchLayeroperator= (NESpaceToBatchLayer &&)=default
 Allow instances of this class to be moved. More...
 
virtual ~NESpaceToBatchLayer ()=default
 Default destructor. More...
 
void configure (const ITensor *input, const ITensor *block_shape, const ITensor *paddings, ITensor *output)
 Set the input and output tensors. More...
 
void configure (const ITensor *input, const int block_shape_x, const int block_shape_y, const Size2D &padding_left, const Size2D &padding_right, ITensor *output)
 Set the input and output tensors. More...
 
void run () override
 Run the kernels contained in the function. More...
 
- Public Member Functions inherited from IFunction
virtual ~IFunction ()=default
 Destructor. More...
 
virtual void prepare ()
 Prepare the function for executing. More...
 

Static Public Member Functions

static Status validate (const ITensorInfo *input, const ITensorInfo *block_shape, const ITensorInfo *paddings, const ITensorInfo *output)
 Static function to check if given info will lead to a valid configuration of NESpaceToBatchLayer. More...
 
static Status validate (const ITensorInfo *input, const int block_shape_x, const int block_shape_y, const Size2D &padding_left, const Size2D &padding_right, const ITensorInfo *output)
 Static function to check if given info will lead to a valid configuration of NESpaceToBatchLayer (Static block shape and paddings) More...
 

Detailed Description

Basic function to spatial divide a tensor.

This function calls the following NEON kernels/functions:

  1. NEMemsetKernel
  2. NESpaceToBatchLayerKernel

Definition at line 42 of file NESpaceToBatchLayer.h.

Constructor & Destructor Documentation

◆ NESpaceToBatchLayer() [1/3]

Default constructor.

Definition at line 35 of file NESpaceToBatchLayer.cpp.

36  : _space_to_batch_kernel(), _memset_kernel(), _has_padding(false)
37 {
38 }

◆ NESpaceToBatchLayer() [2/3]

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

◆ NESpaceToBatchLayer() [3/3]

Allow instances of this class to be moved.

◆ ~NESpaceToBatchLayer()

virtual ~NESpaceToBatchLayer ( )
virtualdefault

Default destructor.

Member Function Documentation

◆ configure() [1/2]

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

Set the input and output tensors.

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]paddings2-D tensor with shape [2, M]. Data types supported: S32
[out]outputTensor output. Data types supported: same as input

Definition at line 40 of file NESpaceToBatchLayer.cpp.

41 {
42  ARM_COMPUTE_ERROR_ON_NULLPTR(input, block_shape, paddings, output);
43 
44  if(input->info()->tensor_shape().total_size() != output->info()->tensor_shape().total_size())
45  {
46  _has_padding = true;
47  _memset_kernel.configure(output, PixelValue(0, input->info()->data_type(), input->info()->quantization_info()));
48  }
49  _space_to_batch_kernel.configure(input, block_shape, paddings, output);
50 }
void configure(const ITensor *input, const ITensor *block_shape, const ITensor *paddings, ITensor *output)
Initialise the kernel's inputs and output.
void configure(ITensor *tensor, const PixelValue &constant_value)
Initialise the kernel's tensor and filling value.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161

References ARM_COMPUTE_ERROR_ON_NULLPTR, NEMemsetKernel::configure(), NESpaceToBatchLayerKernel::configure(), ITensorInfo::data_type(), ITensor::info(), ITensorInfo::quantization_info(), ITensorInfo::tensor_shape(), and TensorShape::total_size().

◆ configure() [2/2]

void configure ( const ITensor input,
const int  block_shape_x,
const int  block_shape_y,
const Size2D padding_left,
const Size2D padding_right,
ITensor output 
)

Set the input and output tensors.

(Static block shape and paddings)

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]padding_leftThe left padding of the output tensor.
[in]padding_rightThe right padding of the output tensor.
[out]outputTensor output. Data types supported: same as input

Definition at line 52 of file NESpaceToBatchLayer.cpp.

53 {
54  ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
55 
56  if(input->info()->tensor_shape().total_size() != output->info()->tensor_shape().total_size())
57  {
58  _has_padding = true;
59  _memset_kernel.configure(output, PixelValue(0, input->info()->data_type(), input->info()->quantization_info()));
60  }
61  _space_to_batch_kernel.configure(input, block_shape_x, block_shape_y, padding_left, padding_right, output);
62 }
void configure(const ITensor *input, const ITensor *block_shape, const ITensor *paddings, ITensor *output)
Initialise the kernel's inputs and output.
void configure(ITensor *tensor, const PixelValue &constant_value)
Initialise the kernel's tensor and filling value.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161

References ARM_COMPUTE_ERROR_ON_NULLPTR, NEMemsetKernel::configure(), NESpaceToBatchLayerKernel::configure(), ITensorInfo::data_type(), ITensor::info(), ITensorInfo::quantization_info(), ITensorInfo::tensor_shape(), and TensorShape::total_size().

◆ operator=() [1/2]

NESpaceToBatchLayer& operator= ( const NESpaceToBatchLayer )
delete

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

◆ operator=() [2/2]

NESpaceToBatchLayer& operator= ( NESpaceToBatchLayer &&  )
default

Allow instances of this class to be moved.

◆ run()

void run ( )
overridevirtual

Run the kernels contained in the function.

For NEON kernels:

  • Multi-threading is used for the kernels which are parallelisable.
  • By default std::thread::hardware_concurrency() threads are used.
Note
CPPScheduler::set_num_threads() can be used to manually set the number of threads

For OpenCL kernels:

  • All the kernels are enqueued on the queue associated with CLScheduler.
  • The queue is then flushed.
Note
The function will not block until the kernels are executed. It is the user's responsibility to wait.
Will call prepare() on first run if hasn't been done

Implements IFunction.

Definition at line 79 of file NESpaceToBatchLayer.cpp.

80 {
81  // Zero out output only if we have paddings
82  if(_has_padding)
83  {
84  NEScheduler::get().schedule(&_memset_kernel, Window::DimY);
85  }
86  NEScheduler::get().schedule(&_space_to_batch_kernel, Window::DimY);
87 }
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
Definition: Window.h:45
virtual void schedule(ICPPKernel *kernel, const Hints &hints)=0
Runs the kernel in the same thread as the caller synchronously.
static IScheduler & get()
Access the scheduler singleton.
Definition: Scheduler.cpp:96

References Window::DimY, Scheduler::get(), and IScheduler::schedule().

◆ validate() [1/2]

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

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

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

Definition at line 64 of file NESpaceToBatchLayer.cpp.

65 {
66  ARM_COMPUTE_RETURN_ON_ERROR(NESpaceToBatchLayerKernel::validate(input, block_shape, paddings, output));
67 
68  return Status{};
69 }
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:193
static Status validate(const ITensorInfo *input, const ITensorInfo *block_shape, const ITensorInfo *paddings, const ITensorInfo *output)
Static function to check if given info will lead to a valid configuration of NESpaceToBatchLayerKerne...

References ARM_COMPUTE_RETURN_ON_ERROR, and NESpaceToBatchLayerKernel::validate().

◆ validate() [2/2]

Status validate ( const ITensorInfo input,
const int  block_shape_x,
const int  block_shape_y,
const Size2D padding_left,
const Size2D padding_right,
const ITensorInfo output 
)
static

Static function to check if given info will lead to a valid configuration of NESpaceToBatchLayer (Static block shape and paddings)

Parameters
[in]inputTensor input info. 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]padding_leftThe left padding of the output tensor.
[in]padding_rightThe right padding of the output tensor.
[in]outputTensor output info. Data types supported: same as input
Returns
a status

Definition at line 71 of file NESpaceToBatchLayer.cpp.

73 {
74  ARM_COMPUTE_RETURN_ON_ERROR(NESpaceToBatchLayerKernel::validate(input, block_shape_x, block_shape_y, padding_left, padding_right, output));
75 
76  return Status{};
77 }
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:193
static Status validate(const ITensorInfo *input, const ITensorInfo *block_shape, const ITensorInfo *paddings, const ITensorInfo *output)
Static function to check if given info will lead to a valid configuration of NESpaceToBatchLayerKerne...

References ARM_COMPUTE_RETURN_ON_ERROR, and NESpaceToBatchLayerKernel::validate().


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