Skip to content

Commit

Permalink
Skip new params for old driver compiler (openvinotoolkit#25453)
Browse files Browse the repository at this point in the history
### Details:
There are new added options for NPU_COMPILATION_MODE_PARAMS, need to
skip for old driver compiler.

### Tickets:
 - *146197*
  • Loading branch information
XinWangIntel authored Jul 10, 2024
1 parent 2e83457 commit 5fd3ba9
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,13 @@ static constexpr ov::Property<uint64_t, ov::PropertyMutability::RO> device_total
*/
static constexpr ov::Property<uint32_t, ov::PropertyMutability::RO> 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<std::string> compilation_mode_params{"NPU_COMPILATION_MODE_PARAMS"};

} // namespace intel_npu
} // namespace ov
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ struct COMPILATION_MODE_PARAMS final : OptionBase<COMPILATION_MODE_PARAMS, std::
}

static bool isPublic() {
return false;
return true;
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,14 +294,6 @@ static constexpr ov::Property<CompilerType> compiler_type{"NPU_COMPILER_TYPE"};
*/
static constexpr ov::Property<std::string> 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<std::string> compilation_mode_params{"NPU_COMPILATION_MODE_PARAMS"};

/**
* @brief [Only for NPU Plugin]
* Type: integer, default is None
Expand Down
42 changes: 42 additions & 0 deletions src/plugins/intel_npu/src/compiler/src/zero_compiler_in_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -376,6 +377,47 @@ std::string LevelZeroCompilerInDriver<TableExtension>::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<COMPILATION_MODE_PARAMS>();
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
Expand Down
8 changes: 8 additions & 0 deletions src/plugins/intel_npu/src/plugin/src/compiled_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<COMPILATION_MODE_PARAMS>();
}}},
// NPU Private
// =========
{ov::intel_npu::tiles.name(),
Expand Down
12 changes: 6 additions & 6 deletions src/plugins/intel_npu/src/plugin/src/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<COMPILATION_MODE_PARAMS>();
}}},
// NPU Private
// =========
{ov::intel_npu::dma_engines.name(),
Expand Down Expand Up @@ -474,12 +480,6 @@ Plugin::Plugin()
[](const Config& config) {
return config.get<COMPILATION_MODE>();
}}},
{ov::intel_npu::compilation_mode_params.name(),
{false,
ov::PropertyMutability::RW,
[](const Config& config) {
return config.get<COMPILATION_MODE_PARAMS>();
}}},
{ov::intel_npu::compiler_type.name(),
{false,
ov::PropertyMutability::RW,
Expand Down
Original file line number Diff line number Diff line change
@@ -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<std::string, // Device name
ov::AnyMap // Config
>;

namespace ov::test::behavior {

class DriverCompilerAdapterPropComTestNPU : public ov::test::behavior::OVPluginTestBase,
public testing::WithParamInterface<CompilationParams> {
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<CompilationParams> 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<ov::AnyMap> 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
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ const std::vector<ov::AnyMap> 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)))}},
Expand All @@ -160,7 +159,6 @@ const std::vector<ov::AnyMap> 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,
Expand Down

0 comments on commit 5fd3ba9

Please sign in to comment.