Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[NPU] Drop redundant SoPtr pairing from the VCLCompilerImpl (#38776)

Patrik Stepanba1eaf40370f
diff --git a/src/plugins/intel_npu/src/compiler_adapter/include/compiler_impl.hpp b/src/plugins/intel_npu/src/compiler_adapter/include/compiler_impl.hpp
index aea9a07bda7..bddcb8d4d53 100644
--- a/src/plugins/intel_npu/src/compiler_adapter/include/compiler_impl.hpp
+++ b/src/plugins/intel_npu/src/compiler_adapter/include/compiler_impl.hpp
@@ -20,7 +20,6 @@
#include "openvino/core/model.hpp"
#include "openvino/runtime/common.hpp"
#include "openvino/runtime/profiling_info.hpp"
-#include "openvino/runtime/so_ptr.hpp"
#include "openvino/runtime/tensor.hpp"
namespace intel_npu {
@@ -138,16 +137,17 @@ private:
};
/**
- * @brief Loads the VCL compiler library and returns a compiler paired with it.
+ * @brief Loads the VCL compiler library and returns a compiler dispatching into it.
*
- * Keeps the load + SoPtr pairing in one place: the returned SoPtr owns the shared library, so the
- * compiler cannot outlive the code it dispatches into.
+ * The returned compiler holds the loader's function table, which is an aliasing `shared_ptr` over
+ * the loader itself, so the library stays loaded for exactly as long as the compiler needs it.
*
* @param optionSupportCache Bound here to the compiler-in-plugin's own cache key. Callers hand over
* the shared cache rather than a pre-bound one, so a compiler can never be paired with a key
* that belongs to a different compiler's answers.
*/
-ov::SoPtr<IVCLCompiler> makeVCLCompiler(const std::optional<IDevice::DeviceProperties>& deviceProperties = std::nullopt,
- const std::shared_ptr<OptionSupportCache>& optionSupportCache = nullptr);
+std::shared_ptr<IVCLCompiler> makeVCLCompiler(
+ const std::optional<IDevice::DeviceProperties>& deviceProperties = std::nullopt,
+ const std::shared_ptr<OptionSupportCache>& optionSupportCache = nullptr);
} // namespace intel_npu
diff --git a/src/plugins/intel_npu/src/compiler_adapter/include/plugin_compiler_adapter.hpp b/src/plugins/intel_npu/src/compiler_adapter/include/plugin_compiler_adapter.hpp
index 36263c3a64f..debffe7730f 100644
--- a/src/plugins/intel_npu/src/compiler_adapter/include/plugin_compiler_adapter.hpp
+++ b/src/plugins/intel_npu/src/compiler_adapter/include/plugin_compiler_adapter.hpp
@@ -6,6 +6,7 @@
#pragma once
+#include <memory>
#include <optional>
#include "intel_npu/common/icompiler_adapter.hpp"
@@ -13,7 +14,6 @@
#include "intel_npu/utils/logger/logger.hpp"
#include "intel_npu/utils/zero/zero_init.hpp"
#include "ivcl_compiler.hpp"
-#include "openvino/runtime/so_ptr.hpp"
#include "ze_graph_ext_wrappers.hpp"
namespace intel_npu {
@@ -31,7 +31,7 @@ public:
* @param compiler The compiler-in-plugin to adapt; must be non-null.
*/
PluginCompilerAdapter(const std::shared_ptr<ZeroInitStructsHolder>& zeroInitStruct,
- ov::SoPtr<IVCLCompiler> compiler);
+ std::shared_ptr<IVCLCompiler> compiler);
std::shared_ptr<IGraph> compile(const std::shared_ptr<const ov::Model>& model,
const Config& config,
@@ -53,7 +53,7 @@ public:
private:
std::shared_ptr<ZeroInitStructsHolder> _zeroInitStruct;
std::shared_ptr<ZeGraphExtWrappers> _zeGraphExt;
- ov::SoPtr<IVCLCompiler> _compiler;
+ std::shared_ptr<IVCLCompiler> _compiler;
Logger _logger;
};
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.cpp
index b45582b4bbe..63cf54fba2f 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
@@ -15,8 +15,8 @@ namespace {
// Loads the compiler-in-plugin, translating any failure into the aborting message callers expect.
// Composing the compiler here, rather than inside PluginCompilerAdapter, keeps the adapter free of
// any knowledge of how a compiler is obtained.
-ov::SoPtr<IVCLCompiler> makePluginCompiler(const std::shared_ptr<IDevice>& device,
- const std::shared_ptr<OptionSupportCache>& optionSupportCache) {
+std::shared_ptr<IVCLCompiler> makePluginCompiler(const std::shared_ptr<IDevice>& device,
+ const std::shared_ptr<OptionSupportCache>& optionSupportCache) {
try {
return makeVCLCompiler(
device ? std::optional<IDevice::DeviceProperties>{device->getDeviceProperties()} : std::nullopt,
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.cpp
index 24e5feeedda..5683987a237 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
@@ -701,22 +701,15 @@ constexpr OptionSupportCache::CacheKey pluginOptionSupportKey =
static_cast<OptionSupportCache::CacheKey>(ov::intel_npu::CompilerType::PLUGIN);
} // namespace
-ov::SoPtr<IVCLCompiler> makeVCLCompiler(const std::optional<IDevice::DeviceProperties>& deviceProperties,
- const std::shared_ptr<OptionSupportCache>& optionSupportCache) {
+std::shared_ptr<IVCLCompiler> makeVCLCompiler(const std::optional<IDevice::DeviceProperties>& deviceProperties,
+ const std::shared_ptr<OptionSupportCache>& optionSupportCache) {
auto vclLoader = VCLLoader::getInstance();
OPENVINO_ASSERT(vclLoader != nullptr, "VCL loader is nullptr");
- auto compiler =
- std::make_shared<VCLCompilerImpl>(vclLoader->sharedFunctions(),
- deviceProperties,
- ScopedOptionSupportCache{optionSupportCache, pluginOptionSupportKey});
-
- // Pairing the compiler with the library keeps the .so alive for as long as the compiler is. The
- // compiler itself never learns that a library is involved.
- auto vclLib = vclLoader->getLibrary();
- OPENVINO_ASSERT(vclLib != nullptr, "VCL library is nullptr");
-
- return ov::SoPtr<IVCLCompiler>(compiler, vclLib);
+ // The function table is an aliasing shared_ptr over the loader, so it keeps the library loaded.
+ return std::make_shared<VCLCompilerImpl>(vclLoader->sharedFunctions(),
+ deviceProperties,
+ ScopedOptionSupportCache{optionSupportCache, pluginOptionSupportKey});
}
} // namespace intel_npu
diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/graph.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/graph.cpp
index 859011a3b76..ea9f71b1758 100644
--- a/src/plugins/intel_npu/src/compiler_adapter/src/graph.cpp
+++ b/src/plugins/intel_npu/src/compiler_adapter/src/graph.cpp
@@ -157,8 +157,8 @@ std::pair<uint64_t, std::optional<std::vector<uint64_t>>> Graph::export_blob(std
}
std::vector<ov::ProfilingInfo> Graph::process_profiling_output(const std::vector<uint8_t>& profData) const {
- // Built through the same factory the adapter uses, so the load and library pairing stay in one
- // place. Profiling decode needs no compiler handle, so this does more work than necessary.
+ // Built through the same factory the adapter uses, so the library load stays in one place.
+ // Profiling decode needs no compiler handle, so this does more work than necessary.
auto compiler = makeVCLCompiler();
OPENVINO_ASSERT(compiler != nullptr, "Profiling post-processing requires the NPU plugin compiler library");
diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/plugin_compiler_adapter.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/plugin_compiler_adapter.cpp
index 457a890fcbc..c0767dd8dce 100644
--- a/src/plugins/intel_npu/src/compiler_adapter/src/plugin_compiler_adapter.cpp
+++ b/src/plugins/intel_npu/src/compiler_adapter/src/plugin_compiler_adapter.cpp
@@ -26,7 +26,7 @@
namespace intel_npu {
PluginCompilerAdapter::PluginCompilerAdapter(const std::shared_ptr<ZeroInitStructsHolder>& zeroInitStruct,
- ov::SoPtr<IVCLCompiler> compiler)
+ std::shared_ptr<IVCLCompiler> compiler)
: _zeroInitStruct(zeroInitStruct),
_compiler(std::move(compiler)),
_logger("PluginCompilerAdapter", Logger::global().level()) {
diff --git a/src/plugins/intel_npu/src/utils/include/intel_npu/utils/vcl/vcl_api.hpp b/src/plugins/intel_npu/src/utils/include/intel_npu/utils/vcl/vcl_api.hpp
index 50cb5879f12..af429ac7121 100644
--- a/src/plugins/intel_npu/src/utils/include/intel_npu/utils/vcl/vcl_api.hpp
+++ b/src/plugins/intel_npu/src/utils/include/intel_npu/utils/vcl/vcl_api.hpp
@@ -92,16 +92,14 @@ public:
* @brief The function table, sharing this loader's lifetime.
*
* An aliasing `shared_ptr`, so a holder of the returned table keeps the library loaded without
- * having to know a library exists.
+ * having to know a library exists. This is the only handle on the library handed out: consumers
+ * need nothing else to dispatch safely, and none of them can extend the library's lifetime
+ * beyond their own use of the table.
*/
std::shared_ptr<const VCLFunctionTable> sharedFunctions() const {
return {shared_from_this(), &_functions};
}
- std::shared_ptr<void> getLibrary() const {
- return lib;
- }
-
private:
explicit VCLLoader(const std::string& library_dir);
diff --git a/src/plugins/intel_npu/tests/unit/npu/compiler_adapter/plugin_compiler_adapter_test.cpp b/src/plugins/intel_npu/tests/unit/npu/compiler_adapter/plugin_compiler_adapter_test.cpp
index 1e1a91765f7..983904fc847 100644
--- a/src/plugins/intel_npu/tests/unit/npu/compiler_adapter/plugin_compiler_adapter_test.cpp
+++ b/src/plugins/intel_npu/tests/unit/npu/compiler_adapter/plugin_compiler_adapter_test.cpp
@@ -54,7 +54,7 @@ struct PluginCompilerAdapterTest : public ::testing::Test {
// The adapter is built with a null ZeroInitStructsHolder throughout: that is the no-driver path,
// which is the only one reachable without an NPU.
std::unique_ptr<PluginCompilerAdapter> makeAdapter() {
- return std::make_unique<PluginCompilerAdapter>(nullptr, ov::SoPtr<::intel_npu::IVCLCompiler>(compiler));
+ return std::make_unique<PluginCompilerAdapter>(nullptr, compiler);
}
static std::shared_ptr<OptionsDesc> makeOptionsDesc() {
@@ -86,10 +86,10 @@ TEST_F(PluginCompilerAdapterTest, InjectedCompilerIsAdapted) {
}
TEST_F(PluginCompilerAdapterTest, NullCompilerIsRejected) {
+ const std::shared_ptr<::intel_npu::IVCLCompiler> noCompiler;
EXPECT_THROW(
{
- auto adapter =
- std::make_unique<PluginCompilerAdapter>(nullptr, ov::SoPtr<::intel_npu::IVCLCompiler>(nullptr));
+ auto adapter = std::make_unique<PluginCompilerAdapter>(nullptr, noCompiler);
(void)adapter;
},
ov::Exception);