OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[NPU] Pass the device descriptor to the plugin compiler only for online compilation (#39532)
Stefania Herganedb5e64687862
diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/compiler_adapter_factory.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/compiler_adapter_factory.cppindex a46d2c14772..1947ecadd12 100644--- a/src/plugins/intel_npu/src/compiler_adapter/src/compiler_adapter_factory.cpp+++ b/src/plugins/intel_npu/src/compiler_adapter/src/compiler_adapter_factory.cpp@@ -18,13 +18,19 @@ namespace {std::shared_ptr<IVCLCompiler> makePluginCompiler(std::shared_ptr<const VCLFunctionTable>& functions,const std::shared_ptr<IDevice>& device,+ std::string_view platform,const std::shared_ptr<OptionSupportCache>& optionSupportCache) {auto vclLoader = VCLLoader::getInstance();OPENVINO_ASSERT(vclLoader != nullptr, "VCL loader is nullptr");functions = vclLoader->sharedFunctions();++ // Only online compilation gets the attached device's descriptor.+ // Offline and cross compilation get a dummy one, so the local device cannot affect the blob.+ const bool onlineCompilation = device && (platform.empty() || device->getName() == platform);+return std::make_shared<VCLCompilerImpl>(functions,- device ? std::optional<IDevice::DeviceProperties>{device->getDeviceProperties()} : std::nullopt,+ onlineCompilation ? std::optional<IDevice::DeviceProperties>{device->getDeviceProperties()} : std::nullopt,ScopedOptionSupportCache{optionSupportCache,static_cast<OptionSupportCache::CacheKey>(ov::intel_npu::CompilerType::PLUGIN)});}@@ -51,7 +57,7 @@ std::unique_ptr<ICompilerAdapter> CompilerAdapterFactory::getCompiler(std::shared_ptr<const VCLFunctionTable> functions;std::shared_ptr<IVCLCompiler> compiler;try {- compiler = makePluginCompiler(functions, device, optionSupportCache);+ compiler = makePluginCompiler(functions, device, platform, optionSupportCache);} catch (const std::exception& vclException) {OPENVINO_THROW("VCL compiler loading failed, aborting. Error: ", vclException.what());}@@ -137,7 +143,7 @@ CompilerAdapterFactory::resolvePreferPluginCompiler(const ov::SoPtr<IEngineBackestd::shared_ptr<IVCLCompiler> pluginCompiler;std::shared_ptr<const VCLFunctionTable> functions;try {- pluginCompiler = makePluginCompiler(functions, device, optionSupportCache);+ pluginCompiler = makePluginCompiler(functions, device, platform, optionSupportCache);} catch (...) {_pluginCompilerPresence.store(PluginCompilerPresence::ABSENT, std::memory_order_release);if (onlineCompilation) {diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/compiler_impl.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/compiler_impl.cppindex 6f4648afc8f..1ef86ccbf4c 100644--- a/src/plugins/intel_npu/src/compiler_adapter/src/compiler_impl.cpp+++ b/src/plugins/intel_npu/src/compiler_adapter/src/compiler_impl.cpp@@ -114,7 +114,7 @@ VCLCompilerImpl::VCLCompilerImpl(const std::shared_ptr<const VCLFunctionTable>&compilerDesc.version = _vclVersion;compilerDesc.debugLevel = static_cast<__vcl_log_level_t>(static_cast<int>(Logger::global().level()) + 1);- vcl_device_desc_t vclDeviceDesc = {};+ std::optional<vcl_device_desc_t> vclDeviceDesc;if (deviceProperties.has_value()) {constexpr auto invalidRevision = std::numeric_limits<uint16_t>::max();const auto revision = deviceProperties->subdeviceId >= invalidRevision@@ -131,18 +131,20 @@ VCLCompilerImpl::VCLCompilerImpl(const std::shared_ptr<const VCLFunctionTable>&deviceProperties->deviceId,deviceProperties->subdeviceId,deviceProperties->numSlices);- vclDeviceDesc = {sizeof(vcl_device_desc_t), deviceProperties->deviceId, revision, deviceProperties->numSlices};+ vclDeviceDesc = vcl_device_desc_t{sizeof(vcl_device_desc_t),+ deviceProperties->deviceId,+ revision,+ deviceProperties->numSlices};} else {- // This information cannot be determined during the initialization phase; set device desc default value, the- // related info will be processed in compile phase if passed by user.- _logger.info("Device description is not provided, using default values");- uint32_t defaultTileCount = std::numeric_limits<uint32_t>::max();- vclDeviceDesc = {sizeof(vcl_device_desc_t), 0x00, std::numeric_limits<uint16_t>::max(), defaultTileCount};+ _logger.info("Device description is not provided, passing a null device descriptor");}THROW_ON_FAIL_FOR_VCL(*_functions,"vclCompilerCreate",- _functions->vclCompilerCreate(&compilerDesc, &vclDeviceDesc, &_compilerHandle, &_logHandle),+ _functions->vclCompilerCreate(&compilerDesc,+ vclDeviceDesc.has_value() ? &vclDeviceDesc.value() : nullptr,+ &_compilerHandle,+ &_logHandle),nullptr);THROW_ON_FAIL_FOR_VCL(*_functions,"vclCompilerGetProperties",diff --git a/src/plugins/intel_npu/tests/unit/npu/compiler_adapter/compiler_impl_test.cpp b/src/plugins/intel_npu/tests/unit/npu/compiler_adapter/compiler_impl_test.cppindex e4fc8ad412e..5332bedc338 100644--- a/src/plugins/intel_npu/tests/unit/npu/compiler_adapter/compiler_impl_test.cpp+++ b/src/plugins/intel_npu/tests/unit/npu/compiler_adapter/compiler_impl_test.cpp@@ -140,15 +140,11 @@ TEST_F(VCLCompilerImplTest, SubdeviceIdExactlyAtTheSentinelAlsoClamps) {EXPECT_EQ(fake.deviceDescs[0].revision, sentinel);}-TEST_F(VCLCompilerImplTest, AbsentDevicePropertiesUseDefaultSentinels) {+TEST_F(VCLCompilerImplTest, AbsentDevicePropertiesPassANullDeviceDescriptor) {auto compiler = makeCompiler(std::nullopt);- ASSERT_EQ(fake.deviceDescs.size(), 1u);- const auto& desc = fake.deviceDescs[0];- EXPECT_EQ(desc.size, sizeof(vcl_device_desc_t));- EXPECT_EQ(desc.deviceID, 0x00u);- EXPECT_EQ(desc.revision, std::numeric_limits<uint16_t>::max());- EXPECT_EQ(desc.tileCount, std::numeric_limits<uint32_t>::max());+ ASSERT_EQ(fake.compilerDescs.size(), 1u);+ EXPECT_TRUE(fake.deviceDescs.empty());}TEST_F(VCLCompilerImplTest, NullApiTableIsRejected) {