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/cpu/operators | |
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/cpu/operators')
-rw-r--r-- | src/cpu/operators/CpuFullyConnected.cpp | 9 | ||||
-rw-r--r-- | src/cpu/operators/CpuMatMul.cpp | 9 |
2 files changed, 10 insertions, 8 deletions
diff --git a/src/cpu/operators/CpuFullyConnected.cpp b/src/cpu/operators/CpuFullyConnected.cpp index 460257902d..395d8d2aa5 100644 --- a/src/cpu/operators/CpuFullyConnected.cpp +++ b/src/cpu/operators/CpuFullyConnected.cpp @@ -32,6 +32,7 @@ #include "src/common/utils/Log.h" #include "src/core/helpers/AutoConfiguration.h" #include "src/core/helpers/MemoryHelpers.h" +#include "src/core/utils/quantization/AsymmHelpers.h" #include "src/cpu/kernels/CpuTransposeKernel.h" #include "src/cpu/operators/CpuConvertFullyConnectedWeights.h" #include "src/cpu/operators/CpuFlatten.h" @@ -63,16 +64,16 @@ Status get_gemmlowp_output_stage_info(const ITensorInfo *src, const ITensorInfo ARM_COMPUTE_RETURN_ON_ERROR(quantization::calculate_quantized_multiplier(multiplier, &output_multiplier, &output_shift)); - PixelValue type_min{}; - PixelValue type_max{}; + int32_t type_min = 0; + int32_t type_max = 0; std::tie(type_min, type_max) = quantization::get_quantized_asymmetric_output_min_max(oq_info, act, data_type); gemmlowp_output_stage_info.gemmlowp_multiplier = output_multiplier; gemmlowp_output_stage_info.gemmlowp_shift = output_shift; gemmlowp_output_stage_info.gemmlowp_offset = oq_unif.offset; gemmlowp_output_stage_info.type = GEMMLowpOutputStageType::QUANTIZE_DOWN_FIXEDPOINT; - gemmlowp_output_stage_info.gemmlowp_min_bound = type_min.get<int32_t>(); - gemmlowp_output_stage_info.gemmlowp_max_bound = type_max.get<int32_t>(); + gemmlowp_output_stage_info.gemmlowp_min_bound = type_min; + gemmlowp_output_stage_info.gemmlowp_max_bound = type_max; return Status{}; } diff --git a/src/cpu/operators/CpuMatMul.cpp b/src/cpu/operators/CpuMatMul.cpp index 369466b669..46858f4659 100644 --- a/src/cpu/operators/CpuMatMul.cpp +++ b/src/cpu/operators/CpuMatMul.cpp @@ -34,6 +34,7 @@ #include "src/core/CPP/Validate.h" #include "src/core/helpers/AutoConfiguration.h" #include "src/core/helpers/MemoryHelpers.h" +#include "src/core/utils/quantization/AsymmHelpers.h" #include "src/cpu/utils/CpuAuxTensorHandler.h" using namespace arm_compute::experimental; @@ -60,16 +61,16 @@ Status get_gemmlowp_output_stage_info(const ITensorInfo *src, const ITensorInfo ARM_COMPUTE_RETURN_ON_ERROR(quantization::calculate_quantized_multiplier(multiplier, &output_multiplier, &output_shift)); - PixelValue type_min{}; - PixelValue type_max{}; + int32_t type_min = 0; + int32_t type_max = 0; std::tie(type_min, type_max) = quantization::get_quantized_asymmetric_output_min_max(oq_info, act, data_type); gemmlowp_output_stage_info.gemmlowp_multiplier = output_multiplier; gemmlowp_output_stage_info.gemmlowp_shift = output_shift; gemmlowp_output_stage_info.gemmlowp_offset = oq_unif.offset; gemmlowp_output_stage_info.type = GEMMLowpOutputStageType::QUANTIZE_DOWN_FIXEDPOINT; - gemmlowp_output_stage_info.gemmlowp_min_bound = type_min.get<int32_t>(); - gemmlowp_output_stage_info.gemmlowp_max_bound = type_max.get<int32_t>(); + gemmlowp_output_stage_info.gemmlowp_min_bound = type_min; + gemmlowp_output_stage_info.gemmlowp_max_bound = type_max; return Status{}; } |