From 904461afd024d5b6bc9ea1137b9f9bb40351d90a Mon Sep 17 00:00:00 2001 From: Rickard Bolin Date: Mon, 7 Apr 2025 16:17:48 +0000 Subject: [PATCH] MLBEDSW-10642: Fix incorrect clip range for fused activations Fused activations should be clipped to to the activation input type range. Was previously incorrectly clipped to the primary operation ofm type. Change-Id: I5bcb00bb0bc57c1344a555a5ded0d4967ba76605 Signed-off-by: Rickard Bolin --- .../ethosu85/ethos_u85_register_cs_generator.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/ethosu/regor/architecture/ethosu85/ethos_u85_register_cs_generator.cpp b/ethosu/regor/architecture/ethosu85/ethos_u85_register_cs_generator.cpp index be931cf7..c732b77e 100644 --- a/ethosu/regor/architecture/ethosu85/ethos_u85_register_cs_generator.cpp +++ b/ethosu/regor/architecture/ethosu85/ethos_u85_register_cs_generator.cpp @@ -953,6 +953,8 @@ void EthosU85RCSGenerator::GenerateActivation(const HLCStripe *stripe, MemoryAcc const HLCParameters *parameters = nullptr; assert(stripe->opGroup != nullptr); EthosU85OpGroup *opGroup = static_cast(stripe->opGroup); + auto &ofm = op->ofm; + DataType clipDataType = ofm.dataType; if ( IsActivation(op->type) ) { // Non-fused activation @@ -968,18 +970,18 @@ void EthosU85RCSGenerator::GenerateActivation(const HLCStripe *stripe, MemoryAcc // Fused activation opType = subOp.type; parameters = &subOp.parameters; - + // Use subOp ifm datatype to calculate clip range + clipDataType = subOp.ifm[0].dataType; // We know there can be only one fused activation break; } } } - auto &ofm = op->ofm; // Clamp quantMin/quantMax to valid range, but completely disable clipping if any are at the edge of the range - int64_t quantizedMin = std::max(IntegerMin(ofm.dataType), IntegerMin(DataType::Int16)); - int64_t quantizedMax = std::min(IntegerMax(ofm.dataType), IntegerMax(DataType::UInt16)); - auto clipRange = DataTypeSizeBits(ofm.dataType) > 16 ? activation_clip_range::NONE : activation_clip_range::B16; + int64_t quantizedMin = std::max(IntegerMin(clipDataType), IntegerMin(DataType::Int16)); + int64_t quantizedMax = std::min(IntegerMax(clipDataType), IntegerMax(DataType::UInt16)); + auto clipRange = DataTypeSizeBits(clipDataType) > 16 ? activation_clip_range::NONE : activation_clip_range::B16; if ( ofm.quantization.quantMin.size() ) { if ( ofm.quantization.quantMin[0] > std::numeric_limits::min() ) -- GitLab