Compute Library
 19.08
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...
 
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. NEPixelWiseMultiplicationKernel
  2. NEFillBorderKernel
  3. NENormalizationLayerKernel

Definition at line 50 of file NENormalizationLayer.h.

Constructor & Destructor Documentation

◆ NENormalizationLayer()

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

Default constructor.

Definition at line 35 of file NENormalizationLayer.cpp.

36  : _memory_group(std::move(memory_manager)), _norm_kernel(), _multiply_kernel(), _border_handler(), _input_squared()
37 {
38 }

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

41 {
42  ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
43 
44  TensorInfo tensor_info(input->info()->tensor_shape(), 1, input->info()->data_type());
45  _input_squared.allocator()->init(tensor_info);
46 
47  // Manage intermediate buffers
48  _memory_group.manage(&_input_squared);
49 
50  // Configure kernels
51  _norm_kernel.configure(input, &_input_squared, output, norm_info);
52  _multiply_kernel.configure(input, input, &_input_squared, 1.0f, ConvertPolicy::SATURATE, RoundingPolicy::TO_ZERO);
53  _border_handler.configure(&_input_squared, _norm_kernel.border_size(), BorderMode::CONSTANT, PixelValue(0.0f));
54 
55  // Allocate the tensor once the configure methods have been called
56  _input_squared.allocator()->allocate();
57 }
Class describing the value of a pixel for any image format.
Definition: PixelValue.h:34
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...
virtual DataType data_type() const =0
Data type used for each element of the tensor.
void configure(const ITensor *input1, const ITensor *input2, ITensor *output, float scale, ConvertPolicy overflow_policy, RoundingPolicy rounding_policy)
Initialise the kernel's input, output and border mode.
void configure(ITensor *tensor, BorderSize border_size, BorderMode border_mode, const PixelValue &constant_border_value=PixelValue())
Initialise the function.
TensorAllocator * allocator()
Return a pointer to the tensor's allocator.
Definition: Tensor.cpp:48
void manage(TensorType *obj)
Sets a object to be managed by the given memory group.
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
void allocate() override
Allocate size specified by TensorInfo of CPU memory.
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
BorderSize border_size() const override
The size of the border for that kernel.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
void configure(const ITensor *input, const ITensor *input_squared, ITensor *output, NormalizationLayerInfo norm_info)
Set the input and output tensors.
Store the tensor's metadata.
Definition: TensorInfo.h:45
Truncates the least significant values that are lost in operations.

References TensorAllocator::allocate(), Tensor::allocator(), ARM_COMPUTE_ERROR_ON_NULLPTR, NENormalizationLayerKernel::border_size(), NENormalizationLayerKernel::configure(), NEFillBorderKernel::configure(), NEPixelWiseMultiplicationKernel::configure(), arm_compute::CONSTANT, ITensorInfo::data_type(), ITensor::info(), TensorAllocator::init(), MemoryGroupBase< TensorType >::manage(), arm_compute::SATURATE, ITensorInfo::tensor_shape(), and arm_compute::TO_ZERO.

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

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

71 {
72  MemoryGroupResourceScope scope_mg(_memory_group);
73 
74  NEScheduler::get().schedule(&_multiply_kernel, Window::DimY);
75  NEScheduler::get().schedule(&_border_handler, Window::DimY);
76  NEScheduler::get().schedule(&_norm_kernel, Window::DimY);
77 }
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
Definition: Window.h:45
Memory group resources scope handling class.
Definition: IMemoryGroup.h:46
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().

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

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

60 {
61  // Perform validation step
63 
64  ARM_COMPUTE_RETURN_ON_ERROR(NENormalizationLayerKernel::validate(input, input, output, norm_info));
66 
67  return Status{};
68 }
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:193
Status class.
Definition: Error.h:52
static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, float scale, ConvertPolicy overflow_policy, RoundingPolicy rounding_policy)
Static function to check if given info will lead to a valid configuration of NEPixelWiseMultiplicatio...
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
Definition: Validate.h:163
Truncates the least significant values that are lost in operations.

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


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