Compute Library
 19.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...
 
void configure (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 48 of file CLL2NormalizeLayer.h.

Constructor & Destructor Documentation

◆ CLL2NormalizeLayer()

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

Constructor.

Definition at line 42 of file CLL2NormalizeLayer.cpp.

43  : _memory_group(std::move(memory_manager)), _reduce_func(), _normalize_kernel(), _sumsq()
44 {
45 }

Member Function Documentation

◆ configure()

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

Set the input and output tensors.

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 47 of file CLL2NormalizeLayer.cpp.

48 {
49  // Manage intermediate buffers
50  _memory_group.manage(&_sumsq);
51 
52  // Configure kernels
53  const uint32_t actual_axis = wrap_around(axis, max_input_tensor_dim);
54  _reduce_func.configure(input, &_sumsq, actual_axis, ReductionOperation::SUM_SQUARE);
55  _normalize_kernel.configure(input, &_sumsq, output, axis, epsilon);
56 
57  // Allocate intermediate tensor
58  _sumsq.allocator()->allocate();
59 }
void configure(ICLTensor *input, ICLTensor *output, unsigned int axis, ReductionOperation op)
Set the input and output tensors.
constexpr float epsilon
void configure(const ICLTensor *input, const ICLTensor *sum, ICLTensor *output, int axis, float epsilon)
Set the input and output tensors.
CLTensorAllocator * allocator()
Return a pointer to the tensor's allocator.
Definition: CLTensor.cpp:55
T wrap_around(T x, T m)
Wrap-around a number within the range 0 <= x < m.
Definition: Helpers.h:764
void manage(TensorType *obj)
Sets a object to be managed by the given memory group.
void allocate() override
Allocate size specified by TensorInfo of OpenCL memory.

References CLTensorAllocator::allocate(), CLTensor::allocator(), arm_compute::test::validation::axis, CLReductionOperation::configure(), CLL2NormalizeLayerKernel::configure(), epsilon, MemoryGroupBase< TensorType >::manage(), arm_compute::SUM_SQUARE, and arm_compute::wrap_around().

◆ 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 82 of file CLL2NormalizeLayer.cpp.

83 {
84  MemoryGroupResourceScope scope_mg(_memory_group);
85 
86  _reduce_func.run();
87  CLScheduler::get().enqueue(_normalize_kernel, true);
88 }
static CLScheduler & get()
Access the scheduler singleton.
Definition: CLScheduler.cpp:41
void run() override
Run the kernels contained in the function.
void enqueue(ICLKernel &kernel, bool flush=true)
Schedule the execution of the passed kernel if possible.
Definition: CLScheduler.cpp:95

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 61 of file CLL2NormalizeLayer.cpp.

62 {
63  TensorShape shape(input->tensor_shape());
64 
65  // Create intermediate tensor info
66  TensorInfo sum_sq;
67  sum_sq.set_data_type(input->data_type());
68  sum_sq.set_tensor_shape(shape);
69 
70  const uint32_t actual_axis = wrap_around(axis, max_input_tensor_dim);
72 
73  // Reduce shape on axis
74  shape.set(actual_axis, 1);
75  sum_sq.set_tensor_shape(shape);
76 
78 
79  return Status{};
80 }
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:193
constexpr float epsilon
static Status validate(const ITensorInfo *input, const ITensorInfo *output, unsigned int axis, ReductionOperation op)
Static function to check if given info will lead to a valid configuration of CLReductionOperation.
T wrap_around(T x, T m)
Wrap-around a number within the range 0 <= x < m.
Definition: Helpers.h:764
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...

References ARM_COMPUTE_RETURN_ON_ERROR, arm_compute::test::validation::axis, ITensorInfo::data_type(), epsilon, TensorInfo::set_data_type(), ITensorInfo::set_tensor_shape(), arm_compute::test::validation::shape, arm_compute::SUM_SQUARE, ITensorInfo::tensor_shape(), CLReductionOperation::validate(), CLL2NormalizeLayerKernel::validate(), and arm_compute::wrap_around().


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