From d9d1df2fe3f930a5cd08ca020aec08082594cd7a Mon Sep 17 00:00:00 2001 From: Marcin Kacprzak Date: Tue, 28 Mar 2023 12:47:12 +0200 Subject: [PATCH] [GNA] Implemented ExecutionMode support in GNA Plugin (#16396) --- .../intel_gna/src/gna_plugin_config.cpp | 23 ++++++++++--- .../intel_gna/src/gna_plugin_config.hpp | 1 + ..._intergration.cpp => core_integration.cpp} | 5 ++- .../gna_executable_network_metrics_test.cpp | 3 +- .../tests/unit/gna_plugin_config_test.cpp | 33 ++++++++++++++++++- 5 files changed, 55 insertions(+), 10 deletions(-) rename src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/ov_plugin/{core_intergration.cpp => core_integration.cpp} (99%) diff --git a/src/plugins/intel_gna/src/gna_plugin_config.cpp b/src/plugins/intel_gna/src/gna_plugin_config.cpp index 0d48a7c313f..bcd003334e2 100644 --- a/src/plugins/intel_gna/src/gna_plugin_config.cpp +++ b/src/plugins/intel_gna/src/gna_plugin_config.cpp @@ -173,14 +173,25 @@ void Config::UpdateFromMap(const std::map& config) { } else if (key == ov::hint::performance_mode) { performance_mode = ov::util::from_string(value, ov::hint::performance_mode); } else if (key == ov::inference_precision) { - std::stringstream ss(value); - ss >> inference_precision; + inference_precision = ov::util::from_string(value); if ((inference_precision != ov::element::i8) && (inference_precision != ov::element::i16)) { - THROW_GNA_EXCEPTION << "Unsupported precision of GNA hardware, should be i16 or i8, but was: " << value; + THROW_GNA_EXCEPTION << "Unsupported precision of GNA hardware, should be I16 or I8, but was: " << value; + } + gnaPrecision = inference_precision == ov::element::i8 ? InferenceEngine::Precision::I8 + : InferenceEngine::Precision::I16; + } else if (key == ov::hint::execution_mode) { + execution_mode = ov::util::from_string(value); + if ((execution_mode != ov::hint::ExecutionMode::ACCURACY) && + (execution_mode != ov::hint::ExecutionMode::PERFORMANCE)) { + THROW_GNA_EXCEPTION << "Unsupported execution mode, should be ACCURACY or PERFORMANCE, but was: " + << value; + } + // Update gnaPrecision basing on execution_mode only if inference_precision is not set + if (config.count(ov::inference_precision.name()) == 0) { + gnaPrecision = execution_mode == ov::hint::ExecutionMode::PERFORMANCE ? InferenceEngine::Precision::I8 + : InferenceEngine::Precision::I16; } - gnaPrecision = (inference_precision == ov::element::i8) ? Precision::I8 : Precision::I16; } else if (key == GNA_CONFIG_KEY(PRECISION)) { - check_compatibility(ov::inference_precision.name()); auto precision = Precision::FromStr(value); if (precision != Precision::I8 && precision != Precision::I16) { THROW_GNA_EXCEPTION << "Unsupported precision of GNA hardware, should be Int16 or Int8, but was: " @@ -313,6 +324,7 @@ void Config::AdjustKeyMapValues() { } else { keyConfigMap[GNA_CONFIG_KEY(PRECISION)] = gnaPrecision.name(); } + keyConfigMap[ov::hint::execution_mode.name()] = ov::util::to_string(execution_mode); OPENVINO_SUPPRESS_DEPRECATED_START if (gnaFlags.pwl_design_algorithm != ov::intel_gna::PWLDesignAlgorithm::UNDEFINED) { keyConfigMap[ov::intel_gna::pwl_design_algorithm.name()] = ov::util::to_string(gnaFlags.pwl_design_algorithm); @@ -364,6 +376,7 @@ const Parameter Config::GetImpactingModelCompilationProperties(bool compiled) { {ov::intel_gna::pwl_design_algorithm.name(), model_mutability}, {ov::intel_gna::pwl_max_error_percent.name(), model_mutability}, {ov::inference_precision.name(), model_mutability}, + {ov::hint::execution_mode.name(), model_mutability}, {ov::hint::num_requests.name(), model_mutability}, }; return supported_properties; diff --git a/src/plugins/intel_gna/src/gna_plugin_config.hpp b/src/plugins/intel_gna/src/gna_plugin_config.hpp index e1e538b6eb5..04542e361aa 100644 --- a/src/plugins/intel_gna/src/gna_plugin_config.hpp +++ b/src/plugins/intel_gna/src/gna_plugin_config.hpp @@ -60,6 +60,7 @@ struct Config { // default precision of GNA hardware model ov::element::Type inference_precision = ov::element::undefined; InferenceEngine::Precision gnaPrecision = InferenceEngine::Precision::I16; + ov::hint::ExecutionMode execution_mode = ov::hint::ExecutionMode::ACCURACY; std::string embedded_export_path; 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_integration.cpp similarity index 99% rename from src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/ov_plugin/core_intergration.cpp rename to src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/ov_plugin/core_integration.cpp index 97208f2a95b..1aa99fe9df9 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_integration.cpp @@ -140,9 +140,8 @@ TEST(OVClassBasicTest, smoke_SetConfigAfterCreatedPrecisionHint) { OV_ASSERT_NO_THROW(precision = core.get_property("GNA", ov::inference_precision)); ASSERT_EQ(ov::element::i16, precision); - ASSERT_THROW( - core.set_property("GNA", {ov::inference_precision(ov::element::i8), {GNA_CONFIG_KEY(PRECISION), "I16"}}), - ov::Exception); + OV_ASSERT_NO_THROW( + core.set_property("GNA", {ov::inference_precision(ov::element::i8), {GNA_CONFIG_KEY(PRECISION), "I16"}})); ASSERT_THROW(core.set_property("GNA", ov::inference_precision(ov::element::i32)), ov::Exception); ASSERT_THROW(core.set_property("GNA", ov::inference_precision(ov::element::undefined)), ov::Exception); ASSERT_THROW(core.set_property("GNA", {{ov::inference_precision.name(), "ABC"}}), ov::Exception); diff --git a/src/plugins/intel_gna/tests/unit/gna_executable_network_metrics_test.cpp b/src/plugins/intel_gna/tests/unit/gna_executable_network_metrics_test.cpp index dcc0200e370..6bd7875a964 100644 --- a/src/plugins/intel_gna/tests/unit/gna_executable_network_metrics_test.cpp +++ b/src/plugins/intel_gna/tests/unit/gna_executable_network_metrics_test.cpp @@ -61,6 +61,7 @@ TEST_F(GnaExecutableNetworkMetricsTest, TestSupportedProperties) { "OPTIMIZATION_CAPABILITIES FULL_DEVICE_NAME GNA_LIBRARY_FULL_VERSION CACHING_PROPERTIES " "GNA_DEVICE_MODE PERFORMANCE_HINT LOG_LEVEL EXECUTION_DEVICES " "GNA_SCALE_FACTOR_PER_INPUT GNA_FIRMWARE_MODEL_IMAGE GNA_HW_EXECUTION_TARGET GNA_HW_COMPILE_TARGET " - "GNA_PWL_DESIGN_ALGORITHM GNA_PWL_MAX_ERROR_PERCENT INFERENCE_PRECISION_HINT PERFORMANCE_HINT_NUM_REQUESTS"; + "GNA_PWL_DESIGN_ALGORITHM GNA_PWL_MAX_ERROR_PERCENT INFERENCE_PRECISION_HINT EXECUTION_MODE_HINT " + "PERFORMANCE_HINT_NUM_REQUESTS"; Run(ov::supported_properties.name(), supportedProperties); } 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 06ef1278ef2..c3a9aeaf7d8 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 @@ -32,7 +32,8 @@ const std::map supportedConfigKeysWithDefaults = { {CONFIG_KEY(SINGLE_THREAD), CONFIG_VALUE(YES)}, {CONFIG_KEY(LOG_LEVEL), PluginConfigParams::LOG_NONE}, {CONFIG_KEY(PERFORMANCE_HINT), "UNDEFINED"}, - {CONFIG_KEY(PERFORMANCE_HINT_NUM_REQUESTS), "1"}}; + {CONFIG_KEY(PERFORMANCE_HINT_NUM_REQUESTS), "1"}, + {ov::hint::execution_mode.name(), ov::util::to_string(ov::hint::ExecutionMode::ACCURACY)}}; IE_SUPPRESS_DEPRECATED_END class GNAPluginConfigTest : public ::testing::Test { @@ -237,3 +238,33 @@ TEST_F(GNAPluginConfigTest, GnaConfigLogLevel) { EXPECT_EQ(config.gnaFlags.log_level, ov::log::Level::TRACE); EXPECT_THROW(config.UpdateFromMap({{CONFIG_KEY(LOG_LEVEL), "LOG_UNSUPPORTED"}}), ov::Exception); } + +TEST_F(GNAPluginConfigTest, GnaConfigExecutionModeUpdatesGnaPrecision) { + SetAndCompare(ov::hint::execution_mode.name(), "PERFORMANCE"); + EXPECT_EQ(config.gnaPrecision, InferenceEngine::Precision::I8); + SetAndCompare(ov::hint::execution_mode.name(), "ACCURACY"); + EXPECT_EQ(config.gnaPrecision, InferenceEngine::Precision::I16); +} + +TEST_F(GNAPluginConfigTest, GnaConfigInferencePrecisionUpdatesGnaPrecision) { + SetAndCompare(ov::inference_precision.name(), ov::util::to_string(ov::element::i8)); + EXPECT_EQ(config.gnaPrecision, InferenceEngine::Precision::I8); + SetAndCompare(ov::inference_precision.name(), ov::util::to_string(ov::element::i16)); + EXPECT_EQ(config.gnaPrecision, InferenceEngine::Precision::I16); +} + +TEST_F(GNAPluginConfigTest, GnaConfigInferencePrecisionHasHigherPriorityI16) { + SetAndCompare(GNA_CONFIG_KEY(PRECISION), Precision(Precision::I8).name()); + SetAndCompare(ov::hint::execution_mode.name(), + ov::util::to_string(ov::hint::ExecutionMode::PERFORMANCE)); + SetAndCompare(ov::inference_precision.name(), ov::util::to_string(ov::element::i16)); + EXPECT_EQ(config.gnaPrecision, InferenceEngine::Precision::I16); +} + +TEST_F(GNAPluginConfigTest, GnaConfigInferencePrecisionHasHigherPriorityI8) { + SetAndCompare(GNA_CONFIG_KEY(PRECISION), Precision(Precision::I16).name()); + SetAndCompare(ov::hint::execution_mode.name(), + ov::util::to_string(ov::hint::ExecutionMode::ACCURACY)); + SetAndCompare(ov::inference_precision.name(), ov::util::to_string(ov::element::i8)); + EXPECT_EQ(config.gnaPrecision, InferenceEngine::Precision::I8); +}