diff --git a/src/plugins/intel_npu/src/plugin/include/plugin.hpp b/src/plugins/intel_npu/src/plugin/include/plugin.hpp index 10f48d90ab4367..a8dc43d5f23393 100644 --- a/src/plugins/intel_npu/src/plugin/include/plugin.hpp +++ b/src/plugins/intel_npu/src/plugin/include/plugin.hpp @@ -29,6 +29,8 @@ class Plugin : public ov::IPlugin { virtual ~Plugin() = default; + void getBackendandMetrics(const Config& config) const; + void set_property(const ov::AnyMap& properties) override; ov::Any get_property(const std::string& name, const ov::AnyMap& arguments) const override; @@ -56,17 +58,17 @@ class Plugin : public ov::IPlugin { private: ov::SoPtr getCompiler(const Config& config) const; - std::shared_ptr _backends; + mutable std::shared_ptr _backends; std::map _config; std::shared_ptr _options; - Config _globalConfig; + mutable Config _globalConfig; Logger _logger; - std::unique_ptr _metrics; + mutable std::unique_ptr _metrics; // properties map: {name -> [supported, mutable, eval function]} - std::map>> _properties; - std::vector _supportedProperties; + mutable std::map>> _properties; + mutable std::vector _supportedProperties; static std::atomic _compiledModelLoadCounter; }; diff --git a/src/plugins/intel_npu/src/plugin/src/plugin.cpp b/src/plugins/intel_npu/src/plugin/src/plugin.cpp index c22fdc4e944805..e849c2b2191c24 100644 --- a/src/plugins/intel_npu/src/plugin/src/plugin.cpp +++ b/src/plugins/intel_npu/src/plugin/src/plugin.cpp @@ -134,37 +134,7 @@ Plugin::Plugin() _globalConfig.parseEnvVars(); Logger::global().setLevel(_globalConfig.get()); - // TODO: generation of available backends list can be done during execution of CMake scripts - std::vector backendRegistry; - -#if defined(OPENVINO_STATIC_LIBRARY) - backendRegistry.push_back(AvailableBackends::LEVEL_ZERO); -#else -# if defined(ENABLE_IMD_BACKEND) - if (const auto* envVar = std::getenv("IE_NPU_USE_IMD_BACKEND")) { - if (envVarStrToBool("IE_NPU_USE_IMD_BACKEND", envVar)) { - backendRegistry.push_back(AvailableBackends::IMD); - } - } -# endif - -# if defined(_WIN32) || defined(_WIN64) || (defined(__linux__) && defined(__x86_64__)) - backendRegistry.push_back(AvailableBackends::LEVEL_ZERO); -# endif -#endif - - OV_ITT_TASK_CHAIN(PLUGIN, itt::domains::NPUPlugin, "Plugin::Plugin", "NPUBackends"); - _backends = std::make_shared(backendRegistry, _globalConfig); - OV_ITT_TASK_NEXT(PLUGIN, "registerOptions"); - _backends->registerOptions(*_options); - - OV_ITT_TASK_NEXT(PLUGIN, "Metrics"); - _metrics = std::make_unique(_backends); - - // parse again env_variables after backend is initialized to get backend proprieties - _globalConfig.parseEnvVars(); - - // Map from name to function {Config -> ov::Any} + // Map from name to function {Config -> ov::Any} // Note that some properties are RW before network is loaded, and become RO after network is loaded _properties = { // OV Public @@ -229,68 +199,14 @@ Plugin::Plugin() [](const Config& config) { return config.getString(); }}}, - {ov::available_devices.name(), - {true, - ov::PropertyMutability::RO, - [&](const Config&) { - return _metrics->GetAvailableDevicesNames(); - }}}, - {ov::device::capabilities.name(), - {true, - ov::PropertyMutability::RO, - [&](const Config&) { - return _metrics->GetOptimizationCapabilities(); - }}}, - {ov::optimal_number_of_infer_requests.name(), - {true, - ov::PropertyMutability::RO, - [&](const Config& config) { - return static_cast(getOptimalNumberOfInferRequestsInParallel(add_platform_to_the_config( - config, - _backends->getCompilationPlatform(config.get(), config.get())))); - }}}, - {ov::range_for_async_infer_requests.name(), - {true, - ov::PropertyMutability::RO, - [&](const Config&) { - return _metrics->GetRangeForAsyncInferRequest(); - }}}, - {ov::range_for_streams.name(), - {true, - ov::PropertyMutability::RO, - [&](const Config&) { - return _metrics->GetRangeForStreams(); - }}}, {ov::num_streams.name(), {true, ov::PropertyMutability::RO, [](const Config& config) { return config.get(); }}}, - {ov::device::uuid.name(), - {true, - ov::PropertyMutability::RO, - [&](const Config& config) { - const auto specifiedDeviceName = get_specified_device_name(config); - auto devUuid = _metrics->GetDeviceUuid(specifiedDeviceName); - return decltype(ov::device::uuid)::value_type{devUuid}; - }}}, - // Add FULL_DEVICE_NAME and DEVICE_ARCHITECTURE in supported - // properties list only in case of non-empty device list (#1424144d) - {ov::device::architecture.name(), - {!_metrics->GetAvailableDevicesNames().empty(), - ov::PropertyMutability::RO, - [&](const Config& config) { - const auto specifiedDeviceName = get_specified_device_name(config); - return _metrics->GetDeviceArchitecture(specifiedDeviceName); - }}}, - {ov::device::full_name.name(), - {!_metrics->GetAvailableDevicesNames().empty(), - ov::PropertyMutability::RO, - [&](const Config& config) { - const auto specifiedDeviceName = get_specified_device_name(config); - return _metrics->GetFullDeviceName(specifiedDeviceName); - }}}, + + {ov::hint::model_priority.name(), {true, ov::PropertyMutability::RW, @@ -299,44 +215,16 @@ Plugin::Plugin() }}}, // OV Internals // ========= - {ov::internal::caching_properties.name(), - {false, - ov::PropertyMutability::RO, - [&](const Config&) { - return _metrics->GetCachingProperties(); - }}}, {ov::internal::exclusive_async_requests.name(), {false, ov::PropertyMutability::RW, [](const Config& config) { return config.get(); }}}, - {ov::internal::supported_properties.name(), - {false, - ov::PropertyMutability::RO, - [&](const Config&) { - return _metrics->GetInternalSupportedProperties(); - }}}, + // NPU Public // ========= - {ov::intel_npu::device_alloc_mem_size.name(), - {true, - ov::PropertyMutability::RO, - [&](const Config& config) { - return _metrics->GetDeviceAllocMemSize(get_specified_device_name(config)); - }}}, - {ov::intel_npu::device_total_mem_size.name(), - {true, - ov::PropertyMutability::RO, - [&](const Config& config) { - return _metrics->GetDeviceTotalMemSize(get_specified_device_name(config)); - }}}, - {ov::intel_npu::driver_version.name(), - {true, - ov::PropertyMutability::RO, - [&](const Config& config) { - return _metrics->GetDriverVersion(); - }}}, + // NPU Private // ========= {ov::intel_npu::dma_engines.name(), @@ -393,12 +281,8 @@ Plugin::Plugin() [](const Config& config) { return config.get(); }}}, - {ov::intel_npu::backend_name.name(), - {false, - ov::PropertyMutability::RO, - [&](const Config&) { - return _metrics->GetBackendName(); - }}}, + {ov::available_devices.name(), + {ov::intel_npu::use_elf_compiler_backend.name(), {false, ov::PropertyMutability::RW, @@ -426,6 +310,141 @@ Plugin::Plugin() } } +void Plugin::getBackendandMetrics(const Config& config) const{ + // TODO: generation of available backends list can be done during execution of CMake scripts + std::vector backendRegistry; + +#if defined(OPENVINO_STATIC_LIBRARY) + backendRegistry.push_back(vpux::AvailableBackends::LEVEL_ZERO); +#else +#if defined(ENABLE_IMD_BACKEND) + if (const auto* envVar = std::getenv("IE_NPU_USE_IMD_BACKEND")) { + if (envVarStrToBool("IE_NPU_USE_IMD_BACKEND", envVar)) { + backendRegistry.push_back(vpux::AvailableBackends::IMD); + } + } +#endif + +#if defined(_WIN32) || defined(_WIN64) || (defined(__linux__) && defined(__x86_64__)) + backendRegistry.push_back(vpux::AvailableBackends::LEVEL_ZERO); +#endif +#endif + + OV_ITT_TASK_CHAIN(PLUGIN, itt::domains::VPUXPlugin, "Plugin::getBackendandMetrics", "NPUBackends"); + _backends = std::make_shared(backendRegistry, config); + OV_ITT_TASK_NEXT(PLUGIN, "registerOptions"); + _backends->registerOptions(*_options); + + OV_ITT_TASK_NEXT(PLUGIN, "Metrics"); + _metrics = std::make_unique(_backends); + + // parse again env_variables after backend is initialized to get backend proprieties + _globalConfig.parseEnvVars(); + + std::map>> updateProperties = + { + {true, + ov::PropertyMutability::RO, + [&](const Config&) { + return _metrics->GetAvailableDevicesNames(); + }}}, + {ov::device::capabilities.name(), + {true, + ov::PropertyMutability::RO, + [&](const Config&) { + return _metrics->GetOptimizationCapabilities(); + }}}, + {ov::optimal_number_of_infer_requests.name(), + {true, + ov::PropertyMutability::RO, + [&](const Config& config) { + return static_cast(getOptimalNumberOfInferRequestsInParallel(add_platform_to_the_config( + config, + _backends->getCompilationPlatform(config.get(), config.get())))); + }}}, + {ov::range_for_async_infer_requests.name(), + {true, + ov::PropertyMutability::RO, + [&](const Config&) { + return _metrics->GetRangeForAsyncInferRequest(); + }}}, + {ov::range_for_streams.name(), + {true, + ov::PropertyMutability::RO, + [&](const Config&) { + return _metrics->GetRangeForStreams(); + }}}, + {ov::device::uuid.name(), + {true, + ov::PropertyMutability::RO, + [&](const Config& config) { + const auto specifiedDeviceName = get_specified_device_name(config); + auto devUuid = _metrics->GetDeviceUuid(specifiedDeviceName); + return decltype(ov::device::uuid)::value_type{devUuid}; + }}}, + // Add FULL_DEVICE_NAME and DEVICE_ARCHITECTURE in supported + // properties list only in case of non-empty device list (#1424144d) + {ov::device::architecture.name(), + {!_metrics->GetAvailableDevicesNames().empty(), + ov::PropertyMutability::RO, + [&](const Config& config) { + const auto specifiedDeviceName = get_specified_device_name(config); + return _metrics->GetDeviceArchitecture(specifiedDeviceName); + }}}, + {ov::device::full_name.name(), + {!_metrics->GetAvailableDevicesNames().empty(), + ov::PropertyMutability::RO, + [&](const Config& config) { + const auto specifiedDeviceName = get_specified_device_name(config); + return _metrics->GetFullDeviceName(specifiedDeviceName); + }}}, + {ov::internal::caching_properties.name(), + {false, + ov::PropertyMutability::RO, + [&](const Config&) { + return _metrics->GetCachingProperties(); + }}}, + {ov::internal::supported_properties.name(), + {false, + ov::PropertyMutability::RO, + [&](const Config&) { + return _metrics->GetInternalSupportedProperties(); + }}}, + {ov::intel_npu::device_alloc_mem_size.name(), + {true, + ov::PropertyMutability::RO, + [&](const Config& config) { + return _metrics->GetDeviceAllocMemSize(get_specified_device_name(config)); + }}}, + {ov::intel_npu::device_total_mem_size.name(), + {true, + ov::PropertyMutability::RO, + [&](const Config& config) { + return _metrics->GetDeviceTotalMemSize(get_specified_device_name(config)); + }}}, + {ov::intel_npu::driver_version.name(), + {true, + ov::PropertyMutability::RO, + [&](const Config& config) { + return _metrics->GetDriverVersion(); + }}}, + {ov::intel_npu::backend_name.name(), + {false, + ov::PropertyMutability::RO, + [&](const Config&) { + return _metrics->GetBackendName(); + }}}, + }; + + _properties.insert(updateProperties.begin(), updateProperties.end()); + + for (auto& property : _properties) { + if (std::get<0>(property.second)) { + _supportedProperties.emplace_back(ov::PropertyName(property.first, std::get<1>(property.second))); + } + } +} + void Plugin::set_property(const ov::AnyMap& properties) { const std::map config = any_copy(properties); for (const auto& configEntry : config) { @@ -467,6 +486,19 @@ std::shared_ptr Plugin::compile_model(const std::shared_ptr< OV_ITT_TASK_CHAIN(PLUGIN_COMPILE_MODEL, itt::domains::NPUPlugin, "Plugin::compile_model", "merge_configs"); auto localConfig = merge_configs(_globalConfig, any_copy(properties)); + getBackendandMetrics(localConfig); + std::printf(" _globalConfig is %s )\n", _globalConfig.toString().c_str()); + const auto compilerType3 = _globalConfig.get(); + if (compilerType3 == ov::intel_npu::CompilerType::DRIVER) { + std::printf(" (1) --1--COMPILER_TYPE is Driver\n"); + } + if (compilerType3 == ov::intel_npu::CompilerType::MLIR) { + std::printf(" (2) --2--COMPILER_TYPE is MLIR\n"); + } + + //update config after update _globalConfig in getBackendandMetrics(). + localConfig = merge_configs(_globalConfig, any_copy(properties)); + const auto set_cache_dir = localConfig.get(); if (!set_cache_dir.empty()) { const auto compilerType = localConfig.get();