From 396cb95774bd7627254e3befec5e34844de701c9 Mon Sep 17 00:00:00 2001 From: Sang-Hoon Park Date: Thu, 26 Mar 2020 14:02:37 +0000 Subject: COMPMID-3284 add utilities for layer normalization of NEON QLSTM Change-Id: Ie98a8c4c30ac7859a989a29cbe7602c1c6fec26b Signed-off-by: Sang-Hoon Park Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/2934 Tested-by: Arm Jenkins Comments-Addressed: Arm Jenkins Reviewed-by: Georgios Pinitas --- arm_compute/core/NEON/NESymm.h | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'arm_compute/core/NEON/NESymm.h') diff --git a/arm_compute/core/NEON/NESymm.h b/arm_compute/core/NEON/NESymm.h index 924840930a..0cc2a963cf 100644 --- a/arm_compute/core/NEON/NESymm.h +++ b/arm_compute/core/NEON/NESymm.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 ARM Limited. + * Copyright (c) 2019-2020 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -25,6 +25,7 @@ #define ARM_COMPUTE_NESYMM_H #include "arm_compute/core/NEON/NEMath.h" +#include "arm_compute/core/utils/quantization/AsymmHelpers.h" #include namespace arm_compute @@ -230,5 +231,26 @@ inline qsymm16x8x2_t vquantize_qsymm16(const float32x4x4_t &qv, const UniformQua return res; } +/** Multiply a neon vector using quantized multiplier and shift + * + * @param[in] input Input vector to mutiply values to be quantized. + * @param[in] qmul Quantized multipler + * @param[in] shift Left bit shift + * + * @return A neon vector holding the multiplied value + */ +inline int32x4x2_t multiply_by_quantized_multipler_2row(int32x4x2_t input, int32_t qmul, int32_t shift) +{ + const auto left_shift = shift > 0 ? shift : 0; + const auto right_shift = shift > 0 ? 0 : -shift; + const auto one_shifted = 1 << left_shift; + + int32x4x2_t result; + result.val[0] = rounding_divide_by_pow2(vqrdmulhq_n_s32(vmulq_n_s32(input.val[0], one_shifted), qmul), right_shift); + result.val[1] = rounding_divide_by_pow2(vqrdmulhq_n_s32(vmulq_n_s32(input.val[1], one_shifted), qmul), right_shift); + + return result; +} + } // namespace arm_compute #endif // ARM_COMPUTE_NESYMM_H -- cgit v1.2.1