diff --git a/src/inference/include/openvino/runtime/intel_npu/properties.hpp b/src/inference/include/openvino/runtime/intel_npu/properties.hpp index 6eb47d32c86697..37db91c1188906 100644 --- a/src/inference/include/openvino/runtime/intel_npu/properties.hpp +++ b/src/inference/include/openvino/runtime/intel_npu/properties.hpp @@ -53,5 +53,13 @@ static constexpr ov::Property device_total */ static constexpr ov::Property driver_version{"NPU_DRIVER_VERSION"}; +/** + * @brief [Only for NPU compiler] + * Type: std::string + * Set various parameters supported by the NPU compiler. + * @ingroup ov_runtime_npu_prop_cpp_api + */ +static constexpr ov::Property compilation_mode_params{"NPU_COMPILATION_MODE_PARAMS"}; + } // namespace intel_npu } // namespace ov diff --git a/src/plugins/intel_npu/src/al/include/intel_npu/al/config/compiler.hpp b/src/plugins/intel_npu/src/al/include/intel_npu/al/config/compiler.hpp index 3900b319bca7e3..fc7f25d62101d2 100644 --- a/src/plugins/intel_npu/src/al/include/intel_npu/al/config/compiler.hpp +++ b/src/plugins/intel_npu/src/al/include/intel_npu/al/config/compiler.hpp @@ -156,7 +156,7 @@ struct COMPILATION_MODE_PARAMS final : OptionBase compiler_type{"NPU_COMPILER_TYPE"}; */ static constexpr ov::Property compilation_mode{"NPU_COMPILATION_MODE"}; -/** - * @brief [Only for NPU compiler] - * Type: std::string, default is empty. - * Sets various parameters supported by the NPU compiler. - * Available values: low-precision=true/low-precision=false - */ -static constexpr ov::Property compilation_mode_params{"NPU_COMPILATION_MODE_PARAMS"}; - /** * @brief [Only for NPU Plugin] * Type: integer, default is None diff --git a/src/plugins/intel_npu/src/compiler/src/zero_compiler_in_driver.cpp b/src/plugins/intel_npu/src/compiler/src/zero_compiler_in_driver.cpp index b5ce38fe0a4f80..ed740a02c58d89 100644 --- a/src/plugins/intel_npu/src/compiler/src/zero_compiler_in_driver.cpp +++ b/src/plugins/intel_npu/src/compiler/src/zero_compiler_in_driver.cpp @@ -10,6 +10,7 @@ #include "graph_transformations.hpp" #include "intel_npu/al/config/common.hpp" +#include "intel_npu/al/config/compiler.hpp" #include "intel_npu/al/config/runtime.hpp" #include "intel_npu/al/itt.hpp" #include "intel_npu/al/prefix.hpp" @@ -376,6 +377,47 @@ std::string LevelZeroCompilerInDriver::serializeConfig( const Config& config, ze_graph_compiler_version_info_t& compilerVersion) const { std::string content = config.toString(); + _logger.debug("Original content of config: %s", content.c_str()); + + // Remove optimization-level and performance-hint-override for old driver which not support them + if ((compilerVersion.major < 5) || (compilerVersion.major == 5 && compilerVersion.minor < 7)) { + std::string valueOfParams = config.get(); + std::string keyOfOptL("optimization-level"); + std::string keyOfPerfHO("performance-hint-override"); + if (valueOfParams != "" && (valueOfParams.find(keyOfOptL) != std::string::npos || + valueOfParams.find(keyOfPerfHO) != std::string::npos)) { + // Remove unsupported options from value + std::ostringstream optLevelStr; + optLevelStr << keyOfOptL << KEY_VALUE_SEPARATOR << "\\d+"; + std::ostringstream perfHintStr; + perfHintStr << keyOfPerfHO << KEY_VALUE_SEPARATOR << "\\S+"; + _logger.warning("%s property is not suppored by this compiler version. Removing from parameters", + keyOfOptL.c_str()); + valueOfParams = std::regex_replace(valueOfParams, std::regex(optLevelStr.str()), ""); + _logger.warning("%s property is not suppored by this compiler version. Removing from parameters", + keyOfPerfHO.c_str()); + valueOfParams = std::regex_replace(valueOfParams, std::regex(perfHintStr.str()), ""); + + // Trim space + valueOfParams = std::regex_replace(valueOfParams, std::regex(R"(^\s+|\s+$)"), ""); + + // Replace the value in content with new value + std::ostringstream compilationParamsStr; + compilationParamsStr << ov::intel_npu::compilation_mode_params.name() << KEY_VALUE_SEPARATOR + << VALUE_DELIMITER << ".*" << VALUE_DELIMITER; + if (valueOfParams == "") { + _logger.warning("Clear empty NPU_COMPILATION_MODE_PARAMS. Removing from parameters"); + content = std::regex_replace(content, std::regex(compilationParamsStr.str()), ""); + } else { + std::ostringstream newValue; + newValue << ov::intel_npu::compilation_mode_params.name() << KEY_VALUE_SEPARATOR << VALUE_DELIMITER + << valueOfParams << VALUE_DELIMITER; + _logger.warning("Replace value of NPU_COMPILATION_MODE_PARAMS with new value %s", + newValue.str().c_str()); + content = std::regex_replace(content, std::regex(compilationParamsStr.str()), newValue.str().c_str()); + } + } + } // As a consequence of complying to the conventions established in the 2.0 OV API, the set of values corresponding // to the "model priority" key has been modified diff --git a/src/plugins/intel_npu/src/plugin/src/compiled_model.cpp b/src/plugins/intel_npu/src/plugin/src/compiled_model.cpp index e2d3fc84f94764..cb454ea4c80cab 100644 --- a/src/plugins/intel_npu/src/plugin/src/compiled_model.cpp +++ b/src/plugins/intel_npu/src/plugin/src/compiled_model.cpp @@ -287,6 +287,14 @@ void CompiledModel::initialize_properties() { }; return supportedProperty; }}}, + // NPU Public + // ========= + {ov::intel_npu::compilation_mode_params.name(), + {true, + ov::PropertyMutability::RO, + [](const Config& config) { + return config.get(); + }}}, // NPU Private // ========= {ov::intel_npu::tiles.name(), diff --git a/src/plugins/intel_npu/src/plugin/src/plugin.cpp b/src/plugins/intel_npu/src/plugin/src/plugin.cpp index 9883f1b067c93d..82d4bd733ce268 100644 --- a/src/plugins/intel_npu/src/plugin/src/plugin.cpp +++ b/src/plugins/intel_npu/src/plugin/src/plugin.cpp @@ -436,6 +436,12 @@ Plugin::Plugin() [&](const Config& config) { return _metrics->GetDriverVersion(); }}}, + {ov::intel_npu::compilation_mode_params.name(), + {true, + ov::PropertyMutability::RW, + [](const Config& config) { + return config.get(); + }}}, // NPU Private // ========= {ov::intel_npu::dma_engines.name(), @@ -474,12 +480,6 @@ Plugin::Plugin() [](const Config& config) { return config.get(); }}}, - {ov::intel_npu::compilation_mode_params.name(), - {false, - ov::PropertyMutability::RW, - [](const Config& config) { - return config.get(); - }}}, {ov::intel_npu::compiler_type.name(), {false, ov::PropertyMutability::RW, diff --git a/src/plugins/intel_npu/tests/functional/behavior/npu_driver_compiler_adapter/properties_compatibility.cpp b/src/plugins/intel_npu/tests/functional/behavior/npu_driver_compiler_adapter/properties_compatibility.cpp new file mode 100644 index 00000000000000..8f1d58945c1fbb --- /dev/null +++ b/src/plugins/intel_npu/tests/functional/behavior/npu_driver_compiler_adapter/properties_compatibility.cpp @@ -0,0 +1,80 @@ +// Copyright (C) 2018-2024 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "base/ov_behavior_test_utils.hpp" +#include "common/npu_test_env_cfg.hpp" +#include "intel_npu/al/config/common.hpp" +#include "shared_test_classes/subgraph/split_conv_concat.hpp" + +using CompilationParams = std::tuple; + +namespace ov::test::behavior { + +class DriverCompilerAdapterPropComTestNPU : public ov::test::behavior::OVPluginTestBase, + public testing::WithParamInterface { +public: + void SetUp() override { + std::tie(target_device, configuration) = this->GetParam(); + SKIP_IF_CURRENT_TEST_IS_DISABLED() + OVPluginTestBase::SetUp(); + } + + static std::string getTestCaseName(testing::TestParamInfo obj) { + std::string targetDevice; + ov::AnyMap configuration; + std::tie(targetDevice, configuration) = obj.param; + std::replace(targetDevice.begin(), targetDevice.end(), ':', '.'); + + std::ostringstream result; + result << "targetDevice=" << targetDevice << "_"; + result << "targetPlatform=" << ov::test::utils::getTestsPlatformFromEnvironmentOr(targetDevice) << "_"; + if (!configuration.empty()) { + for (auto& configItem : configuration) { + result << "configItem=" << configItem.first << "_"; + configItem.second.print(result); + } + } + return result.str(); + } + + void TearDown() override { + if (!configuration.empty()) { + utils::PluginCache::get().reset(); + } + APIBaseTest::TearDown(); + } + +protected: + ov::AnyMap configuration; +}; + +TEST_P(DriverCompilerAdapterPropComTestNPU, TestNewPro) { + auto simpleFunc = ov::test::utils::make_split_conv_concat(); + ov::Core core; + EXPECT_NO_THROW(auto model = core.compile_model(simpleFunc, target_device, configuration)); +} + +const std::vector configs = { + {ov::intel_npu::compiler_type(ov::intel_npu::CompilerType::DRIVER)}, + {ov::intel_npu::compiler_type(ov::intel_npu::CompilerType::DRIVER), + ov::intel_npu::compilation_mode_params("dummy-op-replacement=true")}, + {ov::intel_npu::compiler_type(ov::intel_npu::CompilerType::DRIVER), + ov::intel_npu::compilation_mode_params("dummy-op-replacement=true optimization-level=1")}, + {ov::intel_npu::compiler_type(ov::intel_npu::CompilerType::DRIVER), + ov::intel_npu::compilation_mode_params("optimization-level=1 dummy-op-replacement=true")}, + {ov::intel_npu::compiler_type(ov::intel_npu::CompilerType::DRIVER), + ov::intel_npu::compilation_mode_params("optimization-level=1")}, + {ov::intel_npu::compiler_type(ov::intel_npu::CompilerType::DRIVER), + ov::intel_npu::compilation_mode_params("optimization-level=1 performance-hint-override=latency")}, + {ov::intel_npu::compiler_type(ov::intel_npu::CompilerType::DRIVER), + ov::intel_npu::compilation_mode_params("performance-hint-override=latency")}}; + +INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTest, + DriverCompilerAdapterPropComTestNPU, + ::testing::Combine(::testing::Values(ov::test::utils::DEVICE_NPU), + ::testing::ValuesIn(configs)), + DriverCompilerAdapterPropComTestNPU::getTestCaseName); +} // namespace ov::test::behavior diff --git a/src/plugins/intel_npu/tests/functional/behavior/ov_plugin/internal_properties_tests.cpp b/src/plugins/intel_npu/tests/functional/behavior/ov_plugin/internal_properties_tests.cpp index 103f7c9cb46d4f..8d00ed60490b16 100644 --- a/src/plugins/intel_npu/tests/functional/behavior/ov_plugin/internal_properties_tests.cpp +++ b/src/plugins/intel_npu/tests/functional/behavior/ov_plugin/internal_properties_tests.cpp @@ -142,7 +142,6 @@ const std::vector CorrectPluginMutableProperties = { {{ov::intel_npu::dpu_groups.name(), 1}}, {{ov::intel_npu::dma_engines.name(), 1}}, {{ov::intel_npu::compilation_mode.name(), "DefaultHW"}}, - {{ov::intel_npu::compilation_mode_params.name(), "dump-task-stats=false propagate-quant-dequant=0"}}, {{ov::intel_npu::platform.name(), removeDeviceNameOnlyID( ov::test::utils::getTestsDeviceNameFromEnvironmentOr(std::string(ov::intel_npu::Platform::AUTO_DETECT)))}}, @@ -160,7 +159,6 @@ const std::vector IncorrectMutablePropertiesWrongValueTypes = { {{ov::intel_npu::profiling_type.name(), 10}}, {{ov::intel_npu::tiles.name(), "none"}}, {{ov::intel_npu::dma_engines.name(), false}}, - {{ov::intel_npu::compilation_mode_params.name(), "not-a-param=true"}}, }; INSTANTIATE_TEST_SUITE_P(compatibility_smoke_BehaviorTests,