Compute Library
 19.08
CLSpaceToBatchLayer Class Reference

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

#include <CLSpaceToBatchLayer.h>

Collaboration diagram for CLSpaceToBatchLayer:
[legend]

Public Member Functions

 CLSpaceToBatchLayer ()
 Default constructor. More...
 
 CLSpaceToBatchLayer (const CLSpaceToBatchLayer &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
CLSpaceToBatchLayeroperator= (const CLSpaceToBatchLayer &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 CLSpaceToBatchLayer (CLSpaceToBatchLayer &&)=default
 Allow instances of this class to be moved. More...
 
CLSpaceToBatchLayeroperator= (CLSpaceToBatchLayer &&)=default
 Allow instances of this class to be moved. More...
 
virtual ~CLSpaceToBatchLayer ()=default
 Default destructor. More...
 
void configure (const ICLTensor *input, const ICLTensor *block_shape, const ICLTensor *paddings, ICLTensor *output)
 Set the input and output tensors. More...
 
void configure (const ICLTensor *input, const int block_shape_x, const int block_shape_y, const Size2D &padding_left, const Size2D &padding_right, ICLTensor *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 CLSpaceToBatchLayer. 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 CLSpaceToBatchLayer (Static block shape and paddings) More...
 

Detailed Description

Basic function to spatial divide a tensor.

This function calls the following OpenCL kernels/functions:

  1. CLMemsetKernel
  2. CLSpaceToBatchLayerKernel

Definition at line 43 of file CLSpaceToBatchLayer.h.

Constructor & Destructor Documentation

◆ CLSpaceToBatchLayer() [1/3]

Default constructor.

Definition at line 35 of file CLSpaceToBatchLayer.cpp.

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

◆ CLSpaceToBatchLayer() [2/3]

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

◆ CLSpaceToBatchLayer() [3/3]

Allow instances of this class to be moved.

◆ ~CLSpaceToBatchLayer()

virtual ~CLSpaceToBatchLayer ( )
virtualdefault

Default destructor.

Member Function Documentation

◆ configure() [1/2]

void configure ( const ICLTensor input,
const ICLTensor block_shape,
const ICLTensor paddings,
ICLTensor 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 CLSpaceToBatchLayer.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 }
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
void configure(const ICLTensor *input, const ICLTensor *block_shape, const ICLTensor *paddings, ICLTensor *output)
Initialise the kernel's inputs and output.
void configure(ICLTensor *tensor, const PixelValue &constant_value, Window *window=nullptr)
Initialise the kernel's tensor and filling value.

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

◆ configure() [2/2]

void configure ( const ICLTensor input,
const int  block_shape_x,
const int  block_shape_y,
const Size2D padding_left,
const Size2D padding_right,
ICLTensor 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 CLSpaceToBatchLayer.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 }
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
void configure(const ICLTensor *input, const ICLTensor *block_shape, const ICLTensor *paddings, ICLTensor *output)
Initialise the kernel's inputs and output.
void configure(ICLTensor *tensor, const PixelValue &constant_value, Window *window=nullptr)
Initialise the kernel's tensor and filling value.

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

◆ operator=() [1/2]

CLSpaceToBatchLayer& operator= ( const CLSpaceToBatchLayer )
delete

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

◆ operator=() [2/2]

CLSpaceToBatchLayer& operator= ( CLSpaceToBatchLayer &&  )
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 81 of file CLSpaceToBatchLayer.cpp.

82 {
83  // Zero out output only if we have paddings
84  if(_has_padding)
85  {
86  CLScheduler::get().enqueue(_memset_kernel, true);
87  }
88  CLScheduler::get().enqueue(_space_to_batch_kernel, true);
89 }
static CLScheduler & get()
Access the scheduler singleton.
Definition: CLScheduler.cpp:41
void enqueue(ICLKernel &kernel, bool flush=true)
Schedule the execution of the passed kernel if possible.
Definition: CLScheduler.cpp:95

References CLScheduler::enqueue(), and CLScheduler::get().

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

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
[out]outputTensor output info. Data types supported: same as input
Returns
a status

Definition at line 64 of file CLSpaceToBatchLayer.cpp.

65 {
66  ARM_COMPUTE_RETURN_ON_ERROR(CLMemsetKernel::validate(output, PixelValue(0, input->data_type(), input->quantization_info())));
67  ARM_COMPUTE_RETURN_ON_ERROR(CLSpaceToBatchLayerKernel::validate(input, block_shape, paddings, output));
68 
69  return Status{};
70 }
static Status validate(const ITensorInfo *tensor, const PixelValue &constant_value, Window *window=nullptr)
Static function to check if given info will lead to a valid configuration of CLMemsetKernel.
#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 CLSpaceToBatchLayerKerne...

References ARM_COMPUTE_RETURN_ON_ERROR, ITensorInfo::data_type(), ITensorInfo::quantization_info(), CLMemsetKernel::validate(), and CLSpaceToBatchLayerKernel::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 CLSpaceToBatchLayer (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.
[out]outputTensor output info. Data types supported: same as input
Returns
a status

Definition at line 72 of file CLSpaceToBatchLayer.cpp.

74 {
75  ARM_COMPUTE_RETURN_ON_ERROR(CLMemsetKernel::validate(output, PixelValue(0, input->data_type(), input->quantization_info())));
76  ARM_COMPUTE_RETURN_ON_ERROR(CLSpaceToBatchLayerKernel::validate(input, block_shape_x, block_shape_y, padding_left, padding_right, output));
77 
78  return Status{};
79 }
static Status validate(const ITensorInfo *tensor, const PixelValue &constant_value, Window *window=nullptr)
Static function to check if given info will lead to a valid configuration of CLMemsetKernel.
#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 CLSpaceToBatchLayerKerne...

References ARM_COMPUTE_RETURN_ON_ERROR, ITensorInfo::data_type(), ITensorInfo::quantization_info(), CLMemsetKernel::validate(), and CLSpaceToBatchLayerKernel::validate().


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