Compute Library
 19.08
NEFuseBatchNormalization Class Reference

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

#include <NEFuseBatchNormalization.h>

Collaboration diagram for NEFuseBatchNormalization:
[legend]

Public Member Functions

 NEFuseBatchNormalization ()
 Default constructor. More...
 
 NEFuseBatchNormalization (const NEFuseBatchNormalization &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NEFuseBatchNormalizationoperator= (const NEFuseBatchNormalization &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NEFuseBatchNormalization (NEFuseBatchNormalization &&)=default
 Allow instances of this class to be moved. More...
 
NEFuseBatchNormalizationoperator= (NEFuseBatchNormalization &&)=default
 Allow instances of this class to be moved. More...
 
 ~NEFuseBatchNormalization ()=default
 Default destructor. More...
 
void configure (const ITensor *input_weights, const ITensor *bn_mean, const ITensor *bn_var, ITensor *fused_weights, ITensor *fused_bias, const ITensor *input_bias=nullptr, const ITensor *bn_beta=nullptr, const ITensor *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 NEFuseBatchNormalization. More...
 

Detailed Description

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

Definition at line 38 of file NEFuseBatchNormalization.h.

Constructor & Destructor Documentation

◆ NEFuseBatchNormalization() [1/3]

Default constructor.

Definition at line 34 of file NEFuseBatchNormalization.cpp.

35  : _fuse_bn_kernel()
36 {
37 }

◆ NEFuseBatchNormalization() [2/3]

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

◆ NEFuseBatchNormalization() [3/3]

Allow instances of this class to be moved.

◆ ~NEFuseBatchNormalization()

Default destructor.

Member Function Documentation

◆ configure()

void configure ( const ITensor input_weights,
const ITensor bn_mean,
const ITensor bn_var,
ITensor fused_weights,
ITensor fused_bias,
const ITensor input_bias = nullptr,
const ITensor bn_beta = nullptr,
const ITensor 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_weights(Optional) Output fused weights tensor. It can be a nullptr in case of in-place computation. Same as input_weights
[out]fused_bias(Optional) Output 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 NEFuseBatchNormalization.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 ITensor *input_weights, const ITensor *bn_mean, const ITensor *bn_var, ITensor *fused_weights, ITensor *fused_bias, const ITensor *input_bias=nullptr, const ITensor *bn_beta=nullptr, const ITensor *bn_gamma=nullptr, float epsilon=0.001f, FuseBatchNormalizationType fbn_type=FuseBatchNormalizationType::CONVOLUTION)
Set the source, destination of the kernel.

References NEFuseBatchNormalizationKernel::configure(), and epsilon.

◆ operator=() [1/2]

NEFuseBatchNormalization& operator= ( const NEFuseBatchNormalization )
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 NEFuseBatchNormalization.cpp.

56 {
57  NEScheduler::get().schedule(&_fuse_bn_kernel, Window::DimY);
58 }
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()

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

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_weights(Optional) Output fused weights tensor info. It can be a nullptr in case of in-place computation. Same as input_weights
[in]fused_bias(Optional) Output 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 NEFuseBatchNormalization.cpp.

51 {
52  return NEFuseBatchNormalizationKernel::validate(input_weights, bn_mean, bn_var, fused_weights, fused_bias, input_bias, bn_beta, bn_gamma, epsilon, fbn_type);
53 }
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 NEFuseBatchNormalization...
constexpr float epsilon

References epsilon, and NEFuseBatchNormalizationKernel::validate().


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