Compute Library
 23.08
CLL2NormalizeLayer Class Reference

Basic function to perform a L2 normalization on a given axis. More...

#include <CLL2NormalizeLayer.h>

Collaboration diagram for CLL2NormalizeLayer:
[legend]

Public Member Functions

 CLL2NormalizeLayer (std::shared_ptr< IMemoryManager > memory_manager=nullptr)
 Constructor. More...
 
 ~CLL2NormalizeLayer ()
 Default Destructor. More...
 
 CLL2NormalizeLayer (const CLL2NormalizeLayer &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 CLL2NormalizeLayer (CLL2NormalizeLayer &&)=default
 Default move constructor. More...
 
CLL2NormalizeLayeroperator= (const CLL2NormalizeLayer &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
CLL2NormalizeLayeroperator= (CLL2NormalizeLayer &&)=default
 Default move assignment operator. More...
 
void configure (ICLTensor *input, ICLTensor *output, int axis, float epsilon=1e-12f)
 Set the input and output tensors. More...
 
void configure (const CLCompileContext &compile_context, ICLTensor *input, ICLTensor *output, int axis, float epsilon=1e-12f)
 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, int axis, float epsilon=1e-12f)
 Static function to check if given info will lead to a valid configuration of CLL2NormalizeLayer. More...
 

Detailed Description

Basic function to perform a L2 normalization on a given axis.

This function runs the following kernels:

  1. CLReductionOperation
  2. CLL2NormalizeLayerKernel

Definition at line 50 of file CLL2NormalizeLayer.h.

Constructor & Destructor Documentation

◆ CLL2NormalizeLayer() [1/3]

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

Constructor.

Definition at line 45 of file CLL2NormalizeLayer.cpp.

46  : _memory_group(std::move(memory_manager)),
47  _reduce_func(),
48  _normalize_kernel(std::make_unique<CLL2NormalizeLayerKernel>()),
49  _sumsq()
50 {
51 }

◆ ~CLL2NormalizeLayer()

~CLL2NormalizeLayer ( )
default

Default Destructor.

◆ CLL2NormalizeLayer() [2/3]

CLL2NormalizeLayer ( const CLL2NormalizeLayer )
delete

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

◆ CLL2NormalizeLayer() [3/3]

Default move constructor.

Member Function Documentation

◆ configure() [1/2]

void configure ( const CLCompileContext compile_context,
ICLTensor input,
ICLTensor output,
int  axis,
float  epsilon = 1e-12f 
)

Set the input and output tensors.

Parameters
[in]compile_contextThe compile context to be used.
[in]inputSource tensor. Data types supported: F16/F32. Data layouts supported: NCHW/NHWC.
[out]outputDestination tensor. Data types and data layouts supported: Same as input.
[in]axisAxis along which to reduce. Negative values wrap around. Maximum supported actual reduction axis : 2
[in]epsilon(Optional) Lower bound value for the normalization.

Definition at line 60 of file CLL2NormalizeLayer.cpp.

61 {
62  ARM_COMPUTE_LOG_PARAMS(input, output, axis, epsilon);
63 
64  // Reset auxiliary tensor
65  _sumsq.allocator()->init(TensorInfo());
66 
67  // Manage intermediate buffers
68  _memory_group.manage(&_sumsq);
69 
70  // Configure kernels
71  const uint32_t actual_axis = wrap_around(axis, max_input_tensor_dim);
72  _reduce_func.configure(compile_context, input, &_sumsq, actual_axis, ReductionOperation::SUM_SQUARE);
73  _normalize_kernel->configure(compile_context, input, &_sumsq, output, axis, epsilon);
74 
75  // Allocate intermediate tensor
76  _sumsq.allocator()->allocate();
77 }

References CLTensorAllocator::allocate(), CLTensor::allocator(), ARM_COMPUTE_LOG_PARAMS, CLReductionOperation::configure(), arm_compute::quantization::epsilon, ITensorAllocator::init(), arm_compute::test::validation::input, MemoryGroup::manage(), arm_compute::SUM_SQUARE, and arm_compute::wrap_around().

◆ configure() [2/2]

void configure ( ICLTensor input,
ICLTensor output,
int  axis,
float  epsilon = 1e-12f 
)

Set the input and output tensors.

Valid data layouts:

  • NHWC
  • NCHW

Valid data type configurations:

src dst
F16 F16
F32 F32
Parameters
[in]inputSource tensor. Data types supported: F16/F32. Data layouts supported: NCHW/NHWC.
[out]outputDestination tensor. Data types and data layouts supported: Same as input.
[in]axisAxis along which to reduce. Negative values wrap around. Maximum supported actual reduction axis : 2
[in]epsilon(Optional) Lower bound value for the normalization.

Definition at line 55 of file CLL2NormalizeLayer.cpp.

56 {
57  configure(CLKernelLibrary::get().get_compile_context(), input, output, axis, epsilon);
58 }

References arm_compute::quantization::epsilon, CLKernelLibrary::get(), and arm_compute::test::validation::input.

◆ operator=() [1/2]

CLL2NormalizeLayer& operator= ( CLL2NormalizeLayer &&  )
default

Default move assignment operator.

◆ operator=() [2/2]

CLL2NormalizeLayer& operator= ( const CLL2NormalizeLayer )
delete

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

◆ run()

void run ( )
overridevirtual

Run the kernels contained in the function.

For CPU 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 100 of file CLL2NormalizeLayer.cpp.

101 {
102  MemoryGroupResourceScope scope_mg(_memory_group);
103 
104  _reduce_func.run();
105  CLScheduler::get().enqueue(*_normalize_kernel, true);
106 }

References CLScheduler::enqueue(), CLScheduler::get(), and CLReductionOperation::run().

◆ validate()

Status validate ( const ITensorInfo input,
const ITensorInfo output,
int  axis,
float  epsilon = 1e-12f 
)
static

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

Parameters
[in]inputSource tensor info. Data types supported: F16/F32. Data layouts supported: NCHW/NHWC.
[in]outputDestination tensor info. Data types and data layouts supported: Same as input.
[in]axisAxis along which to reduce. Negative values wrap around. Maximum supported actual reduction axis : 2
[in]epsilon(Optional) Lower bound value for the normalization.
Returns
a status

Definition at line 79 of file CLL2NormalizeLayer.cpp.

80 {
81  TensorShape shape(input->tensor_shape());
82 
83  // Create intermediate tensor info
84  TensorInfo sum_sq;
85  sum_sq.set_data_type(input->data_type());
86  sum_sq.set_tensor_shape(shape);
87 
88  const uint32_t actual_axis = wrap_around(axis, max_input_tensor_dim);
90 
91  // Reduce shape on axis
92  shape.set(actual_axis, 1);
93  sum_sq.set_tensor_shape(shape);
94 
96 
97  return Status{};
98 }

References ARM_COMPUTE_RETURN_ON_ERROR, arm_compute::quantization::epsilon, arm_compute::test::validation::input, TensorInfo::set_data_type(), TensorInfo::set_tensor_shape(), arm_compute::test::validation::shape, arm_compute::SUM_SQUARE, CLL2NormalizeLayerKernel::validate(), CLReductionOperation::validate(), and arm_compute::wrap_around().


The documentation for this class was generated from the following files:
arm_compute::MemoryGroup::manage
void manage(IMemoryManageable *obj) override
Sets a object to be managed by the given memory group.
Definition: MemoryGroup.h:79
arm_compute::CLScheduler::enqueue
void enqueue(ICLKernel &kernel, bool flush=true)
Schedule the execution of the passed kernel if possible.
Definition: CLScheduler.cpp:205
arm_compute::ITensorAllocator::init
void init(const TensorInfo &input, size_t alignment=0)
Initialize a tensor based on the passed TensorInfo.
Definition: ITensorAllocator.cpp:33
arm_compute::wrap_around
T wrap_around(T x, T m)
Wrap-around a number within the range 0 <= x < m.
Definition: Helpers.h:268
arm_compute::CLKernelLibrary::get
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
Definition: CLKernelLibrary.cpp:39
ARM_COMPUTE_RETURN_ON_ERROR
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204
arm_compute::test::validation::shape
shape
Definition: DFT.cpp:115
arm_compute::ReductionOperation::SUM_SQUARE
@ SUM_SQUARE
Sum of squares.
arm_compute::CLReductionOperation::run
void run() override
Run the kernels contained in the function.
Definition: CLReductionOperation.cpp:139
arm_compute::CLTensorAllocator::allocate
void allocate() override
Allocate size specified by TensorInfo of OpenCL memory.
Definition: CLTensorAllocator.cpp:127
arm_compute::CLTensor::allocator
CLTensorAllocator * allocator()
Return a pointer to the tensor's allocator.
Definition: CLTensor.cpp:61
arm_compute::CLScheduler::get
static CLScheduler & get()
Access the scheduler singleton.
Definition: CLScheduler.cpp:103
arm_compute::CLL2NormalizeLayer::configure
void configure(ICLTensor *input, ICLTensor *output, int axis, float epsilon=1e-12f)
Set the input and output tensors.
Definition: CLL2NormalizeLayer.cpp:55
arm_compute::CLL2NormalizeLayerKernel::validate
static Status validate(const ITensorInfo *input, const ITensorInfo *sum, const ITensorInfo *output, int axis, float epsilon)
Static function to check if given info will lead to a valid configuration of CLL2NormalizeLayerKernel...
Definition: CLL2NormalizeLayerKernel.cpp:149
arm_compute::CLReductionOperation::configure
void configure(ICLTensor *input, ICLTensor *output, unsigned int axis, ReductionOperation op, bool keep_dims=true)
Set the input and output tensors.
Definition: CLReductionOperation.cpp:106
ARM_COMPUTE_LOG_PARAMS
#define ARM_COMPUTE_LOG_PARAMS(...)
Definition: Log.h:35
arm_compute::CLReductionOperation::validate
static Status validate(const ITensorInfo *input, const ITensorInfo *output, unsigned int axis, ReductionOperation op, bool keep_dims=true)
Static function to check if given info will lead to a valid configuration of CLReductionOperation.
Definition: CLReductionOperation.cpp:48
arm_compute::test::validation::input
auto input
Definition: LSTMLayerQuantized.cpp:486
arm_compute::quantization::epsilon
constexpr float epsilon
Definition: AsymmHelpers.cpp:39