diff options
author | Viet-Hoa Do <viet-hoa.do@arm.com> | 2023-04-26 15:38:45 +0100 |
---|---|---|
committer | Viet-Hoa Do <viet-hoa.do@arm.com> | 2023-05-02 08:57:02 +0000 |
commit | a62129a02397ba87171ebf4477795f628dcec0f6 (patch) | |
tree | 91e53cc8982d9f16e66db53f81830fb05da83596 /src/core/utils/quantization/AsymmHelpers.cpp | |
parent | f0ff76dbfc9137d0dfc5e99666e24c7a2ca8b072 (diff) | |
download | ComputeLibrary-a62129a02397ba87171ebf4477795f628dcec0f6.tar.gz |
Fix fully connected and matmul mismatches
* There is an issue with quantized fully connected and matmul
when the lower bound of bounded ReLU is negative.
* Use int32_t for the calculation of min/max quantized value
rather than PixelValue to avoid this issue.
Partially resolves: COMPMID-5996
Signed-off-by: Viet-Hoa Do <viet-hoa.do@arm.com>
Change-Id: I7b22e9d56a2441fc6a4c5c4e627f57d6e00d6ff1
Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/9502
Tested-by: Arm Jenkins <bsgcomp@arm.com>
Reviewed-by: Jakub Sujak <jakub.sujak@arm.com>
Comments-Addressed: Arm Jenkins <bsgcomp@arm.com>
Benchmark: Arm Jenkins <bsgcomp@arm.com>
Diffstat (limited to 'src/core/utils/quantization/AsymmHelpers.cpp')
-rw-r--r-- | src/core/utils/quantization/AsymmHelpers.cpp | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/src/core/utils/quantization/AsymmHelpers.cpp b/src/core/utils/quantization/AsymmHelpers.cpp index ba9a97aef9..f5b69c7a44 100644 --- a/src/core/utils/quantization/AsymmHelpers.cpp +++ b/src/core/utils/quantization/AsymmHelpers.cpp @@ -24,6 +24,7 @@ #include "arm_compute/core/utils/quantization/AsymmHelpers.h" #include "arm_compute/core/Helpers.h" #include "support/ToolchainSupport.h" +#include "src/core/utils/quantization/AsymmHelpers.h" #include <cmath> #include <limits> @@ -177,11 +178,15 @@ std::pair<int, int> get_min_max_values_from_quantized_data_type(DataType data_ty return std::make_pair(min_quant_val, max_quant_val); } -std::tuple<PixelValue, PixelValue> get_quantized_asymmetric_output_min_max(const QuantizationInfo &q_info, const ActivationLayerInfo &act_info, DataType data_type) +std::tuple<int32_t, int32_t> get_quantized_asymmetric_output_min_max(const QuantizationInfo &q_info, const ActivationLayerInfo &act_info, DataType data_type) { - PixelValue type_min{}; - PixelValue type_max{}; - std::tie(type_min, type_max) = get_min_max(data_type); + ARM_COMPUTE_ERROR_ON(data_type != DataType::QASYMM8 && data_type != DataType::QASYMM8_SIGNED); + + const auto min_max = get_min_max(data_type); + + int32_t type_min = std::get<0>(min_max).get<int32_t>(); + int32_t type_max = std::get<1>(min_max).get<int32_t>(); + const UniformQuantizationInfo q_unif = q_info.uniform(); if(act_info.enabled()) @@ -189,15 +194,15 @@ std::tuple<PixelValue, PixelValue> get_quantized_asymmetric_output_min_max(const switch(act_info.activation()) { case ActivationLayerInfo::ActivationFunction::RELU: - type_min = PixelValue(q_unif.offset); + type_min = q_unif.offset; break; case ActivationLayerInfo::ActivationFunction::BOUNDED_RELU: - type_min = PixelValue(q_unif.offset); - type_max = PixelValue(act_info.a(), data_type, q_info); + type_min = q_unif.offset; + type_max = (data_type == DataType::QASYMM8) ? quantize_qasymm8(act_info.a(), q_info) : quantize_qasymm8_signed(act_info.a(), q_info); break; case ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU: - type_min = PixelValue(act_info.b(), data_type, q_info); - type_max = PixelValue(act_info.a(), data_type, q_info); + type_min = (data_type == DataType::QASYMM8) ? quantize_qasymm8(act_info.b(), q_info) : quantize_qasymm8_signed(act_info.b(), q_info); + type_max = (data_type == DataType::QASYMM8) ? quantize_qasymm8(act_info.a(), q_info) : quantize_qasymm8_signed(act_info.a(), q_info); break; default: ARM_COMPUTE_ERROR("Activation function not supported."); @@ -205,7 +210,7 @@ std::tuple<PixelValue, PixelValue> get_quantized_asymmetric_output_min_max(const } } - return std::make_pair(type_min, type_max); + return std::make_tuple(type_min, type_max); } void compute_quantized_multipliers_and_shifts(const ITensorInfo *input, |