Compute Library
 22.05
qlstm_layer_normalization.cl File Reference
#include "helpers_asymm.h"

Go to the source code of this file.

Macros

#define VEC_SIZE   16
 
#define multiply_by_quantized_multiplier(input, qmul, shift)   MULTIPLY_BY_QUANTIZED_MULTIPLIER(input, qmul, shift, 16)
 
#define PERFORM_REDUCTION_IMPL(type)
 
#define PERFORM_REDUCTION_STR(input, type)   perform_reduction_##type(input)
 
#define PERFORM_REDUCTION(input, type)   PERFORM_REDUCTION_STR(input, type)
 

Functions

int perform_reduction_int (int16 sum)
 
long perform_reduction_long (long16 sum)
 
int2 get_invsqrt_quantized_multiplier_exp (int in, int reverse_shift)
 Compute quantized multiplier and shift for the inverse square root of input. More...
 

Macro Definition Documentation

◆ multiply_by_quantized_multiplier

#define multiply_by_quantized_multiplier (   input,
  qmul,
  shift 
)    MULTIPLY_BY_QUANTIZED_MULTIPLIER(input, qmul, shift, 16)

Definition at line 55 of file qlstm_layer_normalization.cl.

Referenced by get_invsqrt_quantized_multiplier_exp().

◆ PERFORM_REDUCTION

#define PERFORM_REDUCTION (   input,
  type 
)    PERFORM_REDUCTION_STR(input, type)

Definition at line 68 of file qlstm_layer_normalization.cl.

Referenced by get_invsqrt_quantized_multiplier_exp().

◆ PERFORM_REDUCTION_IMPL

#define PERFORM_REDUCTION_IMPL (   type)
Value:
inline VEC_DATA_TYPE(type, 1) perform_reduction_##type(VEC_DATA_TYPE(type, 16) sum) \
{ \
sum.s01234567 += sum.s89abcdef; \
sum.s0123 += sum.s4567; \
sum.s01 += sum.s23; \
sum.s0 += sum.s1; \
return sum.s0; \
}
decltype(strategy::transforms) typedef type
#define VEC_DATA_TYPE(type, size)
Definition: helpers.h:727

Definition at line 56 of file qlstm_layer_normalization.cl.

◆ PERFORM_REDUCTION_STR

#define PERFORM_REDUCTION_STR (   input,
  type 
)    perform_reduction_##type(input)

Definition at line 67 of file qlstm_layer_normalization.cl.

◆ VEC_SIZE

Function Documentation

◆ get_invsqrt_quantized_multiplier_exp()

int2 get_invsqrt_quantized_multiplier_exp ( int  in,
int  reverse_shift 
)
inline

Compute quantized multiplier and shift for the inverse square root of input.

Using 3-bit fixed point and 5 iteration of Newton-Raphson method.

Parameters
[in]inInput to use
[in]reverse_shift-1 to reverse the shift direction
Returns
: .s0 Quantized multiplier for inverse square root .s1 Shift for inverse square root

Definition at line 84 of file qlstm_layer_normalization.cl.

References ASYMM_MULT, ASYMM_RESCALE, ASYMM_ROUNDING_DIVIDE_BY_POW2, arm_compute::test::validation::b, bias, CONVERT, CONVERT_TO_IMAGE_STRUCT, CONVERT_TO_VECTOR_STRUCT, IMAGE_DECLARATION, arm_compute::test::validation::input, multiply_by_quantized_multiplier, MULTIPLY_BY_QUANTIZED_MULTIPLIER, offset(), PERFORM_REDUCTION, arm_compute::test::validation::reference::qlstm_layer_normalization(), VEC_DATA_TYPE, VEC_SIZE, VECTOR_DECLARATION, vector_offset(), VLOAD, VSTORE, and arm_compute::test::validation::w.

85 {
86  int2 stddev_inv;
87  int stddev_inv_multiplier = INT_MAX;
88  int stddev_inv_shift = 0;
89  int input = in;
90  if(input <= 1)
91  {
92  stddev_inv.s0 = stddev_inv_multiplier;
93  stddev_inv.s1 = stddev_inv_shift;
94  return stddev_inv;
95  }
96 
97  stddev_inv_shift = 11;
98  while(input >= (1 << 29))
99  {
100  input /= 4;
101  ++stddev_inv_shift;
102  }
103 
104  const unsigned int max_left_shift_bits = clz(input) - 1;
105  const unsigned int max_left_shift_bits_pairs = max_left_shift_bits / 2;
106  const unsigned int left_shift_bit_pairs = max_left_shift_bits_pairs - 1;
107  stddev_inv_shift -= left_shift_bit_pairs;
108  input <<= 2 * left_shift_bit_pairs;
109 
110  typedef int FixedPointRawType;
111  const unsigned int fixedpoint_position = 3;
112  const unsigned int fixedpoint_int_position = sizeof(FixedPointRawType) * 8 - 1 - fixedpoint_position;
113  typedef FixedPointRawType FixedPoint3;
114  typedef FixedPointRawType FixedPoint0;
115 
116  const FixedPoint3 fixedpoint_input = (input >> 1);
117  const FixedPoint3 fixedpoint_half_input = ASYMM_ROUNDING_DIVIDE_BY_POW2(fixedpoint_input, 1, 1);
118  const FixedPoint3 fixedpoint_half_three = (0x1 << fixedpoint_int_position) + (0x1 << (fixedpoint_int_position - 1));
119  FixedPoint3 x = 0x1 << fixedpoint_int_position;
120 
121  const int num_iteration = 5;
122  for(int i = 0; i < num_iteration; i++)
123  {
124  int x3 = ASYMM_RESCALE(ASYMM_MULT(ASYMM_MULT(x, x, 1), x, 1), 9, fixedpoint_position, 1);
125  x = ASYMM_RESCALE(ASYMM_MULT(fixedpoint_half_three, x, 1) - ASYMM_MULT(fixedpoint_half_input, x3, 1), 6, fixedpoint_position, 1);
126  }
127  const FixedPoint0 fixedpoint_half_sqrt_2 = 1518500250;
128  x = ASYMM_MULT(fixedpoint_half_sqrt_2, x, 1);
129  stddev_inv_multiplier = x;
130  if(stddev_inv_shift < 0)
131  {
132  stddev_inv_multiplier <<= -stddev_inv_shift;
133  stddev_inv_shift = 0;
134  }
135  stddev_inv_shift *= reverse_shift;
136 
137  stddev_inv.s0 = stddev_inv_multiplier;
138  stddev_inv.s1 = stddev_inv_shift;
139  return stddev_inv;
140 }
#define ASYMM_MULT(a, b, size)
#define ASYMM_ROUNDING_DIVIDE_BY_POW2(x, exponent, size)
#define ASYMM_RESCALE(value, src_integer_bits, dst_integer_bits, size)

◆ perform_reduction_int()

int perform_reduction_int ( int16  sum)
inline

Definition at line 70 of file qlstm_layer_normalization.cl.

85 {

◆ perform_reduction_long()

long perform_reduction_long ( long16  sum)
inline

Definition at line 71 of file qlstm_layer_normalization.cl.

85 {