Compute Library
 21.02
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...
 
virtual void run_nd (const Window &window, const ThreadInfo &info, const Window &thread_locator)
 legacy compatibility layer for implemantions which do not support thread_locator In these cases we simply narrow the interface down the legacy version More...
 
virtual void run_op (ITensorPack &tensors, const Window &window, const ThreadInfo &info)
 Execute the kernel on the passed window. 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 36 of file NEBatchNormalizationLayerKernel.h.

Constructor & Destructor Documentation

◆ NEBatchNormalizationLayerKernel() [1/3]

Default constructor.

Definition at line 307 of file NEBatchNormalizationLayerKernel.cpp.

Referenced by NEBatchNormalizationLayerKernel::name().

308  : _func(nullptr), _input(nullptr), _output(nullptr), _mean(nullptr), _var(nullptr), _gamma(nullptr), _beta(nullptr), _epsilon(), _act_info()
309 {
310 }

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

Referenced by NEBatchNormalizationLayerKernel::name().

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

References ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, arm_compute::auto_init_if_empty(), arm_compute::calculate_max_window(), ICloneable< T >::clone(), ITensorInfo::data_layout(), ActivationLayerInfo::enabled(), arm_compute::quantization::epsilon, ITensor::info(), arm_compute::test::validation::input, arm_compute::NCHW, ITensorInfo::num_dimensions(), Dimensions< T >::set_num_dimensions(), ITensorInfo::set_valid_region(), ITensorInfo::tensor_shape(), and arm_compute::validate_arguments().

Referenced by NEBatchNormalizationLayerKernel::name().

316 {
318 
319  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), (output != nullptr) ? output->info() : nullptr,
320  mean->info(), var->info(),
321  (beta != nullptr) ? beta->info() : nullptr,
322  (gamma != nullptr) ? gamma->info() : nullptr,
323  epsilon, act_info));
324 
325  _input = input;
326  _output = input;
327  _mean = mean;
328  _var = var;
329  _gamma = gamma;
330  _beta = beta;
331  _epsilon = epsilon;
332  _act_info = act_info;
333 
334  const bool run_in_place = (output == nullptr) || (output == input);
335  if(!run_in_place)
336  {
337  _output = output;
338  }
339 
340  // Configure activation function to run
341  const bool is_nchw = _input->info()->data_layout() == DataLayout::NCHW;
342  if(is_nchw)
343  {
344  if(_act_info.enabled())
345  {
346  configure_fused();
347  }
348  else
349  {
350  configure_non_fused();
351  }
352  }
353 
354  // Configure kernel window
355  Window win = calculate_max_window(*input->info(), Steps());
356  INEKernel::configure(win);
357 
358  if(output != nullptr)
359  {
360  // Output auto initialization if not yet initialized
361  auto_init_if_empty(*output->info(), *input->info()->clone());
362 
363  Coordinates coord;
364  coord.set_num_dimensions(output->info()->num_dimensions());
365  output->info()->set_valid_region(ValidRegion(coord, output->info()->tensor_shape()));
366  }
367 }
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
bool enabled() const
Check if initialised.
Definition: Types.h:1600
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:455
bool auto_init_if_empty(ITensorInfo &info, const TensorShape &shape, int num_channels, DataType data_type, QuantizationInfo quantization_info=QuantizationInfo())
Auto initialize the tensor info (shape, number of channels and data type) if the current assignment i...
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor&#39;s metadata.
Num samples, channels, height, width.
Status validate_arguments(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const GEMMLowpOutputStageInfo *output_stage)
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
virtual DataLayout data_layout() const =0
Get the data layout of the tensor.

◆ name()

◆ operator=() [1/2]

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

Referenced by NEBatchNormalizationLayerKernel::name().

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

Reimplemented from ICPPKernel.

Definition at line 379 of file NEBatchNormalizationLayerKernel.cpp.

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, ITensorInfo::data_layout(), ITensorInfo::data_type(), ITensor::info(), arm_compute::NCHW, and IKernel::window().

Referenced by NEBatchNormalizationLayerKernel::name().

380 {
384  ARM_COMPUTE_ERROR_ON(_func == nullptr && _input->info()->data_layout() == DataLayout::NCHW);
385 
386  const bool is_nchw = _input->info()->data_layout() == DataLayout::NCHW;
387  if(is_nchw)
388  {
389  (this->*_func)(window);
390  }
391  else
392  {
393  const auto *uk = get_implementation(BatchNormalizationSelectorData{ _input->info()->data_type() });
394  uk->ukernel(_input, _output, _mean, _var, _beta, _gamma, _epsilon, _act_info, window);
395  }
396 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
virtual DataType data_type() const =0
Data type used for each element of the tensor.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor&#39;s metadata.
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:941
Num samples, channels, height, width.
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205
virtual DataLayout data_layout() const =0
Get the data layout of the tensor.

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

References ARM_COMPUTE_RETURN_ON_ERROR, and arm_compute::validate_arguments().

Referenced by NEBatchNormalizationLayerKernel::name(), and NEBatchNormalizationLayer::validate().

373 {
374  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output, mean, var, beta, gamma, epsilon, act_info));
375 
376  return Status{};
377 }
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204
Status validate_arguments(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const GEMMLowpOutputStageInfo *output_stage)

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