Compute Library
 19.08
NEBatchNormalizationLayerKernel Class Reference

Interface for the batch normalization layer kernel. More...

#include <NEBatchNormalizationLayerKernel.h>

Collaboration diagram for NEBatchNormalizationLayerKernel:
[legend]

Public Member Functions

const char * name () const override
 Name of the kernel. More...
 
 NEBatchNormalizationLayerKernel ()
 Default constructor. More...
 
 NEBatchNormalizationLayerKernel (const NEBatchNormalizationLayerKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NEBatchNormalizationLayerKerneloperator= (const NEBatchNormalizationLayerKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NEBatchNormalizationLayerKernel (NEBatchNormalizationLayerKernel &&)=default
 Default Move Constructor. More...
 
NEBatchNormalizationLayerKerneloperator= (NEBatchNormalizationLayerKernel &&)=default
 Default move assignment operator. More...
 
 ~NEBatchNormalizationLayerKernel ()=default
 Default destructor. More...
 
void configure (ITensor *input, ITensor *output, const ITensor *mean, const ITensor *var, const ITensor *beta=nullptr, const ITensor *gamma=nullptr, float epsilon=0.001f, ActivationLayerInfo act_info=ActivationLayerInfo())
 Set the input and output tensors. 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 *output, const ITensorInfo *mean, const ITensorInfo *var, const ITensorInfo *beta=nullptr, const ITensorInfo *gamma=nullptr, float epsilon=0.001f, ActivationLayerInfo act_info=ActivationLayerInfo())
 Static function to check if given info will lead to a valid configuration of NEBatchNormalizationLayerKernel. More...
 

Detailed Description

Interface for the batch normalization layer kernel.

Definition at line 35 of file NEBatchNormalizationLayerKernel.h.

Constructor & Destructor Documentation

◆ NEBatchNormalizationLayerKernel() [1/3]

Default constructor.

Definition at line 406 of file NEBatchNormalizationLayerKernel.cpp.

407  : _func(nullptr), _input(nullptr), _output(nullptr), _mean(nullptr), _var(nullptr), _gamma(nullptr), _beta(nullptr), _epsilon(), _act_info()
408 {
409 }

◆ NEBatchNormalizationLayerKernel() [2/3]

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

◆ NEBatchNormalizationLayerKernel() [3/3]

Default Move Constructor.

◆ ~NEBatchNormalizationLayerKernel()

Default destructor.

Member Function Documentation

◆ configure()

void configure ( ITensor input,
ITensor output,
const ITensor mean,
const ITensor var,
const ITensor beta = nullptr,
const ITensor gamma = nullptr,
float  epsilon = 0.001f,
ActivationLayerInfo  act_info = ActivationLayerInfo() 
)

Set the input and output tensors.

Note
If the output tensor is a nullptr, the batch normalization function will be performed in-place
Parameters
[in,out]inputSource tensor. In case of output tensor = nullptr, this tensor will store the result. 3 lower dimensions represent a single input with dimensions [width, height, FM]. The rest are optional and used for representing batches. Data types supported: F16/F32.
[out]outputDestination tensor. Output will have the same number of dimensions as input. Data type supported: same as input
[in]meanMean values tensor. 1 dimension with size equal to the feature maps [FM]. Data types supported: Same as input
[in]varVariance values tensor. 1 dimension with size equal to the feature maps [FM]. Data types supported: Same as input
[in]beta(Optional) Beta values tensor info. 1 dimension with size equal to the feature maps [FM]. If not provided, default value for beta is 0. Data types supported: Same as input
[in]gamma(Optional) Gamma values tensor info. 1 dimension with size equal to the feature maps [FM]. If not provided, default value for gamma is 1. Data types supported: Same as input
[in]epsilon(Optional) Small value to avoid division with zero. Default value is 0.001f.
[in]act_info(Optional) Activation layer information in case of a fused activation. Only RELU, BOUNDED_RELU and LU_BOUNDED_RELU supported.

Definition at line 411 of file NEBatchNormalizationLayerKernel.cpp.

415 {
416  ARM_COMPUTE_ERROR_ON_NULLPTR(input, mean, var);
417 
418  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), (output != nullptr) ? output->info() : nullptr,
419  mean->info(), var->info(),
420  (beta != nullptr) ? beta->info() : nullptr,
421  (gamma != nullptr) ? gamma->info() : nullptr,
422  epsilon, act_info));
423 
424  _input = input;
425  _output = input;
426  _mean = mean;
427  _var = var;
428  _gamma = gamma;
429  _beta = beta;
430  _epsilon = epsilon;
431  _act_info = act_info;
432 
433  const bool run_in_place = (output == nullptr) || (output == input);
434  if(!run_in_place)
435  {
436  _output = output;
437  }
438 
439  // Configure activation function to run
440  if(_act_info.enabled())
441  {
442  configure_fused();
443  }
444  else
445  {
446  configure_non_fused();
447  }
448 
449  // Configure kernel window
450  auto win_config = validate_and_configure_window(input->info(), (run_in_place) ? nullptr : output->info(), mean->info(), var->info(), (gamma != nullptr) ? gamma->info() : nullptr,
451  (beta != nullptr) ? beta->info() : nullptr);
452  ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
453  INEKernel::configure(win_config.second);
454 }
bool enabled() const
Check if initialised.
Definition: Types.h:1565
std::pair< Status, Window > validate_and_configure_window(ITensorInfo *input, ITensorInfo *weights, ITensorInfo *biases, ITensorInfo *output, const PadStrideInfo &conv_info, unsigned int depth_multiplier, const Size2D &dilation)
constexpr float epsilon
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:327
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161

References arm_compute::test::validation::act_info, ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, ActivationLayerInfo::enabled(), epsilon, ITensor::info(), and arm_compute::validate_and_configure_window().

Referenced by NEBatchNormalizationLayer::configure().

◆ name()

const char* name ( ) const
inlineoverridevirtual

Name of the kernel.

Returns
Kernel name

Implements ICPPKernel.

Definition at line 38 of file NEBatchNormalizationLayerKernel.h.

39  {
40  return "NEBatchNormalizationLayerKernel";
41  }

◆ operator=() [1/2]

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

◆ operator=() [2/2]

Default move assignment operator.

◆ 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 469 of file NEBatchNormalizationLayerKernel.cpp.

470 {
474  ARM_COMPUTE_ERROR_ON(_func == nullptr);
475 
476  (this->*_func)(window);
477 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:337
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:160
#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

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, arm_compute::test::validation::info, and IKernel::window().

◆ validate()

Status validate ( const ITensorInfo input,
const ITensorInfo output,
const ITensorInfo mean,
const ITensorInfo var,
const ITensorInfo beta = nullptr,
const ITensorInfo gamma = nullptr,
float  epsilon = 0.001f,
ActivationLayerInfo  act_info = ActivationLayerInfo() 
)
static

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

Parameters
[in]inputSource tensor info. In case of output tensor = nullptr, this tensor will store the result. 3 lower dimensions represent a single input with dimensions [width, height, FM]. The rest are optional and used for representing batches. Data types supported: F16/F32.
[in]outputDestination tensor info. Output will have the same number of dimensions as input. Data type supported: same as input
[in]meanMean values tensor info. 1 dimension with size equal to the feature maps [FM]. Data types supported: Same as input
[in]varVariance values tensor info. 1 dimension with size equal to the feature maps [FM]. Data types supported: Same as input
[in]beta(Optional) Beta values tensor info. 1 dimension with size equal to the feature maps [FM]. If not provided, default value for beta is 0. Data types supported: Same as input
[in]gamma(Optional) Gamma values tensor info. 1 dimension with size equal to the feature maps [FM]. If not provided, default value for gamma is 1. Data types supported: Same as input
[in]epsilon(Optional) Small value to avoid division with zero. Default value is 0.001f.
[in]act_info(Optional) Activation layer information in case of a fused activation. Only RELU, BOUNDED_RELU and LU_BOUNDED_RELU supported.
Returns
a status

Definition at line 456 of file NEBatchNormalizationLayerKernel.cpp.

460 {
461  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output, mean, var, beta, gamma, epsilon, act_info));
462  ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(), output ? output->clone().get() : nullptr, mean->clone().get(), var->clone().get(),
463  (gamma != nullptr) ? gamma->clone().get() : nullptr, (beta != nullptr) ? beta->clone().get() : nullptr)
464  .first);
465 
466  return Status{};
467 }
std::pair< Status, Window > validate_and_configure_window(ITensorInfo *input, ITensorInfo *weights, ITensorInfo *biases, ITensorInfo *output, const PadStrideInfo &conv_info, unsigned int depth_multiplier, const Size2D &dilation)
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:193
constexpr float epsilon
Status class.
Definition: Error.h:52
virtual std::unique_ptr< T > clone() const =0
Provide a clone of the current object of class T.

References arm_compute::test::validation::act_info, ARM_COMPUTE_RETURN_ON_ERROR, ICloneable< T >::clone(), epsilon, and arm_compute::validate_and_configure_window().

Referenced by NEBatchNormalizationLayer::validate().


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