diff options
Diffstat (limited to 'tests/validation/reference')
-rw-r--r-- | tests/validation/reference/Convolution3d.h | 13 | ||||
-rw-r--r-- | tests/validation/reference/DepthwiseConvolutionLayer.cpp | 7 | ||||
-rw-r--r-- | tests/validation/reference/FullyConnectedLayer.cpp | 7 | ||||
-rw-r--r-- | tests/validation/reference/UtilsQuantizedAsymm.h | 26 |
4 files changed, 34 insertions, 19 deletions
diff --git a/tests/validation/reference/Convolution3d.h b/tests/validation/reference/Convolution3d.h index 23918a4055..6ac5df93b3 100644 --- a/tests/validation/reference/Convolution3d.h +++ b/tests/validation/reference/Convolution3d.h @@ -21,8 +21,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#ifndef __ARM_COMPUTE_TEST_VALIDATION_CONVOLUTION_H__ -#define __ARM_COMPUTE_TEST_VALIDATION_CONVOLUTION_H__ +#ifndef ARM_COMPUTE_TEST_VALIDATION_CONVOLUTION_H +#define ARM_COMPUTE_TEST_VALIDATION_CONVOLUTION_H #include "arm_compute/core/utils/quantization/AsymmHelpers.h" #include "tests/validation/Helpers.h" @@ -133,7 +133,7 @@ inline void convolution3d(const SimpleTensor<T> &in, const SimpleTensor<TW> &wei int output_multiplier = 0; int output_shift = 0; const float multiplier = input_scale * weights_scale / output_scale; - arm_compute::quantization::calculate_quantized_multiplier_less_than_one(multiplier, &output_multiplier, &output_shift); + arm_compute::quantization::calculate_quantized_multiplier(multiplier, &output_multiplier, &output_shift); const int half_width_weights_start = width_weights / 2; const int half_width_weights_end = ((width_weights % 2) == 0) ? (half_width_weights_start - 1) : half_width_weights_start; @@ -171,9 +171,8 @@ inline void convolution3d(const SimpleTensor<T> &in, const SimpleTensor<TW> &wei // Accumulate the bias acc += (*b_ptr); - acc = validation::asymm_rounding_divide_by_pow2(validation::asymm_int_mult(acc, output_multiplier), output_shift); - acc += output_offset; - acc = utility::clamp<int32_t>(acc, 0, 255); + // Quantize down + acc = validation::quantize_down_scale_by_fixedpoint(acc, output_multiplier, output_shift, output_offset, 0, 255); // Store the result *out_ptr = acc; @@ -182,4 +181,4 @@ inline void convolution3d(const SimpleTensor<T> &in, const SimpleTensor<TW> &wei } // namespace convolution_3d } // namespace test } // namespace arm_compute -#endif /*__ARM_COMPUTE_TEST_VALIDATION_CONVOLUTION_H__ */ +#endif /* ARM_COMPUTE_TEST_VALIDATION_CONVOLUTION_H */ diff --git a/tests/validation/reference/DepthwiseConvolutionLayer.cpp b/tests/validation/reference/DepthwiseConvolutionLayer.cpp index 608093d381..0c7e92b8d0 100644 --- a/tests/validation/reference/DepthwiseConvolutionLayer.cpp +++ b/tests/validation/reference/DepthwiseConvolutionLayer.cpp @@ -197,7 +197,7 @@ SimpleTensor<T> depthwise_convolution_quantized(const SimpleTensor<T> &src, cons int output_shift = 0; const float weights_scale = (is_quantized_per_channel) ? weights_scale_vec[out_z] : weights_scale_vec[0]; const float multiplier = input_scale * weights_scale / output_scale; - arm_compute::quantization::calculate_quantized_multiplier_less_than_one(multiplier, &output_multiplier, &output_shift); + arm_compute::quantization::calculate_quantized_multiplier(multiplier, &output_multiplier, &output_shift); for(int y = minimum_y; y <= minimum_y + maximum_y; y += conv_info.stride().second) { @@ -220,9 +220,8 @@ SimpleTensor<T> depthwise_convolution_quantized(const SimpleTensor<T> &src, cons } } val += bias_val; - val = asymm_rounding_divide_by_pow2(asymm_int_mult(val, output_multiplier), output_shift); - val += output_offset; - val = utility::clamp<int32_t>(val, 0, 255); + // Quantize down + val = quantize_down_scale_by_fixedpoint(val, output_multiplier, output_shift, output_offset, 0, 255); // Store the result dst[out_pos++] = val; diff --git a/tests/validation/reference/FullyConnectedLayer.cpp b/tests/validation/reference/FullyConnectedLayer.cpp index cd84b9cfd1..261c6453b9 100644 --- a/tests/validation/reference/FullyConnectedLayer.cpp +++ b/tests/validation/reference/FullyConnectedLayer.cpp @@ -81,7 +81,7 @@ void vector_matrix_multiply(const SimpleTensor<T> &src, const SimpleTensor<T> &w int output_multiplier = 0; int output_shift = 0; const float multiplier = input_scale * weights_scale / output_scale; - arm_compute::quantization::calculate_quantized_multiplier_less_than_one(multiplier, &output_multiplier, &output_shift); + arm_compute::quantization::calculate_quantized_multiplier(multiplier, &output_multiplier, &output_shift); for(int y = 0; y < rows_weights; ++y) { @@ -96,9 +96,8 @@ void vector_matrix_multiply(const SimpleTensor<T> &src, const SimpleTensor<T> &w // Accumulate the bias acc += bias_ptr[y]; - acc = asymm_rounding_divide_by_pow2(asymm_int_mult(acc, output_multiplier), output_shift); - acc += output_offset; - acc = utility::clamp<int32_t>(acc, 0, 255); + // Quantize down + acc = quantize_down_scale_by_fixedpoint(acc, output_multiplier, output_shift, output_offset, 0, 255); // Store the result dst_ptr[y] = static_cast<T>(acc); diff --git a/tests/validation/reference/UtilsQuantizedAsymm.h b/tests/validation/reference/UtilsQuantizedAsymm.h index b7b69d588a..444696c93a 100644 --- a/tests/validation/reference/UtilsQuantizedAsymm.h +++ b/tests/validation/reference/UtilsQuantizedAsymm.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited. + * Copyright (c) 2017-2019 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -21,8 +21,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#ifndef __ARM_COMPUTE_TEST_VALIDATION_UTILS_QUANTIZED_ASYMM_H__ -#define __ARM_COMPUTE_TEST_VALIDATION_UTILS_QUANTIZED_ASYMM_H__ +#ifndef ARM_COMPUTE_TEST_VALIDATION_UTILS_QUANTIZED_ASYMM_H +#define ARM_COMPUTE_TEST_VALIDATION_UTILS_QUANTIZED_ASYMM_H #include <cstdint> @@ -51,7 +51,25 @@ inline int32_t asymm_int_mult(int32_t a, int32_t b) int32_t ab_x2_high32 = static_cast<int32_t>((ab_64 + nudge) / (1ll << 31)); return overflow ? std::numeric_limits<int32_t>::max() : ab_x2_high32; } + +/** Quantize down the input value in range [min, max]. */ +inline int32_t quantize_down_scale_by_fixedpoint(int32_t val, int32_t result_mult_int, int32_t result_shift, + int32_t result_offset_after_shift, int32_t min, int32_t max) +{ + int32_t res = 0; + if(result_shift < 0) + { + res = asymm_int_mult(val * (1 << (-result_shift)), result_mult_int); + } + else + { + res = asymm_rounding_divide_by_pow2(asymm_int_mult(val, result_mult_int), result_shift); + } + res += result_offset_after_shift; + res = utility::clamp<int32_t>(res, min, max); + return res; +} } // namespace validation } // namespace test } // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_VALIDATION_UTILS_QUANTIZED_ASYMM_H__ */ +#endif /* ARM_COMPUTE_TEST_VALIDATION_UTILS_QUANTIZED_ASYMM_H */ |