Skip to content

Commit adc2201

Browse files
committed
fix 3720 platfrom compilerType issue
1 parent 800c78e commit adc2201

File tree

11 files changed

+294
-147
lines changed

11 files changed

+294
-147
lines changed

src/plugins/intel_npu/src/compiler_adapter/include/compiler_adapter_factory.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ class CompilerAdapterFactory final {
2121
if (engineBackend == nullptr || engineBackend->getName() != "LEVEL0") {
2222
return std::make_unique<PluginCompilerAdapter>(nullptr);
2323
}
24+
std::cout << "===== Creating PluginCompilerAdapter with ZeroInitStructsHolder" << std::endl;
2425
return std::make_unique<PluginCompilerAdapter>(engineBackend->getInitStructs());
2526
}
2627
case ov::intel_npu::CompilerType::DRIVER: {
2728
if (engineBackend == nullptr || engineBackend->getName() != "LEVEL0") {
2829
OPENVINO_THROW("NPU Compiler Adapter must be used with LEVEL0 backend");
2930
}
30-
31+
std::cout << "===== Creating DriverCompilerAdapter with ZeroInitStructsHolder" << std::endl;
3132
return std::make_unique<DriverCompilerAdapter>(engineBackend->getInitStructs());
3233
}
3334
default:

src/plugins/intel_npu/src/plugin/src/plugin.cpp

Lines changed: 151 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -145,51 +145,106 @@ void update_log_level(const std::map<std::string, std::string>& propertiesMap) {
145145
}
146146

147147
std::string getDeviceFromProperties(const ov::AnyMap& propertiesMap) {
148-
const std::string defaultDevice = std::string(ov::intel_npu::Platform::NPU4000);
148+
const std::string defaultDevice = "";
149149
auto it = propertiesMap.find(std::string(DEVICE_ID::key()));
150150
if (it != propertiesMap.end()) {
151151
return it->second.as<std::string>();
152152
}
153153

154154
it = propertiesMap.find(std::string(PLATFORM::key()));
155155
if (it != propertiesMap.end()) {
156-
return it->second.as<std::string>();
156+
auto platformStr = it->second.as<std::string>();
157+
if (platformStr == ov::intel_npu::Platform::AUTO_DETECT) {
158+
return defaultDevice;
159+
}
160+
161+
platformStr = utils::getPlatformByDeviceName(platformStr);
162+
platformStr = ov::intel_npu::Platform::standardize(platformStr);
163+
std::cout << "S====tandardized platform is: " << platformStr << std::endl;
164+
return platformStr;
157165
}
158166
return defaultDevice;
159167
}
160168

161-
void checkUpdateforspecialPlatform(const FilteredConfig& base_conf, ov::AnyMap& propertiesMap, Logger& log) {
162-
// If there is no compiler_type provided, use base_config value, check and update by the device
163-
// update the compilerType by device:
169+
void checkUpdateforSpecialPlatform(const FilteredConfig& base_conf,
170+
ov::AnyMap& propertiesMap,
171+
const std::string& deviceName,
172+
Logger& log) {
173+
// If there is no compiler_type provided, use base_config default value
174+
// Default compilerType for different platform is up to device:
164175
// 3720 -> DRIVER
165-
// 4000 and later -> MLIR
166-
auto it_compiler_type = propertiesMap.find(std::string(COMPILER_TYPE::key()));
167-
// If user set compilerType, will not update by device
168-
if (it_compiler_type == propertiesMap.end()) {
169-
// if platform is provided by local config = use that
170-
const ov::AnyMap localProperties = propertiesMap;
171-
std::string getdevice = getDeviceFromProperties(localProperties);
172-
if (getdevice == std::string((ov::intel_npu::Platform::NPU3720))) {
173-
if (base_conf.get<COMPILER_TYPE>() != ov::intel_npu::CompilerType::DRIVER) {
174-
log.warning(
175-
"Platform '3720' is selected, but the used compiler_type is not set to 'DRIVER'. Forcely use the "
176-
"compiler_type to 'DRIVER'. Maybe cause the compilerType inconsistency issues.");
177-
}
178-
// To avoid compilerType inconsistency issues, only set DRIVER if compiler_type is not set by user
179-
propertiesMap[std::string(COMPILER_TYPE::key())] =
180-
COMPILER_TYPE::toString(ov::intel_npu::CompilerType::DRIVER);
176+
// 4000 and later -> default
177+
178+
// const ov::AnyMap localProperties = propertiesMap;
179+
std::string getdevice = getDeviceFromProperties(propertiesMap);
180+
std::cout << "The device from properties '" << getdevice << "' VS actual device from backend'" << deviceName << "'"
181+
<< std::endl;
182+
if (deviceName.empty() && getdevice.empty()) {
183+
OPENVINO_THROW("Device name is empty!");
184+
}
185+
std::cout << " ==checkUpdateforSpecialPlatform==1==" << std::endl;
186+
std::string usedDevice = deviceName;
187+
if (deviceName != getdevice) {
188+
log.info("The device from properties '%s' is different from the actual device '%s', use device '%s' to check "
189+
"compiler_type.",
190+
getdevice.c_str(),
191+
deviceName.c_str(),
192+
deviceName.c_str());
193+
194+
usedDevice = deviceName.empty() ? getdevice : deviceName;
195+
std::cout << " ==checkUpdateforSpecialPlatform==2==" << std::endl;
196+
}
197+
std::cout << " ==checkUpdateforSpecialPlatform==3==" << std::endl;
198+
// If the platform is not 3720 or user set compilerType, will not update by device
199+
auto it = propertiesMap.find(std::string(COMPILER_TYPE::key()));
200+
if (usedDevice != std::string(ov::intel_npu::Platform::NPU3720) || it != propertiesMap.end()) {
201+
std::cout << " ==checkUpdateforSpecialPlatform==3==" << std::endl;
202+
return;
203+
}
204+
std::cout << " ==checkUpdateforSpecialPlatform==4==" << std::endl;
205+
if (it == propertiesMap.end()) {
206+
std::cout << " ==checkUpdateforSpecialPlatform==5==" << std::endl;
207+
if (base_conf.get<COMPILER_TYPE>() != ov::intel_npu::CompilerType::DRIVER) {
208+
std::cout << " ==checkUpdateforSpecialPlatform==6==" << std::endl;
209+
log.warning(
210+
"Platform '3720' is selected, but the used compiler_type is not set to 'DRIVER'. Forcely use the "
211+
"compiler_type to 'DRIVER'. Maybe cause the compilerType inconsistency issues.");
181212
}
213+
std::cout << " ==checkUpdateforSpecialPlatform==7==" << std::endl;
214+
// To avoid compilerType inconsistency issues, only set DRIVER if compiler_type is not set by user
215+
propertiesMap[std::string(COMPILER_TYPE::key())] = COMPILER_TYPE::toString(ov::intel_npu::CompilerType::DRIVER);
216+
std::cout << " ==checkUpdateforSpecialPlatform==8==" << std::endl;
182217
}
183218
}
184219

185-
static ov::intel_npu::CompilerType resolveCompilerType(const FilteredConfig& base_conf, const ov::AnyMap& local_conf) {
220+
static ov::intel_npu::CompilerType resolveCompilerType(const FilteredConfig& base_conf,
221+
const ov::AnyMap& local_conf,
222+
const std::string& deviceName) {
186223
// first look if provided config changes compiler type
187224
auto it = local_conf.find(std::string(COMPILER_TYPE::key()));
188225
if (it != local_conf.end()) {
189226
// if compiler_type is provided by local config = use that
190227
return COMPILER_TYPE::parse(it->second.as<std::string>());
191228
}
192-
// if there is no compiler_type provided = use base_config value
229+
// if there is no compiler_type provided = use base_config value and update default vaule by platform if needed
230+
// Default compilerType for different platform is up to device:
231+
// 3720 -> DRIVER
232+
// 4000 and later -> default
233+
if (!deviceName.empty()) {
234+
if (deviceName == std::string(ov::intel_npu::Platform::NPU3720)) {
235+
return ov::intel_npu::CompilerType::DRIVER;
236+
}
237+
} else {
238+
std::string getdevice = getDeviceFromProperties(local_conf);
239+
if (getdevice == std::string(ov::intel_npu::Platform::NPU3720)) {
240+
return ov::intel_npu::CompilerType::DRIVER;
241+
}
242+
if (getdevice == std::string(ov::intel_npu::Platform::AUTO_DETECT)) {
243+
Logger::global().warning("Device is set to AUTO_DETECT, cannot decide the default compiler_type by device, "
244+
"use the default compiler_type.");
245+
}
246+
}
247+
193248
return base_conf.get<COMPILER_TYPE>();
194249
}
195250

@@ -663,6 +718,9 @@ std::shared_ptr<ov::ICompiledModel> Plugin::compile_model(const std::shared_ptr<
663718
// activate the NPUW path
664719
auto useNpuwKey = ov::intel_npu::use_npuw.name();
665720
ov::AnyMap localProperties = properties;
721+
for (auto it : localProperties) {
722+
std::cout << "Compile_model: Local property: " << it.first << "=" << it.second.as<std::string>() << std::endl;
723+
}
666724
if (localProperties.count(useNpuwKey)) {
667725
if (localProperties.at(useNpuwKey).as<bool>() == true) {
668726
return ov::npuw::ICompiledModel::create(model->clone(), shared_from_this(), localProperties);
@@ -679,17 +737,27 @@ std::shared_ptr<ov::ICompiledModel> Plugin::compile_model(const std::shared_ptr<
679737
}
680738

681739
// For 3720, need check and update its compiler_type
682-
checkUpdateforspecialPlatform(_globalConfig, localProperties, _logger);
683-
740+
auto deviceTmp = _backend == nullptr ? nullptr : _backend->getDevice();
741+
std::string deviceName = deviceTmp != nullptr ? deviceTmp->getName() : "";
742+
checkUpdateforSpecialPlatform(_globalConfig, localProperties, deviceName, _logger);
743+
std::cout << " ==compile_model=========2====" << std::endl;
684744
const std::map<std::string, std::string> localPropertiesMap = any_copy(localProperties);
745+
for (auto it : localPropertiesMap) {
746+
std::cout << "Compile_model2: Local property: " << it.first << "=" << it.second << std::endl;
747+
}
748+
685749
update_log_level(localPropertiesMap);
686750

687751
// create compiler
752+
std::cout << " ==compile_model=== compile create ==========1====" << std::endl;
688753
CompilerAdapterFactory compilerAdapterFactory;
689-
auto compiler = compilerAdapterFactory.getCompiler(_backend, resolveCompilerType(_globalConfig, properties));
754+
auto compiler =
755+
compilerAdapterFactory.getCompiler(_backend, resolveCompilerType(_globalConfig, localProperties, deviceName));
756+
std::cout << " ==compile_model=== compile create ==========2====" << std::endl;
690757

691758
OV_ITT_TASK_CHAIN(PLUGIN_COMPILE_MODEL, itt::domains::NPUPlugin, "Plugin::compile_model", "fork_local_config");
692759
auto localConfig = fork_local_config(localPropertiesMap, compiler);
760+
std::cout << " ===== the final config is: " << localConfig.toString() << std::endl;
693761

694762
const auto set_cache_dir = localConfig.get<CACHE_DIR>();
695763
if (!set_cache_dir.empty()) {
@@ -703,7 +771,31 @@ std::shared_ptr<ov::ICompiledModel> Plugin::compile_model(const std::shared_ptr<
703771
utils::getCompilationPlatform(localConfig.get<PLATFORM>(),
704772
localConfig.get<DEVICE_ID>(),
705773
_backend == nullptr ? std::vector<std::string>() : _backend->getDeviceNames());
774+
std::string getPlatfrom1 = getDeviceFromProperties(localProperties);
775+
std::cout << "The platform from properties is: '" << getPlatfrom1 << "'" << std::endl;
776+
std::cout << "The platform from getCompilationPlatform is: '" << platform << "'" << std::endl;
777+
706778
auto device = _backend == nullptr ? nullptr : _backend->getDevice(localConfig.get<DEVICE_ID>());
779+
780+
if (deviceTmp == device) {
781+
if (deviceTmp != nullptr) {
782+
std::cout << "The selected device is: " << device->getName() << std::endl;
783+
} else {
784+
if (deviceTmp == nullptr) {
785+
std::cout << "The selected device from driver is: nullptr" << std::endl;
786+
} else {
787+
std::cout << "The selected device from driver is: " << deviceTmp->getName() << std::endl;
788+
}
789+
if (device == nullptr) {
790+
std::cout << "The selected device from config and driver is: nullptr" << std::endl;
791+
} else {
792+
std::cout << "The selected device from config and driver is: " << device->getName() << std::endl;
793+
}
794+
}
795+
} else {
796+
std::cout << "The selected device is NOT EQUAL, deviceTmp is " << deviceTmp->getName() << ", device is "
797+
<< device->getName() << std::endl;
798+
}
707799
localConfig.update({{ov::intel_npu::platform.name(), platform}});
708800

709801
auto updateBatchMode = [&](ov::intel_npu::BatchMode mode) {
@@ -981,12 +1073,23 @@ ov::SupportedOpsMap Plugin::query_model(const std::shared_ptr<const ov::Model>&
9811073
CompilerAdapterFactory compilerAdapterFactory;
9821074
auto npu_plugin_properties = properties;
9831075
exclude_model_ptr_from_map(npu_plugin_properties);
984-
checkUpdateforspecialPlatform(_globalConfig, npu_plugin_properties, _logger);
1076+
for (auto it : npu_plugin_properties) {
1077+
std::cout << "Query_model: Local property: " << it.first << "=" << it.second.as<std::string>() << std::endl;
1078+
}
1079+
1080+
auto device = _backend == nullptr ? nullptr : _backend->getDevice();
1081+
std::string deviceName = device != nullptr ? device->getName() : "";
1082+
checkUpdateforSpecialPlatform(_globalConfig, npu_plugin_properties, deviceName, _logger);
1083+
for (auto it : npu_plugin_properties) {
1084+
std::cout << "Query_model2: Local property: " << it.first << "=" << it.second.as<std::string>() << std::endl;
1085+
}
9851086
const std::map<std::string, std::string> propertiesMap = any_copy(npu_plugin_properties);
9861087
update_log_level(propertiesMap);
1088+
std::cout << " ==query_model=== compile create ==========1====" << std::endl;
9871089
auto compiler =
988-
compilerAdapterFactory.getCompiler(_backend, resolveCompilerType(_globalConfig, npu_plugin_properties));
989-
1090+
compilerAdapterFactory.getCompiler(_backend,
1091+
resolveCompilerType(_globalConfig, npu_plugin_properties, deviceName));
1092+
std::cout << " ==query_model=== compile create ==========1====" << std::endl;
9901093
auto localConfig = fork_local_config(propertiesMap, compiler, OptionMode::CompileTime);
9911094
_logger.setLevel(localConfig.get<LOG_LEVEL>());
9921095
const auto platform =
@@ -1017,13 +1120,24 @@ std::shared_ptr<ov::ICompiledModel> Plugin::parse(const ov::Tensor& tensorBig,
10171120
// ov::hint::model has no corresponding "Config" implementation thus we need to remove it from the
10181121
// list of properties
10191122
auto originalModel = exclude_model_ptr_from_map(npu_plugin_properties);
1020-
checkUpdateforspecialPlatform(_globalConfig, npu_plugin_properties, _logger);
1123+
for (auto it : npu_plugin_properties) {
1124+
std::cout << "Parse: Local property1: " << it.first << "=" << it.second.as<std::string>() << std::endl;
1125+
}
1126+
auto deviceTmp = _backend == nullptr ? nullptr : _backend->getDevice();
1127+
std::string deviceName = deviceTmp != nullptr ? deviceTmp->getName() : "";
1128+
checkUpdateforSpecialPlatform(_globalConfig, npu_plugin_properties, deviceName, _logger);
1129+
for (auto it : npu_plugin_properties) {
1130+
std::cout << "Parse2: Local property: " << it.first << "=" << it.second.as<std::string>() << std::endl;
1131+
}
10211132

10221133
CompilerAdapterFactory compilerAdapterFactory;
10231134
const auto propertiesMap = any_copy(npu_plugin_properties);
10241135
update_log_level(propertiesMap);
1136+
std::cout << " ==parse=== compile create ==========1====" << std::endl;
10251137
auto compiler =
1026-
compilerAdapterFactory.getCompiler(_backend, resolveCompilerType(_globalConfig, npu_plugin_properties));
1138+
compilerAdapterFactory.getCompiler(_backend,
1139+
resolveCompilerType(_globalConfig, npu_plugin_properties, deviceName));
1140+
std::cout << " ==parse=== compile create ==========2====" << std::endl;
10271141
OV_ITT_TASK_CHAIN(PLUGIN_PARSE_MODEL, itt::domains::NPUPlugin, "Plugin::parse", "fork_local_config");
10281142
auto localConfig = fork_local_config(propertiesMap, compiler, OptionMode::RunTime);
10291143
_logger.setLevel(localConfig.get<LOG_LEVEL>());
@@ -1033,6 +1147,12 @@ std::shared_ptr<ov::ICompiledModel> Plugin::parse(const ov::Tensor& tensorBig,
10331147
_backend == nullptr ? std::vector<std::string>() : _backend->getDeviceNames());
10341148
localConfig.update({{ov::intel_npu::platform.name(), platform}});
10351149
auto device = _backend == nullptr ? nullptr : _backend->getDevice(localConfig.get<DEVICE_ID>());
1150+
if (deviceTmp == device) {
1151+
std::cout << "2The selected device is: " << device->getName() << std::endl;
1152+
} else {
1153+
std::cout << "2The selected device is NOT EQUAL, deviceTmp is " << deviceTmp->getName() << ", device is "
1154+
<< device->getName() << std::endl;
1155+
}
10361156

10371157
const auto loadedFromCache = localConfig.get<LOADED_FROM_CACHE>();
10381158
if (!loadedFromCache) {

src/plugins/intel_npu/tests/functional/behavior/ov_infer_request/infer_request_run.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ class InferRequestRunTests : public ov::test::behavior::OVPluginTestBase,
8282
auto hash = std::to_string(std::hash<std::string>()(test_name));
8383
std::stringstream ss;
8484
auto ts = duration_cast<nanoseconds>(high_resolution_clock::now().time_since_epoch());
85-
ss << hash << "_" << "_" << ts.count();
85+
ss << hash << "_"
86+
<< "_" << ts.count();
8687
return ss.str();
8788
}
8889

@@ -466,7 +467,7 @@ TEST_P(BatchingRunTests, CheckBatchingSupportInfer) {
466467
TEST_P(BatchingRunTests, CheckBatchingSupportAsync) {
467468
SKIP_IF_CURRENT_TEST_IS_DISABLED();
468469

469-
ov::CompiledModel compiled_model;
470+
ov::CompiledModel compiled_model;
470471
ov::InferRequest inference_request;
471472
auto batch_shape = Shape{4, 2, 32, 32};
472473
std::shared_ptr<ov::Model> ov_model_batch = createModel(element::f32, batch_shape, "N...");
@@ -556,6 +557,7 @@ TEST_P(BatchingRunTests, SetInputTensorAsync) {
556557
}
557558

558559
TEST_P(BatchingRunTests, SetInputTensorInfer_Caching) {
560+
// need to skip or set driver compiler type
559561
auto batch_shape = Shape{4, 2, 2, 2};
560562
auto shape_size = ov::shape_size(batch_shape);
561563
auto model = createModel(element::f32, batch_shape, "N...");
@@ -565,6 +567,7 @@ TEST_P(BatchingRunTests, SetInputTensorInfer_Caching) {
565567

566568
m_cache_dir = generateCacheDirName(GetTestName());
567569
core->set_property({ov::cache_dir(m_cache_dir)});
570+
core->set_property({ov::intel_npu::compiler_type(ov::intel_npu::CompilerType::DRIVER)});
568571
auto compiled_model_no_cache = core->compile_model(model, target_device, configuration);
569572
compiled_model = core->compile_model(model, target_device, configuration);
570573
ov::InferRequest inference_request;

src/plugins/intel_npu/tests/functional/behavior/ov_plugin/caching_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ using namespace ov::test::behavior;
1212

1313
namespace {
1414

15-
std::vector<ov::AnyMap> config = {{}};
15+
std::vector<ov::AnyMap> config = {{ov::intel_npu::compiler_type(ov::intel_npu::CompilerType::DRIVER)}};
1616

1717
INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests,
1818
OVCompileModelLoadFromFileTestBaseNPU,

src/plugins/intel_npu/tests/functional/behavior/ov_plugin/caching_tests.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "intel_npu/utils/zero/zero_init.hpp"
1313
#include "openvino/core/log_util.hpp"
14+
// #include "intel_npu/npu_private_properties.hpp"
1415

1516
namespace ov {
1617
namespace test {
@@ -20,6 +21,7 @@ using OVCompileModelLoadFromFileTestBaseNPU = CompileModelLoadFromFileTestBase;
2021

2122
TEST_P(OVCompileModelLoadFromFileTestBaseNPU, BlobWithOVHeaderAligmentCanBeImported) {
2223
core->set_property(ov::cache_dir(m_cacheFolderName));
24+
// core->set_property({intel_npu::compiler_type(ov::intel_npu::CompilerType::DRIVER)});
2325

2426
ze_device_external_memory_properties_t externalMemorydDesc = {};
2527
externalMemorydDesc.stype = ZE_STRUCTURE_TYPE_DEVICE_EXTERNAL_MEMORY_PROPERTIES;

src/plugins/intel_npu/tests/functional/behavior/remote_tensor_tests/remote_run.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ class RemoteRunTests : public ov::test::behavior::OVPluginTestBase,
7474
auto hash = std::to_string(std::hash<std::string>()(test_name));
7575
std::stringstream ss;
7676
auto ts = duration_cast<nanoseconds>(high_resolution_clock::now().time_since_epoch());
77-
ss << hash << "_" << "_" << ts.count();
77+
ss << hash << "_"
78+
<< "_" << ts.count();
7879
return ss.str();
7980
}
8081

@@ -556,6 +557,7 @@ TEST_P(RemoteRunTests, CheckImportModelPath) {
556557

557558
m_cache_dir = generateCacheDirName(GetTestName());
558559
core->set_property({ov::cache_dir(m_cache_dir)});
560+
core->set_property({ov::intel_npu::compiler_type(ov::intel_npu::CompilerType::DRIVER)});
559561
auto compiled_model_no_cache = core->compile_model(ov_model, zero_context, configuration);
560562
compiled_model = core->compile_model(ov_model, zero_context, configuration);
561563

0 commit comments

Comments
 (0)