From c71a4f173944f02f525108e901d1b81f2c9bdc4c Mon Sep 17 00:00:00 2001 From: Alexander Bengtsson Date: Thu, 13 Feb 2025 15:40:23 +0100 Subject: [PATCH] MLBEDSW-10436: Handle empty quantizations in SupportsFusedRescale - Empty quantizations are interpreted as unit-scales in RCS Do the same thing in SupportsFusedRescale Change-Id: Ia9becbd4db8746d29eb65ad9d5389171deffa99d Signed-off-by: Alexander Bengtsson --- ethosu/regor/architecture/ethosu55/ethos_u55_constraints.cpp | 4 ++-- ethosu/regor/architecture/ethosu85/ethos_u85_constraints.cpp | 4 ++-- ethosu/regor/compiler/quantization.hpp | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ethosu/regor/architecture/ethosu55/ethos_u55_constraints.cpp b/ethosu/regor/architecture/ethosu55/ethos_u55_constraints.cpp index da197be9..55334b5a 100644 --- a/ethosu/regor/architecture/ethosu55/ethos_u55_constraints.cpp +++ b/ethosu/regor/architecture/ethosu55/ethos_u55_constraints.cpp @@ -82,8 +82,9 @@ bool EthosU55Constraints::SupportsFusedRescale(OpType opType, TensorUsage tensor DataType rescaleToType, DataType opFromType, DataType opToType, const Quantization &quantization) { auto npuOp = ArchEthosU55::GetHWOp(opType); - bool globalScale = quantization.scales.size() == 1; + bool globalScale = quantization.scales.size() <= 1; bool isUnitScale = quantization.IsUnitScale(); + int64_t zp = quantization.zeroPoints.size() ? quantization.zeroPoints.front() : 0; if ( tensorUsage == TensorUsage::IFM ) { @@ -100,7 +101,6 @@ bool EthosU55Constraints::SupportsFusedRescale(OpType opType, TensorUsage tensor bool scaleSupported = qs.shift == 0 && static_cast(qs.scale) == qs.scale; // Make sure the rescale can be done without clipping - int64_t zp = quantization.zeroPoints.front(); int64_t value = (zp < 0 ? int64_t(IntegerMax(rescaleFromType)) : IntegerMin(rescaleFromType)); value = value - zp; value = (value * qs.scale) >> qs.shift; diff --git a/ethosu/regor/architecture/ethosu85/ethos_u85_constraints.cpp b/ethosu/regor/architecture/ethosu85/ethos_u85_constraints.cpp index 7988eb91..2badd56d 100644 --- a/ethosu/regor/architecture/ethosu85/ethos_u85_constraints.cpp +++ b/ethosu/regor/architecture/ethosu85/ethos_u85_constraints.cpp @@ -102,8 +102,9 @@ bool EthosU85Constraints::SupportsFusedRescale(OpType opType, TensorUsage tensor DataType rescaleToType, DataType opFromType, DataType opToType, const Quantization &quantization) { auto npuOp = ArchEthosU85::GetHWOp(opType); - bool globalScale = quantization.scales.size() == 1; + bool globalScale = quantization.scales.size() <= 1; bool isUnitScale = quantization.IsUnitScale(); + int64_t zp = quantization.zeroPoints.size() ? quantization.zeroPoints.front() : 0; if ( tensorUsage == TensorUsage::IFM ) { @@ -118,7 +119,6 @@ bool EthosU85Constraints::SupportsFusedRescale(OpType opType, TensorUsage tensor // Make sure shift is valid if ( qs.shift < 0 || qs.shift > 63 ) return false; // Make sure the rescale can be done without clipping - int64_t zp = quantization.zeroPoints.front(); int64_t value = (zp < 0 ? int64_t(IntegerMax(rescaleFromType)) : IntegerMin(rescaleFromType)); value = value - zp; value = (value * qs.scale) >> qs.shift; diff --git a/ethosu/regor/compiler/quantization.hpp b/ethosu/regor/compiler/quantization.hpp index a79212d0..dd054078 100644 --- a/ethosu/regor/compiler/quantization.hpp +++ b/ethosu/regor/compiler/quantization.hpp @@ -1,5 +1,5 @@ // -// SPDX-FileCopyrightText: Copyright 2023-2024 Arm Limited and/or its affiliates +// SPDX-FileCopyrightText: Copyright 2023-2025 Arm Limited and/or its affiliates // // SPDX-License-Identifier: Apache-2.0 // @@ -57,7 +57,7 @@ public: { return other.scales == scales && other.zeroPoints == zeroPoints; } - bool IsUnitScale() const { return Quantization::Unit().scales == scales; } + bool IsUnitScale() const { return Quantization::Unit().scales == scales || scales.empty(); } explicit operator bool() const { return IsValid(); } Quantization &operator=(const Quantization &other) -- GitLab