From 7a6960b2f47db998f3b9ccd0a3de0c123b2eeb5f Mon Sep 17 00:00:00 2001 From: Mikhail Ryzhov Date: Fri, 4 Nov 2022 02:58:01 +0100 Subject: [PATCH] [GNA] Added support of the all log levels (#13359) * Added GNA logger * Added GNA logger class * Replaced old looger by the new one * Added support of the all log levels in the tests * Renaming * fixed cpplint issue * Reduced error level * fixed cpplint issues * Fixed linking error * Fixed linux build * Rebase fix * Removed unused code * Fixed compile issue after rebase * Aligned code usage and style * Fixed default constructor * Fixed test * One more rebase * Added exveption test * Fixed the old logging tests * restored static constants * Removed dublicated log messages * Removed incorrect log::level comparation * Fixed generic api test * Rebased --- .../intel_gna/src/backend/am_intel_dnn.cpp | 21 +-- .../intel_gna/src/backend/am_intel_dnn.hpp | 2 +- src/plugins/intel_gna/src/backend/dnn.cpp | 7 +- .../intel_gna/src/backend/dnn_components.cpp | 10 +- src/plugins/intel_gna/src/backend/dnn_types.h | 2 +- .../intel_gna/src/backend/gna_limitations.cpp | 17 +-- .../intel_gna/src/backend/gna_limitations.hpp | 2 +- .../intel_gna/src/backend/make_pwl.cpp | 27 ++-- .../pwl_border_values_counter_identity.cpp | 2 +- .../backend/pwl_segments_creator_identity.cpp | 5 +- .../src/frontend/model_quantizer.hpp | 18 +-- .../intel_gna/src/frontend/quantization.cpp | 12 +- .../src/frontend/scale_factor_calc.hpp | 42 +++--- .../src/gna2_model_export_helper.cpp | 5 +- .../intel_gna/src/gna2_model_helper.cpp | 2 +- src/plugins/intel_gna/src/gna_device.cpp | 24 ++-- .../intel_gna/src/gna_graph_compiler.cpp | 59 ++++---- .../intel_gna/src/gna_graph_patterns.hpp | 2 +- src/plugins/intel_gna/src/gna_graph_tools.hpp | 9 +- src/plugins/intel_gna/src/gna_groups.hpp | 1 - .../intel_gna/src/gna_model_serial.hpp | 1 - src/plugins/intel_gna/src/gna_plugin.cpp | 43 +++--- src/plugins/intel_gna/src/gna_plugin.hpp | 3 +- .../intel_gna/src/gna_plugin_config.cpp | 23 +--- .../src/layers/gna_convolution_layer.cpp | 2 +- .../intel_gna/src/layers/gna_crop_layer.cpp | 8 +- .../src/layers/gna_fake_quantize_layer.hpp | 1 - .../src/layers/gna_layer_helpers.hpp | 1 - .../intel_gna/src/layers/gna_permute.hpp | 2 +- .../src/{gna_plugin_log.hpp => log/debug.hpp} | 48 +------ .../dump.cpp} | 70 +++++----- .../dump.hpp} | 13 +- src/plugins/intel_gna/src/log/log.hpp | 126 ++++++++++++++++++ .../intel_gna/src/memory/gna_mem_requests.hpp | 3 +- .../src/memory/gna_mem_requests_queue.hpp | 6 +- .../intel_gna/src/memory/gna_memory.hpp | 16 +-- .../intel_gna/src/memory/gna_memory_util.cpp | 2 +- .../src/optimizer/gna_pass_manager.cpp | 80 +++++------ src/plugins/intel_gna/src/preprocessing.cpp | 2 +- .../intel_gna/src/request/subrequest_impl.cpp | 2 +- .../intel_gna/src/request/worker_factory.cpp | 2 +- .../intel_gna/src/request/worker_impl.cpp | 2 +- .../src/request/worker_pool_impl.cpp | 2 +- src/plugins/intel_gna/src/runtime/cnn.cpp | 2 +- .../src/runtime/gna_float_runtime.cpp | 6 +- src/plugins/intel_gna/src/runtime/pwl.cpp | 37 ++--- ...onvert_matmul_to_pointwise_convolution.cpp | 4 +- .../handle_transposes_around_matmul.cpp | 1 - .../src/transformations/insert_copy_layer.cpp | 1 - .../transformations/insert_identity_layer.cpp | 8 +- .../insert_reshape_around_matmul.cpp | 2 +- ...transpose_after_convolution_or_pooling.cpp | 5 +- .../src/transformations/pwl_approximation.cpp | 2 - .../reorder_activation_and_pooling.cpp | 6 +- .../src/transformations/split_eltwise.cpp | 3 +- .../transformations/swap_input_matmul_gna.cpp | 5 +- .../pass_tests/concat_restrictions.cpp | 39 +++--- .../behavior/ov_plugin/core_intergration.cpp | 15 ++- .../tests/unit/gna_plugin_config_test.cpp | 10 +- .../intel_gna/tests/unit/log/logger.cpp | 94 +++++++++++++ 60 files changed, 585 insertions(+), 382 deletions(-) rename src/plugins/intel_gna/src/{gna_plugin_log.hpp => log/debug.hpp} (51%) rename src/plugins/intel_gna/src/{gna2_model_debug_log.cpp => log/dump.cpp} (91%) rename src/plugins/intel_gna/src/{gna2_model_debug_log.hpp => log/dump.hpp} (81%) create mode 100644 src/plugins/intel_gna/src/log/log.hpp create mode 100644 src/plugins/intel_gna/tests/unit/log/logger.cpp diff --git a/src/plugins/intel_gna/src/backend/am_intel_dnn.cpp b/src/plugins/intel_gna/src/backend/am_intel_dnn.cpp index 5b9e157e25a..dd8181293d0 100644 --- a/src/plugins/intel_gna/src/backend/am_intel_dnn.cpp +++ b/src/plugins/intel_gna/src/backend/am_intel_dnn.cpp @@ -20,19 +20,19 @@ #include #include "memory/gna_memory_util.hpp" -#include "gna_plugin_log.hpp" -#include "dnn.hpp" -#include "am_intel_dnn.hpp" -#include "dnn_types.h" +#include "log/log.hpp" +#include "log/dump.hpp" +#include "backend/dnn.hpp" +#include "backend/am_intel_dnn.hpp" +#include "backend/dnn_types.h" #include "gna/gna_config.hpp" -#include "gna_types.h" -#include "gna_limitations.hpp" +#include "backend/gna_types.h" +#include "backend/gna_limitations.hpp" #include "layers/gna_convolution_layer.hpp" #include "memory/gna_memory.hpp" #include #include "gna2_model_helper.hpp" -#include "gna2_model_debug_log.hpp" /** * whether to dump weights and biases @@ -47,6 +47,7 @@ #define LIGHT_DUMP using namespace GNAPluginNS::backend; +using namespace ov::intel_gna; using GNAPluginNS::GNAConvolutionLayer::outputFromConv; using GNAPluginNS::GNAConvolutionLayer::outputFromPooling; @@ -1417,7 +1418,7 @@ void GNAPluginNS::backend::AMIntelDNN::InitGNAStruct(Gna2Model *gnaModel, const memset(gnaModel->Operations, 0, gnaModel->NumberOfOperations * sizeof(Gna2Operation)); gnaOperation = gnaModel->Operations; for (int i = 0; i < component.size(); i++) { - gnalog() << "Component + " << i << "=GNA_" << std::distance(gnaModel->Operations, gnaOperation) << "\n"; + log::debug() << "Component + " << i << "=GNA_" << std::distance(gnaModel->Operations, gnaOperation) << "\n"; auto& comp = component[i]; switch (comp.operation) { @@ -1687,7 +1688,7 @@ void GNAPluginNS::backend::AMIntelDNN::DestroyGNAStruct(Gna2Model *gnaModel) { void GNAPluginNS::backend::AMIntelDNN::WriteInputAndOutputTextGNA(const Gna2Model & model) { #ifdef LIGHT_DUMP - WriteInputAndOutputTextGNAImpl( + dump::WriteInputAndOutputTextGNAImpl( model, getDumpFilePrefixGNA(), getRefFolderName()); @@ -1757,7 +1758,7 @@ void GNAPluginNS::backend::AMIntelDNN::WriteInputAndOutputText() { if (numItems) { auto rmse = sqrt(summOfSqDiff / numItems); auto avg = summOfDiff / numItems; - std :: cout << std::left << std::setw(55) << out_file_name.str() + log::trace() << std::left << std::setw(55) << out_file_name.str() << " RMSE="<< std::fixed << std::setprecision(5) << std::right << std::setw(8) << rmse << " avg=" << std::fixed << std::setprecision(5) << std::right << std::setw(8) << avg << " maxD="<< std::fixed << std::setprecision(5) << std::right << std::setw(8) << maxD << std::endl; diff --git a/src/plugins/intel_gna/src/backend/am_intel_dnn.hpp b/src/plugins/intel_gna/src/backend/am_intel_dnn.hpp index 148ae87c56d..4c9c6897d64 100644 --- a/src/plugins/intel_gna/src/backend/am_intel_dnn.hpp +++ b/src/plugins/intel_gna/src/backend/am_intel_dnn.hpp @@ -12,7 +12,7 @@ #include "gna_types.h" #include "gna/gna_config.hpp" -#include "gna_plugin_log.hpp" +#include "log/debug.hpp" #include "common/gna_target.hpp" #include "memory/gna_memory.hpp" #include diff --git a/src/plugins/intel_gna/src/backend/dnn.cpp b/src/plugins/intel_gna/src/backend/dnn.cpp index 4692facadaa..28c2264e618 100644 --- a/src/plugins/intel_gna/src/backend/dnn.cpp +++ b/src/plugins/intel_gna/src/backend/dnn.cpp @@ -7,7 +7,7 @@ #include #include "gna2_model_helper.hpp" -#include "gna2_model_debug_log.hpp" +#include "log/dump.hpp" #ifndef _NO_MKL_ #include @@ -15,11 +15,10 @@ #include "runtime/floatmath.h" #include "dnn.hpp" -#include "gna_plugin_log.hpp" + #include "runtime/pwl.h" #include "runtime/cnn.h" - void GNAPluginNS::backend::ClearScoreError(intel_score_error_t *error) { error->num_scores = 0; error->num_errors = 0; @@ -67,7 +66,7 @@ void GNAPluginNS::backend::SoftmaxGoogle(float *ptr_output, float *ptr_input, co fprintf(stderr, "Warning: attempt to take log(0) in SoftmaxGoogle()!\n"); sum = 1.0e-20f; } - diff = max_score + log(sum); + diff = max_score + std::log(sum); for (uint32_t i = 0; i < num_outputs; i++) { ptr_output[i] = ptr_input[i] - diff; } diff --git a/src/plugins/intel_gna/src/backend/dnn_components.cpp b/src/plugins/intel_gna/src/backend/dnn_components.cpp index 501c991eff7..4af9b27f612 100644 --- a/src/plugins/intel_gna/src/backend/dnn_components.cpp +++ b/src/plugins/intel_gna/src/backend/dnn_components.cpp @@ -12,7 +12,9 @@ #include #include "dnn_components.hpp" +#include "log/log.hpp" +using namespace ov::intel_gna; using namespace GNAPluginNS; using namespace GNAPluginNS::backend; @@ -21,9 +23,9 @@ intel_dnn_component_t & DnnComponents::addComponent(const std::string layerName, delayedOperations += isDelayed ? 1 : 0; components.emplace_back(DnnComponentExtra{layerName, {}, isDelayed}); auto ¤tComponent = components.back().dnnComponent; -#ifdef PLOT - std::cout << "IR layer : " << std::left << std::setw(20) << layerName << " " << layerMetaType << "_" << components.size() - 1 << std::endl; -#endif + + log::trace() << "IR layer : " << std::left << std::setw(20) << layerName << " " << layerMetaType << "_" << components.size() - 1 << std::endl; + currentComponent.original_layer_name = components.back().name.c_str(); int execOrder = 0; if (!isDelayed) { @@ -33,7 +35,7 @@ intel_dnn_component_t & DnnComponents::addComponent(const std::string layerName, execOrder = - static_cast(delayedOperations); } - gnalog() << "IR layer : " << std::left << std::setw(20) << layerName << " " << layerMetaType << "_" << execOrder << std::endl; + log::debug() << "IR layer : " << std::left << std::setw(20) << layerName << " " << layerMetaType << "_" << execOrder << std::endl; return currentComponent; } diff --git a/src/plugins/intel_gna/src/backend/dnn_types.h b/src/plugins/intel_gna/src/backend/dnn_types.h index 4eb481df629..5ff50231d31 100644 --- a/src/plugins/intel_gna/src/backend/dnn_types.h +++ b/src/plugins/intel_gna/src/backend/dnn_types.h @@ -11,7 +11,7 @@ #include #include "gna_types.h" -#include "gna_plugin_log.hpp" +#include "log/debug.hpp" enum DnnActivationType : uint8_t { kActNone, diff --git a/src/plugins/intel_gna/src/backend/gna_limitations.cpp b/src/plugins/intel_gna/src/backend/gna_limitations.cpp index 80bc9f98094..20e6e85df70 100644 --- a/src/plugins/intel_gna/src/backend/gna_limitations.cpp +++ b/src/plugins/intel_gna/src/backend/gna_limitations.cpp @@ -1,13 +1,9 @@ // Copyright (C) 2018-2022 Intel Corporation // SPDX-License-Identifier: Apache-2.0 // - -#include "gna_limitations.hpp" - -#include "gna/gna_config.hpp" - #include #include + #include #include #include @@ -15,6 +11,11 @@ #include "gna_graph_tools.hpp" #include "gna_lib_ver_selector.hpp" #include "common/gna_target.hpp" +#include "log/log.hpp" +#include "gna_limitations.hpp" +#include "gna/gna_config.hpp" + +using namespace ov::intel_gna; namespace GNAPluginNS { namespace GNALimitations { @@ -425,7 +426,7 @@ bool ValidateConvConcatAxis(const InferenceEngine::ConcatLayer* concat_layer) { return true; } -bool AreLayersSupported(InferenceEngine::CNNNetwork& network, std::string& errMessage, bool userWarning) { +bool AreLayersSupported(InferenceEngine::CNNNetwork& network, std::string& errMessage) { IE_SUPPRESS_DEPRECATED_START InferenceEngine::InputsDataMap inputs = network.getInputsInfo(); std::unordered_set allLayers; @@ -477,8 +478,8 @@ bool AreLayersSupported(InferenceEngine::CNNNetwork& network, std::string& errMe check_result = false; } } else if (info.isConcat()) { - if (userWarning && !ValidateConcatAxis(layer, errMessage)) { - std::cout << errMessage; + if (!ValidateConcatAxis(layer, errMessage)) { + log::warning() << errMessage; } } }, false); diff --git a/src/plugins/intel_gna/src/backend/gna_limitations.hpp b/src/plugins/intel_gna/src/backend/gna_limitations.hpp index 48efbb2e1fc..4e04e0ab3f2 100644 --- a/src/plugins/intel_gna/src/backend/gna_limitations.hpp +++ b/src/plugins/intel_gna/src/backend/gna_limitations.hpp @@ -201,7 +201,7 @@ public: }; } // namespace Cnn2D -bool AreLayersSupported(InferenceEngine::CNNNetwork& network, std::string& errMessage, bool userWarning); +bool AreLayersSupported(InferenceEngine::CNNNetwork& network, std::string& errMessage); inline size_t GetMinBatchToFitInBuffer(InferenceEngine::DataPtr input) { auto total_size = InferenceEngine::details::product(std::begin(input->getDims()), std::end(input->getDims())); diff --git a/src/plugins/intel_gna/src/backend/make_pwl.cpp b/src/plugins/intel_gna/src/backend/make_pwl.cpp index ce91ed9bdae..76756172e10 100644 --- a/src/plugins/intel_gna/src/backend/make_pwl.cpp +++ b/src/plugins/intel_gna/src/backend/make_pwl.cpp @@ -16,6 +16,9 @@ #include "round_float_define.hpp" #include "pwl_input_params.hpp" #include "pwl_segments_creator_factory.hpp" +#include "log/log.hpp" + +using namespace ov::intel_gna; // This function performs emulation of HW saturation of PWL segments in SW // by inserting additional segments when overflow would happen @@ -55,7 +58,7 @@ static void insert_extra_pwl_segments(std::vector& gna_pwl, } if (!extra_segments.empty()) - gnalog() << "Additional segment(s) added to protect against saturation\n"; + log::debug() << "Additional segment(s) added to protect against saturation\n"; for (auto i = extra_segments.rbegin(); i != extra_segments.rend(); i++) { gna_pwl.insert(gna_pwl.begin() + i->first, i->second); @@ -63,20 +66,20 @@ static void insert_extra_pwl_segments(std::vector& gna_pwl, } static void print_segments_header(const DnnActivation& fun) { - gnalog() << "=========================== " << intel_dnn_activation_name[fun] << + log::debug() << "=========================== " << intel_dnn_activation_name[fun] << " segments ===========================\n"; - gnalog() << std::setw(12) << std::setfill(' ') << "x" << std::setw(12) << std::setfill(' ') << + log::debug() << std::setw(12) << std::setfill(' ') << "x" << std::setw(12) << std::setfill(' ') << "y" << std::setw(12) << std::setfill(' ') << "slope" << std::endl; } static void print_segments_header() { - gnalog() << "=========================== segments ===========================\n"; - gnalog() << std::setw(12) << std::setfill(' ') << "x" << std::setw(12) << std::setfill(' ') << + log::debug() << "=========================== segments ===========================\n"; + log::debug() << std::setw(12) << std::setfill(' ') << "x" << std::setw(12) << std::setfill(' ') << "y" << std::setw(12) << std::setfill(' ') << "slope" << std::endl; } static void print_segment(double x, double y, double slope) { - gnalog() << std::setw(12) << std::setfill(' ') << x << std::setw(12) << std::setfill(' ') << + log::debug() << std::setw(12) << std::setfill(' ') << x << std::setw(12) << std::setfill(' ') << y << std::setw(12) << std::setfill(' ') << slope << std::endl; } @@ -89,9 +92,9 @@ void make_gna_pwl(const DnnActivation& fun, const bool low_precision, const bool is_fused_with_conv2d, std::vector &gna_pwl) { - gnalog() << "make_gna_pwl\n"; - gnalog() << " in_scale " << in_scale << "\n"; - gnalog() << " out_scale " << out_scale << "\n"; + log::debug() << "make_gna_pwl\n"; + log::debug() << " in_scale " << in_scale << "\n"; + log::debug() << " out_scale " << out_scale << "\n"; print_segments_header(fun); if (fun.type == kActIdentity) { auto pwl_creator = ov::intel_gna::backend::PWLSegmentsCreatorFactory::CreateCreator(fun.type); @@ -348,9 +351,9 @@ static void make_gna_pwl(const T* m, return a + b; }; - gnalog() << "make_gna_pwl\n"; - gnalog() << " in_scale " << in_scale << "\n"; - gnalog() << " out_scale " << out_scale << "\n"; + log::debug() << "make_gna_pwl\n"; + log::debug() << " in_scale " << in_scale << "\n"; + log::debug() << " out_scale " << out_scale << "\n"; print_segments_header(); gna_pwl.resize(0); for (size_t i = 0; i < count; i++) { diff --git a/src/plugins/intel_gna/src/backend/pwl_border_values_counter_identity.cpp b/src/plugins/intel_gna/src/backend/pwl_border_values_counter_identity.cpp index d3982993704..814025a8103 100644 --- a/src/plugins/intel_gna/src/backend/pwl_border_values_counter_identity.cpp +++ b/src/plugins/intel_gna/src/backend/pwl_border_values_counter_identity.cpp @@ -5,7 +5,7 @@ #include #include "pwl_border_values_counter_identity.hpp" -#include "gna_plugin_log.hpp" +#include "log/debug.hpp" #include "pwl_input_params.hpp" #include "round_float_define.hpp" diff --git a/src/plugins/intel_gna/src/backend/pwl_segments_creator_identity.cpp b/src/plugins/intel_gna/src/backend/pwl_segments_creator_identity.cpp index e89b39dccfc..9861162275e 100644 --- a/src/plugins/intel_gna/src/backend/pwl_segments_creator_identity.cpp +++ b/src/plugins/intel_gna/src/backend/pwl_segments_creator_identity.cpp @@ -4,7 +4,8 @@ #include "pwl_segments_creator_identity.hpp" -#include "gna_plugin_log.hpp" +#include "log/debug.hpp" +#include "log/log.hpp" #include "gna_slope_scale.h" #include "pwl_input_params.hpp" #include "pwl_tools.hpp" @@ -51,7 +52,7 @@ std::vector PWLSegmentsCreatorIdentity::CreateSegments(const auto y0 = CountYAndValidateForX0(border_values, segments[1]); if (y0 != 0) { - gnalog() << "PWL does not pass (0,0), F(0)=" << y0 << "! Adjusting PWL segments."; + log::debug() << "PWL does not pass (0,0), F(0)=" << y0 << "! Adjusting PWL segments."; // if y0 != 0 add new segment, update previous one and cound properly next one if needed. // create a new segment with xBase = 0 and yBase = 0 diff --git a/src/plugins/intel_gna/src/frontend/model_quantizer.hpp b/src/plugins/intel_gna/src/frontend/model_quantizer.hpp index 84dc1f661af..40daaf47b19 100644 --- a/src/plugins/intel_gna/src/frontend/model_quantizer.hpp +++ b/src/plugins/intel_gna/src/frontend/model_quantizer.hpp @@ -84,12 +84,12 @@ class ModelQuantizer { LayersQuantizer lc(GNAPluginNS::kScaleFactorDefault); auto sorted_new_net = InferenceEngine::details::CNNNetSortTopologically(copied_net); - gnalog() << "Sorted layers: " << std::endl; + log::debug() << "Sorted layers: " << std::endl; for (auto &&layer : sorted_new_net) { auto quant_data = InferenceEngine::getInjectedData(layer); quant_data->_inputs_int8_precision = inputs_int8_precision; quant_data->_weights_int8_precision = weights_int8_precision; - gnalog() << layer->name << std::endl; + log::debug() << layer->name << std::endl; } // Filling scale factors for input layers, memory layers will have scale factor of 1.0 by default @@ -160,22 +160,22 @@ class ModelQuantizer { std::distance(inf_loop_history.rbegin(), std::find_if_not(inf_loop_history.rbegin(), inf_loop_history.rend(), [&inf_loop_history](const std::string& str) { return str == inf_loop_history.back(); })) > 3)) { - gnalog() << "inf_loop_pattern:\n"; + log::debug() << "inf_loop_pattern:\n"; for (const auto& s : inf_loop_pattern) { - gnalog() << "\t " << s << '\n'; + log::debug() << "\t " << s << '\n'; } inf_loop_pattern.clear(); int pattern_len = (inf_loop_history.size() - i) / 2; - gnalog() << "pattern_len: " << pattern_len << '\n'; + log::debug() << "pattern_len: " << pattern_len << '\n'; for (int j = 0; j < pattern_len; j++) { inf_loop_pattern.emplace_back(inf_loop_history[inf_loop_history.size() - pattern_len + j]); } - gnalog() << "inf_loop_history:\n"; + log::debug() << "inf_loop_history:\n"; for (const auto& s : inf_loop_history) { - gnalog() << "\t " << s << '\n'; + log::debug() << "\t " << s << '\n'; } inf_loop_history.clear(); - gnalog() << "infinite loop detected\n"; + log::debug() << "infinite loop detected\n"; break; } @@ -191,7 +191,7 @@ class ModelQuantizer { inf_loop_history.end(), inf_loop_pattern.begin())) { inf_loop_count = 0; inf_loop_pattern.clear(); - gnalog() << "infinite loop fixed\n"; + log::debug() << "infinite loop fixed\n"; } } diff --git a/src/plugins/intel_gna/src/frontend/quantization.cpp b/src/plugins/intel_gna/src/frontend/quantization.cpp index 5deb0977c35..2c29dfb5b94 100644 --- a/src/plugins/intel_gna/src/frontend/quantization.cpp +++ b/src/plugins/intel_gna/src/frontend/quantization.cpp @@ -3,12 +3,14 @@ // #include -#include #include +#include "log/debug.hpp" +#include "log/log.hpp" #include "backend/gna_types.h" #include "quantization.hpp" #include +using namespace ov::intel_gna; std::pair FindMinMaxValues(void* ptr_float_memory, size_t num_elements) { float* ptr_float_feat = reinterpret_cast(ptr_float_memory); @@ -154,7 +156,7 @@ void QuantizeWeights(const QuantizationData& data, float* ptr_float_weig } if (num_saturate > 0) { - gnalog() << "Warning: " << num_saturate << " / " << (data.num_rows * data.num_columns) + log::warning() << num_saturate << " / " << (data.num_rows * data.num_columns) << " saturations in int8 weights quantization." << std::endl; } } @@ -215,7 +217,7 @@ void QuantizeWeights(const QuantizationData& data, float* ptr_float_wei } if (num_saturate > 0) { - gnalog() << "Warning: " << num_saturate << " / " << (data.num_rows * data.num_columns) + log::warning() << num_saturate << " / " << (data.num_rows * data.num_columns) << " saturations in int16 weights quantization." << std::endl; } } @@ -252,7 +254,7 @@ void QuantizeBiases(const QuantizationData& data, float* ptr_float_bias } if (num_saturate > 0) { - gnalog() << "Warning: " << num_saturate << " / " << data.num_rows + log::warning() << num_saturate << " / " << data.num_rows << " saturations in int32 biases quantization." << std::endl; } } @@ -277,7 +279,7 @@ void QuantizeBiases(const QuantizationData& data, float* pt } } if (num_saturate > 0) { - gnalog() << "Warning: " << num_saturate << " / " << data.num_rows + log::warning() << num_saturate << " / " << data.num_rows << " saturations in compound biases quantization." << std::endl; } } diff --git a/src/plugins/intel_gna/src/frontend/scale_factor_calc.hpp b/src/plugins/intel_gna/src/frontend/scale_factor_calc.hpp index 0404147fd00..89906007121 100644 --- a/src/plugins/intel_gna/src/frontend/scale_factor_calc.hpp +++ b/src/plugins/intel_gna/src/frontend/scale_factor_calc.hpp @@ -15,12 +15,14 @@ #include "gna_upstream_iterator.hpp" #include "layers/gna_layer_info.hpp" #include "layers/gna_convolution_layer.hpp" -#include "gna_plugin_log.hpp" +#include "log/debug.hpp" #include "gna_slope_scale.h" #include "runtime/pwl.h" #include "gna_data_types.hpp" #include "round_float_define.hpp" +using namespace ov::intel_gna; + namespace GNAPluginNS { namespace frontend { @@ -230,14 +232,14 @@ static bool requantizeInput(InferenceEngine::CNNLayerPtr input, float newOutputS auto maxSF = CalculateScaleFactorFromStats(levels, quantDataForInputLayer->_dst_quant.GetMinValues().front(), quantDataForInputLayer->_dst_quant.GetMaxValues().front()); if (newOutputScale > maxSF) { - gnalog() << layer->name << ": Scale factor " << newOutputScale << " is too large. The maximum scale factor: " + log::debug() << layer->name << ": Scale factor " << newOutputScale << " is too large. The maximum scale factor: " << maxSF << " levels=" << levels << " min=" << quantDataForInputLayer->_dst_quant.GetMinValues().front() << " max=" << quantDataForInputLayer->_dst_quant.GetMaxValues().front() << "\n"; return false; } } if (info.isActivation() || info.isConst()) { - gnawarn() << "[WARNING] requantize " << layer->name + log::warning() << "requantize " << layer->name << ". Layer new output scale: " << newOutputScale << ", was " << quantDataForInputLayer->_dst_quant.GetScale() << std::endl; quantDataForInputLayer->_dst_quant.SetScale(newOutputScale); @@ -281,7 +283,7 @@ static bool requantizeInput(InferenceEngine::CNNLayerPtr input, float newOutputS auto restartedPrevLayer = InferenceEngine::CNNNetPrevLayer(layer, ix); auto otherPrevLayer = InferenceEngine::CNNNetPrevLayer(layer, !ix); if (infiniteLoopCount % 2 == 1) { - gnawarn() << "[WARNING] going into the loop: swap inputs order for Eltwise Multiply" << std::endl; + log::warning() << "going into the loop: swap inputs order for Eltwise Multiply" << std::endl; std::swap(restartedPrevLayer, otherPrevLayer); } auto otherPrevQuantData = InferenceEngine::getInjectedData(*otherPrevLayer); @@ -378,7 +380,7 @@ class ScaleFactorPerLayer { auto scaleFactors = generateScaleFactors(startRange, endRange, steps); auto newScaleFactor = selectBestOutputScaleFactors(quantizedParams->_src_quant.GetScale(), scaleFactors, slopes); if (!fp32eq(sf, newScaleFactor) && !fp32eq(newScaleFactor, 0.0f) && !std::isinf(newScaleFactor)) { - gnalog() << "[INFO] Adjusting scale factor for " << cnnLayer->name + log::debug() << "[INFO] Adjusting scale factor for " << cnnLayer->name << " from: " << sf << " to: " << newScaleFactor << "\n"; sf = newScaleFactor; } @@ -656,21 +658,21 @@ class ScaleFactorPerLayer { // need to search for requantiseable layer prior memory output layer InferenceEngine::CNNLayerPtr restartedLayer; - gnalog() << "Memory layer :" << input->name << " scale factor: " << quantSibling->_dst_quant.GetScale() + log::debug() << "Memory layer :" << input->name << " scale factor: " << quantSibling->_dst_quant.GetScale() << " doesn't match its outputs counterpart: " << cnnLayer->name << " scale factor: " << inputQuant->_dst_quant.GetScale() << "\n"; - gnalog() << "[UFS] searching for quantizeable input layer for: " << cnnLayer->name << "\n"; + log::debug() << "[UFS] searching for quantizeable input layer for: " << cnnLayer->name << "\n"; CNNNetDFS(InferenceEngine::CNNLayerPtr(cnnLayer, [](InferenceEngine::CNNLayer*) {}), [&restartedLayer, cnnLayer](InferenceEngine::CNNLayerPtr layer) { - gnalog() << "[UFS] from : " << cnnLayer->name << " reached: " << layer->name; + log::debug() << "[UFS] from : " << cnnLayer->name << " reached: " << layer->name; // found that direct input to concat is a indirect parent of align filter - so no link required auto info = LayerInfo(layer); if (!info.isWeightable() && !info.isActivation()) { - gnalog() << "... skipped\n"; + log::debug() << "... skipped\n"; return; } restartedLayer = layer; - gnalog() << "... OK, need requantize\n"; + log::debug() << "... OK, need requantize\n"; }, true, [&restartedLayer, &cnnLayer](InferenceEngine::CNNLayer* from) { // aborting UFS once found suitable layer return make_upstream_order(restartedLayer == nullptr ? from : nullptr); @@ -696,7 +698,7 @@ class ScaleFactorPerLayer { return true; } - gnawarn() << "[INFO] quantization : input scale factor (" << inputQuant->_dst_quant.GetScale() << ")" + log::info() << "quantization : input scale factor (" << inputQuant->_dst_quant.GetScale() << ")" << " for " << cnnLayer->name << ", that is child of " << prevLayer->name << " doesnt match : " << activation_scale_factor << ", restarting from corresponding memory: " << input->name << std::endl; @@ -916,12 +918,12 @@ class ScaleFactorPerLayer { if (quantData->_weights_quant.GetScale() > maxValue && !fp32eq(quantData->_weights_quant.GetScale(), maxValue)) { float newOutputScale = quantParams0->_dst_quant.GetScale() * maxValue; - gnalog() << "[INFO] weights saturated for " << eltwiseLayer->name << ", try to requiantize input " << in1->name << std::endl; + log::debug() << "[INFO] weights saturated for " << eltwiseLayer->name << ", try to requiantize input " << in1->name << std::endl; if (requantizeInput(in1, newOutputScale, result, infiniteLoopCount)) { return true; } // we unable to rescale the input - results might be bad - gnawarn() << "[INFO] weights saturated for " << eltwiseLayer->name << "\n"; + log::info() << "weights saturated for " << eltwiseLayer->name << "\n"; } if (!quantData->_dst_quant.IsStatsSet()) { @@ -1101,19 +1103,19 @@ class ScaleFactorPerLayer { InferenceEngine::CNNLayerPtr restartedLayer; // making a link activation possible without extra layer if first input to concat not a parent / indirect parent of second input // using ufs - upper first search - gnalog() << "[UFS] searching for quantizeable layer prior: " << concatLayer->name << ", via " << layerIdToUpdate << "\n"; + log::debug() << "[UFS] searching for quantizeable layer prior: " << concatLayer->name << ", via " << layerIdToUpdate << "\n"; CNNNetDFS(InferenceEngine::CNNLayerPtr(concatLayer, [](InferenceEngine::CNNLayer*) {}), [&restartedLayer, concatLayer](InferenceEngine::CNNLayerPtr layer) { - gnalog() << "[UFS] from : " << concatLayer->name << " reached: " << layer->name; + log::debug() << "[UFS] from : " << concatLayer->name << " reached: " << layer->name; // found that direct input to concat is a indirect parent of align filter - so no link required auto info = LayerInfo(layer); if (!info.isWeightable() && !info.isActivation() && !info.isConst() && !info.isMemory()) { - gnalog() << "... skipped\n"; + log::debug() << "... skipped\n"; return; } restartedLayer = layer; - gnalog() << "... OK, need requantize\n"; + log::debug() << "... OK, need requantize\n"; }, true, [&restartedLayer, &concatLayer, &layerIdToUpdate](InferenceEngine::CNNLayer* from) { // aborting UFS once found functional layer, and using only specified input of concat return make_upstream_order(restartedLayer == nullptr ? from : nullptr, @@ -1150,7 +1152,7 @@ class ScaleFactorPerLayer { newScaleFactor, weightsScales, { 1.0f }); } if (!slopes.empty() && !fp32eq(bestWeightsScale, prevLayerQuant->_weights_quant.GetScale())) { - gnalog() << "[INFO][Concat] Optimizing weights scale factor for '" << prevLayer->name << "' layer. Change from " + log::debug() << "[INFO][Concat] Optimizing weights scale factor for '" << prevLayer->name << "' layer. Change from " << prevLayerQuant->_weights_quant.GetScale() << " to " << bestWeightsScale << "\n"; prevLayerQuant->_weights_quant.SetScale(bestWeightsScale); @@ -1162,7 +1164,7 @@ class ScaleFactorPerLayer { quantDataForConCatInput->_dst_quant.SetScale(newScaleFactor); } else if (restarLayerInfo.isConst() || restarLayerInfo.isMemory()) { - gnalog() << "... warning " << restartedLayer->type << " layer will be requantized\n"; + log::debug() << "... warning " << restartedLayer->type << " layer will be requantized\n"; quantDataForConCatInput->_src_quant.SetScale(sourceQuantParams->_dst_quant.GetScale()); quantDataForConCatInput->_dst_quant.SetScale(sourceQuantParams->_dst_quant.GetScale()); } else { @@ -1282,7 +1284,7 @@ class ScaleFactorPerLayer { if (static_cast(tmp_dst_quant_scale * quant->_src_quant.GetScale()) > static_cast(limit - 1) * std::get<0>(*itt)) { - gnawarn() << "Output scale for " << wl->name + log::warning() << "Output scale for " << wl->name << " too large and are being reduced. Else saturations likely will happen \n"; // reduce weight scale according experimental heuristic while ((itt + 1) != thresholds.end() && quant->_dst_quant.GetScale() * quant->_src_quant.GetScale() / diff --git a/src/plugins/intel_gna/src/gna2_model_export_helper.cpp b/src/plugins/intel_gna/src/gna2_model_export_helper.cpp index baa42222065..2d8b07d83dc 100644 --- a/src/plugins/intel_gna/src/gna2_model_export_helper.cpp +++ b/src/plugins/intel_gna/src/gna2_model_export_helper.cpp @@ -11,6 +11,7 @@ #include "gna/gna_config.hpp" #include "common/gna_target.hpp" #include "common/versioning.hpp" +#include "log/log.hpp" #include "gna2-tlv-writer.h" @@ -18,6 +19,8 @@ #include #include +using namespace ov::intel_gna; + void * ExportSueLegacyUsingGnaApi2( uint32_t modelId, uint32_t deviceIndex, @@ -123,7 +126,7 @@ std::string WriteAllEndpoints(std::ostream& outStream, outStream.write(scaleFactorTlv.data(), scaleFactorTlv.size()); } if (allEndpoints.size() != 1) { - gnawarn() << "Number of endpoints: " << allEndpoints.size() << " for " << endPointType << "\n"; + log::warning() << "Number of endpoints: " << allEndpoints.size() << " for " << endPointType << "\n"; } std::stringstream stream; diff --git a/src/plugins/intel_gna/src/gna2_model_helper.cpp b/src/plugins/intel_gna/src/gna2_model_helper.cpp index e4af5a31e2b..ac0323ab5fe 100644 --- a/src/plugins/intel_gna/src/gna2_model_helper.cpp +++ b/src/plugins/intel_gna/src/gna2_model_helper.cpp @@ -10,7 +10,7 @@ #include #include -#include "gna_plugin_log.hpp" +#include "log/debug.hpp" #include "gna2_model_helper.hpp" Gna2DataType Gna2DataTypeFromBytes(uint32_t num_bytes_per_input) { diff --git a/src/plugins/intel_gna/src/gna_device.cpp b/src/plugins/intel_gna/src/gna_device.cpp index 5fd561d53e3..44feb59aa85 100644 --- a/src/plugins/intel_gna/src/gna_device.cpp +++ b/src/plugins/intel_gna/src/gna_device.cpp @@ -19,16 +19,18 @@ #include "gna2-model-export-api.h" #include "gna2_model_export_helper.hpp" #include "gna2_model_helper.hpp" -#include "gna2_model_debug_log.hpp" +#include "log/dump.hpp" #include "backend/am_intel_dnn.hpp" #include "backend/gna_limitations.hpp" #include "common/gna_target.hpp" #include "gna/gna_config.hpp" -#include "gna_plugin_log.hpp" +#include "log/log.hpp" + #include "layers/gna_convolution_layer.hpp" #include "memory/gna_mem_requests.hpp" +using namespace ov::intel_gna; std::mutex GNADeviceHelper::acrossPluginsSync{}; @@ -65,7 +67,7 @@ uint8_t* GNADeviceHelper::alloc(uint32_t size_requested, uint32_t *size_granted) const auto status = Gna2MemoryAlloc(size_requested, size_granted, &memPtr); checkGna2Status(status, "Gna2MemoryAlloc"); - gnalog() << "Gna2MemoryAlloc(" << size_requested << ") -> " << *size_granted << ", " << memPtr << "\n"; + log::debug() << "Gna2MemoryAlloc(" << size_requested << ") -> " << *size_granted << ", " << memPtr << "\n"; allAllocations.Add(memPtr, size_requested, *size_granted); if (memPtr == nullptr) { THROW_GNA_EXCEPTION << "GNAAlloc failed to allocate memory. Requested: " << size_requested << " Granted: " << *(size_granted); @@ -93,7 +95,7 @@ void GNADeviceHelper::tagMemoryRegion(void* memPtr, const GNAPluginNS::memory::r } const auto status = Gna2MemorySetTag(memPtr, memoryTag); checkGna2Status(status, "Gna2MemorySetTag"); - gnalog() << "Gna2MemorySetTag(" << memPtr << ", " << memoryTag << ")\n"; + log::debug() << "Gna2MemorySetTag(" << memPtr << ", " << memoryTag << ")\n"; const auto tagSuccess = allAllocations.SetTagFor(memPtr, memoryTag); if (!tagSuccess) { THROW_GNA_EXCEPTION << "Allocation not found when tagging memory\n"; @@ -111,10 +113,10 @@ void GNADeviceHelper::free(void* ptr) { removeSuccess = allAllocations.Remove(ptr); } if (!message.empty()) { - gnawarn() << message; + log::error() << message; } if (!removeSuccess) { - gnawarn() << "Allocation not found when freeing memory\n"; + log::error() << "Allocation not found when freeing memory\n"; } } @@ -144,7 +146,7 @@ void GNADeviceHelper::dumpAllAllocations(const uint64_t idx, const std::string& if (file) { file.write(static_cast(a.ptr), a.sizeGranted); } else { - gnawarn() << "Can not dump memory region, file not created: '" << filename << "'\n"; + log::error() << "Can not dump memory region, file not created: '" << filename << "'\n"; } } } @@ -155,7 +157,7 @@ uint32_t GNADeviceHelper::enqueueRequest(const uint32_t requestConfigID, Gna2Acc if ((gna2AccelerationMode == Gna2AccelerationModeHardware || gna2AccelerationMode == Gna2AccelerationModeHardwareWithSoftwareFallback) && detectedGnaDevVersion == Gna2DeviceVersionSoftwareEmulation) { - gnawarn() << "GNA Device not detected, consider using other mode of acceleration"; + log::warning() << "GNA Device not detected, consider using other mode of acceleration"; } const auto status1 = Gna2RequestConfigSetAccelerationMode(requestConfigID, gna2AccelerationMode); @@ -218,7 +220,7 @@ uint32_t GNADeviceHelper::createModel(Gna2Model& gnaModel) const { #endif const std::string mode = useDeviceEmbeddedExport ? "_ee" : ""; const auto fileSuffix = mode + "_devVersion_" + toHexString(detectedGnaDevVersion); - DumpGna2Model(gnaModel, path, false, allAllocations, fileSuffix); + dump::DumpGna2Model(gnaModel, path, false, allAllocations, fileSuffix); } const auto status = Gna2ModelCreate(nGnaDeviceIndex, &gnaModel, &modelId); @@ -551,14 +553,14 @@ void GNADeviceHelper::close() { try { waitForRequest(requestId); } catch (...) { - gnawarn() << "Request with Id " << requestId << " was not awaited successfully"; + log::warning() << "Request with Id " << requestId << " was not awaited successfully"; } } std::unique_lock lockGnaCalls{ acrossPluginsSync }; const auto status = Gna2DeviceClose(nGnaDeviceIndex); const auto message = checkGna2Status(status, "Gna2DeviceClose", true); if (!message.empty()) { - gnawarn() << "GNA Device was not successfully closed: " << message << std::endl; + log::warning() << "GNA Device was not successfully closed: " << message << std::endl; } deviceOpened = false; } diff --git a/src/plugins/intel_gna/src/gna_graph_compiler.cpp b/src/plugins/intel_gna/src/gna_graph_compiler.cpp index a72aa88d179..0ffdd1b149c 100644 --- a/src/plugins/intel_gna/src/gna_graph_compiler.cpp +++ b/src/plugins/intel_gna/src/gna_graph_compiler.cpp @@ -20,7 +20,7 @@ #include "gna_graph_compiler.hpp" #include "gna_data_types.hpp" -#include "gna_plugin_log.hpp" +#include "log/log.hpp" #include "layers/gna_layer_info.hpp" #include "ie_memcpy.h" #include "caseless.hpp" @@ -41,6 +41,7 @@ using namespace InferenceEngine; using namespace std; +using namespace ov::intel_gna; using namespace GNAPluginNS; using namespace memory; @@ -437,9 +438,9 @@ void GNAGraphCompiler::finalizeConvolution1DPrimitive(InferenceEngine::CNNLayerP const auto num_filter_coefficients = ALIGN(std::max(single_conv_kernel_size, effectiveStride), 8); const auto num_conv_kernel_padding = num_filter_coefficients - single_conv_kernel_size; if (num_conv_kernel_padding == 0) { - gnalog() << LAYER_NAME(&convolution) << "Kernel is aligned \n"; + log::debug() << LAYER_NAME(&convolution) << "Kernel is aligned \n"; } else { - gnalog() << LAYER_NAME(&convolution) << "Kernel padding is " << num_conv_kernel_padding << "\n"; + log::debug() << LAYER_NAME(&convolution) << "Kernel padding is " << num_conv_kernel_padding << "\n"; } // have to pad input to let last kernel meets it's corresponding input @@ -465,9 +466,9 @@ void GNAGraphCompiler::finalizeConvolution1DPrimitive(InferenceEngine::CNNLayerP } if (num_input_padding == 0) { - gnalog() << LAYER_NAME(&convolution) << "Inputs are aligned \n"; + log::debug() << LAYER_NAME(&convolution) << "Inputs are aligned \n"; } else { - gnalog() << LAYER_NAME(&convolution) << "Inputs padding is " << num_input_padding << "\n"; + log::debug() << LAYER_NAME(&convolution) << "Inputs padding is " << num_input_padding << "\n"; } if (num_columns_out_unpadded != out_batch * out_channels * out_width) { @@ -657,9 +658,9 @@ void GNAGraphCompiler::finalizeConvolution2DPrimitive(InferenceEngine::CNNLayerP // if kernel padding to multiple of 8 will cause missed outputs, need to pad further if (num_input_padding == 0) { - gnalog() << LAYER_NAME(&convolution) << "Inputs are aligned \n"; + log::debug() << LAYER_NAME(&convolution) << "Inputs are aligned \n"; } else { - gnalog() << LAYER_NAME(&convolution) << "Inputs padding is " << num_input_padding << "\n"; + log::debug() << LAYER_NAME(&convolution) << "Inputs padding is " << num_input_padding << "\n"; } void* ptr_inputs = nullptr; @@ -1069,11 +1070,11 @@ void GNAGraphCompiler::ConcatPrimitive(InferenceEngine::CNNLayerPtr layer) { } // Concat axis validation - if (!GNALimitations::ValidateConvConcatAxis(concatLayer) && gnaFlags->log_level == ov::log::Level::WARNING) { + if (!GNALimitations::ValidateConvConcatAxis(concatLayer)) { std::ostringstream in_dims_oss; auto in_dims = concatLayer->insData[0].lock()->getDims(); std::copy(in_dims.begin(), in_dims.end(), std::ostream_iterator(in_dims_oss, ",")); - std::cout << "[ WARNING ] Topology with layer: " + layer->name + ", type: " + layer->type + + log::warning() << "Topology with layer: " + layer->name + ", type: " + layer->type + ", and concatenation axis(" + std::to_string(concatLayer->_axis) + ") for input dimensions(" + in_dims_oss.str() + ") not supported\n"; } @@ -1100,7 +1101,7 @@ void GNAGraphCompiler::ConcatPrimitive(InferenceEngine::CNNLayerPtr layer) { for (auto &&outLayer : getInputTo(concatLayer->outData.front())) { auto concatCandidate = find_cascaded_concat_recursively(outLayer.second); if (!concatCandidate) continue; - gnalog() << "Cascaded concat connection found from: " << layer->name << ", to: " << concatCandidate->name << std::endl; + log::debug() << "Cascaded concat connection found from: " << layer->name << ", to: " << concatCandidate->name << std::endl; connectOutput(layer, &concatLayerInfo.gna_ptr, concatLayerInfo.reserved_size); } @@ -1169,7 +1170,7 @@ void GNAGraphCompiler::CropPrimitive(InferenceEngine::CNNLayerPtr layer) { } } } else { - gnalog() << "Crop " << layer->name << " is being replaced by Affine layer...\n"; + log::debug() << "Crop " << layer->name << " is being replaced by Affine layer...\n"; IE_ASSERT(!layer->outData.empty()); auto outputs = *layer->outData.begin(); @@ -1518,7 +1519,7 @@ void GNAGraphCompiler::AffinePrimitive(InferenceEngine::CNNLayerPtr layer, bool << layer->name << ", cannot be connected to its parent: " << prevLayer->name << " due to precision mismatch"; } - gnalog() << "Connection " << prevLayer->name << " to " << layer->name << " is using BIAS as input" << std::endl; + log::debug() << "Connection " << prevLayer->name << " to " << layer->name << " is using BIAS as input" << std::endl; useBiasConnection = true; } @@ -1568,7 +1569,7 @@ void GNAGraphCompiler::AffinePrimitive(InferenceEngine::CNNLayerPtr layer, bool } // this affine connected to convolution via pool or activation - gnalog() << "Transposing weights for layer: " << layer->name << "\n"; + log::debug() << "Transposing weights for layer: " << layer->name << "\n"; transpose = !isDiag; transposedRows = connectionInfo.permute->input()->getDims()[3]; @@ -2261,7 +2262,7 @@ void GNAGraphCompiler::connectOutput(InferenceEngine::CNNLayerPtr layer, return output_offset; }; - gnalog() << "Connecting output " << layer->name << " ...\n"; + log::debug() << "Connecting output " << layer->name << " ...\n"; // in case of Memory Layer it's input allocated in meminput layer if (layer->outData.size() == 1) { for (int j = 0; j != getInputTo(layer->outData.front()).size(); j++) { @@ -2275,7 +2276,7 @@ void GNAGraphCompiler::connectOutput(InferenceEngine::CNNLayerPtr layer, auto nextLayer = CNNNetGetNextLayerSkipCertain(layer, 0, j, isNonFunctional); if (!nextLayer.first) { - gnalog() << "for layer: " << layer->name << "outData[0] has non functional connection at " << j; + log::debug() << "for layer: " << layer->name << "outData[0] has non functional connection at " << j; } auto nextMemoryLayerIt = std::find_if(begin(memory_connection), end(memory_connection), @@ -2454,7 +2455,7 @@ GNAPluginNS::ConnectionDetails GNAGraphCompiler::connectInput(CNNLayerPtr layer, THROW_GNA_EXCEPTION << "Input layer was not found"; } - gnalog() << "Connecting input " << layer->name << " to " << prevLayer->name << " ...\n"; + log::debug() << "Connecting input " << layer->name << " to " << prevLayer->name << " ...\n"; // real input not a memory input if (LayerInfo(prevLayer).isInput()) { @@ -2472,7 +2473,7 @@ GNAPluginNS::ConnectionDetails GNAGraphCompiler::connectInput(CNNLayerPtr layer, if (num_data_bytes_in < minInput) { const uint32_t noOfInputsDivisor = gnaFlags->input_low_precision ? GNALimitations::noOfInputsLowPrecDivisor : GNALimitations::noOfInputsDivisor; - gnalog() << "[INPUT] : requested bytes: " << num_data_bytes_in << ", extended to" << ALIGN(minInput, noOfInputsDivisor); + log::debug() << "[INPUT] : requested bytes: " << num_data_bytes_in << ", extended to" << ALIGN(minInput, noOfInputsDivisor); num_data_bytes_in = ALIGN(minInput, noOfInputsDivisor); } @@ -2539,11 +2540,11 @@ GNAPluginNS::ConnectionDetails GNAGraphCompiler::connectInput(CNNLayerPtr layer, }); if (it != splitLayerInfoItem.splitOutputLayers.end()) { - gnalog() << "Connecting " << splitName << " input \n"; + log::debug() << "Connecting " << splitName << " input \n"; // splitting layer should take the execution order from the connected layer splittingLayer->userValue = layer->userValue; auto res = connectInput(splittingLayer, ptr, std::max(splitLayerInfoItem.reserved_size, num_data_bytes_in), it->offset + offset, 0); - gnalog() << "Connected \n"; + log::debug() << "Connected \n"; return res; } } @@ -2610,7 +2611,7 @@ GNAPluginNS::ConnectionDetails GNAGraphCompiler::connectInput(CNNLayerPtr layer, // several layers are to be skipped right now if (LayerInfo(prevLayer).isNonFunctional()) { - gnalog() << "Skipping non functional layer: " << prevLayer->name << "\n"; + log::debug() << "Skipping non functional layer: " << prevLayer->name << "\n"; return connectInput(prevLayer, ptr, num_data_bytes_in, offset, 0); } @@ -2620,7 +2621,7 @@ GNAPluginNS::ConnectionDetails GNAGraphCompiler::connectInput(CNNLayerPtr layer, // we should have GNA primitive for it THROW_GNA_EXCEPTION << "missed gna primitive for permute: " << prevLayer->name; } - gnalog() << "Skipping trivial permute layer: " << prevLayer->name << "\n"; + log::debug() << "Skipping trivial permute layer: " << prevLayer->name << "\n"; return connectInput(prevLayer, ptr, num_data_bytes_in, offset, 0); } @@ -2637,20 +2638,20 @@ void GNAGraphCompiler::Reset() { } void GNAGraphCompiler::printTensorDesc(const std::string& name, const InferenceEngine::TensorDesc& desc) { - gnalog() << name << " layout: " << desc.getLayout() << " shape: "; + log::debug() << name << " layout: " << desc.getLayout() << " shape: "; for (auto i = 0; i < desc.getDims().size(); i++) { if (i > 0) { - gnalog() << 'x'; + log::debug() << 'x'; } - gnalog() << desc.getDims()[i]; + log::debug() << desc.getDims()[i]; } - gnalog() << "\n"; + log::debug() << "\n"; } void GNAGraphCompiler::printConvolutionLayer(const InferenceEngine::ConvolutionLayer& layer) { const char x = 'x'; - gnalog() << "ConvolutionLayer '" + log::debug() << "ConvolutionLayer '" << layer.name << "' Kernel: " << layer._kernel_x << x << layer._kernel_y @@ -2662,7 +2663,7 @@ void GNAGraphCompiler::printConvolutionLayer(const InferenceEngine::ConvolutionL << layer._dilation_x << x << layer._dilation_y << " Auto Padding: '" << layer._auto_pad << "'"; - gnalog() << "\n"; + log::debug() << "\n"; printTensorDesc("Input", layer.input()->getTensorDesc()); printTensorDesc("Output", layer.outData.front()->getTensorDesc()); } @@ -2670,7 +2671,7 @@ void GNAGraphCompiler::printConvolutionLayer(const InferenceEngine::ConvolutionL void GNAGraphCompiler::printPoolingLayer(const InferenceEngine::PoolingLayer& layer) { const char x = 'x'; - gnalog() << "PoolingLayer '" + log::debug() << "PoolingLayer '" << layer.name << "' Kernel: " << layer._kernel_x << x << layer._kernel_y @@ -2680,7 +2681,7 @@ void GNAGraphCompiler::printPoolingLayer(const InferenceEngine::PoolingLayer& la << layer._stride_x << x << layer._stride_y << " Auto Padding: '" << layer._auto_pad << "'"; - gnalog() << "\n"; + log::debug() << "\n"; printTensorDesc("Input", layer.input()->getTensorDesc()); printTensorDesc("Output", layer.outData.front()->getTensorDesc()); } diff --git a/src/plugins/intel_gna/src/gna_graph_patterns.hpp b/src/plugins/intel_gna/src/gna_graph_patterns.hpp index 8161d251da3..f61f78226a1 100644 --- a/src/plugins/intel_gna/src/gna_graph_patterns.hpp +++ b/src/plugins/intel_gna/src/gna_graph_patterns.hpp @@ -6,7 +6,7 @@ #include #include "gna_data_types.hpp" #include "gna_graph_tools.hpp" -#include "gna_plugin_log.hpp" +#include "log/debug.hpp" #include "gna_upstream_iterator.hpp" #include "layers/gna_layer_info.hpp" #include "ops/util/util.hpp" diff --git a/src/plugins/intel_gna/src/gna_graph_tools.hpp b/src/plugins/intel_gna/src/gna_graph_tools.hpp index db89da1df0d..6ad60032fdd 100644 --- a/src/plugins/intel_gna/src/gna_graph_tools.hpp +++ b/src/plugins/intel_gna/src/gna_graph_tools.hpp @@ -5,7 +5,8 @@ #pragma once #include -#include "gna_plugin_log.hpp" +#include "log/debug.hpp" +#include "log/log.hpp" #include "frontend/quantized_layer_params.hpp" #include #include @@ -13,6 +14,8 @@ #include #include +using namespace ov::intel_gna; + namespace InferenceEngine { static constexpr size_t invalid_data_idx = std::numeric_limits::max(); @@ -657,7 +660,7 @@ inline void CNNNetworkRemoveLayer(CNNLayerPtr layer, bool checkDims = true) { if (!layer) { IE_THROW() << "Cannot remove layer pointed to NULL"; } - gnalog() << "Removing " << layer->name << " layer\n"; + log::debug() << "Removing " << layer->name << " layer\n"; if (layer->insData.size() != 1) { IE_THROW() << "Cannot remove layer : "<< layer->name <<" that has different number of inputs than 1"; } @@ -735,7 +738,7 @@ inline void CNNNetworkReconnectLayer(CNNLayerPtr old_prev_layer, CNNLayerPtr new IE_THROW() << "Cannot reconnect layer new parent is NULL"; } - gnalog() << "Reconnecting " << old_prev_layer->name << " --> " << layer->name << " layer to " + log::debug() << "Reconnecting " << old_prev_layer->name << " --> " << layer->name << " layer to " << new_prev_layer->name << " -- > " << layer->name << "layer\n"; if (layer->insData.size() < 1) { diff --git a/src/plugins/intel_gna/src/gna_groups.hpp b/src/plugins/intel_gna/src/gna_groups.hpp index 91d4d6a15bf..8433b62b56a 100644 --- a/src/plugins/intel_gna/src/gna_groups.hpp +++ b/src/plugins/intel_gna/src/gna_groups.hpp @@ -6,7 +6,6 @@ #include #include "gna_graph_tools.hpp" -#include "gna_plugin_log.hpp" #include "layers/gna_layer_info.hpp" namespace GNAPluginNS { diff --git a/src/plugins/intel_gna/src/gna_model_serial.hpp b/src/plugins/intel_gna/src/gna_model_serial.hpp index 057f9a12718..1ecb2bc7a8a 100644 --- a/src/plugins/intel_gna/src/gna_model_serial.hpp +++ b/src/plugins/intel_gna/src/gna_model_serial.hpp @@ -10,7 +10,6 @@ #include #include "descriptions/gna_desc.hpp" -#include "gna_plugin_log.hpp" #include "serial/headers/latest/gna_model_header.hpp" #include "gna2-model-api.h" diff --git a/src/plugins/intel_gna/src/gna_plugin.cpp b/src/plugins/intel_gna/src/gna_plugin.cpp index d11abd27492..0dca0b14e32 100644 --- a/src/plugins/intel_gna/src/gna_plugin.cpp +++ b/src/plugins/intel_gna/src/gna_plugin.cpp @@ -45,6 +45,7 @@ #include "request/model_wrapper_factory.hpp" #include "request/worker_pool_impl.hpp" #include "request/worker_factory.hpp" +#include "log/log.hpp" #include #include @@ -119,11 +120,11 @@ inline uint32_t ToByteSize(const Gna2DataType type) { } } -using namespace InferenceEngine; using namespace std; +using namespace InferenceEngine; +using namespace InferenceEngine::details; using namespace GNAPluginNS; using namespace GNAPluginNS::memory; -using namespace InferenceEngine::details; namespace InferenceEngine { template<> @@ -147,9 +148,9 @@ void GNAPlugin::copyInputData(T *dst, for (uint32_t j = 0; j < num_vector_elements; j++) { if (!std::is_same::value) { if (!gnaFlags->input_low_precision) { - dst[j * num_group + i] = GNAPluginNS::ConvertFloatToInt16(src[i * num_vector_elements + j] * scaleFactor); + dst[j * num_group + i] = ConvertFloatToInt16(src[i * num_vector_elements + j] * scaleFactor); } else { - dst[j * num_group + i] = GNAPluginNS::ConvertFloatToInt8(src[i * num_vector_elements + j] * scaleFactor); + dst[j * num_group + i] = ConvertFloatToInt8(src[i * num_vector_elements + j] * scaleFactor); } } else { dst[j * num_group + i] = src[i * num_vector_elements + j]; @@ -174,15 +175,14 @@ void GNAPlugin::copyInputData(T *dst, std::memset(ptr_dst_vec, 0, num_vector_stride * sizeof(T)); if (!gnaFlags->input_low_precision) { for (uint32_t j = 0; j < num_vector_elements; j++) { - ptr_dst_vec[j] = GNAPluginNS::ConvertFloatToInt16(ptr_src_vec[j] * scaleFactor); + ptr_dst_vec[j] = ConvertFloatToInt16(ptr_src_vec[j] * scaleFactor); } } else { for (uint32_t j = 0; j < num_vector_elements; j++) { - ptr_dst_vec[j] = GNAPluginNS::ConvertFloatToInt8(ptr_src_vec[j] * scaleFactor); + ptr_dst_vec[j] = ConvertFloatToInt8(ptr_src_vec[j] * scaleFactor); } } } - } else { for (uint32_t i = 0; i < num_frames; i++) { void *ptr_dst_vec = reinterpret_cast(dst) + i * num_vector_stride * sizeof(T); @@ -353,6 +353,7 @@ GNAPlugin::GNAPlugin(const std::map& configMap) { Init(); SetConfig(configMap); InitGNADevice(); + GnaLog(gnaFlags->log_level); } void GNAPlugin::Init() { @@ -420,10 +421,10 @@ void GNAPlugin::UpdateInputScaleFromNetwork(InferenceEngine::CNNNetwork& network auto scaleInput = frontend::CalculateScaleFactorFromStats(levels, inputRange.first[0], inputRange.second[0]); if (!config.inputScaleFactorsPerInput.empty() || !config.inputScaleFactors.empty()) { - gnawarn() << "WARNING: Scale factor calculated during model quantization (" << scaleInput + log::warning() << "Scale factor calculated during model quantization (" << scaleInput << ") will be used instead of user input (" << (*inputs_ptr_)[input.first].scale_factor << ").\n"; if ((*inputs_ptr_)[input.first].scale_factor < scaleInput) { - gnawarn() << "WARNING: Scale factor calculated based on input values (" << (*inputs_ptr_)[input.first].scale_factor + log::warning() << "Scale factor calculated based on input values (" << (*inputs_ptr_)[input.first].scale_factor << ") is smaller than scale factor used to quantize model (" << scaleInput << "). " << "Input values will be clamped.\n"; } @@ -564,7 +565,7 @@ void GNAPlugin::FillInputsAndOutputsTranspositionInfo(const InferenceEngine::CNN OV_ITT_SCOPED_TASK(itt::domains::GNA_LT, "FillInputsAndOutputsTranspositionInfo"); auto printTranspositionInfo = [](const std::vector &transpositionInfo) { for (const auto &transpositionInfoPart : transpositionInfo) { - gnalog() << "transpose=" << transpositionInfoPart.transpose << " rows_num=" << transpositionInfoPart.num_transpose_rows + log::debug() << "transpose=" << transpositionInfoPart.transpose << " rows_num=" << transpositionInfoPart.num_transpose_rows << " columns_num=" << transpositionInfoPart.num_transpose_columns << "\n"; } }; @@ -577,7 +578,7 @@ void GNAPlugin::FillInputsAndOutputsTranspositionInfo(const InferenceEngine::CNN if (transpositionInfo.empty()) continue; transpose_inputs_info.insert({inputLayer->name, transpositionInfo}); - gnalog() << "Input " << inputLayer->name << " transposition info: \n"; + log::debug() << "Input " << inputLayer->name << " transposition info: \n"; printTranspositionInfo(transpositionInfo); } @@ -596,7 +597,7 @@ void GNAPlugin::FillInputsAndOutputsTranspositionInfo(const InferenceEngine::CNN } } transpose_outputs_info.insert({outLayer->name, transpositionInfo}); - gnalog() << "Output " << outLayer->name << " transposition info: \n"; + log::debug() << "Output " << outLayer->name << " transposition info: \n"; printTranspositionInfo(transpositionInfo); } } @@ -793,9 +794,7 @@ void GNAPlugin::LoadNetwork(const CNNNetwork& _network) { // Check the network std::string error; - if (!GNAPluginNS::GNALimitations::AreLayersSupported(network, - error, - gnaFlags->log_level == ov::log::Level::WARNING)) { + if (!GNAPluginNS::GNALimitations::AreLayersSupported(network, error)) { THROW_GNA_EXCEPTION << error.c_str(); } @@ -943,7 +942,7 @@ void GNAPlugin::LoadNetwork(const CNNNetwork& _network) { // keep inputs information and create input primitives inputs_data_map_ = newNet.getInputsInfo(); if (inputs_data_map_.empty()) { - gnawarn() << "No inputs for the topology\n"; + log::warning() << "No inputs for the topology\n"; } // keep output dims @@ -969,7 +968,7 @@ void GNAPlugin::LoadNetwork(const CNNNetwork& _network) { } if (graphCompiler.dnnComponents.components.empty()) { - gnawarn() << "No GNA primitives created based on topology. This might indicate trivial topology\n"; + log::warning() << "No GNA primitives created based on topology. This might indicate trivial topology\n"; trivialTopology = true; } @@ -993,13 +992,13 @@ void GNAPlugin::LoadNetwork(const CNNNetwork& _network) { // searching for outData represented in GNA blob // using ufs - upper first search - gnalog() << "[UFS] searching for : " << outPort.first << " representation in GNA\n"; + log::debug() << "[UFS] searching for : " << outPort.first << " representation in GNA\n"; bool stopSearching = false; CNNNetDFS( outLayer, [this, &outPort, &stopSearching](CNNLayerPtr layer) { - gnalog() << "[UFS] from : " << outPort.first << " reached: " << layer->name << "\n"; + log::debug() << "[UFS] from : " << outPort.first << " reached: " << layer->name << "\n"; stopSearching = TryToInitOutput(outPort.first, layer); }, true, @@ -1633,7 +1632,7 @@ InferenceEngine::IExecutableNetworkInternal::Ptr GNAPlugin::ImportNetwork(std::i IE_ASSERT(config.inputScaleFactorsPerInput.size() <= inputs_ptr_->size()); for (auto&& sf : config.inputScaleFactorsPerInput) { if (sf.second != GNAPluginNS::kScaleFactorDefault) { - gnalog() << "[Import Network] Using input scale factor defined in configuration for input " << sf.first + log::debug() << "[Import Network] Using input scale factor defined in configuration for input " << sf.first << std::endl; (*inputs_ptr_)[sf.first].scale_factor = sf.second; } @@ -1642,7 +1641,7 @@ InferenceEngine::IExecutableNetworkInternal::Ptr GNAPlugin::ImportNetwork(std::i IE_ASSERT(config.inputScaleFactors.size() <= inputs_ptr_->size()); for (size_t id = 0; id < config.inputScaleFactors.size(); ++id) { if (id < inputs_ptr_->size() && config.inputScaleFactors[id] != GNAPluginNS::kScaleFactorDefault) { - gnalog() << "[Import Network] Using input scale factor defined in configuration for input " << id + log::debug() << "[Import Network] Using input scale factor defined in configuration for input " << id << std::endl; inputs_ptr_->Get().at(id).scale_factor = config.inputScaleFactors[id]; } @@ -1706,7 +1705,7 @@ void GNAPlugin::Export(std::ostream &outStream) { for (auto && memoryConnection : graphCompiler.memory_connection) { auto state = std::make_shared(memoryConnection.first, std::make_shared (memoryConnection.second)); - gnalog() << "Scale factor Memory layer " << state->GetScaleFactor() << std::endl; + log::debug() << "Scale factor Memory layer " << state->GetScaleFactor() << std::endl; serial.AddState(memoryConnection.second.gna_ptr, memoryConnection.second.reserved_size, memoryConnection.first, state->GetScaleFactor()); } diff --git a/src/plugins/intel_gna/src/gna_plugin.hpp b/src/plugins/intel_gna/src/gna_plugin.hpp index 22d1ff584a1..46435a4adf7 100644 --- a/src/plugins/intel_gna/src/gna_plugin.hpp +++ b/src/plugins/intel_gna/src/gna_plugin.hpp @@ -20,7 +20,8 @@ #include "backend/am_intel_dnn.hpp" #include "gna_data_types.hpp" #include "gna_graph_compiler.hpp" -#include "gna_plugin_log.hpp" +#include "log/debug.hpp" +#include "log/log.hpp" #include "gna_plugin_config.hpp" #include #include diff --git a/src/plugins/intel_gna/src/gna_plugin_config.cpp b/src/plugins/intel_gna/src/gna_plugin_config.cpp index 0770884bd68..c8aedca9068 100644 --- a/src/plugins/intel_gna/src/gna_plugin_config.cpp +++ b/src/plugins/intel_gna/src/gna_plugin_config.cpp @@ -8,6 +8,7 @@ #include #include "gna_plugin.hpp" #include "gna_plugin_config.hpp" +#include "log/log.hpp" #include "common/gna_target.hpp" #include "cpp_interfaces/interface/ie_internal_plugin_config.hpp" #include "ie_common.h" @@ -17,6 +18,7 @@ using namespace InferenceEngine; using namespace InferenceEngine::details; +using namespace ov::intel_gna; namespace GNAPluginNS { const uint8_t Config::max_num_requests; @@ -60,8 +62,6 @@ void Config::UpdateFromMap(const std::map& config) { } }; - auto &log = gnalog(); - auto check_compatibility = [&](const std::string& recommended_key) { if (config.count(recommended_key)) { if (value != config.at(recommended_key)) { @@ -171,7 +171,6 @@ OPENVINO_SUPPRESS_DEPRECATED_END } else if (value == PluginConfigParams::NO) { gnaFlags.compact_mode = false; } else { - log << "GNA compact mode should be true/false (YES/NO), but not " << value; THROW_GNA_EXCEPTION << "GNA compact mode should be true/false (YES/NO), but not " << value; } } else if (key == CONFIG_KEY(EXCLUSIVE_ASYNC_REQUESTS)) { @@ -180,7 +179,6 @@ OPENVINO_SUPPRESS_DEPRECATED_END } else if (value == PluginConfigParams::NO) { gnaFlags.exclusive_async_requests = false; } else { - log << "EXCLUSIVE_ASYNC_REQUESTS should be YES/NO, but not" << value; THROW_GNA_EXCEPTION << "EXCLUSIVE_ASYNC_REQUESTS should be YES/NO, but not" << value; } } else if (key == ov::hint::performance_mode) { @@ -197,7 +195,6 @@ OPENVINO_SUPPRESS_DEPRECATED_END check_compatibility(ov::hint::inference_precision.name()); auto precision = Precision::FromStr(value); if (precision != Precision::I8 && precision != Precision::I16) { - log << "Unsupported precision of GNA hardware, should be Int16 or Int8, but was: " << value; THROW_GNA_EXCEPTION << "Unsupported precision of GNA hardware, should be Int16 or Int8, but was: " << value; } @@ -214,8 +211,6 @@ OPENVINO_SUPPRESS_DEPRECATED_START } else if (value == PluginConfigParams::NO) { gnaFlags.uniformPwlDesign = false; } else { - log << "GNA pwl uniform algorithm parameter " - << "should be equal to YES/NO, but not" << value; THROW_GNA_EXCEPTION << "GNA pwl uniform algorithm parameter " << "should be equal to YES/NO, but not" << value; } @@ -231,8 +226,6 @@ OPENVINO_SUPPRESS_DEPRECATED_START THROW_GNA_EXCEPTION << "Invalid value of PWL max error percent"; } catch (std::out_of_range&) { - log << "Unsupported PWL error percent value: " << value - << ", should be greater than 0 and less than 100"; THROW_GNA_EXCEPTION << "Unsupported PWL error percent value: " << value << ", should be greater than 0 and less than 100"; } @@ -244,8 +237,6 @@ OPENVINO_SUPPRESS_DEPRECATED_END } else if (value == PluginConfigParams::NO) { gnaFlags.performance_counting = false; } else { - log << "GNA performance counter enabling parameter " - << "should be equal to YES/NO, but not" << value; THROW_GNA_EXCEPTION << "GNA performance counter enabling parameter " << "should be equal to YES/NO, but not" << value; } @@ -261,8 +252,6 @@ OPENVINO_SUPPRESS_DEPRECATED_START try { gnaFlags.num_requests = get_max_num_requests(); } catch (std::out_of_range&) { - log << "Unsupported accelerator lib number of threads: " << value - << ", should be greater than 0 and less than " << Config::max_num_requests; THROW_GNA_EXCEPTION << "Unsupported accelerator lib number of threads: " << value << ", should be greater than 0 and less than" << Config::max_num_requests; } @@ -272,17 +261,11 @@ OPENVINO_SUPPRESS_DEPRECATED_START } else if (value == PluginConfigParams::NO) { gnaFlags.gna_openmp_multithreading = true; } else { - log << "SINGLE_THREAD should be YES/NO, but not" << value; THROW_GNA_EXCEPTION << "SINGLE_THREAD should be YES/NO, but not" << value; } OPENVINO_SUPPRESS_DEPRECATED_END } else if (key == CONFIG_KEY(LOG_LEVEL) || key == ov::log::level) { - if (value == PluginConfigParams::LOG_WARNING || value == PluginConfigParams::LOG_NONE || value == PluginConfigParams::LOG_DEBUG) { - gnaFlags.log_level = ov::util::from_string(value, ov::log::level); - } else { - log << "Currently only LOG_LEVEL = LOG_WARNING, LOG_DEBUG and LOG_NONE are supported, not " << value; - THROW_GNA_EXCEPTION << "Currently only LOG_LEVEL = LOG_WARNING, LOG_DEBUG and LOG_NONE are supported, not " << value; - } + gnaFlags.log_level = ov::util::from_string(value, ov::log::level); } else { IE_THROW(NotFound) << "[GNAPlugin] in function " << __PRETTY_FUNCTION__<< ": " diff --git a/src/plugins/intel_gna/src/layers/gna_convolution_layer.cpp b/src/plugins/intel_gna/src/layers/gna_convolution_layer.cpp index 013f7ece4f9..b9abd142fe3 100644 --- a/src/plugins/intel_gna/src/layers/gna_convolution_layer.cpp +++ b/src/plugins/intel_gna/src/layers/gna_convolution_layer.cpp @@ -12,7 +12,7 @@ #include #include "gna_graph_tools.hpp" -#include "gna_plugin_log.hpp" +#include "log/debug.hpp" namespace GNAPluginNS { namespace GNAConvolutionLayer { diff --git a/src/plugins/intel_gna/src/layers/gna_crop_layer.cpp b/src/plugins/intel_gna/src/layers/gna_crop_layer.cpp index 6457fcb9dd8..b10c16619af 100644 --- a/src/plugins/intel_gna/src/layers/gna_crop_layer.cpp +++ b/src/plugins/intel_gna/src/layers/gna_crop_layer.cpp @@ -1,11 +1,13 @@ // Copyright (C) 2022 Intel Corporation // SPDX-License-Identifier: Apache-2.0 // +#include #include "gna_crop_layer.hpp" -#include "../gna_plugin_log.hpp" +#include "log/log.hpp" +#include "log/debug.hpp" -#include +using namespace ov::intel_gna; namespace GNAPluginNS { @@ -22,7 +24,7 @@ SimpleCrop get_crop_params(const std::vector& axis_in, for (int n = 0; n < axis_in.size(); n++) { const auto axis = axis_in[n]; if (axis < 0 || axis >= input_dims.size()) { - gnawarn() << "Crop axis outside of input shape size detected.\n"; + log::warning() << "Crop axis outside of input shape size detected.\n"; continue; } const auto input_dim = input_dims[axis]; diff --git a/src/plugins/intel_gna/src/layers/gna_fake_quantize_layer.hpp b/src/plugins/intel_gna/src/layers/gna_fake_quantize_layer.hpp index fe3090773e4..aee179df473 100644 --- a/src/plugins/intel_gna/src/layers/gna_fake_quantize_layer.hpp +++ b/src/plugins/intel_gna/src/layers/gna_fake_quantize_layer.hpp @@ -5,7 +5,6 @@ #pragma once #include "gna_layer_info.hpp" -#include "gna_plugin_log.hpp" #include "gna_layer_helpers.hpp" #include "frontend/weights_converter.hpp" diff --git a/src/plugins/intel_gna/src/layers/gna_layer_helpers.hpp b/src/plugins/intel_gna/src/layers/gna_layer_helpers.hpp index 193eb8ce1e0..5601b71a519 100644 --- a/src/plugins/intel_gna/src/layers/gna_layer_helpers.hpp +++ b/src/plugins/intel_gna/src/layers/gna_layer_helpers.hpp @@ -5,7 +5,6 @@ #pragma once #include "gna_layer_info.hpp" -#include "gna_plugin_log.hpp" namespace GNAPluginNS { namespace LayerUtils { diff --git a/src/plugins/intel_gna/src/layers/gna_permute.hpp b/src/plugins/intel_gna/src/layers/gna_permute.hpp index 7b107bd1f88..a7b7a73dc54 100644 --- a/src/plugins/intel_gna/src/layers/gna_permute.hpp +++ b/src/plugins/intel_gna/src/layers/gna_permute.hpp @@ -7,7 +7,7 @@ #include #include #include "ie_common.h" -#include "gna_plugin_log.hpp" +#include "log/debug.hpp" namespace GNAPluginNS { template diff --git a/src/plugins/intel_gna/src/gna_plugin_log.hpp b/src/plugins/intel_gna/src/log/debug.hpp similarity index 51% rename from src/plugins/intel_gna/src/gna_plugin_log.hpp rename to src/plugins/intel_gna/src/log/debug.hpp index cfb911ddb0e..799cdbf2f43 100644 --- a/src/plugins/intel_gna/src/gna_plugin_log.hpp +++ b/src/plugins/intel_gna/src/log/debug.hpp @@ -4,53 +4,21 @@ #pragma once -#include #include // #define GNA_DEBUG + #ifdef GNA_DEBUG -#include + /** * @brief used for creating graphviz charts, and layers dump */ #define PLOT -#define GNA_HEAP_PROFILER -#define MODEL_DUMP -#define gnalog() std::cout -#define gnawarn() std::cerr -#else -#ifdef VERBOSE -#define VERBOSE_LEVEL (1) -#else -#define VERBOSE_LEVEL (0) -#endif - -#ifdef PLOT -#define PLOT_LEVEL (1) -#else -#define PLOT_LEVEL (0) -#endif - -class GnaLog { - public : - template - GnaLog & operator << (const T &obj) { - return *this; - } - - GnaLog & operator<< (std::ostream & (*manip)(std::ostream &)) { - return *this; - } -}; - -inline GnaLog & gnalog() { - static GnaLog l; - return l; -} -inline GnaLog & gnawarn() { - return gnalog(); -} +/** + * @brief used for dumping allocated memory + */ +#define GNA_MEMORY_DUMP #endif @@ -66,13 +34,11 @@ inline GnaLog & gnawarn() { # define __PRETTY_FUNCTION__ __FUNCTION__ #endif - - #define GNA_LAYER_ASSERT(layer, expr)\ if (!(expr)) { \ THROW_GNA_LAYER_EXCEPTION(layer) << ": " << #expr; \ } -#define THROW_GNA_EXCEPTION IE_THROW() << "[GNAPlugin] in function " << __PRETTY_FUNCTION__<< ": " +#define THROW_GNA_EXCEPTION IE_THROW() << "[openvino_intel_gna_plugin] in function " << __PRETTY_FUNCTION__<< ": " #define THROW_GNA_LAYER_EXCEPTION(layer) THROW_GNA_EXCEPTION << LAYER_NAME(layer) #define LAYER_NAME(layer) (layer)->type << " layer : \"" << (layer)->name << "\" " diff --git a/src/plugins/intel_gna/src/gna2_model_debug_log.cpp b/src/plugins/intel_gna/src/log/dump.cpp similarity index 91% rename from src/plugins/intel_gna/src/gna2_model_debug_log.cpp rename to src/plugins/intel_gna/src/log/dump.cpp index fa18c8e594c..e17e095ee4f 100644 --- a/src/plugins/intel_gna/src/gna2_model_debug_log.cpp +++ b/src/plugins/intel_gna/src/log/dump.cpp @@ -1,16 +1,9 @@ // Copyright (C) 2018-2022 Intel Corporation // SPDX-License-Identifier: Apache-2.0 // - -#include "gna2_model_helper.hpp" #include #include #include - -#include "gna2_model_debug_log.hpp" -#include "gna2-model-api.h" -#include "gna_device.hpp" - #include #include #include @@ -20,9 +13,17 @@ #include #include -namespace { +#include "dump.hpp" +#include "log.hpp" +#include "gna2_model_helper.hpp" +#include "gna2-model-api.h" +#include "gna_device.hpp" -std::string GetLayerType(Gna2OperationType type) { +namespace ov { +namespace intel_gna { +namespace dump { + +inline std::string GetLayerType(Gna2OperationType type) { switch (type) { case Gna2OperationTypeFullyConnectedAffine: return "Gna2OperationTypeFullyConnectedAffine"; case Gna2OperationTypeElementWiseAffine: return "Gna2OperationTypeElementWiseAffine"; @@ -34,17 +35,17 @@ std::string GetLayerType(Gna2OperationType type) { } } -void write_pwl(std::ostream & pwl_file, const Gna2PwlSegment* const segments, const uint32_t numberOfSegments) { +inline void write_pwl(std::ostream & pwl_file, const Gna2PwlSegment* const segments, const uint32_t numberOfSegments) { for (uint32_t k = 0; k < numberOfSegments; k++) { pwl_file << segments[k].Slope << ", " << segments[k].xBase << ", " << segments[k].yBase << "\n"; } } -void write_pwl(std::ostream & pwl_file, const Gna2Tensor& activation) { +inline void write_pwl(std::ostream & pwl_file, const Gna2Tensor& activation) { write_pwl(pwl_file, static_cast(activation.Data), activation.Shape.Dimensions[0]); } -std::string GetSimpleString(Gna2Shape shape) { +inline std::string GetSimpleString(Gna2Shape shape) { std::stringstream out; for (uint32_t i = 0; i < shape.NumberOfDimensions; i++) { out << shape.Dimensions[i]; @@ -62,7 +63,7 @@ uint32_t FindInMapOrReturnOne(MapType map, typename MapType::key_type key) { return 1; } -uint32_t GetTypeByteSize(Gna2DataType type) { +inline uint32_t GetTypeByteSize(Gna2DataType type) { static const std::map operandTypeMap = { {Gna2DataTypeNone, 1}, {Gna2DataTypeBoolean, 1}, @@ -81,7 +82,7 @@ uint32_t GetTypeByteSize(Gna2DataType type) { return FindInMapOrReturnOne(operandTypeMap, type); } -uint32_t GetGnaShapeSize(const Gna2Shape& shape, const uint32_t bytesPerElement) { +inline uint32_t GetGnaShapeSize(const Gna2Shape& shape, const uint32_t bytesPerElement) { if (shape.NumberOfDimensions == 0) { return 0; } @@ -144,8 +145,6 @@ int32_t GetValue(const Gna2Tensor& tensor, const T & elementIndex) { return intValue; } -} // namespace - void WriteInputAndOutputTextGNAImpl(const Gna2Model & gnaModel, const std::string dumpFolderNameGNA, const std::string refFolderName) { for (uint32_t i = 0; i < gnaModel.NumberOfOperations; i++) { const auto & operation = gnaModel.Operations[i]; @@ -199,7 +198,7 @@ void WriteInputAndOutputTextGNAImpl(const Gna2Model & gnaModel, const std::strin if (numItems) { auto rmse = std::sqrt(summOfSqDiff / numItems); auto avg = summOfDiff / numItems; - std::cout << std::left << std::setw(55) << out_file_name.str() + log::debug() << std::left << std::setw(55) << out_file_name.str() << " RMSE=" << std::fixed << std::setprecision(5) << std::right << std::setw(8) << rmse << " avg=" << std::fixed << std::setprecision(5) << std::right << std::setw(8) << avg << " maxD=" << std::fixed << std::setprecision(5) << std::right << std::setw(8) << maxD << std::endl; @@ -215,8 +214,6 @@ void WriteInputAndOutputTextGNAImpl(const Gna2Model & gnaModel, const std::strin } } -namespace { - template static std::string GetName(T name, size_t index) { return name; @@ -236,7 +233,7 @@ std::string FindInMapOrReturnUnknown(MapType map, typename MapType::key_type key return std::string {"unknown"}; } -std::string GetOperandType(Gna2DataType type) { +inline std::string GetOperandType(Gna2DataType type) { static const std::map operandTypeMap = { {Gna2DataTypeNone, "Gna2DataTypeNone"}, {Gna2DataTypeBoolean, "Gna2DataTypeBoolean"}, @@ -256,7 +253,7 @@ std::string GetOperandType(Gna2DataType type) { return FindInMapOrReturnUnknown(operandTypeMap, type); } -std::string GetOperandName(Gna2OperationType type, size_t index) { +inline std::string GetOperandName(Gna2OperationType type, size_t index) { static const std::map> operationOperandNamesMap = { {Gna2OperationTypeConvolution, {"inputs", "outputs", "filters", "biases", "activationFunction"}}, {Gna2OperationTypeCopy, {"inputs", "outputs"}}, @@ -269,7 +266,7 @@ std::string GetOperandName(Gna2OperationType type, size_t index) { return FindInMapOrReturnUnknown(operationOperandNamesMap, type, index); } -std::string GetBiasMode(Gna2BiasMode mode) { +inline std::string GetBiasMode(Gna2BiasMode mode) { static const std::map biasModeMap = { {Gna2BiasModeDefault, "Gna2BiasModeDefault"}, {Gna2BiasModePerStride, "Gna2BiasModePerStride"}, @@ -278,7 +275,7 @@ std::string GetBiasMode(Gna2BiasMode mode) { return FindInMapOrReturnUnknown(biasModeMap, mode); } -std::string GetPoolingMode(Gna2PoolingMode mode) { +inline std::string GetPoolingMode(Gna2PoolingMode mode) { static const std::map poolingModeMap = { {Gna2PoolingModeDisabled, "Gna2PoolingModeDisabled"}, {Gna2PoolingModeMax, "Gna2PoolingModeMax"}, @@ -287,7 +284,7 @@ std::string GetPoolingMode(Gna2PoolingMode mode) { return FindInMapOrReturnUnknown(poolingModeMap, mode); } -void DumpShape(std::ostream& dumpFile, Gna2Shape* shape, const std::string paramName) { +inline void DumpShape(std::ostream& dumpFile, Gna2Shape* shape, const std::string paramName) { dumpFile << "\tParameter name: " << paramName << ", "; dumpFile << "parameter type: Gna2Shape\n"; dumpFile << "\t\tNumber of dimensions: " << shape->NumberOfDimensions; @@ -298,7 +295,7 @@ void DumpShape(std::ostream& dumpFile, Gna2Shape* shape, const std::string param dumpFile << "]\n"; } -void DumpConvolutionParameters(std::ostream& dumpFile, void** parameters, size_t knownParamCount, const std::vector paramNames) { +inline void DumpConvolutionParameters(std::ostream& dumpFile, void** parameters, size_t knownParamCount, const std::vector paramNames) { size_t i = 0; while (i < knownParamCount) { @@ -319,12 +316,12 @@ void DumpConvolutionParameters(std::ostream& dumpFile, void** parameters, size_t } } -void DumpCopyParameters(std::ostream& dumpFile, void** parameters, size_t knownParamCount, const std::vector paramNames) { +inline void DumpCopyParameters(std::ostream& dumpFile, void** parameters, size_t knownParamCount, const std::vector paramNames) { Gna2Shape* subTensorShape = reinterpret_cast(parameters[CopyShapeParamIdx]); DumpShape(dumpFile, subTensorShape, paramNames[CopyShapeParamIdx]); } -void DumpFCAffineParameters(std::ostream& dumpFile, void** parameters, size_t knownParamCount, const std::vector paramNames) { +inline void DumpFCAffineParameters(std::ostream& dumpFile, void** parameters, size_t knownParamCount, const std::vector paramNames) { size_t i = 0; while (i < knownParamCount) { @@ -341,15 +338,15 @@ void DumpFCAffineParameters(std::ostream& dumpFile, void** parameters, size_t kn } } -void DumpIntParameter(std::ostream& dumpFile, void** parameters, size_t knownParamCount, const std::vector paramNames) { +inline void DumpIntParameter(std::ostream& dumpFile, void** parameters, size_t knownParamCount, const std::vector paramNames) { uint32_t* param = reinterpret_cast(parameters[0]); if (param != nullptr) dumpFile << "\tParameter name: " << paramNames[0] << ", value: " << *param << "\n"; } -std::vector GetParamaterNames(Gna2OperationType type) { +inline std::vector GetParamaterNames(Gna2OperationType type) { // This map must be aligned with dumpParamMap in this file - const std::map> operationParamaterNamesMap = { + static const std::map> operationParamaterNamesMap = { {Gna2OperationTypeConvolution, {"convolutionStride", "biasMode", "poolingMode", "poolingWindow", "poolingStride", "zeroPadding"}}, {Gna2OperationTypeCopy, {"shape (sub-tensor shape)"}}, {Gna2OperationTypeFullyConnectedAffine, {"biasMode", "biasVectorIndex"}}, @@ -362,7 +359,7 @@ std::vector GetParamaterNames(Gna2OperationType type) { typedef void (*dumpParameters) (std::ostream&, void**, size_t, const std::vector); -dumpParameters GetParamDumpFunc(Gna2OperationType type) { +inline dumpParameters GetParamDumpFunc(Gna2OperationType type) { // This map must be aligned with operationParamaterNamesMap in this file static const std::map dumpParamMap = { {Gna2OperationTypeConvolution, DumpConvolutionParameters}, @@ -374,7 +371,7 @@ dumpParameters GetParamDumpFunc(Gna2OperationType type) { return dumpParamMap.find(type) != dumpParamMap.end() ? dumpParamMap.find(type)->second : nullptr; } -void DumpPwl(std::ostream& dumpFile, const Gna2Tensor& activation) { +inline void DumpPwl(std::ostream& dumpFile, const Gna2Tensor& activation) { const Gna2PwlSegment* const segments = static_cast(activation.Data); const uint32_t numberOfSegments = activation.Shape.Dimensions[0]; @@ -398,7 +395,7 @@ void DumpPwl(std::ostream& dumpFile, const Gna2Tensor& activation) { } } -void DumpCompoundBias(std::ostream& dumpFile, const Gna2Tensor& tensor) { +inline void DumpCompoundBias(std::ostream& dumpFile, const Gna2Tensor& tensor) { uint32_t i = 0; while (i < tensor.Shape.Dimensions[0]) { @@ -408,7 +405,7 @@ void DumpCompoundBias(std::ostream& dumpFile, const Gna2Tensor& tensor) { } } -void DumpCharArray(std::ostream& dumpFile, const char *carray, size_t count) { +inline void DumpCharArray(std::ostream& dumpFile, const char *carray, size_t count) { auto i = 0; while (*(carray + i) != 0 && i < count) { dumpFile << *(carray + i) << " "; @@ -416,7 +413,6 @@ void DumpCharArray(std::ostream& dumpFile, const char *carray, size_t count) { } dumpFile << "\n"; } -} // namespace void DumpGna2Model(const Gna2Model& gnaModel, const std::string& dumpFolderNameGNA, @@ -517,3 +513,7 @@ void DumpGna2Model(const Gna2Model& gnaModel, } } } + +} // namespace dump +} // namespace intel_gna +} // namespace ov \ No newline at end of file diff --git a/src/plugins/intel_gna/src/gna2_model_debug_log.hpp b/src/plugins/intel_gna/src/log/dump.hpp similarity index 81% rename from src/plugins/intel_gna/src/gna2_model_debug_log.hpp rename to src/plugins/intel_gna/src/log/dump.hpp index d5c363f806d..4666bdfa413 100644 --- a/src/plugins/intel_gna/src/gna2_model_debug_log.hpp +++ b/src/plugins/intel_gna/src/log/dump.hpp @@ -11,14 +11,15 @@ #include "gna2-model-api.h" #include "gna_device.hpp" +namespace ov { +namespace intel_gna { +namespace dump { + void WriteInputAndOutputTextGNAImpl(const Gna2Model & gnaModel, const std::string dumpFolderNameGNA, const std::string refFolderName); void DumpGna2Model(const Gna2Model& gnaModel, const std::string& dumpFolderNameGNA, bool dumpData, const GnaAllocations& allAllocations, const std::string& modeOfOperation); -template -std::string toHexString(T t) { - std::ostringstream o; - o << std::hex << t; - return o.str(); -} +} // namespace dump +} // namespace intel_gna +} // namespace ov \ No newline at end of file diff --git a/src/plugins/intel_gna/src/log/log.hpp b/src/plugins/intel_gna/src/log/log.hpp new file mode 100644 index 00000000000..ea655d0fb9c --- /dev/null +++ b/src/plugins/intel_gna/src/log/log.hpp @@ -0,0 +1,126 @@ +// Copyright (C) 2022 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include + +#include "openvino/runtime/properties.hpp" + +namespace ov { +namespace intel_gna { + +/** + * @brief Log manager. It supports all ov::log::Level values. + * To use it need to set log level then just call one of the logging methods: + * GnaLog::Gnalog(ov::log::Level::DEBUG); + * GnaLog::info() << "log message"; // this message will be printed + * GnaLog::trace() << "log message"; // this message shoudl not be printed + */ +class GnaLog { + GnaLog() = default; + + static GnaLog& log(ov::log::Level log_level) { + GnaLog& obj = get_instance(); + obj.message_level_ = log_level; + obj << "[" << log_level << "]" << " "; + return obj; + } + + /** Configuration log level. It should be set in the plugin configuration */ + ov::log::Level log_level_ = ov::log::Level::NO; + + /** Log level of particular log message */ + ov::log::Level message_level_ = ov::log::Level::NO; + + public : + GnaLog(const GnaLog&) = delete; + void operator = (const GnaLog&) = delete; + + GnaLog(ov::log::Level log_level) { + get_instance().log_level_ = log_level; + } + + static GnaLog& get_instance() { + static GnaLog log_obj; + return log_obj; + } + + /** + * @brief Set ERROR log level + * @return GnaLog object + */ + static GnaLog& error() { + return log(ov::log::Level::ERR); + } + + /** + * @brief Set WARNING log level + * @return GnaLog object + */ + static GnaLog& warning() { + return log(ov::log::Level::WARNING); + } + + /** + * @brief Set DEBUG log level + * @return GnaLog object + */ + static GnaLog& debug() { + return log(ov::log::Level::DEBUG); + } + + /** + * @brief Set INFO log level + * @return GnaLog object + */ + static GnaLog& info() { + return log(ov::log::Level::INFO); + } + + /** + * @brief Set TRACE log level + * @return GnaLog object + */ + static GnaLog& trace() { + return log(ov::log::Level::TRACE); + } + + template + GnaLog &operator << (const T &obj) { + if (message_level_ <= log_level_) { + if (message_level_ == ov::log::Level::ERR) { + std::cerr << obj; + } else { + std::cout << obj; + } + } + return *this; + } + + GnaLog &operator << (std::ostream & (*manip)(std::ostream &)) { + if (message_level_ <= log_level_) { + if (message_level_ == ov::log::Level::ERR) { + std::cerr << manip; + } else { + std::cout << manip; + } + } + return *this; + } +}; + +template +std::string toHexString(T t) { + std::ostringstream o; + o << std::hex << t; + return o.str(); +} + +// alias for GnaLog class to make it aligned with snake style code +using log = GnaLog; + +} // namespace intel_gna +} // namespace ov \ No newline at end of file diff --git a/src/plugins/intel_gna/src/memory/gna_mem_requests.hpp b/src/plugins/intel_gna/src/memory/gna_mem_requests.hpp index de07d4c5630..286ce730631 100644 --- a/src/plugins/intel_gna/src/memory/gna_mem_requests.hpp +++ b/src/plugins/intel_gna/src/memory/gna_mem_requests.hpp @@ -8,7 +8,6 @@ #include #include -#include "gna_plugin_log.hpp" #include "gna_mem_regions.hpp" namespace GNAPluginNS { @@ -21,7 +20,7 @@ enum rType : uint8_t { REQUEST_INITIALIZER = 0x8, }; -#ifdef GNA_HEAP_PROFILER +#ifdef GNA_MEMORY_DUMP inline const char* rTypeToStr(uint8_t type) { const char* strType = "UNKNOWN"; diff --git a/src/plugins/intel_gna/src/memory/gna_mem_requests_queue.hpp b/src/plugins/intel_gna/src/memory/gna_mem_requests_queue.hpp index 85163fd0325..944e95e26b9 100644 --- a/src/plugins/intel_gna/src/memory/gna_mem_requests_queue.hpp +++ b/src/plugins/intel_gna/src/memory/gna_mem_requests_queue.hpp @@ -12,11 +12,13 @@ #include #include -#include "gna_plugin_log.hpp" +#include "log/log.hpp" #include "gna_mem_requests.hpp" #include "gna_lib_ver_selector.hpp" #include "memory_solver.hpp" +using namespace ov::intel_gna; + namespace GNAPluginNS { namespace memory { @@ -201,7 +203,7 @@ public: void iterate_binded(GNAPluginNS::memory::MemRequest & reference, const T & visitor) { for (auto &re : _mem_requests) { if ((re._type & REQUEST_BIND) && (re._ptr_in == reference._ptr_out)) { - // std::cout << " [binded=" << re._type << ", ptr=" << re._ptr_out <<"]\n"; + log::trace() << " [binded=" << re._type << ", ptr=" << re._ptr_out <<"]\n"; visitor(reference, re); // primitive loop check if (re._ptr_in == re._ptr_out) continue; diff --git a/src/plugins/intel_gna/src/memory/gna_memory.hpp b/src/plugins/intel_gna/src/memory/gna_memory.hpp index a7853c0dfa2..ac67ae9ca37 100644 --- a/src/plugins/intel_gna/src/memory/gna_memory.hpp +++ b/src/plugins/intel_gna/src/memory/gna_memory.hpp @@ -19,10 +19,10 @@ #include "gna_lib_ver_selector.hpp" #include "memory_solver.hpp" #include "gna_allocator.hpp" -#include "gna_plugin_log.hpp" +#include "log/log.hpp" #include "memory/gna_allocator.hpp" -#ifdef GNA_HEAP_PROFILER +#ifdef GNA_MEMORY_DUMP #include #endif @@ -108,7 +108,7 @@ protected: if (queue.second->calcSize(_is_compact_mode) != 0) { // 3rd stage -- allocation total memory setting to 0 internally queue.second->_basePtr = allocate(ALIGN(queue.second->getSize(), _page_alignment)); - gnalog() << rRegionToStr(queue.second->_region_type) << "(" << static_cast(queue.second->_basePtr.get()) << ")" + log::debug() << rRegionToStr(queue.second->_region_type) << "(" << static_cast(queue.second->_basePtr.get()) << ")" << " allocated: " << ALIGN(queue.second->getSize(), _page_alignment) << std::endl; // 4th stage -- setting proper GNA memory region tag for embedded TLV export _allocator.setTag(queue.second->getBasePtr(), queue.first); @@ -116,7 +116,7 @@ protected: allocateRegion(queue.second.get()); } } -#ifdef GNA_HEAP_PROFILER +#ifdef GNA_MEMORY_DUMP memoryDump(); #endif } @@ -157,7 +157,7 @@ protected: void iterate_binded(GNAPluginNS::memory::MemRequest & reference, const T & visitor) { for (auto &re : getQueue(REGION_AUTO)->_mem_requests) { if ((re._type & REQUEST_BIND) && (re._ptr_in == reference._ptr_out)) { - // std::cout << " [binded=" << rTypeToStr(re._type) << ", ptr=" << re._ptr_out <<"]\n"; + // log::trace() << " [binded=" << rTypeToStr(re._type) << ", ptr=" << re._ptr_out <<"]\n"; visitor(reference, re); // primitive loop check if (re._ptr_in == re._ptr_out) continue; @@ -165,7 +165,7 @@ protected: iterate_binded(re, visitor); } } -#ifdef GNA_HEAP_PROFILER +#ifdef GNA_MEMORY_DUMP memoryDump(); #endif } @@ -245,7 +245,7 @@ protected: binded._element_size = reference._element_size; }); - gnalog() << static_cast(cptr) << "(" << sz + re._padding << ")" << std::endl; + log::debug() << static_cast(cptr) << "(" << sz + re._padding << ")" << std::endl; switch (re._type & ~REQUEST_BIND) { case REQUEST_ALLOCATE : break; @@ -268,7 +268,7 @@ protected: } } -#ifdef GNA_HEAP_PROFILER +#ifdef GNA_MEMORY_DUMP void memoryDump() { for (const auto &queue : _mem_queues) { std::ofstream dumpFile("gna_memory_requests_" + rRegionToStr(queue.first) + ".txt", std::ios::out); diff --git a/src/plugins/intel_gna/src/memory/gna_memory_util.cpp b/src/plugins/intel_gna/src/memory/gna_memory_util.cpp index 8c43ec139ec..5b561ec8735 100644 --- a/src/plugins/intel_gna/src/memory/gna_memory_util.cpp +++ b/src/plugins/intel_gna/src/memory/gna_memory_util.cpp @@ -5,7 +5,7 @@ #include "gna_memory_util.hpp" #include -#include "gna_plugin_log.hpp" +#include "log/debug.hpp" int32_t GNAPluginNS::memory::MemoryOffset(void *ptr_target, void *ptr_base) { auto target = reinterpret_cast(ptr_target); diff --git a/src/plugins/intel_gna/src/optimizer/gna_pass_manager.cpp b/src/plugins/intel_gna/src/optimizer/gna_pass_manager.cpp index 5734866a5dd..4f46a40abc3 100644 --- a/src/plugins/intel_gna/src/optimizer/gna_pass_manager.cpp +++ b/src/plugins/intel_gna/src/optimizer/gna_pass_manager.cpp @@ -25,7 +25,8 @@ #include #include "backend/dnn_types.h" -#include "gna_plugin_log.hpp" +#include "log/debug.hpp" +#include "log/log.hpp" #include "frontend/quantization.hpp" #include "frontend/quantized_layer_params.hpp" #include @@ -45,8 +46,9 @@ using namespace InferenceEngine; using namespace InferenceEngine::details; using namespace GNAPluginNS; +using namespace ov::intel_gna; -#define pass_trace() gnalog() << "[" << getName() << "] " +#define pass_trace() log::debug() << "[" << getName() << "] " std::shared_ptr BasePass::getPassManager() { auto sharedMgr = mgr.lock(); @@ -87,7 +89,7 @@ static void insertDiagonalLayerBetween(InferenceEngine::CNNLayerPtr prevLayer, size_t in_data_idx = invalid_data_idx) { auto quantized = InferenceEngine::getInjectedData(prevLayer); auto diagName = std::string("SyntheticScaleShift_") + std::to_string(passmanager->getIntVar(diagonalLayersCounterName)++); - gnalog() << "Inserted Diagonal Layer " << diagName <<" between: " << prevLayer->name << " and " << nextLayer->name << "\n" << std::flush; + log::debug() << "Inserted Diagonal Layer " << diagName <<" between: " << prevLayer->name << " and " << nextLayer->name << "\n" << std::flush; auto diagLayer = std::make_shared(LayerParams({diagName, "ScaleShift", Precision::FP32})); IE_ASSERT(diagLayer != nullptr); @@ -126,7 +128,7 @@ static CNNLayerPtr InsertCopyLayer(CNNLayerPtr prevLayer, CNNLayerPtr nextLayer, OV_ITT_SCOPED_TASK(itt::domains::GNA_LT, "InsertCopyLayer"); auto quantized = InferenceEngine::getInjectedData(prevLayer); std::string copyName = copyLayerType + std::string("_") + std::to_string(passmanager->getIntVar(copyLayersCounter)++); - gnalog() << "Inserted " << copyName << " between: " << prevLayer->name << " and " << nextLayer->name << std::endl; + log::debug() << "Inserted " << copyName << " between: " << prevLayer->name << " and " << nextLayer->name << std::endl; CNNLayerPtr copyLayer = std::make_shared(LayerParams({copyName, copyLayerType, Precision::FP32})); @@ -161,7 +163,7 @@ static std::vector getCandidatesForIdentityInsertion(const CNNLayer auto prevLayer = CNNNetPrevLayerSkipCertain(l, idx, [skipFq](CNNLayerPtr ptr) { return LayerInfo(ptr).isNonFunctional() || skipFq && LayerInfo(ptr).isFakeQuantize(); }); - gnalog() << "CNNNetPrevLayerSkipCertain for :: " << l->name << "returned: " << prevLayer->name << std::endl; + log::debug() << "CNNNetPrevLayerSkipCertain for :: " << l->name << "returned: " << prevLayer->name << std::endl; return prevLayer; }; @@ -414,7 +416,7 @@ void ReorderMaxPoolPass::run() { auto convolution = LayerInfo(CNNNetPrevLayer(static_cast(activation))); if (!convolution.isConvolution()) continue; - gnalog() << "MaxPooling: " << pool << ", reordered with activation: " << activation << "\n"; + log::debug() << "MaxPooling: " << pool << ", reordered with activation: " << activation << "\n"; CNNNetSwapLayers(activation, pool); } @@ -489,10 +491,10 @@ void SubstituteSoftSignPass::run() { if (mulSame != mul) continue; // pattern matched - lets substitute - gnalog() << "SoftSign subgraph found consits of: \n" + log::debug() << "SoftSign subgraph found consits of: \n" << "\t" << abs->name << "\n"; - if (addition != nullptr) gnalog() << "\t" << addition->name << "\n"; - gnalog() << "\t" << mul->name << "\n" + if (addition != nullptr) log::debug() << "\t" << addition->name << "\n"; + log::debug() << "\t" << mul->name << "\n" << std::endl; // creating softsign layer @@ -609,7 +611,7 @@ void SubstitutePReluPass::run() { } // hurray we found parametric relu group - dont know what to do with it though - gnalog() << "PRelu with negative slope of " << -LayerInfo(scale).as()->scale << " found" << std::endl; + log::debug() << "PRelu with negative slope of " << -LayerInfo(scale).as()->scale << " found" << std::endl; // removing all layers references except of relu layer outputLayers.clear(); @@ -752,7 +754,7 @@ void RemovePermutationsNHWCToNCHWPass::run() { } for (auto&& to_remove : permutations_to_remove) { - gnalog() << to_remove->type << " layer '" << to_remove->name << "' will be removed" << '\n'; + log::debug() << to_remove->type << " layer '" << to_remove->name << "' will be removed" << '\n'; CNNNetworkRemoveLayer(to_remove, false); } } @@ -787,7 +789,7 @@ void InsertIdentityLayerPass::run() { if (hasNextFuncLayer) continue; auto identityLayer = createIdentityLayer(l->outData[0]->getTensorDesc()); - gnalog() << "Inserted "<< identityLayer->name << " after " << l->name << std::endl; + log::debug() << "Inserted "<< identityLayer->name << " after " << l->name << std::endl; auto nextLayer = CNNNetCheckNextLayerSkipCertain(l, 0, 0, true, [](CNNLayerPtr layer) { return false; }).first; CNNNetworkInsertLayer(l, nextLayer, identityLayer); @@ -802,7 +804,7 @@ void InsertIdentityLayerPass::run() { true_layer = prev; prev = CNNNetPrevLayer(prev); } else { - gnawarn() << "Could not find Functional parent for " << original_prev_layer->name << ", using original layer"; + log::warning() << "Could not find Functional parent for " << original_prev_layer->name << ", using original layer"; prev = original_prev_layer; true_layer = l; break; @@ -848,7 +850,7 @@ void InsertIdentityLayerPass::run() { auto inputData = true_layer->insData[insDataIdx].lock(); auto identityLayer = createIdentityLayer(inputData->getTensorDesc()); - gnalog() << "Inserted "<< identityLayer->name << " between: " << prev->name << " and " << true_layer->name << "\n" << std::flush; + log::debug() << "Inserted "<< identityLayer->name << " between: " << prev->name << " and " << true_layer->name << "\n" << std::flush; // copy offset - to be used while connecting outputs if (prev->params.find("output_offset") != prev->params.end()) { @@ -1080,7 +1082,7 @@ void FlattenTrivialConcatPass::run() { auto reshape = CNNNetworkCreateReshape(tensor, reshapeName, quantized); CNNNetworkInsertLayer(getCreatorLayer(concatInput).lock(), l, reshape); - gnalog() << "\tInserted " << reshapeName << " between " << getCreatorLayer(concatInput).lock()->name << " and " << l->name << std::endl; + log::debug() << "\tInserted " << reshapeName << " between " << getCreatorLayer(concatInput).lock()->name << " and " << l->name << std::endl; } // Reshape concat outputs back to the original size @@ -1095,7 +1097,7 @@ void FlattenTrivialConcatPass::run() { new_tensor.reshape(SizeVector({1, total_size}), Layout::NC); auto new_output = CNNReplaceDataWithChangedTensorDescription(output, new_tensor); - gnalog() << "\tChanged " << output->getName() << " dims to 2D" << std::endl; + log::debug() << "\tChanged " << output->getName() << " dims to 2D" << std::endl; auto reshapeName = l->name + "_output_"+ std::to_string(output_idx) +"_reshape"; @@ -1106,7 +1108,7 @@ void FlattenTrivialConcatPass::run() { } else { CNNNetworkInsertLayer(l, nullptr, reshape, output_idx); } - gnalog() << "\tInserted " << reshapeName << " after " << l->name << std::endl; + log::debug() << "\tInserted " << reshapeName << " after " << l->name << std::endl; } concatLayer->_axis = 1; @@ -1159,7 +1161,7 @@ void InsertConcatAligningFilterPass::run() { // input layer parameters are copied not using GNA-primitives - so nothing to allign here. if (!useAlignFilterIf(input_idx)) continue; - gnalog() << "Inserted Concat Aligning Layer between: " << prevLayer->name << " and " << l->name << std::endl; + log::debug() << "Inserted Concat Aligning Layer between: " << prevLayer->name << " and " << l->name << std::endl; // insert the filter auto filterName = std::string("ConcatAlignFilter_") + std::to_string(numOfFilterLayers++); @@ -1288,13 +1290,13 @@ void ReorderConcatInputsPass::run() { bool bFinish = false; // making a link activation possible without extra layer if first input to concat not a parent / indirect parent of second input // using ufs - upper first search - gnalog() << "[UFS] searching for: " << prevInputToConcat->name << "\n"; + log::debug() << "[UFS] searching for: " << prevInputToConcat->name << "\n"; CNNNetDFS(currConcatLayer, [&currConcatLayer, &prevInputToConcat, &bFinish](CNNLayerPtr layer) { - gnalog() << "[UFS] from : " << currConcatLayer->name << " reached: " << layer->name << "\n"; + log::debug() << "[UFS] from : " << currConcatLayer->name << " reached: " << layer->name << "\n"; // found that direct input to concat is a indirect parent of align filter - so no link required if (layer.get() == prevInputToConcat.get() || LayerInfo(prevInputToConcat).isInput()) { - gnalog() << "[UFS] copy layer insertion needed\n"; + log::debug() << "[UFS] copy layer insertion needed\n"; bFinish = true; } }, true, [&bFinish](InferenceEngine::CNNLayer* from) { @@ -1356,7 +1358,7 @@ void InsertSplitAligningFilterPass::run() { if ((currentOffset != ALIGN64(currentOffset)) || (padding != 0)) { // check that this split output actually connected to further layers if (getInputTo(splitOutput).empty()) { - gnalog() << "Output port: " << splitOutIndex << " of " << l->name << " unconnected, skipping\n"; + log::debug() << "Output port: " << splitOutIndex << " of " << l->name << " unconnected, skipping\n"; } else { if (splitOutput->getDims().size() > 1 && splitOutput->getDims().front() > 1) { THROW_GNA_EXCEPTION << l->name << " Convolution Filter doesn't support batch=" @@ -1369,14 +1371,14 @@ void InsertSplitAligningFilterPass::run() { #ifdef PLOT // getting list of layers attached to current split output - gnalog() << "Inserted Affine Filter: " << filterName << " between: " << l->name << " and "; + log::debug() << "Inserted Affine Filter: " << filterName << " between: " << l->name << " and "; for (auto &&followingLayers : getInputTo(splitOutput)) { if (getInputTo(splitOutput).size() != 1) { - gnalog() << "\n "; + log::debug() << "\n "; } - gnalog() << followingLayers.second->name; + log::debug() << followingLayers.second->name; } - gnalog() << std::endl; + log::debug() << std::endl; #endif auto filterLayer = std::make_shared(LayerParams({filterName, "ConvolutionFilter", Precision::FP32})); @@ -1622,7 +1624,7 @@ void SubstituteScaleShiftBroadCastPass::run() { // TODO: add broadcasting rules checks - gnalog() << "Substitution ScaleShift broadcast for layer: " << l->name << "\n"; + log::debug() << "Substitution ScaleShift broadcast for layer: " << l->name << "\n"; if (nElements % scaleShift->_weights->size()) { THROW_GNA_EXCEPTION << "Cannot tile weights for layer: " << l->name << ", due to weights size not GCD of dims product"; } @@ -1641,7 +1643,7 @@ void SubstituteScaleShiftBroadCastPass::run() { auto layer_before_scale_shift = getCreatorLayer(insData); CNNNetworkInsertLayer(layer_before_scale_shift.lock(), l, reshape); - gnalog() << "\tInserted " << reshapeName << " between " << layer_before_scale_shift.lock()->name << " and " << l->name << std::endl; + log::debug() << "\tInserted " << reshapeName << " between " << layer_before_scale_shift.lock()->name << " and " << l->name << std::endl; } } @@ -1694,7 +1696,7 @@ void BroadcastConstPass::run() { prevLayer->outData.front()->setDims(nextLayer->outData.front()->getDims()); prevLayer->outData.front()->setLayout(nextLayer->outData.front()->getLayout()); } - gnalog() << "Const layer '" << constLayer->name << "' was changed to match output of '" << nextLayer->name << "'\n"; + log::debug() << "Const layer '" << constLayer->name << "' was changed to match output of '" << nextLayer->name << "'\n"; } } @@ -1823,7 +1825,7 @@ void FuseMultipleIdentitiesPass::run() { if (LayerInfo(l).isNonFunctional() || LayerInfo(l).has32BInput()) { continue; } - gnalog() << "CNNNetPrevLayer skip non functional from :: " << l->name; + log::debug() << "CNNNetPrevLayer skip non functional from :: " << l->name; auto isFunctional = [](CNNLayerPtr ptr) { return !LayerInfo(ptr).isNonFunctional(); }; @@ -1836,7 +1838,7 @@ void FuseMultipleIdentitiesPass::run() { return LayerInfo(candidate.first).isLink(); }), prevLayersReached.end()); if (prevLayersReached.empty()) { - gnalog() << ", connected to link output only" << std::endl; + log::debug() << ", connected to link output only" << std::endl; continue; } } @@ -1852,7 +1854,7 @@ void FuseMultipleIdentitiesPass::run() { } auto prevLayer = prevLayersReached.front().first; auto outDataIdx = prevLayersReached.front().second; - gnalog() << ", reached " << prevLayer->name << " at " << outDataIdx << std::endl; + log::debug() << ", reached " << prevLayer->name << " at " << outDataIdx << std::endl; if (!LayerInfo(prevLayer).has32BOutput()) continue; @@ -2253,7 +2255,7 @@ void TransposeWeightsFromNCHWToNHWCPass::run() { auto printTranspositionInfo = [](const std::vector &transpositionInfo) { for (const auto &transpositionInfoPart : transpositionInfo) { - gnalog() << "transpose=" << transpositionInfoPart.transpose << " rows_num=" << transpositionInfoPart.num_transpose_rows + log::debug() << "transpose=" << transpositionInfoPart.transpose << " rows_num=" << transpositionInfoPart.num_transpose_rows << " columns_num=" << transpositionInfoPart.num_transpose_columns << "\n"; } }; @@ -2296,7 +2298,7 @@ void TransposeWeightsFromNCHWToNHWCPass::run() { ConvertTensorFromNCHWToNHWC(weightable->precision.size(), 1, weightable->_biases->size(), weightable->_biases->cbuffer().as(), true, transpositionInfo); } - gnalog() << l->name << " weights and biases rows transposition info:\n"; + log::debug() << l->name << " weights and biases rows transposition info:\n"; printTranspositionInfo(transpositionInfo); } } @@ -2330,7 +2332,7 @@ void TransposeWeightsFromNCHWToNHWCPass::run() { ConvertTensorFromNCHWToNHWC(precision, weightsRows, weightsColumns, weightable->_weights->buffer().as(), true, transpositionInfo); - gnalog() << l->name << " weights rows transposition info:\n"; + log::debug() << l->name << " weights rows transposition info:\n"; printTranspositionInfo(transpositionInfo); } } @@ -2354,7 +2356,7 @@ void TransposeWeightsFromNCHWToNHWCPass::run() { ConvertTensorFromNCHWToNHWC(precision, weightsRows, weightsColumns, weightable->_weights->cbuffer().as(), false, transpositionInfo); - gnalog() << l->name << " weights columns transposition info:\n"; + log::debug() << l->name << " weights columns transposition info:\n"; printTranspositionInfo(transpositionInfo); } } @@ -2380,7 +2382,7 @@ void TransposeWeightsFromNCHWToNHWCPass::run() { auto blob = secondInput->blobs["custom"]; ConvertTensorFromNCHWToNHWC(blob->getTensorDesc().getPrecision().size(), 1, blob->size(), blob->buffer().as(), true, transpositionInfo); - gnalog() << secondInput->name << " data transposition info:\n"; + log::debug() << secondInput->name << " data transposition info:\n"; printTranspositionInfo(transpositionInfo); } } @@ -2425,7 +2427,7 @@ void TransposeWeightsFromNCHWToNHWCPass::run() { TranspositionInfo concatTranspositionInfo{true, rows, columns}; ConvertTensorFromNCHWToNHWC(blob->getTensorDesc().getPrecision().size(), 1, blob->size(), blob->buffer().as(), true, {concatTranspositionInfo}); - gnalog() << input->name << " data transposition info:\n"; + log::debug() << input->name << " data transposition info:\n"; printTranspositionInfo({concatTranspositionInfo}); } } @@ -2456,7 +2458,7 @@ int PassManager::run(int index) { } auto layers = CNNNetSortTopologically(network); pass->attach(layers); - gnalog() << "PASS: " << ++index << "/" << passes.size() << ":" << pass->getName() << "\n"; + log::debug() << "PASS: " << ++index << "/" << passes.size() << ":" << pass->getName() << "\n"; pass->run(); dumpNetworkAfterPass(pass); } diff --git a/src/plugins/intel_gna/src/preprocessing.cpp b/src/plugins/intel_gna/src/preprocessing.cpp index 7c4fdf5c18e..88f577f613a 100644 --- a/src/plugins/intel_gna/src/preprocessing.cpp +++ b/src/plugins/intel_gna/src/preprocessing.cpp @@ -35,6 +35,6 @@ void GNAPluginNS::ConvertToInt16(int16_t *ptr_dst, return; } for (uint32_t i = 0; i < num_rows*num_columns; i++) { - ptr_dst[i] = GNAPluginNS::ConvertFloatToInt16(ptr_src[i]*scale_factor); + ptr_dst[i] = ConvertFloatToInt16(ptr_src[i]*scale_factor); } } diff --git a/src/plugins/intel_gna/src/request/subrequest_impl.cpp b/src/plugins/intel_gna/src/request/subrequest_impl.cpp index 58fdf45950c..a98217513f0 100644 --- a/src/plugins/intel_gna/src/request/subrequest_impl.cpp +++ b/src/plugins/intel_gna/src/request/subrequest_impl.cpp @@ -6,7 +6,7 @@ #include -#include "gna_plugin_log.hpp" +#include "log/debug.hpp" namespace GNAPluginNS { namespace request { diff --git a/src/plugins/intel_gna/src/request/worker_factory.cpp b/src/plugins/intel_gna/src/request/worker_factory.cpp index b5fe1538cbe..2efa6c0eaa6 100644 --- a/src/plugins/intel_gna/src/request/worker_factory.cpp +++ b/src/plugins/intel_gna/src/request/worker_factory.cpp @@ -6,7 +6,7 @@ #include "backend/am_intel_dnn.hpp" #include "gna_device_interface.hpp" -#include "gna_plugin_log.hpp" +#include "log/debug.hpp" #include "request/model_wrapper.hpp" #include "runtime/gna_float_runtime.hpp" #include "subrequest_impl.hpp" diff --git a/src/plugins/intel_gna/src/request/worker_impl.cpp b/src/plugins/intel_gna/src/request/worker_impl.cpp index 1cf608970fa..1ad03cba83e 100644 --- a/src/plugins/intel_gna/src/request/worker_impl.cpp +++ b/src/plugins/intel_gna/src/request/worker_impl.cpp @@ -6,7 +6,7 @@ #include -#include "gna_plugin_log.hpp" +#include "log/debug.hpp" #include "model_wrapper.hpp" #include "subrequest.hpp" diff --git a/src/plugins/intel_gna/src/request/worker_pool_impl.cpp b/src/plugins/intel_gna/src/request/worker_pool_impl.cpp index 504312c023a..9d2b874a29a 100644 --- a/src/plugins/intel_gna/src/request/worker_pool_impl.cpp +++ b/src/plugins/intel_gna/src/request/worker_pool_impl.cpp @@ -4,7 +4,7 @@ #include "worker_pool_impl.hpp" -#include "gna_plugin_log.hpp" +#include "log/debug.hpp" #include "worker.hpp" namespace GNAPluginNS { diff --git a/src/plugins/intel_gna/src/runtime/cnn.cpp b/src/plugins/intel_gna/src/runtime/cnn.cpp index 19afe3fd747..6b2f7161287 100644 --- a/src/plugins/intel_gna/src/runtime/cnn.cpp +++ b/src/plugins/intel_gna/src/runtime/cnn.cpp @@ -6,13 +6,13 @@ #include #include #include -#include #include "cnn.h" #include "backend/dnn_types.h" #include "backend/gna_limitations.hpp" #include "gna_lib_ver_selector.hpp" #include "layers/gna_convolution_layer.hpp" +#include "log/debug.hpp" using namespace GNAPluginNS::GNAConvolutionLayer; diff --git a/src/plugins/intel_gna/src/runtime/gna_float_runtime.cpp b/src/plugins/intel_gna/src/runtime/gna_float_runtime.cpp index b1f83f48645..cf31bb6c1ae 100644 --- a/src/plugins/intel_gna/src/runtime/gna_float_runtime.cpp +++ b/src/plugins/intel_gna/src/runtime/gna_float_runtime.cpp @@ -1,11 +1,11 @@ // Copyright (C) 2018-2022 Intel Corporation // SPDX-License-Identifier: Apache-2.0 // - -#include #include -#include + +#include "backend/dnn_types.h" #include "gna_float_runtime.hpp" +#include "log/debug.hpp" using namespace GNAPluginNS; using namespace GNAPluginNS::runtime; diff --git a/src/plugins/intel_gna/src/runtime/pwl.cpp b/src/plugins/intel_gna/src/runtime/pwl.cpp index a8eaadda78c..dde7ceecfc0 100644 --- a/src/plugins/intel_gna/src/runtime/pwl.cpp +++ b/src/plugins/intel_gna/src/runtime/pwl.cpp @@ -25,11 +25,14 @@ #endif #include "pwl.h" -#include "gna_plugin_log.hpp" +#include "log/debug.hpp" +#include "log/log.hpp" #include "gna_slope_scale.h" #include "round_float_define.hpp" #include "ops/reference/pwl.hpp" +using namespace ov::intel_gna; + double relu(const double x) { if (x < 0) { return(0.0); } else { return(x); } } double leaky_relu(const double x) { if (x < 0.0) { return(LEAKYRELU_SLOPE*x); } else { return(x); } } double clipping(const double x, const double lbound, const double ubound) { return((x < lbound)?lbound:((x > ubound)?ubound:x)); } @@ -129,7 +132,7 @@ void PwlDesign(const DnnActivation& activation_type, switch (activation_type) { case kActSigmoid: { - gnalog() << "=========================== Sigmoid Segments===========================\n"; + log::debug() << "=========================== Sigmoid Segments===========================\n"; uint32_t num_segment_size = 0; int32_t offset = 0; ptr_segment[0].xBase = static_cast(INT32_MIN & XBASEMASK); // zero out the 2 lsb @@ -165,7 +168,7 @@ void PwlDesign(const DnnActivation& activation_type, ptr_segment[i].xBase = ptr_segment[i].xBase | slope_scale_index; } ptr_segment[i].yBase = FLOAT_TO_INT16(floatval * scale_out); - gnalog() << (static_cast((ptr_segment[i].xBase & XBASEMASK))/scale_out) + log::debug() << (static_cast((ptr_segment[i].xBase & XBASEMASK))/scale_out) << " " << (static_cast((ptr_segment[i].yBase))/scale_out) << " " @@ -176,7 +179,7 @@ void PwlDesign(const DnnActivation& activation_type, break; case kActTanh: { - gnalog() << "=========================== Tanh Segments===========================\n"; + log::debug() << "=========================== Tanh Segments===========================\n"; uint32_t num_segment_size = 0; int32_t offset = 0; ptr_segment[0].xBase = static_cast(INT32_MIN & XBASEMASK); // zero out the 2 lsb @@ -212,7 +215,7 @@ void PwlDesign(const DnnActivation& activation_type, ptr_segment[i].xBase = ptr_segment[i].xBase | slope_scale_index; } ptr_segment[i].yBase = FLOAT_TO_INT16(floatval * scale_out); - gnalog() << (static_cast((ptr_segment[i].xBase & XBASEMASK))/scale_out) + log::debug() << (static_cast((ptr_segment[i].xBase & XBASEMASK))/scale_out) << " " << (static_cast((ptr_segment[i].yBase))/scale_out) << " " @@ -226,7 +229,7 @@ void PwlDesign(const DnnActivation& activation_type, auto softsign = [](const double x) { return(x / (1.0 + fabs(x))); }; - gnalog() << "=========================== SoftSign Segments===========================\n"; + log::debug() << "=========================== SoftSign Segments===========================\n"; uint32_t num_segment_size = 0; int32_t offset = 0; ptr_segment[0].xBase = static_cast(INT32_MIN & XBASEMASK); // zero out the 2 lsb @@ -259,7 +262,7 @@ void PwlDesign(const DnnActivation& activation_type, ptr_segment[i].xBase = ptr_segment[i].xBase | slope_scale_index; } ptr_segment[i].yBase = FLOAT_TO_INT16(floatval * scale_out); - gnalog() << (static_cast((ptr_segment[i].xBase & XBASEMASK)) / scale_out) + log::debug() << (static_cast((ptr_segment[i].xBase & XBASEMASK)) / scale_out) << " " << (static_cast((ptr_segment[i].yBase)) / scale_out) << " " @@ -279,16 +282,16 @@ void PwlDesign(const DnnActivation& activation_type, int16_t y_lower_limit = INT16_MIN; int16_t y_upper_limit = INT16_MAX; if (activation_type == kActKaldiLstmClipping) - gnalog() << "=========================== Clipping Segments ===========================\n"; + log::debug() << "=========================== Clipping Segments ===========================\n"; else - gnalog() << "=========================== Identity Segments ===========================\n"; + log::debug() << "=========================== Identity Segments ===========================\n"; if (x_lower_limit < INT32_MIN) { - std::cerr << "Warning: saturation in PwlDesign! " << x_lower_limit << " < INT32_MIN"<< std::endl; + log::warning() << "Saturation in PwlDesign! " << x_lower_limit << " < INT32_MIN"<< std::endl; x_lower_limit = INT32_MIN; y_lower_limit = static_cast((scale_out / scale_in)*static_cast(INT32_MIN) - 0.5); } if (x_upper_limit > INT32_MAX) { - std::cerr << "Warning: saturation in PwlDesign! " << x_upper_limit << " > INT32_MAX"<< std::endl; + log::warning() << "Saturation in PwlDesign! " << x_upper_limit << " > INT32_MAX"<< std::endl; x_upper_limit = INT32_MAX; y_upper_limit = static_cast((scale_out / scale_in)*static_cast(INT32_MAX) + 0.5); } @@ -299,7 +302,7 @@ void PwlDesign(const DnnActivation& activation_type, ptr_segment[0].yBase = y_lower_limit; ptr_segment[0].slope = 0; - gnalog() << ptr_segment[0].xBase / scale_in + log::debug() << ptr_segment[0].xBase / scale_in << " " << ptr_segment[0].yBase / scale_out << " " << 0 << "\n"; @@ -327,7 +330,7 @@ void PwlDesign(const DnnActivation& activation_type, break; case kActPow: { - gnalog() << "=========================== Pow Segments===========================\n"; + log::debug() << "=========================== Pow Segments===========================\n"; uint32_t num_segment_size = 0; auto fp32eq = [](float p1, float p2) -> bool { @@ -375,7 +378,7 @@ void PwlDesign(const DnnActivation& activation_type, ptr_segment[i].xBase = ptr_segment[i].xBase | s.slope_scale_index; ptr_segment[i].yBase = FLOAT_TO_INT16(val * scale_out); - gnalog() << (static_cast((ptr_segment[i].xBase & XBASEMASK)) / scale_out) + log::debug() << (static_cast((ptr_segment[i].xBase & XBASEMASK)) / scale_out) << " " << (static_cast((ptr_segment[i].yBase)) / scale_out) << " " @@ -473,7 +476,7 @@ void PwlApply32(intel_dnn_component_t *component, case kActLog: for (uint32_t i = num_row_start; i <= num_row_end; i++) { for (uint32_t j = num_col_start; j <= num_col_end; j++) { - ptr_out[i * num_columns + j] = log(ptr_in[i * num_columns + j]); + ptr_out[i * num_columns + j] = std::log(ptr_in[i * num_columns + j]); } } break; @@ -494,14 +497,14 @@ void PwlApply32(intel_dnn_component_t *component, case kActNegLog: for (uint32_t i = num_row_start; i <= num_row_end; i++) { for (uint32_t j = num_col_start; j <= num_col_end; j++) { - ptr_out[i * num_columns + j] = static_cast(-1.0 * log(ptr_in[i * num_columns + j])); + ptr_out[i * num_columns + j] = static_cast(-1.0 * std::log(ptr_in[i * num_columns + j])); } } break; case kActNegHalfLog: for (uint32_t i = num_row_start; i <= num_row_end; i++) { for (uint32_t j = num_col_start; j <= num_col_end; j++) { - ptr_out[i * num_columns + j] = static_cast(-0.5 * log(ptr_in[i * num_columns + j])); + ptr_out[i * num_columns + j] = static_cast(-0.5 * std::log(ptr_in[i * num_columns + j])); } } break; diff --git a/src/plugins/intel_gna/src/transformations/convert_matmul_to_pointwise_convolution.cpp b/src/plugins/intel_gna/src/transformations/convert_matmul_to_pointwise_convolution.cpp index 7d4eb34127d..7c8a20a29b6 100644 --- a/src/plugins/intel_gna/src/transformations/convert_matmul_to_pointwise_convolution.cpp +++ b/src/plugins/intel_gna/src/transformations/convert_matmul_to_pointwise_convolution.cpp @@ -12,13 +12,15 @@ #include "layers/gna_permute.hpp" #include "backend/gna_limitations.hpp" +#include "log/log.hpp" +using namespace ov::intel_gna; using namespace ov::intel_gna::pass; static bool BiasValidation(const ngraph::Output& output) { auto bias_output_shape = output.get_node()->get_output_shape(0); if (bias_output_shape.size() > 4) { - gnalog() << "bias output shape (" << output.get_node()->get_friendly_name() << ") is more than 4\n"; + log::debug() << "bias output shape (" << output.get_node()->get_friendly_name() << ") is more than 4\n"; return false; } diff --git a/src/plugins/intel_gna/src/transformations/handle_transposes_around_matmul.cpp b/src/plugins/intel_gna/src/transformations/handle_transposes_around_matmul.cpp index 653252c4e71..f36a634a17d 100644 --- a/src/plugins/intel_gna/src/transformations/handle_transposes_around_matmul.cpp +++ b/src/plugins/intel_gna/src/transformations/handle_transposes_around_matmul.cpp @@ -13,7 +13,6 @@ #include #include -#include "gna_plugin_log.hpp" #include "backend/gna_limitations.hpp" using namespace ov::intel_gna::pass; diff --git a/src/plugins/intel_gna/src/transformations/insert_copy_layer.cpp b/src/plugins/intel_gna/src/transformations/insert_copy_layer.cpp index d6429a14b19..fa436caf425 100644 --- a/src/plugins/intel_gna/src/transformations/insert_copy_layer.cpp +++ b/src/plugins/intel_gna/src/transformations/insert_copy_layer.cpp @@ -12,7 +12,6 @@ #include #include -#include "gna_plugin_log.hpp" #include "ops/util/util.hpp" using namespace ov::intel_gna::pass; diff --git a/src/plugins/intel_gna/src/transformations/insert_identity_layer.cpp b/src/plugins/intel_gna/src/transformations/insert_identity_layer.cpp index 6d1a6ba3020..90cce190aa4 100644 --- a/src/plugins/intel_gna/src/transformations/insert_identity_layer.cpp +++ b/src/plugins/intel_gna/src/transformations/insert_identity_layer.cpp @@ -12,8 +12,10 @@ #include #include #include +#include "log/log.hpp" #include "ops/util/util.hpp" +using namespace ov::intel_gna; using namespace ov::intel_gna::pass; using namespace ov::intel_gna::rt_info; using namespace ov::intel_gna::ngraph_util; @@ -21,7 +23,7 @@ using namespace ov::intel_gna::ngraph_util; namespace { void mark_for_identity_insertion(std::shared_ptr node, size_t input_index) { - gnalog() << "Mark input as candidate for identity insertion " << input_index << ":" << node->get_friendly_name() << std::endl; + log::debug() << "Mark input as candidate for identity insertion " << input_index << ":" << node->get_friendly_name() << std::endl; auto input = node->input(input_index); add_precision_change_flag(input, ov::element::i32, ov::element::i16); } @@ -39,7 +41,7 @@ void insert_identity_layer_after(std::shared_ptr& input_op, size_t index) { NGRAPH_CHECK(input_op); - gnalog() << "Insert identity layer after " << input_op->get_friendly_name() << + log::debug() << "Insert identity layer after " << input_op->get_friendly_name() << " (" << input_op->get_type_name() << "):"<< index << std::endl; auto consumers = input_op->output(index).get_target_inputs(); @@ -55,7 +57,7 @@ void insert_identity_layer_between(std::shared_ptr& input_op, NGRAPH_CHECK(input_op); NGRAPH_CHECK(output_op); - gnalog() << "Insert identity layer after " << input_op->get_friendly_name() << + log::debug() << "Insert identity layer after " << input_op->get_friendly_name() << " (" << input_op->get_type_name() << ") and before " << index << ":" << output_op->get_friendly_name() << " (" << output_op->get_type_name() << ")" << std::endl; diff --git a/src/plugins/intel_gna/src/transformations/insert_reshape_around_matmul.cpp b/src/plugins/intel_gna/src/transformations/insert_reshape_around_matmul.cpp index ab95ea957fe..af3c25c08f9 100644 --- a/src/plugins/intel_gna/src/transformations/insert_reshape_around_matmul.cpp +++ b/src/plugins/intel_gna/src/transformations/insert_reshape_around_matmul.cpp @@ -11,7 +11,7 @@ #include #include -#include "gna_plugin_log.hpp" +#include "log/debug.hpp" using namespace ov::intel_gna::pass; diff --git a/src/plugins/intel_gna/src/transformations/insert_transpose_after_convolution_or_pooling.cpp b/src/plugins/intel_gna/src/transformations/insert_transpose_after_convolution_or_pooling.cpp index 7b6aa260273..cd2914873ca 100644 --- a/src/plugins/intel_gna/src/transformations/insert_transpose_after_convolution_or_pooling.cpp +++ b/src/plugins/intel_gna/src/transformations/insert_transpose_after_convolution_or_pooling.cpp @@ -10,7 +10,8 @@ #include #include #include -#include "gna_plugin_log.hpp" +#include "log/debug.hpp" +#include "log/log.hpp" using namespace ov::intel_gna::pass; @@ -84,7 +85,7 @@ bool InsertTransposeAfterConvOrPool::run_on_model(const std::shared_ptrget_friendly_name() << "\n"; + log::debug() << "Insert Transpose after " << node->get_friendly_name() << "\n"; auto consumers = node->output(0).get_target_inputs(); diff --git a/src/plugins/intel_gna/src/transformations/pwl_approximation.cpp b/src/plugins/intel_gna/src/transformations/pwl_approximation.cpp index 9be9c587583..f1ce35419a7 100644 --- a/src/plugins/intel_gna/src/transformations/pwl_approximation.cpp +++ b/src/plugins/intel_gna/src/transformations/pwl_approximation.cpp @@ -18,8 +18,6 @@ #include #include -#include "gna_plugin_log.hpp" - static constexpr double EXP_BREAK = 0.045; using namespace ov::intel_gna; diff --git a/src/plugins/intel_gna/src/transformations/reorder_activation_and_pooling.cpp b/src/plugins/intel_gna/src/transformations/reorder_activation_and_pooling.cpp index c4e62a75f86..200422c2ec6 100644 --- a/src/plugins/intel_gna/src/transformations/reorder_activation_and_pooling.cpp +++ b/src/plugins/intel_gna/src/transformations/reorder_activation_and_pooling.cpp @@ -10,8 +10,10 @@ #include #include #include -#include +#include "log/log.hpp" +#include "log/debug.hpp" +using namespace ov::intel_gna; using namespace ov::intel_gna::pass; ReorderActivationAndPooling::ReorderActivationAndPooling() { @@ -43,7 +45,7 @@ ReorderActivationAndPooling::ReorderActivationAndPooling() { auto act = pool_node->input_value(0).get_node_shared_ptr(); IE_ASSERT(act != nullptr); - gnalog() << "Reorder " << pool_node->get_friendly_name() << " and " << act->get_friendly_name() << "\n"; + log::debug() << "Reorder " << pool_node->get_friendly_name() << " and " << act->get_friendly_name() << "\n"; auto node_before_act = act->input_value(0).get_node_shared_ptr(); IE_ASSERT(node_before_act != nullptr); diff --git a/src/plugins/intel_gna/src/transformations/split_eltwise.cpp b/src/plugins/intel_gna/src/transformations/split_eltwise.cpp index ed86bdd37ff..30f771d1d49 100644 --- a/src/plugins/intel_gna/src/transformations/split_eltwise.cpp +++ b/src/plugins/intel_gna/src/transformations/split_eltwise.cpp @@ -13,6 +13,7 @@ #include "ops/util/util.hpp" #include "backend/gna_limitations.hpp" #include "layers/gna_split_layer.hpp" +#include "log/log.hpp" using namespace ov::intel_gna::pass; using namespace ov::intel_gna::ngraph_util; @@ -60,7 +61,7 @@ SplitEltwise::SplitEltwise() { auto split_sizes_per_axis = GNAPluginNS::AlignedSplitSizesPerAxis(o_dims); if (0 == split_sizes_per_axis.second.size()) { - gnalog() << "Splitting didn't succeed for layer " << eltwise_node->get_friendly_name() + log::debug() << "Splitting didn't succeed for layer " << eltwise_node->get_friendly_name() << " on axis " << split_sizes_per_axis.first << std::endl; return false; } diff --git a/src/plugins/intel_gna/src/transformations/swap_input_matmul_gna.cpp b/src/plugins/intel_gna/src/transformations/swap_input_matmul_gna.cpp index 53b8b7a5f60..5de64b2562f 100644 --- a/src/plugins/intel_gna/src/transformations/swap_input_matmul_gna.cpp +++ b/src/plugins/intel_gna/src/transformations/swap_input_matmul_gna.cpp @@ -16,8 +16,9 @@ #include #include -#include "gna_plugin_log.hpp" +#include "log/log.hpp" +using namespace ov::intel_gna; using namespace ov::intel_gna::pass; static void SwapAndTransposeInputs( @@ -57,7 +58,7 @@ static void SwapAndTransposeInputs( return matmul_input; }; - gnalog() << "Swap and transpose inputs for " << matmul_node->get_friendly_name() << "\n"; + log::debug() << "Swap and transpose inputs for " << matmul_node->get_friendly_name() << "\n"; bool first_input_const = false; bool second_input_const = false; diff --git a/src/plugins/intel_gna/tests/functional/pass_tests/concat_restrictions.cpp b/src/plugins/intel_gna/tests/functional/pass_tests/concat_restrictions.cpp index 386a19d9c29..8b41dbdaa68 100644 --- a/src/plugins/intel_gna/tests/functional/pass_tests/concat_restrictions.cpp +++ b/src/plugins/intel_gna/tests/functional/pass_tests/concat_restrictions.cpp @@ -208,6 +208,17 @@ public: return result.str(); } static const char* getMatch() { return T::getMatch(); } + void test_output() { + std::stringstream what; + std::streambuf* sbuf = std::cout.rdbuf(); + std::streambuf *ebuf = std::cerr.rdbuf(); + std::cout.rdbuf(what.rdbuf()); + std::cerr.rdbuf(what.rdbuf()); + LoadNetwork(); + EXPECT_TRUE(what.str().find(getMatch()) != std::string::npos); + std::cout.rdbuf(sbuf); + std::cerr.rdbuf(ebuf); + } protected: void SetUp() override { InferenceEngine::SizeVector inputShape; @@ -230,12 +241,7 @@ using ConvConcatNHWCRestrictionsNeg = ConcatRestrictions; using ConvConcatNHWCRestrictionsPos = ConcatRestrictions; TEST_P(ReLUConcatRestrictionsNeg, CompareWithRefImpl) { - std::stringstream what; - std::streambuf* sbuf = std::cout.rdbuf(); - std::cout.rdbuf(what.rdbuf()); - LoadNetwork(); - EXPECT_TRUE(what.str().find(getMatch()) != std::string::npos); - std::cout.rdbuf(sbuf); + test_output(); }; // TODO: this test is left for future when GNA plugin handles const tranposition required for concats with interleaved layers @@ -244,12 +250,7 @@ TEST_P(ReLUConcatRestrictionsNeg, CompareWithRefImpl) { //}; TEST_P(MatMulConcatRestrictionsNeg, CompareWithRefImpl) { - std::stringstream what; - std::streambuf* sbuf = std::cout.rdbuf(); - std::cout.rdbuf(what.rdbuf()); - LoadNetwork(); - EXPECT_TRUE(what.str().find(getMatch()) != std::string::npos); - std::cout.rdbuf(sbuf); + test_output();; }; TEST_P(MatMulConcatRestrictionsPos, CompareWithRefImpl) { @@ -272,12 +273,7 @@ TEST_P(ConvNCHWConcatRestrictionsPos, CompareWithRefImpl) { }; TEST_P(ConvNHWCConcatRestrictionsNeg, CompareWithRefImpl) { - std::stringstream what; - std::streambuf* sbuf = std::cout.rdbuf(); - std::cout.rdbuf(what.rdbuf()); - LoadNetwork(); - EXPECT_TRUE(what.str().find(getMatch()) != std::string::npos); - std::cout.rdbuf(sbuf); + test_output(); }; TEST_P(ConvNHWCConcatRestrictionsPos, CompareWithRefImpl) { @@ -285,12 +281,7 @@ TEST_P(ConvNHWCConcatRestrictionsPos, CompareWithRefImpl) { }; TEST_P(ConvConcatNHWCRestrictionsNeg, CompareWithRefImpl) { - std::stringstream what; - std::streambuf* sbuf = std::cout.rdbuf(); - std::cout.rdbuf(what.rdbuf()); - LoadNetwork(); - EXPECT_TRUE(what.str().find(getMatch()) != std::string::npos); - std::cout.rdbuf(sbuf); + test_output(); }; TEST_P(ConvConcatNHWCRestrictionsPos, CompareWithRefImpl) { diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/ov_plugin/core_intergration.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/ov_plugin/core_intergration.cpp index 46e4d6086be..b40cfc84537 100644 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/ov_plugin/core_intergration.cpp +++ b/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/ov_plugin/core_intergration.cpp @@ -279,6 +279,14 @@ TEST(OVClassBasicTest, smoke_SetConfigAfterCreatedLogLevel) { ov::Core core; auto level = ov::log::Level::NO; + OV_ASSERT_NO_THROW(core.set_property("GNA", ov::log::level(ov::log::Level::INFO))); + OV_ASSERT_NO_THROW(level = core.get_property("GNA", ov::log::level)); + ASSERT_EQ(ov::log::Level::INFO, level); + + OV_ASSERT_NO_THROW(core.set_property("GNA", ov::log::level(ov::log::Level::ERR))); + OV_ASSERT_NO_THROW(level = core.get_property("GNA", ov::log::level)); + ASSERT_EQ(ov::log::Level::ERR, level); + OV_ASSERT_NO_THROW(core.set_property("GNA", ov::log::level(ov::log::Level::WARNING))); OV_ASSERT_NO_THROW(level = core.get_property("GNA", ov::log::level)); ASSERT_EQ(ov::log::Level::WARNING, level); @@ -287,13 +295,14 @@ TEST(OVClassBasicTest, smoke_SetConfigAfterCreatedLogLevel) { OV_ASSERT_NO_THROW(level = core.get_property("GNA", ov::log::level)); ASSERT_EQ(ov::log::Level::DEBUG, level); + OV_ASSERT_NO_THROW(core.set_property("GNA", ov::log::level(ov::log::Level::TRACE))); + OV_ASSERT_NO_THROW(level = core.get_property("GNA", ov::log::level)); + ASSERT_EQ(ov::log::Level::TRACE, level); + OV_ASSERT_NO_THROW(core.set_property("GNA", ov::log::level(ov::log::Level::NO))); OV_ASSERT_NO_THROW(level = core.get_property("GNA", ov::log::level)); ASSERT_EQ(ov::log::Level::NO, level); - ASSERT_THROW(core.set_property("GNA", ov::log::level(ov::log::Level::ERR)), ov::Exception); - ASSERT_THROW(core.set_property("GNA", ov::log::level(ov::log::Level::INFO)), ov::Exception); - ASSERT_THROW(core.set_property("GNA", ov::log::level(ov::log::Level::TRACE)), ov::Exception); ASSERT_THROW(core.set_property("GNA", {{ ov::log::level.name(), "NO" }}), ov::Exception); } diff --git a/src/plugins/intel_gna/tests/unit/gna_plugin_config_test.cpp b/src/plugins/intel_gna/tests/unit/gna_plugin_config_test.cpp index c6e6485f9dc..c06e2567583 100644 --- a/src/plugins/intel_gna/tests/unit/gna_plugin_config_test.cpp +++ b/src/plugins/intel_gna/tests/unit/gna_plugin_config_test.cpp @@ -220,7 +220,11 @@ TEST_F(GNAPluginConfigTest, GnaConfigLogLevel) { EXPECT_EQ(config.gnaFlags.log_level, ov::log::Level::NO); SetAndCompare(CONFIG_KEY(LOG_LEVEL), PluginConfigParams::LOG_DEBUG); EXPECT_EQ(config.gnaFlags.log_level, ov::log::Level::DEBUG); - ExpectThrow(CONFIG_KEY(LOG_LEVEL), PluginConfigParams::LOG_ERROR); - ExpectThrow(CONFIG_KEY(LOG_LEVEL), PluginConfigParams::LOG_INFO); - ExpectThrow(CONFIG_KEY(LOG_LEVEL), PluginConfigParams::LOG_TRACE); + SetAndCompare(CONFIG_KEY(LOG_LEVEL), PluginConfigParams::LOG_ERROR); + EXPECT_EQ(config.gnaFlags.log_level, ov::log::Level::ERR); + SetAndCompare(CONFIG_KEY(LOG_LEVEL), PluginConfigParams::LOG_INFO); + EXPECT_EQ(config.gnaFlags.log_level, ov::log::Level::INFO); + SetAndCompare(CONFIG_KEY(LOG_LEVEL), PluginConfigParams::LOG_TRACE); + EXPECT_EQ(config.gnaFlags.log_level, ov::log::Level::TRACE); + EXPECT_THROW(config.UpdateFromMap({{CONFIG_KEY(LOG_LEVEL), "LOG_UNSUPPORTED"}}), ov::Exception); } diff --git a/src/plugins/intel_gna/tests/unit/log/logger.cpp b/src/plugins/intel_gna/tests/unit/log/logger.cpp new file mode 100644 index 00000000000..33539ac373b --- /dev/null +++ b/src/plugins/intel_gna/tests/unit/log/logger.cpp @@ -0,0 +1,94 @@ +// Copyright (C) 2022 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include +#include "openvino/runtime/properties.hpp" +#include "log/log.hpp" + +using namespace ov::intel_gna; + +namespace test { + +using GnaLogTestParams = std::tuple; + +class GnaLogTest : public ::testing::TestWithParam { + protected: + void SetUp() override {} + public: + static std::string GetTestCaseName(const testing::TestParamInfo& obj) { + ov::log::Level log_level, message_level; + std::tie(log_level, message_level) = obj.param; + std::ostringstream result; + result << "LogLevel=" << log_level; + result << "_MsgLevel=" << message_level; + return result.str(); + } +}; + +TEST_P(GnaLogTest, LogLevel) { + std::string test_message = "Test message"; + std::stringstream expected_message; + std::stringstream buffer; + std::streambuf *sbuf = std::cout.rdbuf(); + std::streambuf *ebuf = std::cerr.rdbuf(); + std::cout.rdbuf(buffer.rdbuf()); + std::cerr.rdbuf(buffer.rdbuf()); + + ov::log::Level log_level, message_level; + std::tie(log_level, message_level) = GetParam(); + + GnaLog log(log_level); + + switch (message_level) { + case ov::log::Level::ERR : + log::error() << test_message << std::endl; + break; + + case ov::log::Level::WARNING : + log::warning() << test_message << std::endl; + break; + + case ov::log::Level::INFO : + log::info() << test_message << std::endl; + break; + + case ov::log::Level::DEBUG : + log::debug() << test_message << std::endl; + break; + + case ov::log::Level::TRACE : + log::trace() << test_message << std::endl; + break; + + default: + break; + } + + expected_message << "[" << message_level << "] " << test_message << std::endl; + if (message_level <= log_level) { + EXPECT_TRUE(buffer.str() == expected_message.str()); + } else { + EXPECT_TRUE(buffer.str().empty()); + } + + std::cout.rdbuf(sbuf); + std::cerr.rdbuf(ebuf); +} + +INSTANTIATE_TEST_SUITE_P(smoke_GnaLogTest, + GnaLogTest, + ::testing::Combine( + ::testing::ValuesIn({ov::log::Level::NO, + ov::log::Level::ERR, + ov::log::Level::WARNING, + ov::log::Level::INFO, + ov::log::Level::DEBUG, + ov::log::Level::TRACE}), + ::testing::ValuesIn({ov::log::Level::ERR, + ov::log::Level::WARNING, + ov::log::Level::INFO, + ov::log::Level::DEBUG, + ov::log::Level::TRACE})), + GnaLogTest::GetTestCaseName); +} //namespace test \ No newline at end of file