diff options
Diffstat (limited to 'tests/validation/reference/GEMMLowp.cpp')
-rw-r--r-- | tests/validation/reference/GEMMLowp.cpp | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/tests/validation/reference/GEMMLowp.cpp b/tests/validation/reference/GEMMLowp.cpp index 4529b91a48..99d08e34f1 100644 --- a/tests/validation/reference/GEMMLowp.cpp +++ b/tests/validation/reference/GEMMLowp.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 ARM Limited. + * Copyright (c) 2017-2020 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -60,9 +60,9 @@ struct DataTypeExtractor } }; -template <typename T> -void quantize_down_int32_to_uint8_scale(const SimpleTensor<T> *in, const SimpleTensor<T> *bias, SimpleTensor<uint8_t> *dst, int32_t result_offset, std::vector<int32_t> result_mult_int, - std::vector<int32_t> result_shift, int32_t min, int32_t max) +template <typename TIn, typename TOut> +void quantize_down_scale(const SimpleTensor<TIn> *in, const SimpleTensor<TIn> *bias, SimpleTensor<TOut> *dst, int32_t result_offset, std::vector<int32_t> result_mult_int, + std::vector<int32_t> result_shift, int32_t min, int32_t max) { const int cols_in = in->shape().x(); const bool is_per_channel = result_mult_int.size() > 1; @@ -86,7 +86,8 @@ void quantize_down_int32_to_uint8_scale(const SimpleTensor<T> *in, const SimpleT result = std::max(min, std::min(max, result)); } - (*dst)[i] = static_cast<uint8_t>(std::max(0, std::min(255, result))); + (*dst)[i] = static_cast<TOut>(std::max<TIn>(std::numeric_limits<TOut>::lowest(), + std::min<TIn>(std::numeric_limits<TOut>::max(), result))); } } @@ -192,24 +193,24 @@ SimpleTensor<T1> gemmlowp(const SimpleTensor<T2> &a, const SimpleTensor<T3> &b, return gemmlowp_matrix_multiply_core<T1, T2, T3>(a, b, shape_c, 0, 0); } -template <typename T> -SimpleTensor<uint8_t> gemmlowp_quantize_down_int32_to_uint8_scale(const SimpleTensor<T> &in, int32_t result_offset, std::vector<int32_t> result_mult_int, std::vector<int32_t> result_shift, - int32_t min, int32_t max) +template <typename TIn, typename TOut> +SimpleTensor<TOut> gemmlowp_quantize_down_scale(const SimpleTensor<TIn> &in, int32_t result_offset, std::vector<int32_t> result_mult_int, std::vector<int32_t> result_shift, + int32_t min, int32_t max) { - SimpleTensor<uint8_t> dst(in.shape(), DataType::QASYMM8); + SimpleTensor<TOut> dst(in.shape(), DataTypeExtractor<TOut>::data_type()); - quantize_down_int32_to_uint8_scale<T>(&in, nullptr, &dst, result_offset, result_mult_int, result_shift, min, max); + quantize_down_scale<TIn, TOut>(&in, nullptr, &dst, result_offset, result_mult_int, result_shift, min, max); return dst; } -template <typename T> -SimpleTensor<uint8_t> gemmlowp_quantize_down_int32_to_uint8_scale(const SimpleTensor<T> &in, const SimpleTensor<T> &bias, int32_t result_offset, std::vector<int32_t> result_mult_int, - std::vector<int32_t> result_shift, int32_t min, int32_t max) +template <typename TIn, typename TOut> +SimpleTensor<TOut> gemmlowp_quantize_down_scale(const SimpleTensor<TIn> &in, const SimpleTensor<TIn> &bias, int32_t result_offset, std::vector<int32_t> result_mult_int, + std::vector<int32_t> result_shift, int32_t min, int32_t max) { - SimpleTensor<uint8_t> dst(in.shape(), DataType::QASYMM8); + SimpleTensor<TOut> dst(in.shape(), DataTypeExtractor<TOut>::data_type()); - quantize_down_int32_to_uint8_scale<T>(&in, &bias, &dst, result_offset, result_mult_int, result_shift, min, max); + quantize_down_scale<TIn, TOut>(&in, &bias, &dst, result_offset, result_mult_int, result_shift, min, max); return dst; } @@ -251,10 +252,14 @@ template SimpleTensor<int16_t> gemmlowp_quantize_down_scale_by_fixedpoint(const template SimpleTensor<int16_t> gemmlowp_quantize_down_scale_by_fixedpoint(const SimpleTensor<int32_t> &a, const SimpleTensor<int32_t> &b, std::vector<int32_t> result_fixedpoint_multiplier, std::vector<int32_t> result_shift, int32_t result_offset_after_shift, int32_t min, int32_t max); -template SimpleTensor<uint8_t> gemmlowp_quantize_down_int32_to_uint8_scale(const SimpleTensor<int32_t> &a, int32_t result_offset, std::vector<int32_t> result_mult_int, - std::vector<int32_t> result_shift, int32_t min, int32_t max); -template SimpleTensor<uint8_t> gemmlowp_quantize_down_int32_to_uint8_scale(const SimpleTensor<int32_t> &a, const SimpleTensor<int32_t> &b, int32_t result_offset, std::vector<int32_t> result_mult_int, - std::vector<int32_t> result_shift, int32_t min, int32_t max); +template SimpleTensor<uint8_t> gemmlowp_quantize_down_scale(const SimpleTensor<int32_t> &a, int32_t result_offset, std::vector<int32_t> result_mult_int, + std::vector<int32_t> result_shift, int32_t min, int32_t max); +template SimpleTensor<uint8_t> gemmlowp_quantize_down_scale(const SimpleTensor<int32_t> &a, const SimpleTensor<int32_t> &b, int32_t result_offset, std::vector<int32_t> result_mult_int, + std::vector<int32_t> result_shift, int32_t min, int32_t max); +template SimpleTensor<int8_t> gemmlowp_quantize_down_scale(const SimpleTensor<int32_t> &a, int32_t result_offset, std::vector<int32_t> result_mult_int, + std::vector<int32_t> result_shift, int32_t min, int32_t max); +template SimpleTensor<int8_t> gemmlowp_quantize_down_scale(const SimpleTensor<int32_t> &a, const SimpleTensor<int32_t> &b, int32_t result_offset, std::vector<int32_t> result_mult_int, + std::vector<int32_t> result_shift, int32_t min, int32_t max); template SimpleTensor<int32_t> gemmlowp_matrix_multiply_core(const SimpleTensor<int8_t> &a, const SimpleTensor<int8_t> &b, TensorShape shape_c, int32_t a_offset, int32_t b_offset); template SimpleTensor<int32_t> gemmlowp_matrix_multiply_core(const SimpleTensor<uint8_t> &a, const SimpleTensor<uint8_t> &b, TensorShape shape_c, int32_t a_offset, int32_t b_offset); template SimpleTensor<int32_t> gemmlowp<int32_t, int8_t, int8_t>(const SimpleTensor<int8_t> &a, const SimpleTensor<int8_t> &b, TensorShape shape_c); |