From 47d5170f7e1f7491db902b8b07703dd395c304be Mon Sep 17 00:00:00 2001 From: Max Bergfelt Date: Tue, 27 May 2025 10:01:53 +0200 Subject: [PATCH] MLBEDSW-10832: Align ElementwiseMul quantization scaling with reference Adjusted quantization scaling of ElementwiseMul to bit-exactly match the scaling calculation of QuantizedConvolutionMultipler in the reference. Scaling of BatchMatMul is consequently aligned. Change-Id: I00cc55d04ed84acdd8785e9f3610f6198423c65e Signed-off-by: Max Bergfelt --- ethosu/regor/architecture/ethosu85/ethos_u85_scaling.cpp | 2 +- ethosu/regor/common/scaling.hpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ethosu/regor/architecture/ethosu85/ethos_u85_scaling.cpp b/ethosu/regor/architecture/ethosu85/ethos_u85_scaling.cpp index b7171177..166774d0 100644 --- a/ethosu/regor/architecture/ethosu85/ethos_u85_scaling.cpp +++ b/ethosu/regor/architecture/ethosu85/ethos_u85_scaling.cpp @@ -99,7 +99,7 @@ void RescaleConvolution(HLCOperation *op) } else { - outScale = ElementwiseMulScale(ifm1Scale, ifm2Scale, ofmScale); + outScale = ElementwiseMulScale(ifm1Scale, ifm2Scale, ofmScale); } } diff --git a/ethosu/regor/common/scaling.hpp b/ethosu/regor/common/scaling.hpp index 0b4d0360..f288dd54 100644 --- a/ethosu/regor/common/scaling.hpp +++ b/ethosu/regor/common/scaling.hpp @@ -50,15 +50,15 @@ public: }; /* Calculate elementwise Mul OFM QuantizedScale */ -template +template QuantizedScale ElementwiseMulScale(double inputScale, double input2Scale, double outputScale) { // clamp to single-point precision T ifm1Scale = ClampToType(inputScale); T ifm2Scale = ClampToType(input2Scale); - T outScale = ClampToType(outputScale); + TDIV outScale = ClampToType(outputScale); - T outputRescale = (ifm1Scale * ifm2Scale) / outScale; + TDIV outputRescale = (ifm1Scale * ifm2Scale) / outScale; return QuantizedScale(outputRescale); } -- GitLab