[GNA] Implemented ExecutionMode support in GNA Plugin (#16396)

This commit is contained in:
Marcin Kacprzak 2023-03-28 12:47:12 +02:00 committed by GitHub
parent a726f0ae38
commit d9d1df2fe3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 55 additions and 10 deletions

View File

@ -173,14 +173,25 @@ void Config::UpdateFromMap(const std::map<std::string, std::string>& 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<ov::element::Type>(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<ov::hint::ExecutionMode>(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;

View File

@ -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;

View File

@ -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);

View File

@ -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);
}

View File

@ -32,7 +32,8 @@ const std::map<std::string, std::string> 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>(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::Type>(ov::element::i8));
EXPECT_EQ(config.gnaPrecision, InferenceEngine::Precision::I8);
SetAndCompare(ov::inference_precision.name(), ov::util::to_string<ov::element::Type>(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>(ov::hint::ExecutionMode::PERFORMANCE));
SetAndCompare(ov::inference_precision.name(), ov::util::to_string<ov::element::Type>(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>(ov::hint::ExecutionMode::ACCURACY));
SetAndCompare(ov::inference_precision.name(), ov::util::to_string<ov::element::Type>(ov::element::i8));
EXPECT_EQ(config.gnaPrecision, InferenceEngine::Precision::I8);
}