Compute Library
 21.02
NENormalizationLayer Class Reference

Basic function to compute a normalization layer. More...

#include <NENormalizationLayer.h>

Collaboration diagram for NENormalizationLayer:
[legend]

Public Member Functions

 NENormalizationLayer (std::shared_ptr< IMemoryManager > memory_manager=nullptr)
 Default constructor. More...
 
 NENormalizationLayer (const NENormalizationLayer &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NENormalizationLayeroperator= (const NENormalizationLayer &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NENormalizationLayer (NENormalizationLayer &&)=delete
 Prevent instances of this class from being moved (As this class contains non movable objects) More...
 
NENormalizationLayeroperator= (NENormalizationLayer &&)=delete
 Prevent instances of this class from being moved (As this class contains non movable objects) More...
 
 ~NENormalizationLayer ()
 Default destructor. More...
 
void configure (const ITensor *input, ITensor *output, const NormalizationLayerInfo &norm_info)
 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 *output, const NormalizationLayerInfo &norm_info)
 Static function to check if given info will lead to a valid configuration of NENormalizationLayer. More...
 

Detailed Description

Basic function to compute a normalization layer.

This function calls the following Neon kernels:

  1. NEPixelWiseMultiplication
  2. NEFillBorderKernel
  3. NENormalizationLayerKernel

Definition at line 49 of file NENormalizationLayer.h.

Constructor & Destructor Documentation

◆ NENormalizationLayer() [1/3]

NENormalizationLayer ( std::shared_ptr< IMemoryManager memory_manager = nullptr)

Default constructor.

Definition at line 38 of file NENormalizationLayer.cpp.

39  : _memory_group(std::move(memory_manager)), _norm_kernel(), _multiply_f(), _input_squared()
40 {
41 }

◆ NENormalizationLayer() [2/3]

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

◆ NENormalizationLayer() [3/3]

Prevent instances of this class from being moved (As this class contains non movable objects)

◆ ~NENormalizationLayer()

~NENormalizationLayer ( )
default

Default destructor.

Member Function Documentation

◆ configure()

void configure ( const ITensor input,
ITensor output,
const NormalizationLayerInfo norm_info 
)

Set the input and output tensors.

Parameters
[in]inputSource tensor. 3 lower dims represent a single input with dimensions [width, height, IFM], and an optional 4th dimension for batch of inputs. Data type supported: F16/F32. Data layouts supported: NCHW/NHWC.
[out]outputDestination with the same dimensions, data type, data layout and number of channels of input
[in]norm_infoNormalization layer information like the normalization type, normalization size and other parameters.

Definition at line 43 of file NENormalizationLayer.cpp.

References TensorAllocator::allocate(), Tensor::allocator(), ARM_COMPUTE_ERROR_ON_NULLPTR, NEPixelWiseMultiplication::configure(), ITensorInfo::data_type(), ITensor::info(), TensorAllocator::init(), MemoryGroup::manage(), arm_compute::SATURATE, ITensorInfo::tensor_shape(), and arm_compute::TO_ZERO.

Referenced by arm_compute::test::validation::TEST_CASE().

44 {
46 
47  TensorInfo tensor_info(input->info()->tensor_shape(), 1, input->info()->data_type());
48  _input_squared.allocator()->init(tensor_info);
49 
50  // Manage intermediate buffers
51  _memory_group.manage(&_input_squared);
52 
53  // Configure kernels
54  _norm_kernel = std::make_unique<NENormalizationLayerKernel>();
55  _norm_kernel->configure(input, &_input_squared, output, norm_info);
56  _multiply_f.configure(input, input, &_input_squared, 1.0f, ConvertPolicy::SATURATE, RoundingPolicy::TO_ZERO);
57 
58  // Allocate the tensor once the configure methods have been called
59  _input_squared.allocator()->allocate();
60 }
void init(const TensorAllocator &allocator, const Coordinates &coords, TensorInfo &sub_info)
Shares the same backing memory with another tensor allocator, while the tensor info might be differen...
TensorAllocator * allocator()
Return a pointer to the tensor&#39;s allocator.
Definition: Tensor.cpp:48
void manage(IMemoryManageable *obj) override
Sets a object to be managed by the given memory group.
Definition: MemoryGroup.h:79
void configure(const ITensor *input1, const ITensor *input2, ITensor *output, float scale, ConvertPolicy overflow_policy, RoundingPolicy rounding_policy, const ActivationLayerInfo &act_info=ActivationLayerInfo())
Initialise the kernel&#39;s inputs, output and convertion policy.
void allocate() override
Allocate size specified by TensorInfo of CPU memory.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
Truncates the least significant values that are lost in operations.

◆ operator=() [1/2]

NENormalizationLayer& operator= ( const NENormalizationLayer )
delete

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

◆ operator=() [2/2]

NENormalizationLayer& operator= ( NENormalizationLayer &&  )
delete

Prevent instances of this class from being moved (As this class contains non movable objects)

◆ 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 73 of file NENormalizationLayer.cpp.

References Window::DimY, Scheduler::get(), NEPixelWiseMultiplication::run(), and IScheduler::schedule().

Referenced by arm_compute::test::validation::TEST_CASE().

74 {
75  MemoryGroupResourceScope scope_mg(_memory_group);
76  _multiply_f.run();
77  NEScheduler::get().schedule(_norm_kernel.get(), Window::DimY);
78 }
void run() override
Run the kernels contained in the function.
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:94

◆ validate()

Status validate ( const ITensorInfo input,
const ITensorInfo output,
const NormalizationLayerInfo norm_info 
)
static

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

Parameters
[in]inputSource tensor. 3 lower dims represent a single input with dimensions [width, height, IFM], and an optional 4th dimension for batch of inputs. Data type supported: F16/F32. Data layouts supported: NCHW/NHWC.
[in]outputDestination with the same dimensions, data type, data layout and number of channels of input
[in]norm_infoNormalization layer information like the normalization type, normalization size and other parameters.
Returns
a status

Definition at line 62 of file NENormalizationLayer.cpp.

References ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR, ARM_COMPUTE_RETURN_ON_ERROR, arm_compute::SATURATE, arm_compute::TO_ZERO, NENormalizationLayerKernel::validate(), and NEPixelWiseMultiplication::validate().

Referenced by arm_compute::test::validation::DATA_TEST_CASE().

63 {
64  // Perform validation step
66 
69 
70  return Status{};
71 }
static Status validate(const ITensorInfo *input, const ITensorInfo *input_squared, const ITensorInfo *output, NormalizationLayerInfo norm_info)
Static function to check if given info will lead to a valid configuration of NENormalizationLayerKern...
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
Definition: Validate.h:163
static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, float scale, ConvertPolicy overflow_policy, RoundingPolicy rounding_policy, const ActivationLayerInfo &act_info=ActivationLayerInfo())
Static function to check if given info will lead to a valid configuration of NEPixelWiseMultiplicatio...
Truncates the least significant values that are lost in operations.

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