Compute Library
 19.08
CLFuseBatchNormalization Class Reference

Basic function to fuse the batch normalization node to a preceding convolution node. More...

#include <CLFuseBatchNormalization.h>

Collaboration diagram for CLFuseBatchNormalization:
[legend]

Public Member Functions

 CLFuseBatchNormalization ()
 Default constructor. More...
 
 CLFuseBatchNormalization (const CLFuseBatchNormalization &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
CLFuseBatchNormalizationoperator= (const CLFuseBatchNormalization &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 CLFuseBatchNormalization (CLFuseBatchNormalization &&)=default
 Allow instances of this class to be moved. More...
 
CLFuseBatchNormalizationoperator= (CLFuseBatchNormalization &&)=default
 Allow instances of this class to be moved. More...
 
 ~CLFuseBatchNormalization ()=default
 Default destructor. More...
 
void configure (const ICLTensor *input_weights, const ICLTensor *bn_mean, const ICLTensor *bn_var, ICLTensor *fused_weights, ICLTensor *fused_bias, const ICLTensor *input_bias=nullptr, const ICLTensor *bn_beta=nullptr, const ICLTensor *bn_gamma=nullptr, float epsilon=0.001f, FuseBatchNormalizationType fbn_type=FuseBatchNormalizationType::CONVOLUTION)
 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_weights, const ITensorInfo *bn_mean, const ITensorInfo *bn_var, const ITensorInfo *fused_weights, const ITensorInfo *fused_bias, const ITensorInfo *input_bias=nullptr, const ITensorInfo *bn_beta=nullptr, const ITensorInfo *bn_gamma=nullptr, float epsilon=0.001f, FuseBatchNormalizationType fbn_type=FuseBatchNormalizationType::CONVOLUTION)
 Static function to check if given info will lead to a valid configuration of CLFuseBatchNormalization. More...
 

Detailed Description

Basic function to fuse the batch normalization node to a preceding convolution node.

Definition at line 37 of file CLFuseBatchNormalization.h.

Constructor & Destructor Documentation

◆ CLFuseBatchNormalization() [1/3]

Default constructor.

Definition at line 34 of file CLFuseBatchNormalization.cpp.

35  : _fuse_bn_kernel()
36 {
37 }

◆ CLFuseBatchNormalization() [2/3]

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

◆ CLFuseBatchNormalization() [3/3]

Allow instances of this class to be moved.

◆ ~CLFuseBatchNormalization()

Default destructor.

Member Function Documentation

◆ configure()

void configure ( const ICLTensor input_weights,
const ICLTensor bn_mean,
const ICLTensor bn_var,
ICLTensor fused_weights,
ICLTensor fused_bias,
const ICLTensor input_bias = nullptr,
const ICLTensor bn_beta = nullptr,
const ICLTensor bn_gamma = nullptr,
float  epsilon = 0.001f,
FuseBatchNormalizationType  fbn_type = FuseBatchNormalizationType::CONVOLUTION 
)

Set the input and output tensors.

Parameters
[in]input_weightsInput weights tensor for convolution or depthwise convolution layer. Data type supported: F16/F32. Data layout supported: NCHW, NHWC
[in]bn_meanBatch normalization layer mean tensor. Same as input_weights
[in]bn_varBatch normalization layer variance tensor. Same as input_weights
[out]fused_weightsOutput fused weights tensor. It can be a nullptr in case of in-place computation. Same as input_weights
[out]fused_biasOutput fused bias tensor. It can be a nullptr in case of in-place computation and input_bias != nullptr. Same as input_weights
[in]input_bias(Optional) Input bias tensor for convolution or depthwise convolution layer. It can be a nullptr in case the bias tensor is not required. Same as input_weights
[in]bn_beta(Optional) Batch normalization layer beta tensor. It can be a nullptr in case the beta tensor is not required. Same as input_weights
Note
if nullptr, bn_beta is set to 0.0
Parameters
[in]bn_gamma(Optional) Batch normalization layer gamma tensor. It can be a nullptr in case the gamma tensor is not required. Same as input_weights
Note
if nullptr, bn_gamma is set to 1.0
Parameters
[in]epsilon(Optional) Batch normalization layer epsilon parameter. Defaults to 0.001f.
[in]fbn_type(Optional) Fused batch normalization type. Defaults to Convolution.

Definition at line 39 of file CLFuseBatchNormalization.cpp.

43 {
44  _fuse_bn_kernel.configure(input_weights, bn_mean, bn_var, fused_weights, fused_bias, input_bias, bn_beta, bn_gamma, epsilon, fbn_type);
45 }
constexpr float epsilon
void configure(const ICLTensor *input_weights, const ICLTensor *bn_mean, const ICLTensor *bn_var, ICLTensor *fused_weights, ICLTensor *fused_bias, const ICLTensor *input_bias=nullptr, const ICLTensor *bn_beta=nullptr, const ICLTensor *bn_gamma=nullptr, float epsilon=0.001f, FuseBatchNormalizationType fbn_type=FuseBatchNormalizationType::CONVOLUTION)
Set the source, destination of the kernel.

References CLFuseBatchNormalizationKernel::configure(), and epsilon.

◆ operator=() [1/2]

CLFuseBatchNormalization& operator= ( const CLFuseBatchNormalization )
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 ( )
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 55 of file CLFuseBatchNormalization.cpp.

56 {
57  CLScheduler::get().enqueue(_fuse_bn_kernel, true);
58 }
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()

Status validate ( const ITensorInfo input_weights,
const ITensorInfo bn_mean,
const ITensorInfo bn_var,
const ITensorInfo fused_weights,
const ITensorInfo fused_bias,
const ITensorInfo input_bias = nullptr,
const ITensorInfo bn_beta = nullptr,
const ITensorInfo bn_gamma = nullptr,
float  epsilon = 0.001f,
FuseBatchNormalizationType  fbn_type = FuseBatchNormalizationType::CONVOLUTION 
)
static

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

Parameters
[in]input_weightsInput weights tensor info for convolution or depthwise convolution layer. Data type supported: F16/F32. Data layout supported: NCHW, NHWC
[in]bn_meanBatch normalization layer mean tensor info. Same as input_weights
[in]bn_varBatch normalization layer variance tensor info. Same as input_weights
[in]fused_weightsOutput fused weights tensor info. It can be a nullptr in case of in-place computation. Same as input_weights
[in]fused_biasOutput fused bias tensor info. It can be a nullptr in case of in-place computation and input_bias != nullptr. Same as input_weights
[in]input_bias(Optional) Input bias tensor info for convolution or depthwise convolution layer. It can be a nullptr in case the bias tensor is not required. Same as input_weights
[in]bn_beta(Optional) Batch normalization layer beta tensor info. It can be a nullptr in case the beta tensor is not required. Same as input_weights
Note
if nullptr, bn_beta is set to 0.0
Parameters
[in]bn_gamma(Optional) Batch normalization layer gamma tensor info. It can be a nullptr in case the gamma tensor is not required. Same as input_weights
Note
if nullptr, bn_gamma is set to 1.0
Parameters
[in]epsilon(Optional) Batch normalization layer epsilon parameter. Defaults to 0.001f.
[in]fbn_type(Optional) Fused batch normalization type. Defaults to Convolution.
Returns
a status

Definition at line 47 of file CLFuseBatchNormalization.cpp.

51 {
52  return CLFuseBatchNormalizationKernel::validate(input_weights, bn_mean, bn_var, fused_weights, fused_bias, input_bias, bn_beta, bn_gamma, epsilon, fbn_type);
53 }
constexpr float epsilon
static Status validate(const ITensorInfo *input_weights, const ITensorInfo *bn_mean, const ITensorInfo *bn_var, const ITensorInfo *fused_weights, const ITensorInfo *fused_bias, const ITensorInfo *input_bias=nullptr, const ITensorInfo *bn_beta=nullptr, const ITensorInfo *bn_gamma=nullptr, float epsilon=0.001f, FuseBatchNormalizationType fbn_type=FuseBatchNormalizationType::CONVOLUTION)
Static function to check if given info will lead to a valid configuration of CLFuseBatchNormalization...

References epsilon, and CLFuseBatchNormalizationKernel::validate().


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