From ed812bdf68388b570af0e46bd722be28cc1a3fdf Mon Sep 17 00:00:00 2001 From: Szymon Irzabek Date: Wed, 13 Jul 2022 11:59:44 +0200 Subject: [PATCH] [GNA] Reduce impact of sf propagation fix (#12115) --- samples/cpp/speech_sample/utils.hpp | 17 ++++++++++++++++- .../intel_gna/frontend/scale_factor_calc.hpp | 3 ++- src/plugins/intel_gna/layers/gna_layer_info.hpp | 2 +- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/samples/cpp/speech_sample/utils.hpp b/samples/cpp/speech_sample/utils.hpp index 7aa3dc975e6..c94d31e5969 100644 --- a/samples/cpp/speech_sample/utils.hpp +++ b/samples/cpp/speech_sample/utils.hpp @@ -29,6 +29,8 @@ struct ScoreErrorT { float maxRelError; float sumRelError; float sumSquaredRelError; + float maxAbsRefScore; + float sumAbsRefScore; }; /** @@ -98,6 +100,8 @@ void clear_score_error(ScoreErrorT* error) { error->maxRelError = 0.0; error->sumRelError = 0.0; error->sumSquaredRelError = 0.0; + error->maxAbsRefScore = 0.0; + error->sumAbsRefScore = 0.0; } /** @@ -111,10 +115,14 @@ void update_score_error(ScoreErrorT* error, ScoreErrorT* totalError) { totalError->numScores += error->numScores; totalError->sumRmsError += error->rmsError; totalError->sumError += error->sumError; + totalError->sumAbsRefScore += error->sumAbsRefScore; totalError->sumSquaredError += error->sumSquaredError; if (error->maxError > totalError->maxError) { totalError->maxError = error->maxError; } + if (error->maxAbsRefScore > totalError->maxAbsRefScore) { + totalError->maxAbsRefScore = error->maxAbsRefScore; + } totalError->sumRelError += error->sumRelError; totalError->sumSquaredRelError += error->sumSquaredRelError; if (error->maxRelError > totalError->maxRelError) { @@ -147,13 +155,18 @@ void compare_scores(float* ptrScoreArray, float score = A[i * numColumns + j]; // std::cout << "score" << score << std::endl; float refscore = B[i * numColumns + j]; + float abs_refscore = fabs(refscore); float error = fabs(refscore - score); - float rel_error = error / (static_cast(fabs(refscore)) + 1e-20f); + float rel_error = error / (static_cast(abs_refscore) + 1e-20f); float squared_error = error * error; float squared_rel_error = rel_error * rel_error; scoreError->numScores++; scoreError->sumError += error; + scoreError->sumAbsRefScore += abs_refscore; scoreError->sumSquaredError += squared_error; + if (abs_refscore > scoreError->maxAbsRefScore) { + scoreError->maxAbsRefScore = abs_refscore; + } if (error > scoreError->maxError) { scoreError->maxError = error; } @@ -267,6 +280,8 @@ float get_gna_frequency_mhz() { * @return none. */ void print_reference_compare_results(ScoreErrorT const& totalError, size_t framesNum, std::ostream& stream) { + stream << " max abs ref score: " << totalError.maxAbsRefScore << std::endl; + stream << " avg abs ref score: " << totalError.sumAbsRefScore / totalError.numScores << std::endl; stream << " max error: " << totalError.maxError << std::endl; stream << " avg error: " << totalError.sumError / totalError.numScores << std::endl; stream << " avg rms error: " << totalError.sumRmsError / framesNum << std::endl; diff --git a/src/plugins/intel_gna/frontend/scale_factor_calc.hpp b/src/plugins/intel_gna/frontend/scale_factor_calc.hpp index 0290431a4e2..7464713d55a 100644 --- a/src/plugins/intel_gna/frontend/scale_factor_calc.hpp +++ b/src/plugins/intel_gna/frontend/scale_factor_calc.hpp @@ -1172,7 +1172,8 @@ class ScaleFactorPerLayer { auto prevLayer = CNNNetPrevLayerSkipCertain(restartedLayer, 0, skipNonFunctional); auto prevLayer2 = prevLayer != nullptr ? CNNNetPrevLayerSkipCertain(prevLayer, 0, skipNonFunctional) : nullptr; - if (fakeQuantize && prevLayer != nullptr && LayerInfo(prevLayer).isWeightableIdentity() && + if (fakeQuantize && prevLayer != nullptr && + (LayerInfo(prevLayer).isConcatAlignFilter() || LayerInfo(prevLayer).isSyntheticScaleShift()) && (prevLayer2 == nullptr || LayerInfo(prevLayer2).has8BOr16BOutput())) { auto weightsScales = generateScaleFactors(MIN_SEARCH_WEIGHTS_VAL, MAX_SEARCH_WEIGHTS_VAL, MAX_SEARCH_WEIGHTS_VAL - MIN_SEARCH_WEIGHTS_VAL); diff --git a/src/plugins/intel_gna/layers/gna_layer_info.hpp b/src/plugins/intel_gna/layers/gna_layer_info.hpp index e205d6f89d6..2c3830130ec 100644 --- a/src/plugins/intel_gna/layers/gna_layer_info.hpp +++ b/src/plugins/intel_gna/layers/gna_layer_info.hpp @@ -378,7 +378,7 @@ class LayerInfo { return isOfType(DelayedCopyLayerName); } bool isWeightableIdentity() const noexcept { - return isConcatAlignFilter() || isSyntheticScaleShift(); + return isConcatAlignFilter() || isSyntheticScaleShift() || isCropAffined(); } bool isFusableWithConv() const noexcept { return isActivation() || isMaxPooling();