Compute Library
 21.08
NEQLSTMLayerNormalizationKernel Class Reference

Kernel to perform layer normalization for QLSTM. More...

#include <NEQLSTMLayerNormalizationKernel.h>

Collaboration diagram for NEQLSTMLayerNormalizationKernel:
[legend]

Public Member Functions

const char * name () const override
 Name of the kernel. More...
 
 NEQLSTMLayerNormalizationKernel ()=default
 Default constructor. More...
 
 NEQLSTMLayerNormalizationKernel (const NEQLSTMLayerNormalizationKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NEQLSTMLayerNormalizationKerneloperator= (const NEQLSTMLayerNormalizationKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NEQLSTMLayerNormalizationKernel (NEQLSTMLayerNormalizationKernel &&)=default
 Default Move Constructor. More...
 
NEQLSTMLayerNormalizationKerneloperator= (NEQLSTMLayerNormalizationKernel &&)=default
 Default move assignment operator. More...
 
 ~NEQLSTMLayerNormalizationKernel ()=default
 Default destructor. More...
 
void configure (const ITensor *input, ITensor *output, const ITensor *weight, const ITensor *bias)
 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...
 
bool is_window_configured () const
 Function to check if the embedded window of this kernel has been configured. More...
 

Static Public Member Functions

static Status validate (const ITensorInfo *input, const ITensorInfo *output, const ITensorInfo *weight, const ITensorInfo *bias)
 Static function to check if given info will lead to a valid configuration of NEQLSTMLayerNormalizationKernel. More...
 

Detailed Description

Kernel to perform layer normalization for QLSTM.

Definition at line 35 of file NEQLSTMLayerNormalizationKernel.h.

Constructor & Destructor Documentation

◆ NEQLSTMLayerNormalizationKernel() [1/3]

Default constructor.

Referenced by NEQLSTMLayerNormalizationKernel::name().

◆ NEQLSTMLayerNormalizationKernel() [2/3]

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

◆ NEQLSTMLayerNormalizationKernel() [3/3]

Default Move Constructor.

◆ ~NEQLSTMLayerNormalizationKernel()

Default destructor.

Referenced by NEQLSTMLayerNormalizationKernel::name().

Member Function Documentation

◆ configure()

void configure ( const ITensor input,
ITensor output,
const ITensor weight,
const ITensor bias 
)

Set the input and output tensors.

Parameters
[in]inputSource tensor. Data types supported: QSYMM16.
[out]outputDestination tensor. Data types supported: Same as input.
[in]weightWeight tensor. Data types supported: Same as input.
[in]biasBias tensor. Data types supported: S32

Definition at line 84 of file NEQLSTMLayerNormalizationKernel.cpp.

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, arm_compute::auto_init_if_empty(), arm_compute::calculate_max_window(), arm_compute::quantization::calculate_quantized_multiplier(), Window::DimX, Window::DimY, Window::Dimension::end(), ITensor::info(), arm_compute::test::validation::input, arm_compute::QSYMM16, UniformQuantizationInfo::scale, Window::set(), Window::Dimension::start(), arm_compute::validate(), and Window::x().

Referenced by NEQLSTMLayerNormalizationKernel::name().

85 {
86  ARM_COMPUTE_ERROR_ON_NULLPTR(input, weight, bias, output);
87  ARM_COMPUTE_ERROR_ON(input == output);
88  ARM_COMPUTE_ERROR_THROW_ON(validate(input->info(), output->info(), weight->info(), bias->info()));
89 
90  static const std::map<DataType, ComputeFuncType> fn_map =
91  {
92  { DataType::QSYMM16, std::mem_fn(&NEQLSTMLayerNormalizationKernel::compute_qsymm16) },
93  };
94 
95  _input = input;
96  _output = output;
97  _weight = weight;
98  _bias = bias;
99  _fn = fn_map.at(_input->info()->data_type());
100 
101  auto_init_if_empty(*_output->info(), *_input->info());
102  _output->info()->set_quantization_info(compute_output_qinfo());
103 
104  const UniformQuantizationInfo wq_info = _weight->info()->quantization_info().uniform();
105  const Status s = quantization::calculate_quantized_multiplier(wq_info.scale, &_output_multiplier, &_output_shift);
106  _output_shift *= -1;
107 
108  if(!bool(s))
109  {
110  _output_multiplier = 0;
111  _output_shift = 0;
112  }
113 
114  Window win = configure_window(output);
115  INEKernel::configure(win);
116 }
static Status validate(const ITensorInfo *input, const ITensorInfo *output, const ITensorInfo *weight, const ITensorInfo *bias)
Static function to check if given info will lead to a valid configuration of NEQLSTMLayerNormalizatio...
quantized, symmetric fixed-point 16-bit number
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_ERROR_THROW_ON(status)
Definition: Error.h:455
Status calculate_quantized_multiplier(float multiplier, int32_t *quant_multiplier, int32_t *shift, bool ignore_epsilon=false)
Calculate quantized representation of multiplier.
UniformQuantizationInfo uniform() const
Return per layer quantization info.
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.
virtual ITensorInfo & set_quantization_info(const QuantizationInfo &quantization_info)=0
Set the quantization settings (scale and offset) of the tensor.
virtual QuantizationInfo quantization_info() const =0
Get the quantization settings (scale and offset) of the tensor.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:157

◆ name()

◆ operator=() [1/2]

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

Referenced by NEQLSTMLayerNormalizationKernel::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 163 of file NEQLSTMLayerNormalizationKernel.cpp.

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_MSG, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, arm_compute::execute_window_loop(), arm_compute::quantization::get_invsqrt_quantized_multiplier_exp(), arm_compute::quantization::multiply_by_quantized_multiplier(), arm_compute::multiply_by_quantized_multiplier_2row(), arm_compute::wrapper::vadd(), arm_compute::wrapper::vcombine(), arm_compute::wrapper::vdup_n(), arm_compute::wrapper::vgethigh(), arm_compute::wrapper::vgetlane(), arm_compute::wrapper::vgetlow(), arm_compute::wrapper::vloadq(), arm_compute::wrapper::vmovl(), arm_compute::wrapper::vmovn(), arm_compute::wrapper::vmul(), arm_compute::wrapper::vpaddl(), arm_compute::wrapper::vqmovn(), arm_compute::wrapper::vstore(), arm_compute::wrapper::vsub(), and IKernel::window().

Referenced by NEQLSTMLayerNormalizationKernel::name().

164 {
168  ARM_COMPUTE_ERROR_ON_MSG(!_fn, "internal function is not defined for computation");
169 
170  _fn(*this);
171 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
Definition: Error.h:456
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:915
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:201

◆ validate()

Status validate ( const ITensorInfo input,
const ITensorInfo output,
const ITensorInfo weight,
const ITensorInfo bias 
)
static

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

Parameters
[in]inputSource tensor info. Data types supported: QSYMM16.
[in]outputDestination tensor info. Data types supported: Same as input.
[in]weightWeight tensor info. Data types supported: Same as input.
[in]biasBias tensor info. Data types supported: S32
Returns
a status

Definition at line 137 of file NEQLSTMLayerNormalizationKernel.cpp.

References ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_RETURN_ERROR_ON, ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN, ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES, ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES, ARM_COMPUTE_UNUSED, ITensorInfo::num_dimensions(), arm_compute::QSYMM16, arm_compute::S32, ITensorInfo::tensor_shape(), ITensorInfo::total_size(), and Dimensions< T >::x().

Referenced by NEQLSTMLayerNormalizationKernel::name().

138 {
139  ARM_COMPUTE_UNUSED(output, bias, weight, input);
140 
141  ARM_COMPUTE_ERROR_ON_NULLPTR(input, weight, bias, output);
142 
146 
147  ARM_COMPUTE_RETURN_ERROR_ON(input->num_dimensions() > max_input_dimension);
148  ARM_COMPUTE_RETURN_ERROR_ON(weight->num_dimensions() > max_weight_dimension);
149  ARM_COMPUTE_RETURN_ERROR_ON(bias->num_dimensions() > max_bias_dimension);
150 
151  ARM_COMPUTE_RETURN_ERROR_ON(input->tensor_shape().x() != weight->tensor_shape().x());
153 
154  if(output->total_size() != 0)
155  {
158  }
159 
160  return Status{};
161 }
quantized, symmetric fixed-point 16-bit number
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
Definition: Error.h:296
1 channel, 1 S32 per channel
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(...)
Definition: Validate.h:439
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...)
Definition: Validate.h:541
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:788
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:157

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