Skip to content

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

[NPU] Extract VCL profiling decoding out of the compiler and remove VCL from Graph (#38654)

Alexandru Enache6d7e2eb34ad3
diff --git a/src/plugins/intel_npu/src/backend/include/zero_profiling.hpp b/src/plugins/intel_npu/src/backend/include/zero_profiling.hpp
index b1120e64913..1f0e50a85f6 100644
--- a/src/plugins/intel_npu/src/backend/include/zero_profiling.hpp
+++ b/src/plugins/intel_npu/src/backend/include/zero_profiling.hpp
@@ -8,6 +8,7 @@
#include <ze_graph_ext.h>
#include <climits>
+#include <exception>
#include <map>
#include "intel_npu/common/igraph.hpp"
@@ -22,6 +23,24 @@ namespace zeroProfiling {
using LayerStatistics = std::vector<ov::ProfilingInfo>;
+template <typename Query>
+LayerStatistics getModelLayerStatistics(const IGraph& graph, const Query& query) {
+ if (!graph.has_profiling_decoder()) {
+ return query.getLayerStatistics();
+ }
+
+ try {
+ // Level Zero provides raw profiling bytes; the graph's decoder converts them to layer statistics.
+ return graph.process_profiling_output(query.template getData<uint8_t>());
+ } catch (const std::exception& ex) {
+ Logger::global().warning(
+ "getModelLayerStatistics - graph profiling decoder failed, falling back to level-zero layer "
+ "statistics: %s",
+ ex.what());
+ return query.getLayerStatistics();
+ }
+}
+
constexpr uint32_t POOL_SIZE = 1;
struct ProfilingPool {
diff --git a/src/plugins/intel_npu/src/backend/src/zero_pipeline.cpp b/src/plugins/intel_npu/src/backend/src/zero_pipeline.cpp
index ff2c35e05fb..87d657db9e5 100644
--- a/src/plugins/intel_npu/src/backend/src/zero_pipeline.cpp
+++ b/src/plugins/intel_npu/src/backend/src/zero_pipeline.cpp
@@ -140,18 +140,11 @@ std::vector<ov::ProfilingInfo> Pipeline::get_profiling_info() const {
_logger.debug("get_profiling_info - completed with _npu_profiling->getNpuInferStatistics()");
return _npu_profiling->getNpuInferStatistics();
}
+
/// PROFILING_TYPE = MODEL or undefined = fallback to model profiling
- if (_config.get<COMPILER_TYPE>() == ov::intel_npu::CompilerType::DRIVER) {
- _logger.debug("get_profiling_info - completed with _profiling_query->getLayerStatistics()");
- return _profiling_query->getLayerStatistics();
- } else if (_config.get<COMPILER_TYPE>() == ov::intel_npu::CompilerType::PLUGIN) {
- // For plugin compiler retrieve raw profiling data from backend and delegate
- // processing to the compiler
- _logger.debug("get_profiling_info - completed with _graph->process_profiling_output()");
- return _graph->process_profiling_output(_profiling_query->getData<uint8_t>());
- } else {
- OPENVINO_THROW("Cannot get profiling info, unknown compiler type");
- }
+ OPENVINO_ASSERT(_profiling_query != nullptr, "Profiling query is unavailable for model-level profiling");
+
+ return zeroProfiling::getModelLayerStatistics(*_graph, *_profiling_query);
}
Pipeline::Pipeline(const std::shared_ptr<ZeroInitStructsHolder>& init_structs,
diff --git a/src/plugins/intel_npu/src/common/CMakeLists.txt b/src/plugins/intel_npu/src/common/CMakeLists.txt
index d70c9112b92..c3371a2e85b 100644
--- a/src/plugins/intel_npu/src/common/CMakeLists.txt
+++ b/src/plugins/intel_npu/src/common/CMakeLists.txt
@@ -11,6 +11,7 @@ set(SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/include/intel_npu/common/icompiled_model.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/intel_npu/common/icompiler_adapter.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/intel_npu/common/igraph.hpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/include/intel_npu/common/iprofiling_decoder.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/intel_npu/common/iparser.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/intel_npu/common/itt.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/intel_npu/common/network_metadata.hpp
diff --git a/src/plugins/intel_npu/src/common/include/intel_npu/common/igraph.hpp b/src/plugins/intel_npu/src/common/include/intel_npu/common/igraph.hpp
index 061778fd9f5..1157a543f1c 100644
--- a/src/plugins/intel_npu/src/common/include/intel_npu/common/igraph.hpp
+++ b/src/plugins/intel_npu/src/common/include/intel_npu/common/igraph.hpp
@@ -13,9 +13,7 @@
#include "intel_npu/common/network_metadata.hpp"
#include "intel_npu/config/config.hpp"
#include "intel_npu/utils/zero/zero_wrappers.hpp"
-#include "openvino/runtime/itensor.hpp"
#include "openvino/runtime/profiling_info.hpp"
-#include "openvino/runtime/so_ptr.hpp"
namespace intel_npu {
@@ -49,8 +47,22 @@ public:
*/
virtual std::pair<uint64_t, std::optional<std::vector<uint64_t>>> export_blob(std::ostream& stream) const;
+ /**
+ * @brief Turns raw, driver-queried profiling bytes into per-layer records.
+ * @note Throws if this graph has no compiler-specific decoder, if the compiled blob it needs is
+ * unavailable, or if the decoder itself fails to decode. Check has_profiling_decoder() first to
+ * distinguish the expected "no decoder" case (fall back to driver layer statistics) from the other
+ * two, which indicate a real error.
+ */
virtual std::vector<ov::ProfilingInfo> process_profiling_output(const std::vector<uint8_t>& profData) const;
+ /**
+ * @brief Whether this graph can decode raw profiling bytes via process_profiling_output().
+ * @note Non-throwing, so callers can pick the driver's own layer statistics up front instead of
+ * relying on a catch block to detect the "no decoder" case.
+ */
+ virtual bool has_profiling_decoder() const;
+
virtual void set_argument_value(uint32_t id, const void* data) const;
virtual void set_argument_value_with_strides(uint32_t id,
const void* data,
diff --git a/src/plugins/intel_npu/src/common/include/intel_npu/common/iprofiling_decoder.hpp b/src/plugins/intel_npu/src/common/include/intel_npu/common/iprofiling_decoder.hpp
new file mode 100644
index 00000000000..2659989bb16
--- /dev/null
+++ b/src/plugins/intel_npu/src/common/include/intel_npu/common/iprofiling_decoder.hpp
@@ -0,0 +1,22 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include <cstdint>
+#include <vector>
+
+#include "openvino/runtime/profiling_info.hpp"
+#include "openvino/runtime/tensor.hpp"
+
+namespace intel_npu {
+
+class IProfilingDecoder {
+public:
+ virtual std::vector<ov::ProfilingInfo> decode(const std::vector<uint8_t>& profData,
+ const ov::Tensor& network) const = 0;
+ virtual ~IProfilingDecoder() = default;
+};
+
+} // namespace intel_npu
diff --git a/src/plugins/intel_npu/src/common/include/intel_npu/common/parser_factory.hpp b/src/plugins/intel_npu/src/common/include/intel_npu/common/parser_factory.hpp
index 9616f9d9336..80f06eb78e5 100644
--- a/src/plugins/intel_npu/src/common/include/intel_npu/common/parser_factory.hpp
+++ b/src/plugins/intel_npu/src/common/include/intel_npu/common/parser_factory.hpp
@@ -4,6 +4,8 @@
#pragma once
+#include <memory>
+
#include "intel_npu/common/iparser.hpp"
#include "intel_npu/utils/zero/zero_init.hpp"
#include "openvino/runtime/intel_npu/properties.hpp"
@@ -12,7 +14,8 @@ namespace intel_npu {
class ParserFactory final {
public:
- std::unique_ptr<IParser> getParser(const std::shared_ptr<ZeroInitStructsHolder>& zeroInitStructs) const;
+ std::unique_ptr<IParser> getParser(const std::shared_ptr<ZeroInitStructsHolder>& zeroInitStructs,
+ bool perfCountEnabled) const;
};
} // namespace intel_npu
diff --git a/src/plugins/intel_npu/src/common/src/igraph.cpp b/src/plugins/intel_npu/src/common/src/igraph.cpp
index 225c3614d61..f9c77043491 100644
--- a/src/plugins/intel_npu/src/common/src/igraph.cpp
+++ b/src/plugins/intel_npu/src/common/src/igraph.cpp
@@ -16,6 +16,10 @@ std::vector<ov::ProfilingInfo> IGraph::process_profiling_output(const std::vecto
OPENVINO_THROW("process_profiling_output not implemented");
}
+bool IGraph::has_profiling_decoder() const {
+ return false;
+}
+
void IGraph::set_argument_value(uint32_t, const void*) const {
OPENVINO_THROW("set_argument_value not implemented");
}
diff --git a/src/plugins/intel_npu/src/compiler_adapter/CMakeLists.txt b/src/plugins/intel_npu/src/compiler_adapter/CMakeLists.txt
index 5267759a9aa..10f9bb0c40b 100644
--- a/src/plugins/intel_npu/src/compiler_adapter/CMakeLists.txt
+++ b/src/plugins/intel_npu/src/compiler_adapter/CMakeLists.txt
@@ -15,6 +15,8 @@ set(SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/include/model_serializer.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/parser.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/plugin_compiler_adapter.hpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/include/vcl_error_utils.hpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/include/vcl_profiling_decoder.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/vcl_version_utils.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/weightless_graph.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/weightless_utils.hpp
@@ -32,6 +34,8 @@ set(SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/parser_factory.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/plugin_compiler_adapter.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/precomp.hpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/vcl_error_utils.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/vcl_profiling_decoder.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/weightless_graph.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/weightless_utils.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/xml_serializer.cpp
@@ -53,6 +57,7 @@ target_include_directories(${TARGET_NAME}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
PRIVATE
+ ${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/backend/include
$<TARGET_PROPERTY:openvino_npu_vm_utils,INTERFACE_INCLUDE_DIRECTORIES>
)
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 bddcb8d4d53..0314429e1ea 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
@@ -19,7 +19,6 @@
#include "openvino/core/except.hpp"
#include "openvino/core/model.hpp"
#include "openvino/runtime/common.hpp"
-#include "openvino/runtime/profiling_info.hpp"
#include "openvino/runtime/tensor.hpp"
namespace intel_npu {
@@ -32,7 +31,7 @@ public:
* @param optionSupportCache The cache used for storing the compiler's option support answers, already bound to
* this compiler's cache key. May be disabled, in which case the compiler is queried every time.
*/
- VCLCompilerImpl(std::shared_ptr<const VCLFunctionTable> functions,
+ VCLCompilerImpl(const std::shared_ptr<const VCLFunctionTable>& functions,
const std::optional<IDevice::DeviceProperties>& deviceProperties = std::nullopt,
ScopedOptionSupportCache optionSupportCache = {});
~VCLCompilerImpl() override;
@@ -92,9 +91,6 @@ public:
*/
uint32_t get_version() const override;
- std::vector<ov::ProfilingInfo> process_profiling_output(const std::vector<uint8_t>& profData,
- const std::vector<uint8_t>& network) const override;
-
/**
* @brief Returns the compiler supported options list
* @note The result is stored in the option support cache, if one was provided, so that subsequent
@@ -136,18 +132,4 @@ private:
Logger _logger;
};
-/**
- * @brief Loads the VCL compiler library and returns a compiler dispatching into it.
- *
- * 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.
- */
-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/graph.hpp b/src/plugins/intel_npu/src/compiler_adapter/include/graph.hpp
index a58f52e77c3..99a8e6db3af 100644
--- a/src/plugins/intel_npu/src/compiler_adapter/include/graph.hpp
+++ b/src/plugins/intel_npu/src/compiler_adapter/include/graph.hpp
@@ -11,9 +11,9 @@
#include <mutex>
#include "intel_npu/common/igraph.hpp"
+#include "intel_npu/common/iprofiling_decoder.hpp"
#include "intel_npu/utils/zero/zero_init.hpp"
#include "intel_npu/utils/zero/zero_wrappers.hpp"
-#include "openvino/runtime/so_ptr.hpp"
#include "ze_graph_ext_wrappers.hpp"
namespace intel_npu {
@@ -26,12 +26,15 @@ public:
NetworkMetadata metadata,
std::optional<ov::Tensor> blob,
const std::optional<std::string>& compatibilityDescriptor = std::nullopt,
- const bool blobIsPersistent = false);
+ const bool blobIsPersistent = false,
+ const std::shared_ptr<IProfilingDecoder>& profilingDecoder = nullptr);
std::pair<uint64_t, std::optional<std::vector<uint64_t>>> export_blob(std::ostream& stream) const override;
std::vector<ov::ProfilingInfo> process_profiling_output(const std::vector<uint8_t>& profData) const override;
+ bool has_profiling_decoder() const override;
+
void set_argument_value(uint32_t id, const void* data) const override;
void set_argument_value_with_strides(uint32_t id,
const void* data,
@@ -90,6 +93,8 @@ protected:
std::optional<ov::Tensor> _blob;
std::optional<std::string> _compatibilityDescriptor;
+ std::shared_ptr<IProfilingDecoder> _profilingDecoder;
+
// In the case of the import path, the blob is released after graph initialization so it can not be any longer
// exported
bool _blobIsReleased = false;
diff --git a/src/plugins/intel_npu/src/compiler_adapter/include/ivcl_compiler.hpp b/src/plugins/intel_npu/src/compiler_adapter/include/ivcl_compiler.hpp
index 0d2bee85f06..fd7d441ecec 100644
--- a/src/plugins/intel_npu/src/compiler_adapter/include/ivcl_compiler.hpp
+++ b/src/plugins/intel_npu/src/compiler_adapter/include/ivcl_compiler.hpp
@@ -14,7 +14,6 @@
#include "intel_npu/config/config.hpp"
#include "openvino/core/model.hpp"
#include "openvino/runtime/common.hpp"
-#include "openvino/runtime/profiling_info.hpp"
#include "openvino/runtime/tensor.hpp"
namespace intel_npu {
@@ -79,12 +78,6 @@ public:
*/
virtual bool is_option_supported(const std::string& option,
const std::optional<std::string>& optValue = std::nullopt) const = 0;
-
- /**
- * @brief Decodes raw profiling output produced by a run of the given network.
- */
- virtual std::vector<ov::ProfilingInfo> process_profiling_output(const std::vector<uint8_t>& profData,
- const std::vector<uint8_t>& network) const = 0;
};
} // namespace intel_npu
diff --git a/src/plugins/intel_npu/src/compiler_adapter/include/parser.hpp b/src/plugins/intel_npu/src/compiler_adapter/include/parser.hpp
index e17541a1184..79f42eb7eaf 100644
--- a/src/plugins/intel_npu/src/compiler_adapter/include/parser.hpp
+++ b/src/plugins/intel_npu/src/compiler_adapter/include/parser.hpp
@@ -6,7 +6,10 @@
#pragma once
+#include <optional>
+
#include "intel_npu/common/iparser.hpp"
+#include "intel_npu/common/iprofiling_decoder.hpp"
#include "intel_npu/utils/logger/logger.hpp"
#include "intel_npu/utils/zero/zero_init.hpp"
#include "openvino/core/model.hpp"
@@ -16,7 +19,8 @@ namespace intel_npu {
class Parser final : public IParser {
public:
- Parser(const std::shared_ptr<ZeroInitStructsHolder>& zeroInitStruct);
+ Parser(const std::shared_ptr<ZeroInitStructsHolder>& zeroInitStruct,
+ const std::shared_ptr<IProfilingDecoder>& profilingDecoder = nullptr);
std::shared_ptr<IGraph> parse(const ov::Tensor& mainBlob,
const Config& config,
@@ -30,6 +34,7 @@ public:
private:
std::shared_ptr<ZeroInitStructsHolder> _zeroInitStruct;
std::shared_ptr<ZeGraphExtWrappers> _zeGraphExt;
+ std::shared_ptr<IProfilingDecoder> _profilingDecoder;
Logger _logger;
};
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 debffe7730f..61dcea04fce 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
@@ -10,6 +10,7 @@
#include <optional>
#include "intel_npu/common/icompiler_adapter.hpp"
+#include "intel_npu/common/iprofiling_decoder.hpp"
#include "intel_npu/common/npu.hpp"
#include "intel_npu/utils/logger/logger.hpp"
#include "intel_npu/utils/zero/zero_init.hpp"
@@ -23,15 +24,16 @@ public:
/**
* @brief Adapts an already-constructed compiler.
*
- * The adapter never loads a compiler itself; composition is the caller's job. See
- * makeVCLCompiler() for the compiler-in-plugin.
+ * The adapter never loads or constructs a compiler itself; composition is the caller's job.
*
* @param zeroInitStruct Pass null to construct without a Level Zero driver; the adapter then
* produces export-only graphs with no runtime metadata.
* @param compiler The compiler-in-plugin to adapt; must be non-null.
+ * @param profilingDecoder The profiling decoder to hand to every compiled graph; may be empty.
*/
PluginCompilerAdapter(const std::shared_ptr<ZeroInitStructsHolder>& zeroInitStruct,
- std::shared_ptr<IVCLCompiler> compiler);
+ const std::shared_ptr<IVCLCompiler>& compiler,
+ const std::shared_ptr<IProfilingDecoder>& profilingDecoder = nullptr);
std::shared_ptr<IGraph> compile(const std::shared_ptr<const ov::Model>& model,
const Config& config,
@@ -54,6 +56,7 @@ private:
std::shared_ptr<ZeroInitStructsHolder> _zeroInitStruct;
std::shared_ptr<ZeGraphExtWrappers> _zeGraphExt;
std::shared_ptr<IVCLCompiler> _compiler;
+ std::shared_ptr<IProfilingDecoder> _profilingDecoder;
Logger _logger;
};
diff --git a/src/plugins/intel_npu/src/compiler_adapter/include/vcl_error_utils.hpp b/src/plugins/intel_npu/src/compiler_adapter/include/vcl_error_utils.hpp
new file mode 100644
index 00000000000..a010ca97d70
--- /dev/null
+++ b/src/plugins/intel_npu/src/compiler_adapter/include/vcl_error_utils.hpp
@@ -0,0 +1,39 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include <string>
+
+#include "intel_npu/utils/vcl/vcl_api.hpp"
+#include "openvino/core/except.hpp"
+
+namespace intel_npu {
+
+/**
+ * @brief Retrieves the latest VCL error log associated with the given log handle.
+ * @note Shared by every VCL caller (compiler, profiling decoder) so the log-retrieval protocol lives in one place.
+ */
+std::string getLatestVCLLog(const VCLFunctionTable& functions, vcl_log_handle_t logHandle);
+
+} // namespace intel_npu
+
+/**
+ * @brief Throws with the VCL error log appended when `ret` is not VCL_RESULT_SUCCESS.
+ * @param functions The function table to fetch the error log through, passed explicitly rather than
+ * captured from the enclosing scope so the macro is usable from free functions and member functions alike.
+ */
+#define THROW_ON_FAIL_FOR_VCL(functions, step, ret, logHandle) \
+ do { \
+ const vcl_result_t vclResult_ = (ret); \
+ if (vclResult_ != VCL_RESULT_SUCCESS) { \
+ OPENVINO_THROW("Failed to call VCL API : ", \
+ step, \
+ " result: 0x", \
+ std::hex, \
+ vclResult_, \
+ " - ", \
+ ::intel_npu::getLatestVCLLog((functions), logHandle)); \
+ } \
+ } while (0)
diff --git a/src/plugins/intel_npu/src/compiler_adapter/include/vcl_profiling_decoder.hpp b/src/plugins/intel_npu/src/compiler_adapter/include/vcl_profiling_decoder.hpp
new file mode 100644
index 00000000000..a4a776ff9e3
--- /dev/null
+++ b/src/plugins/intel_npu/src/compiler_adapter/include/vcl_profiling_decoder.hpp
@@ -0,0 +1,35 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include <memory>
+#include <vector>
+
+#include "intel_npu/common/iprofiling_decoder.hpp"
+#include "intel_npu/utils/logger/logger.hpp"
+#include "intel_npu/utils/vcl/vcl_api.hpp"
+
+namespace intel_npu {
+
+/**
+ * @brief Decodes VCL profiling output using only the VCL profiling entry points.
+ */
+class VCLProfilingDecoder final : public IProfilingDecoder {
+public:
+ /**
+ * @param functions A shared pointer to the VCL function table. Must expose the profiling entry points.
+ */
+ explicit VCLProfilingDecoder(const std::shared_ptr<const VCLFunctionTable>& functions);
+
+ std::vector<ov::ProfilingInfo> decode(const std::vector<uint8_t>& profData,
+ const ov::Tensor& network) const override;
+
+private:
+ std::shared_ptr<const VCLFunctionTable> _functions;
+
+ Logger _logger;
+};
+
+} // namespace intel_npu
diff --git a/src/plugins/intel_npu/src/compiler_adapter/include/weightless_graph.hpp b/src/plugins/intel_npu/src/compiler_adapter/include/weightless_graph.hpp
index b92141946de..9ae6add1930 100644
--- a/src/plugins/intel_npu/src/compiler_adapter/include/weightless_graph.hpp
+++ b/src/plugins/intel_npu/src/compiler_adapter/include/weightless_graph.hpp
@@ -9,6 +9,7 @@
#include <unordered_map>
#include "graph.hpp"
+#include "intel_npu/common/iprofiling_decoder.hpp"
#include "intel_npu/utils/zero/zero_tensor.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/runtime/iremote_context.hpp"
@@ -41,7 +42,8 @@ public:
std::shared_ptr<const ov::Model>,
std::pair<std::string, std::shared_ptr<ov::ICore>>>&& weightsSource,
const bool blobIsPersistent = false,
- const std::optional<std::string>& compatibilityDescriptor = std::nullopt);
+ const std::optional<std::string>& compatibilityDescriptor = std::nullopt,
+ const std::shared_ptr<IProfilingDecoder>& profilingDecoder = nullptr);
/**
* @brief The main schedule along with the weights initialization ones are exported.
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 63cf54fba2f..a46d2c14772 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
@@ -7,24 +7,28 @@
#include "compiler_impl.hpp"
#include "driver_compiler_adapter.hpp"
#include "intel_npu/npu_private_properties.hpp"
+#include "intel_npu/utils/vcl/vcl_api.hpp"
+#include "openvino/core/except.hpp"
#include "plugin_compiler_adapter.hpp"
+#include "vcl_profiling_decoder.hpp"
namespace intel_npu {
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.
-std::shared_ptr<IVCLCompiler> makePluginCompiler(const std::shared_ptr<IDevice>& device,
+
+std::shared_ptr<IVCLCompiler> makePluginCompiler(std::shared_ptr<const VCLFunctionTable>& functions,
+ const std::shared_ptr<IDevice>& device,
const std::shared_ptr<OptionSupportCache>& optionSupportCache) {
- try {
- return makeVCLCompiler(
- device ? std::optional<IDevice::DeviceProperties>{device->getDeviceProperties()} : std::nullopt,
- optionSupportCache);
- } catch (const std::exception& vclException) {
- OPENVINO_THROW("VCL compiler loading failed, aborting. Error: ", vclException.what());
- }
+ auto vclLoader = VCLLoader::getInstance();
+ OPENVINO_ASSERT(vclLoader != nullptr, "VCL loader is nullptr");
+ functions = vclLoader->sharedFunctions();
+ return std::make_shared<VCLCompilerImpl>(
+ functions,
+ device ? std::optional<IDevice::DeviceProperties>{device->getDeviceProperties()} : std::nullopt,
+ ScopedOptionSupportCache{optionSupportCache,
+ static_cast<OptionSupportCache::CacheKey>(ov::intel_npu::CompilerType::PLUGIN)});
}
+
} // namespace
std::unique_ptr<ICompilerAdapter> CompilerAdapterFactory::getCompiler(
@@ -44,8 +48,25 @@ std::unique_ptr<ICompilerAdapter> CompilerAdapterFactory::getCompiler(
}
if (compilerType == ov::intel_npu::CompilerType::PLUGIN) {
+ std::shared_ptr<const VCLFunctionTable> functions;
+ std::shared_ptr<IVCLCompiler> compiler;
+ try {
+ compiler = makePluginCompiler(functions, device, optionSupportCache);
+ } catch (const std::exception& vclException) {
+ OPENVINO_THROW("VCL compiler loading failed, aborting. Error: ", vclException.what());
+ }
+
+ std::shared_ptr<IProfilingDecoder> profilingDecoder;
+ try {
+ profilingDecoder = std::make_shared<VCLProfilingDecoder>(functions);
+ } catch (const std::exception& ex) {
+ Logger::global().warning("Failed to create the VCL profiling decoder for plugin compilation: %s",
+ ex.what());
+ }
+
return std::make_unique<PluginCompilerAdapter>(engineBackend ? engineBackend->getInitStructs() : nullptr,
- makePluginCompiler(device, optionSupportCache));
+ compiler,
+ profilingDecoder);
}
if (compilerType == ov::intel_npu::CompilerType::DRIVER) {
@@ -113,12 +134,10 @@ CompilerAdapterFactory::resolvePreferPluginCompiler(const ov::SoPtr<IEngineBacke
}
if (pluginCompilerPresence == PluginCompilerPresence::UNKNOWN) {
+ std::shared_ptr<IVCLCompiler> pluginCompiler;
+ std::shared_ptr<const VCLFunctionTable> functions;
try {
- auto pluginCompiler =
- std::make_unique<PluginCompilerAdapter>(engineBackend ? engineBackend->getInitStructs() : nullptr,
- makePluginCompiler(device, optionSupportCache));
- _pluginCompilerPresence.store(PluginCompilerPresence::PRESENT, std::memory_order_release);
- return {std::move(pluginCompiler), ov::intel_npu::CompilerType::PLUGIN};
+ pluginCompiler = makePluginCompiler(functions, device, optionSupportCache);
} catch (...) {
_pluginCompilerPresence.store(PluginCompilerPresence::ABSENT, std::memory_order_release);
if (onlineCompilation) {
@@ -126,6 +145,21 @@ CompilerAdapterFactory::resolvePreferPluginCompiler(const ov::SoPtr<IEngineBacke
}
OPENVINO_THROW("Failed to create plugin compiler for offline or cross compilation.");
}
+
+ _pluginCompilerPresence.store(PluginCompilerPresence::PRESENT, std::memory_order_release);
+ std::shared_ptr<IProfilingDecoder> profilingDecoder;
+ try {
+ profilingDecoder = std::make_shared<VCLProfilingDecoder>(functions);
+ } catch (const std::exception& ex) {
+ Logger::global().warning("Failed to create the VCL profiling decoder for plugin compilation: %s",
+ ex.what());
+ }
+
+ auto pluginAdapter =
+ std::make_unique<PluginCompilerAdapter>(engineBackend ? engineBackend->getInitStructs() : nullptr,
+ pluginCompiler,
+ profilingDecoder);
+ return {std::move(pluginAdapter), ov::intel_npu::CompilerType::PLUGIN};
}
// Should not reach here, but throw in case of unexpected state.
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 5683987a237..6f4648afc8f 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
@@ -6,7 +6,6 @@
#include <algorithm>
#include <cinttypes>
-#include <cstring>
#include <limits>
#include <mutex>
#include <sstream>
@@ -16,7 +15,6 @@
#include "intel_npu/config/options.hpp"
#include "intel_npu/npu_private_properties.hpp"
-#include "intel_npu/profiling.hpp"
#include "intel_npu/utils/utils.hpp"
#include "intel_npu/utils/vcl/vcl_allocator.hpp"
#include "intel_npu/utils/vcl/vcl_api.hpp"
@@ -24,6 +22,7 @@
#include "openvino/runtime/make_tensor.hpp"
#include "openvino/util/file_util.hpp"
#include "openvino/util/shared_object.hpp"
+#include "vcl_error_utils.hpp"
#include "vcl_version_utils.hpp"
#include "weightless_utils.hpp"
#include "ze_graph_ext_wrappers.hpp"
@@ -34,42 +33,6 @@ using vcl_version_utils::checkVclVersion;
using vcl_version_utils::getUsedVclVersion;
using vcl_version_utils::UsedVersion;
-static inline std::string getLatestVCLLog(const VCLFunctionTable& functions, vcl_log_handle_t logHandle) {
- Logger _logger("VCLAPI", Logger::global().level());
- _logger.debug("getLatestVCLLog start");
-
- vcl_version_info_t compilerVersion;
- vcl_version_info_t profilingVersion;
- vcl_result_t ret = functions.vclGetVersion(&compilerVersion, &profilingVersion);
-
- if (ret != VCL_RESULT_SUCCESS || compilerVersion.major < 3) {
- _logger.warning("Failed to get VCL version: 0x%x", ret);
- return "Can not get VCL log, VCL version is too old!";
- }
-
- // Get log size
- size_t size = 0;
- // Null graph handle to get error log
- ret = functions.vclLogHandleGetString(logHandle, &size, nullptr);
- if (VCL_RESULT_SUCCESS != ret) {
- return "Failed to get size of latest VCL log";
- }
-
- if (size <= 0) {
- return "No error stored in VCL when error detected";
- }
-
- // Get log content
- std::string logContent{};
- logContent.resize(size);
- ret = functions.vclLogHandleGetString(logHandle, &size, logContent.data());
- if (VCL_RESULT_SUCCESS != ret) {
- return "Size of latest error log > 0, failed to get content";
- }
- _logger.debug("getLatestBuildError end");
- return logContent;
-}
-
static std::optional<std::string> getVCLCompatibilityString(const VCLFunctionTable& functions,
vcl_executable_handle_t executable,
vcl_log_handle_t logHandle) {
@@ -111,29 +74,10 @@ static std::optional<std::string> getVCLCompatibilityString(const VCLFunctionTab
return compatibilityString;
}
-/**
- * @brief Throws with the VCL error log appended when `ret` is not VCL_RESULT_SUCCESS.
- * @param functions The function table to fetch the error log through, passed explicitly rather than
- * captured from the enclosing scope so the macro is usable outside VCLCompilerImpl members.
- */
-#define THROW_ON_FAIL_FOR_VCL(functions, step, ret, logHandle) \
- do { \
- const vcl_result_t vclResult_ = (ret); \
- if (vclResult_ != VCL_RESULT_SUCCESS) { \
- OPENVINO_THROW("Failed to call VCL API : ", \
- step, \
- " result: 0x", \
- std::hex, \
- vclResult_, \
- " - ", \
- getLatestVCLLog((functions), logHandle)); \
- } \
- } while (0)
-
-VCLCompilerImpl::VCLCompilerImpl(std::shared_ptr<const VCLFunctionTable> functions,
+VCLCompilerImpl::VCLCompilerImpl(const std::shared_ptr<const VCLFunctionTable>& functions,
const std::optional<IDevice::DeviceProperties>& deviceProperties,
ScopedOptionSupportCache optionSupportCache)
- : _functions(std::move(functions)),
+ : _functions(functions),
_logHandle(nullptr),
_optionSupportCache(std::move(optionSupportCache)),
_logger("VCLCompilerImpl", Logger::global().level()) {
@@ -490,56 +434,6 @@ std::pair<ov::Tensor, std::optional<std::string>> VCLCompilerImpl::compileWsIter
return compile(model, updatedConfig, true);
}
-std::vector<ov::ProfilingInfo> VCLCompilerImpl::process_profiling_output(const std::vector<uint8_t>& profData,
- const std::vector<uint8_t>& network) const {
- _logger.debug("process_profiling_output start");
-
- vcl_profiling_handle_t profilingHandle;
- vcl_profiling_input_t profilingInput = {network.data(), network.size(), profData.data(), profData.size()};
- vcl_log_handle_t logHandle;
- THROW_ON_FAIL_FOR_VCL(*_functions,
- "vclProfilingCreate",
- _functions->vclProfilingCreate(&profilingInput, &profilingHandle, &logHandle),
- nullptr);
-
- vcl_profiling_properties_t profProperties;
- THROW_ON_FAIL_FOR_VCL(*_functions,
- "vclProfilingGetProperties",
- _functions->vclProfilingGetProperties(profilingHandle, &profProperties),
- logHandle);
-
- _logger.info("VCL Profiling Properties: Version: %d.%d",
- profProperties.version.major,
- profProperties.version.minor);
-
- // We only use layer level info
- vcl_profiling_request_type_t request = VCL_PROFILING_LAYER_LEVEL;
-
- vcl_profiling_output_t profOutput;
- profOutput.data = NULL;
- THROW_ON_FAIL_FOR_VCL(*_functions,
- "vclGetDecodedProfilingBuffer",
- _functions->vclGetDecodedProfilingBuffer(profilingHandle, request, &profOutput),
- logHandle);
- if (profOutput.data == NULL) {
- OPENVINO_THROW("Failed to get VCL profiling output");
- }
-
- std::vector<ze_profiling_layer_info> layerInfo(profOutput.size / sizeof(ze_profiling_layer_info));
- if (profOutput.size > 0) {
- _logger.debug("VCL profiling output size: %d", profOutput.size);
- std::memcpy(layerInfo.data(), profOutput.data, profOutput.size);
- }
-
- THROW_ON_FAIL_FOR_VCL(*_functions,
- "vclProfilingDestroy",
- _functions->vclProfilingDestroy(profilingHandle),
- logHandle);
-
- // Return processed profiling info
- return intel_npu::profiling::convertLayersToIeProfilingInfo(layerInfo);
-}
-
uint32_t VCLCompilerImpl::get_version() const {
return ZE_MAKE_VERSION(_compilerProperties.version.major, _compilerProperties.version.minor);
}
@@ -695,21 +589,4 @@ bool VCLCompilerImpl::is_option_supported(const std::string& option, const std::
return supported;
}
-namespace {
-// The cache key under which the compiler-in-plugin's option-support answers are stored.
-constexpr OptionSupportCache::CacheKey pluginOptionSupportKey =
- static_cast<OptionSupportCache::CacheKey>(ov::intel_npu::CompilerType::PLUGIN);
-} // namespace
-
-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");
-
- // 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/driver_compiler_adapter.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/driver_compiler_adapter.cpp
index 558ba301943..d2d1fe7fe0c 100644
--- a/src/plugins/intel_npu/src/compiler_adapter/src/driver_compiler_adapter.cpp
+++ b/src/plugins/intel_npu/src/compiler_adapter/src/driver_compiler_adapter.cpp
@@ -11,6 +11,7 @@
#include <vector>
#include "graph.hpp"
+#include "intel_npu/common/iprofiling_decoder.hpp"
#include "intel_npu/common/itt.hpp"
#include "intel_npu/common/option_support_cache.hpp"
#include "intel_npu/config/config.hpp"
@@ -143,7 +144,9 @@ std::shared_ptr<IGraph> DriverCompilerAdapter::compile(const std::shared_ptr<con
graphDesc,
std::move(networkMeta),
/* blob = */ std::nullopt,
- get_compatibility_descriptor(graphDesc._handle));
+ get_compatibility_descriptor(graphDesc._handle),
+ false,
+ /* profilingDecoder = */ nullptr);
}
std::shared_ptr<IGraph> DriverCompilerAdapter::compileWS(std::shared_ptr<ov::Model>&& model,
@@ -265,7 +268,8 @@ std::shared_ptr<IGraph> DriverCompilerAdapter::compileWS(std::shared_ptr<ov::Mod
/* initBlobs = */ std::nullopt,
std::move(model),
/* persistentBlob = */ false,
- get_compatibility_descriptor(mainGraphHandle._handle));
+ get_compatibility_descriptor(mainGraphHandle._handle),
+ /* profilingDecoder = */ nullptr);
}
ov::SupportedOpsMap DriverCompilerAdapter::query(const std::shared_ptr<const ov::Model>& model,
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 ea9f71b1758..6db9f66dc51 100644
--- a/src/plugins/intel_npu/src/compiler_adapter/src/graph.cpp
+++ b/src/plugins/intel_npu/src/compiler_adapter/src/graph.cpp
@@ -6,13 +6,10 @@
#include <iterator>
-#include "compiler_impl.hpp"
#include "intel_npu/config/options.hpp"
#include "intel_npu/utils/utils.hpp"
-#include "intel_npu/utils/vcl/vcl_api.hpp"
#include "intel_npu/utils/zero/zero_cmd_queue_pool.hpp"
#include "intel_npu/utils/zero/zero_utils.hpp"
-#include "openvino/runtime/make_tensor.hpp"
namespace intel_npu {
@@ -22,7 +19,8 @@ Graph::Graph(const std::shared_ptr<ZeGraphExtWrappers>& zeGraphExt,
NetworkMetadata metadata,
std::optional<ov::Tensor> blob,
const std::optional<std::string>& compatibilityDescriptor,
- const bool blobIsPersistent)
+ const bool blobIsPersistent,
+ const std::shared_ptr<IProfilingDecoder>& profilingDecoder)
: IGraph(),
_zeGraphExt(zeGraphExt),
_zeroInitStruct(zeroInitStruct),
@@ -30,6 +28,7 @@ Graph::Graph(const std::shared_ptr<ZeGraphExtWrappers>& zeGraphExt,
_metadata(std::move(metadata)),
_blob(std::move(blob)),
_compatibilityDescriptor(compatibilityDescriptor),
+ _profilingDecoder(profilingDecoder),
_blobIsPersistent(blobIsPersistent),
_logger("Graph", Logger::global().level()) {}
@@ -157,15 +156,13 @@ 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 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");
-
- std::vector<uint8_t> blob(_blob->get_byte_size());
- blob.assign(reinterpret_cast<const uint8_t*>(_blob->data()),
- reinterpret_cast<const uint8_t*>(_blob->data()) + _blob->get_byte_size());
- return compiler->process_profiling_output(profData, blob);
+ OPENVINO_ASSERT(_profilingDecoder != nullptr, "No VCL profiling decoder is available for this graph");
+ OPENVINO_ASSERT(_blob.has_value(), "VCL profiling decoder requires the compiled network blob");
+ return _profilingDecoder->decode(profData, _blob.value());
+}
+
+bool Graph::has_profiling_decoder() const {
+ return _profilingDecoder != nullptr;
}
void Graph::set_argument_value(uint32_t id, const void* data) const {
diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/parser.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/parser.cpp
index 2b72fed272c..07d99d10527 100644
--- a/src/plugins/intel_npu/src/compiler_adapter/src/parser.cpp
+++ b/src/plugins/intel_npu/src/compiler_adapter/src/parser.cpp
@@ -14,8 +14,10 @@
namespace intel_npu {
-Parser::Parser(const std::shared_ptr<ZeroInitStructsHolder>& zeroInitStruct)
+Parser::Parser(const std::shared_ptr<ZeroInitStructsHolder>& zeroInitStruct,
+ const std::shared_ptr<IProfilingDecoder>& profilingDecoder)
: _zeroInitStruct(zeroInitStruct),
+ _profilingDecoder(profilingDecoder),
_logger("Parser", Logger::global().level()) {
_logger.info("initialize Parser start");
@@ -73,7 +75,8 @@ std::shared_ptr<IGraph> Parser::parse(
std::move(mainNetworkMetadata),
mainBlob,
compatibilityDescriptor,
- blobIsPersistent);
+ blobIsPersistent,
+ _profilingDecoder);
}
// The presence of init schedules means weights separation has been enabled at compilation time. Use a specific
@@ -103,7 +106,8 @@ std::shared_ptr<IGraph> Parser::parse(
initBlobs,
std::move(weightsSource),
blobIsPersistent,
- compatibilityDescriptor);
+ compatibilityDescriptor,
+ _profilingDecoder);
}
} // namespace intel_npu
diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/parser_factory.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/parser_factory.cpp
index 77597670d46..c027c235fa5 100644
--- a/src/plugins/intel_npu/src/compiler_adapter/src/parser_factory.cpp
+++ b/src/plugins/intel_npu/src/compiler_adapter/src/parser_factory.cpp
@@ -4,16 +4,32 @@
#include "intel_npu/common/parser_factory.hpp"
+#include <exception>
+
+#include "intel_npu/utils/vcl/vcl_api.hpp"
#include "parser.hpp"
+#include "vcl_profiling_decoder.hpp"
namespace intel_npu {
-std::unique_ptr<IParser> ParserFactory::getParser(const std::shared_ptr<ZeroInitStructsHolder>& zeroInitStructs) const {
+std::unique_ptr<IParser> ParserFactory::getParser(const std::shared_ptr<ZeroInitStructsHolder>& zeroInitStructs,
+ bool perfCountEnabled) const {
OPENVINO_ASSERT(
zeroInitStructs != nullptr,
"Could not find an NPU device. The driver compiler requires a valid device to be present in the system.");
- return std::make_unique<Parser>(zeroInitStructs);
+ std::shared_ptr<IProfilingDecoder> profilingDecoder;
+ if (perfCountEnabled) {
+ try {
+ auto vclLoader = VCLLoader::getInstance();
+ OPENVINO_ASSERT(vclLoader != nullptr, "VCL loader is nullptr");
+ profilingDecoder = std::make_shared<VCLProfilingDecoder>(vclLoader->sharedFunctions());
+ } catch (const std::exception& ex) {
+ Logger::global().warning("Failed to create the VCL profiling decoder for model import: %s", ex.what());
+ }
+ }
+
+ return std::make_unique<Parser>(zeroInitStructs, profilingDecoder);
}
} // namespace intel_npu
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 c0767dd8dce..421bb7797b8 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
@@ -9,26 +9,24 @@
#include "dynamic_graph.hpp"
#include "graph.hpp"
-#include "intel_npu/common/device_helpers.hpp"
#include "intel_npu/common/itt.hpp"
#include "intel_npu/config/options.hpp"
#include "intel_npu/npu_private_properties.hpp"
#include "intel_npu/utils/logger/logger.hpp"
-#include "intel_npu/utils/utils.hpp"
#include "intel_npu/utils/vm/npu_vm_runtime_api.hpp"
-#include "intel_npu/utils/zero/zero_result.hpp"
#include "mem_usage.hpp"
#include "openvino/core/model.hpp"
-#include "openvino/runtime/make_tensor.hpp"
#include "weightless_graph.hpp"
#include "weightless_utils.hpp"
namespace intel_npu {
PluginCompilerAdapter::PluginCompilerAdapter(const std::shared_ptr<ZeroInitStructsHolder>& zeroInitStruct,
- std::shared_ptr<IVCLCompiler> compiler)
+ const std::shared_ptr<IVCLCompiler>& compiler,
+ const std::shared_ptr<IProfilingDecoder>& profilingDecoder)
: _zeroInitStruct(zeroInitStruct),
- _compiler(std::move(compiler)),
+ _compiler(compiler),
+ _profilingDecoder(profilingDecoder),
_logger("PluginCompilerAdapter", Logger::global().level()) {
_logger.info("initialize PluginCompilerAdapter start");
@@ -57,7 +55,6 @@ std::shared_ptr<IGraph> PluginCompilerAdapter::compile(const std::shared_ptr<con
_logger.debug("compile start");
auto [tensor, compatibilityDescriptor] = _compiler->compile(model, config);
_logger.debug("compile end");
-
const auto& compilationMode = config.get<COMPILATION_MODE>();
const bool isHostCompile = compilationMode.find("HostCompile_Interpreter") != std::string::npos;
const BlobType blobType = isHostCompile ? BlobType::BYTECODE : BlobType::ELF;
@@ -97,7 +94,8 @@ std::shared_ptr<IGraph> PluginCompilerAdapter::compile(const std::shared_ptr<con
std::move(networkMeta),
std::move(tensor),
compatibilityDescriptor,
- /* persistentBlob = */ true); // exporting the blob shall be available in such a scenario
+ /* persistentBlob = */ true, // exporting the blob shall be available in such a scenario
+ _profilingDecoder);
}
std::shared_ptr<IGraph> PluginCompilerAdapter::compileWS(std::shared_ptr<ov::Model>&& model,
@@ -253,8 +251,9 @@ std::shared_ptr<IGraph> PluginCompilerAdapter::compileWS(std::shared_ptr<ov::Mod
std::move(initNetworkMetadata),
tensorsInits,
std::move(model),
- /* persistentBlob = */ true,
- compatibilityDescriptor); // exporting the blob shall be available in such a scenario
+ /* persistentBlob = */ true, // exporting the blob shall be available in such a scenario
+ compatibilityDescriptor,
+ _profilingDecoder);
}
ov::SupportedOpsMap PluginCompilerAdapter::query(const std::shared_ptr<const ov::Model>& model,
diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/vcl_error_utils.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/vcl_error_utils.cpp
new file mode 100644
index 00000000000..a3a60eeeb75
--- /dev/null
+++ b/src/plugins/intel_npu/src/compiler_adapter/src/vcl_error_utils.cpp
@@ -0,0 +1,47 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "vcl_error_utils.hpp"
+
+#include "intel_npu/utils/logger/logger.hpp"
+
+namespace intel_npu {
+
+std::string getLatestVCLLog(const VCLFunctionTable& functions, vcl_log_handle_t logHandle) {
+ Logger _logger("VCLAPI", Logger::global().level());
+ _logger.debug("getLatestVCLLog start");
+
+ vcl_version_info_t compilerVersion;
+ vcl_version_info_t profilingVersion;
+ vcl_result_t ret = functions.vclGetVersion(&compilerVersion, &profilingVersion);
+
+ if (ret != VCL_RESULT_SUCCESS || compilerVersion.major < 3) {
+ _logger.warning("Failed to get VCL version: 0x%x", ret);
+ return "Can not get VCL log, VCL version is too old!";
+ }
+
+ // Get log size
+ size_t size = 0;
+ // Null graph handle to get error log
+ ret = functions.vclLogHandleGetString(logHandle, &size, nullptr);
+ if (VCL_RESULT_SUCCESS != ret) {
+ return "Failed to get size of latest VCL log";
+ }
+
+ if (size <= 0) {
+ return "No error stored in VCL when error detected";
+ }
+
+ // Get log content
+ std::string logContent{};
+ logContent.resize(size);
+ ret = functions.vclLogHandleGetString(logHandle, &size, logContent.data());
+ if (VCL_RESULT_SUCCESS != ret) {
+ return "Size of latest error log > 0, failed to get content";
+ }
+ _logger.debug("getLatestBuildError end");
+ return logContent;
+}
+
+} // namespace intel_npu
diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/vcl_profiling_decoder.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/vcl_profiling_decoder.cpp
new file mode 100644
index 00000000000..bc73b5e09b2
--- /dev/null
+++ b/src/plugins/intel_npu/src/compiler_adapter/src/vcl_profiling_decoder.cpp
@@ -0,0 +1,97 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "vcl_profiling_decoder.hpp"
+
+#include <level_zero/ze_api.h>
+#include <ze_graph_ext.h>
+#include <ze_graph_profiling_ext.h>
+
+#include <cstring>
+#include <memory>
+#include <type_traits>
+
+#include "intel_npu/profiling.hpp"
+#include "vcl_error_utils.hpp"
+
+namespace intel_npu {
+
+VCLProfilingDecoder::VCLProfilingDecoder(const std::shared_ptr<const VCLFunctionTable>& functions)
+ : _functions(functions),
+ _logger("VCLProfilingDecoder", Logger::global().level()) {
+ OPENVINO_ASSERT(_functions != nullptr, "VCLProfilingDecoder requires a non-null VCLFunctionTable");
+ OPENVINO_ASSERT(_functions->vclGetVersion && _functions->vclLogHandleGetString && _functions->vclProfilingCreate &&
+ _functions->vclProfilingGetProperties && _functions->vclGetDecodedProfilingBuffer &&
+ _functions->vclProfilingDestroy,
+ "VCLProfilingDecoder received a VCLFunctionTable missing a required profiling entry point. "
+ "Was it populated from a VCLLoader?");
+}
+
+std::vector<ov::ProfilingInfo> VCLProfilingDecoder::decode(const std::vector<uint8_t>& profData,
+ const ov::Tensor& network) const {
+ _logger.debug("decode start");
+
+ vcl_profiling_handle_t profilingHandle;
+ vcl_profiling_input_t profilingInput = {network.data<const uint8_t>(),
+ network.get_byte_size(),
+ profData.data(),
+ profData.size()};
+ vcl_log_handle_t logHandle;
+ THROW_ON_FAIL_FOR_VCL(*_functions,
+ "vclProfilingCreate",
+ _functions->vclProfilingCreate(&profilingInput, &profilingHandle, &logHandle),
+ nullptr);
+ // Destroys the handle if a later step throws. The success path releases it and destroys it explicitly, so a
+ // destroy failure there is still reported.
+ auto profilingHandleDeleter = [functions = _functions](vcl_profiling_handle_t handle) {
+ functions->vclProfilingDestroy(handle); // best-effort: runs during stack unwinding, must not throw
+ };
+ std::unique_ptr<std::remove_pointer_t<vcl_profiling_handle_t>, decltype(profilingHandleDeleter)>
+ profilingHandleGuard(profilingHandle, profilingHandleDeleter);
+
+ vcl_profiling_properties_t profProperties;
+ THROW_ON_FAIL_FOR_VCL(*_functions,
+ "vclProfilingGetProperties",
+ _functions->vclProfilingGetProperties(profilingHandle, &profProperties),
+ logHandle);
+
+ _logger.info("VCL Profiling Properties: Version: %d.%d",
+ profProperties.version.major,
+ profProperties.version.minor);
+
+ // We only use layer level info
+ vcl_profiling_request_type_t request = VCL_PROFILING_LAYER_LEVEL;
+
+ vcl_profiling_output_t profOutput;
+ profOutput.data = NULL;
+ THROW_ON_FAIL_FOR_VCL(*_functions,
+ "vclGetDecodedProfilingBuffer",
+ _functions->vclGetDecodedProfilingBuffer(profilingHandle, request, &profOutput),
+ logHandle);
+ if (profOutput.data == NULL) {
+ OPENVINO_THROW("Failed to get VCL profiling output");
+ }
+
+ std::vector<ze_profiling_layer_info> layerInfo(profOutput.size / sizeof(ze_profiling_layer_info));
+ if (profOutput.size > 0) {
+ OPENVINO_ASSERT(profOutput.size % sizeof(ze_profiling_layer_info) == 0,
+ "Unexpected VCL profiling buffer size: ",
+ profOutput.size,
+ " bytes is not a multiple of sizeof(ze_profiling_layer_info) (",
+ sizeof(ze_profiling_layer_info),
+ ")");
+ _logger.debug("VCL profiling output size: %d", profOutput.size);
+ std::memcpy(layerInfo.data(), profOutput.data, profOutput.size);
+ }
+
+ THROW_ON_FAIL_FOR_VCL(*_functions,
+ "vclProfilingDestroy",
+ _functions->vclProfilingDestroy(profilingHandleGuard.release()),
+ logHandle);
+
+ // Return processed profiling info
+ return intel_npu::profiling::convertLayersToIeProfilingInfo(layerInfo);
+}
+
+} // namespace intel_npu
diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/weightless_graph.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/weightless_graph.cpp
index c9b7fefed1c..067ff95ad85 100644
--- a/src/plugins/intel_npu/src/compiler_adapter/src/weightless_graph.cpp
+++ b/src/plugins/intel_npu/src/compiler_adapter/src/weightless_graph.cpp
@@ -11,7 +11,6 @@
#include <queue>
#include "intel_npu/config/options.hpp"
-#include "intel_npu/prefix.hpp"
#include "intel_npu/utils/utils.hpp"
#include "intel_npu/utils/zero/zero_cmd_queue_pool.hpp"
#include "intel_npu/utils/zero/zero_utils.hpp"
@@ -264,14 +263,16 @@ WeightlessGraph::WeightlessGraph(
std::variant<std::monostate, std::shared_ptr<const ov::Model>, std::pair<std::string, std::shared_ptr<ov::ICore>>>&&
weightsSource,
const bool blobIsPersistent,
- const std::optional<std::string>& compatibilityDescriptor)
+ const std::optional<std::string>& compatibilityDescriptor,
+ const std::shared_ptr<IProfilingDecoder>& profilingDecoder)
: Graph(zeGraphExt,
zeroInitStruct,
mainGraphDesc,
std::move(mainMetadata),
std::move(mainBlob),
compatibilityDescriptor,
- blobIsPersistent),
+ blobIsPersistent,
+ profilingDecoder),
_initsGraphDesc(initGraphDesc),
_initBlobs(std::move(initBlobs)),
_initsMetadata(std::move(initMetadata)),
diff --git a/src/plugins/intel_npu/src/plugin/include/blob_format_importers.hpp b/src/plugins/intel_npu/src/plugin/include/blob_format_importers.hpp
index 689cd68cff4..a919994e1c6 100644
--- a/src/plugins/intel_npu/src/plugin/include/blob_format_importers.hpp
+++ b/src/plugins/intel_npu/src/plugin/include/blob_format_importers.hpp
@@ -45,8 +45,6 @@ public:
*
* @param backend The current backend in use, required for creating and using a parser.
* @param network_name The resulted graph object will use this network name.
- * @param device_name The name of the device. Used to update the compiler type if "perf count" was enabled via the
- * configuration.
* @param core The OV core. The weights separation feature may depend on this object to extract the original
* weights.
* @return A graph object. The type of graph depends on the content of the blob. E.g. a "weightless" graph will be
@@ -54,7 +52,6 @@ public:
*/
std::shared_ptr<IGraph> create_graph(const ov::SoPtr<IEngineBackend>& backend,
const std::string_view network_name,
- const std::string_view device_name,
const std::shared_ptr<ov::ICore>& core);
/**
diff --git a/src/plugins/intel_npu/src/plugin/src/blob_format_importers.cpp b/src/plugins/intel_npu/src/plugin/src/blob_format_importers.cpp
index 274698c19ec..231d2ff3089 100644
--- a/src/plugins/intel_npu/src/plugin/src/blob_format_importers.cpp
+++ b/src/plugins/intel_npu/src/plugin/src/blob_format_importers.cpp
@@ -4,7 +4,6 @@
#include "blob_format_importers.hpp"
-#include "intel_npu/common/compiler_adapter_factory.hpp"
#include "intel_npu/common/itt.hpp"
#include "intel_npu/common/parser_factory.hpp"
#include "intel_npu/config/options.hpp"
@@ -46,22 +45,6 @@ constexpr std::string_view NEW_PAGE_ALIGNED_BUFFER_MESSAGE =
const std::vector<size_t> CONSTANT_NODE_DUMMY_SHAPE{1};
-/**
- * @brief Special case for PERF_COUNT as it requires compiler_type detection in case it is still set to PREFER_PLUGIN
- */
-void update_compiler_type_if_perf_count(Config& config,
- const ov::SoPtr<IEngineBackend>& backend,
- const std::string_view device_name) {
- if (config.has<PERF_COUNT>() && config.get<PERF_COUNT>() &&
- config.get<COMPILER_TYPE>() == ov::intel_npu::CompilerType::PREFER_PLUGIN) {
- ov::intel_npu::CompilerType compilerType = config.get<COMPILER_TYPE>();
- CompilerAdapterFactory factory;
- (void)factory.getCompiler(backend, compilerType, device_name);
-
- config.update(ov::intel_npu::compiler_type.name(), COMPILER_TYPE::toString(compilerType));
- }
-}
-
/**
* @brief Uses the provided decryption callback to decrypt the given payload.
*/
@@ -411,7 +394,6 @@ IBlobFormatImporter::IBlobFormatImporter(const std::shared_ptr<const ov::Model>&
std::shared_ptr<IGraph> IBlobFormatImporter::create_graph(const ov::SoPtr<IEngineBackend>& backend,
const std::string_view network_name,
- const std::string_view device_name,
const std::shared_ptr<ov::ICore>& core) {
OV_ITT_TASK_CHAIN(PARSE_AND_CREATE_GRAPH, itt::domains::NPUPlugin, "IBlobFormatImporter", "create_graph");
m_logger.debug("Creating a graph");
@@ -426,12 +408,10 @@ std::shared_ptr<IGraph> IBlobFormatImporter::create_graph(const ov::SoPtr<IEngin
const std::optional<std::vector<ov::Tensor>> init_schedules = extract_init_schedules();
m_batch_size = extract_batch_size();
- update_compiler_type_if_perf_count(m_config, backend, device_name);
-
OV_ITT_TASK_NEXT(PARSE_AND_CREATE_GRAPH, "get_parser");
m_logger.trace("Creating the parser");
ParserFactory parserFactory;
- auto parser = parserFactory.getParser(backend->getInitStructs());
+ auto parser = parserFactory.getParser(backend->getInitStructs(), m_config.get<PERF_COUNT>());
std::variant<std::monostate, std::shared_ptr<const ov::Model>, std::pair<std::string, std::shared_ptr<ov::ICore>>>
weights_source;
diff --git a/src/plugins/intel_npu/src/plugin/src/plugin.cpp b/src/plugins/intel_npu/src/plugin/src/plugin.cpp
index 735dc6bb43b..e52d35d8e7f 100644
--- a/src/plugins/intel_npu/src/plugin/src/plugin.cpp
+++ b/src/plugins/intel_npu/src/plugin/src/plugin.cpp
@@ -611,10 +611,7 @@ std::shared_ptr<ov::ICompiledModel> Plugin::import_model(BlobSource& blobSource,
}
const std::shared_ptr<IGraph> graph =
- blobFormatImporter->create_graph(_backend,
- "net" + std::to_string(_compiledModelLoadCounter++),
- device->getName(),
- get_core());
+ blobFormatImporter->create_graph(_backend, "net" + std::to_string(_compiledModelLoadCounter++), get_core());
return std::make_shared<CompiledModel>(blobFormatImporter->create_dummy_model(),
shared_from_this(),
diff --git a/src/plugins/intel_npu/tests/functional/internal/backend/zero_infer_request_tests.cpp b/src/plugins/intel_npu/tests/functional/internal/backend/zero_infer_request_tests.cpp
index 23972353fc8..427d49c2b17 100644
--- a/src/plugins/intel_npu/tests/functional/internal/backend/zero_infer_request_tests.cpp
+++ b/src/plugins/intel_npu/tests/functional/internal/backend/zero_infer_request_tests.cpp
@@ -18,6 +18,7 @@
#include "intel_npu/common/device_helpers.hpp"
#include "intel_npu/config/config.hpp"
#include "intel_npu/utils/utils.hpp"
+#include "intel_npu/utils/vcl/vcl_api.hpp"
#include "openvino/op/add.hpp"
#include "openvino/op/less_eq.hpp"
#include "openvino/op/non_zero.hpp"
@@ -209,8 +210,10 @@ TEST_P(ZeroInferRequestTests, BooleanSetTensorSetTensorsWork) {
? std::dynamic_pointer_cast<::intel_npu::ICompilerAdapter>(
std::make_shared<::intel_npu::DriverCompilerAdapter>(zeroInitStruct))
: std::dynamic_pointer_cast<::intel_npu::ICompilerAdapter>(
- std::make_shared<::intel_npu::PluginCompilerAdapter>(zeroInitStruct,
- ::intel_npu::makeVCLCompiler()));
+ std::make_shared<::intel_npu::PluginCompilerAdapter>(
+ zeroInitStruct,
+ std::make_shared<::intel_npu::VCLCompilerImpl>(
+ ::intel_npu::VCLLoader::getInstance()->sharedFunctions())));
} catch (...) {
GTEST_SKIP() << "Couldn't load compiler library";
}
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.cpp
index 72178781c0f..e4fc8ad412e 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
@@ -230,9 +230,7 @@ TEST_F(VCLCompilerImplTest, ConstructionAcceptsALibraryBelowTheFloorAndDefersThe
//
TEST_F(VCLCompilerImplTest, DestructionDestroysTheCompilerExactlyOnce) {
- {
- auto compiler = makeCompiler();
- }
+ { auto compiler = makeCompiler(); }
EXPECT_EQ(fake.compilerDestroyCount, 1);
}
@@ -590,83 +588,6 @@ TEST_F(VCLCompilerImplTest, TheBulkListContradictingACachedNegativeIsRejected) {
EXPECT_THROW((void)compiler->get_supported_options(), ov::Exception);
}
-//
-// --- process_profiling_output ---
-//
-
-TEST_F(VCLCompilerImplTest, ProcessProfilingOutputFollowsCreateGetDestroyOrdering) {
- fake.profilingPayload.assign(2 * sizeof(ze_profiling_layer_info), 0);
- auto compiler = makeCompiler();
-
- const std::vector<uint8_t> profData{1, 2, 3};
- const std::vector<uint8_t> network{4, 5, 6, 7};
- const auto info = compiler->process_profiling_output(profData, network);
-
- EXPECT_EQ(fake.callCount("vclProfilingCreate"), 1u);
- EXPECT_EQ(fake.callCount("vclProfilingGetProperties"), 1u);
- EXPECT_EQ(fake.callCount("vclGetDecodedProfilingBuffer"), 1u);
- EXPECT_EQ(fake.profilingDestroyCount, 1);
-
- EXPECT_LT(fake.indexOf("vclProfilingCreate"), fake.indexOf("vclProfilingGetProperties"));
- EXPECT_LT(fake.indexOf("vclProfilingGetProperties"), fake.indexOf("vclGetDecodedProfilingBuffer"));
- EXPECT_LT(fake.indexOf("vclGetDecodedProfilingBuffer"), fake.indexOf("vclProfilingDestroy"));
-
- // One entry per ze_profiling_layer_info in the returned buffer.
- EXPECT_EQ(info.size(), 2u);
-}
-
-TEST_F(VCLCompilerImplTest, ProcessProfilingOutputSizesByLayerInfoStride) {
- fake.profilingPayload.assign(5 * sizeof(ze_profiling_layer_info), 0);
- auto compiler = makeCompiler();
- EXPECT_EQ(compiler->process_profiling_output({1}, {2}).size(), 5u);
-}
-
-TEST_F(VCLCompilerImplTest, ProcessProfilingOutputThrowsOnNullData) {
- fake.forceNullProfilingData = true;
- auto compiler = makeCompiler();
-
- try {
- compiler->process_profiling_output({1}, {2});
- FAIL() << "Expected a throw on NULL profiling data";
- } catch (const ov::Exception& error) {
- EXPECT_NE(std::string(error.what()).find("Failed to get VCL profiling output"), std::string::npos);
- }
-}
-
-TEST_F(VCLCompilerImplTest, ProcessProfilingOutputThrowsWhenCreateFails) {
- // A decodable payload, so the scripted vclProfilingCreate failure is the only reason to throw.
- fake.profilingPayload.assign(sizeof(ze_profiling_layer_info), 0);
- auto compiler = makeCompiler();
- fake.failWith("vclProfilingCreate", VCL_RESULT_ERROR_UNKNOWN);
-
- try {
- compiler->process_profiling_output({1}, {2});
- FAIL() << "Expected a throw on vclProfilingCreate failure";
- } catch (const ov::Exception& error) {
- EXPECT_NE(std::string(error.what()).find("vclProfilingCreate"), std::string::npos);
- }
- // Nothing was created, so nothing must be destroyed.
- EXPECT_EQ(fake.profilingDestroyCount, 0);
-}
-
-TEST_F(VCLCompilerImplTest, ProcessProfilingOutputThrowsWhenDestroyFails) {
- // The payload must decode successfully, otherwise the null-data guard throws first and the
- // destroy-failure path is never reached.
- fake.profilingPayload.assign(sizeof(ze_profiling_layer_info), 0);
- auto compiler = makeCompiler();
- fake.failWith("vclProfilingDestroy", VCL_RESULT_ERROR_UNKNOWN);
-
- try {
- compiler->process_profiling_output({1}, {2});
- FAIL() << "Expected a throw on vclProfilingDestroy failure";
- } catch (const ov::Exception& error) {
- EXPECT_NE(std::string(error.what()).find("vclProfilingDestroy"), std::string::npos);
- }
- // The decode ran to completion before destroy was attempted.
- EXPECT_EQ(fake.callCount("vclGetDecodedProfilingBuffer"), 1u);
- EXPECT_EQ(fake.profilingDestroyCount, 1);
-}
-
//
// --- compile ---
//
diff --git a/src/plugins/intel_npu/tests/unit/npu/compiler_adapter/fake_vcl_compiler.hpp b/src/plugins/intel_npu/tests/unit/npu/compiler_adapter/fake_vcl_compiler.hpp
index 1f1c4610444..8897f202c44 100644
--- a/src/plugins/intel_npu/tests/unit/npu/compiler_adapter/fake_vcl_compiler.hpp
+++ b/src/plugins/intel_npu/tests/unit/npu/compiler_adapter/fake_vcl_compiler.hpp
@@ -94,11 +94,6 @@ public:
}
return false;
}
-
- std::vector<ov::ProfilingInfo> process_profiling_output(const std::vector<uint8_t>&,
- const std::vector<uint8_t>&) const override {
- return {};
- }
};
} // namespace fake_vcl
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 983904fc847..7c4385e42c7 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
@@ -12,6 +12,7 @@
#include <vector>
#include "fake_vcl_compiler.hpp"
+#include "graph.hpp"
#include "intel_npu/config/config.hpp"
#include "intel_npu/config/options.hpp"
#include "intel_npu/npu_private_properties.hpp"
@@ -48,13 +49,29 @@ std::shared_ptr<ov::Model> makeWeightlessModel() {
return std::make_shared<ov::Model>(ov::OutputVector{add}, ov::ParameterVector{input}, "adapter_ws_test_model");
}
+class RecordingProfilingDecoder final : public ::intel_npu::IProfilingDecoder {
+public:
+ std::vector<ov::ProfilingInfo> decode(const std::vector<uint8_t>& profData,
+ const ov::Tensor& network) const override {
+ ++calls;
+ receivedData = profData;
+ networkSize = network.get_byte_size();
+ return {};
+ }
+
+ mutable size_t calls = 0;
+ mutable std::vector<uint8_t> receivedData;
+ mutable size_t networkSize = 0;
+};
+
struct PluginCompilerAdapterTest : public ::testing::Test {
std::shared_ptr<FakeVCLCompiler> compiler = std::make_shared<FakeVCLCompiler>();
// 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, compiler);
+ std::unique_ptr<PluginCompilerAdapter> makeAdapter(
+ const std::shared_ptr<::intel_npu::IProfilingDecoder>& profilingDecoder = nullptr) {
+ return std::make_unique<PluginCompilerAdapter>(nullptr, compiler, profilingDecoder);
}
static std::shared_ptr<OptionsDesc> makeOptionsDesc() {
@@ -107,6 +124,57 @@ TEST_F(PluginCompilerAdapterTest, CompileProducesAGraphEvenWithoutADriver) {
EXPECT_TRUE(graph->get_metadata().name.empty());
}
+TEST_F(PluginCompilerAdapterTest, CompiledGraphUsesInjectedProfilingDecoder) {
+ auto decoder = std::make_shared<RecordingProfilingDecoder>();
+ auto adapter = makeAdapter(decoder);
+ auto config = makeConfig();
+ const auto graph = adapter->compile(makeModel(), config, AdapterDescriptor{});
+ const std::vector<uint8_t> profData{1, 2, 3};
+
+ ASSERT_NE(graph, nullptr);
+ EXPECT_TRUE(graph->process_profiling_output(profData).empty());
+ EXPECT_EQ(decoder->calls, 1u);
+ EXPECT_EQ(decoder->receivedData, profData);
+ EXPECT_EQ(decoder->networkSize, compiler->compileResult.get_byte_size());
+}
+
+TEST_F(PluginCompilerAdapterTest, CompiledGraphWithoutProfilingDecoderThrowsOnProfilingOutput) {
+ auto adapter = makeAdapter(); // no profiling decoder injected
+ auto config = makeConfig();
+ const auto graph = adapter->compile(makeModel(), config, AdapterDescriptor{});
+
+ ASSERT_NE(graph, nullptr);
+ EXPECT_FALSE(graph->has_profiling_decoder());
+ try {
+ (void)graph->process_profiling_output({1, 2, 3});
+ FAIL() << "Expected a throw when no profiling decoder is available";
+ } catch (const ov::Exception& error) {
+ EXPECT_NE(std::string(error.what()).find("No VCL profiling decoder is available"), std::string::npos);
+ }
+}
+
+TEST_F(PluginCompilerAdapterTest, GraphWithDecoderButNoBlobThrowsOnProfilingOutput) {
+ auto decoder = std::make_shared<RecordingProfilingDecoder>();
+ ::intel_npu::Graph graph(nullptr,
+ nullptr,
+ ::intel_npu::GraphDescriptor{},
+ ::intel_npu::NetworkMetadata{},
+ /* blob = */ std::nullopt,
+ std::nullopt,
+ false,
+ decoder);
+
+ EXPECT_TRUE(graph.has_profiling_decoder());
+ try {
+ (void)graph.process_profiling_output({1, 2, 3});
+ FAIL() << "Expected a throw when the graph has no retained blob";
+ } catch (const ov::Exception& error) {
+ EXPECT_NE(std::string(error.what()).find("requires the compiled network blob"), std::string::npos);
+ }
+ // The missing-blob guard must fire before the decoder is ever invoked.
+ EXPECT_EQ(decoder->calls, 0u);
+}
+
TEST_F(PluginCompilerAdapterTest, CompilePropagatesCompilerFailures) {
compiler->throwOnCompile = true;
auto adapter = makeAdapter();
diff --git a/src/plugins/intel_npu/tests/unit/npu/compiler_adapter/vcl_profiling_decoder_test.cpp b/src/plugins/intel_npu/tests/unit/npu/compiler_adapter/vcl_profiling_decoder_test.cpp
new file mode 100644
index 00000000000..2c4f45d427f
--- /dev/null
+++ b/src/plugins/intel_npu/tests/unit/npu/compiler_adapter/vcl_profiling_decoder_test.cpp
@@ -0,0 +1,192 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "vcl_profiling_decoder.hpp"
+
+#include <gtest/gtest.h>
+#include <level_zero/ze_api.h>
+#include <ze_graph_ext.h>
+#include <ze_graph_profiling_ext.h>
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "fake_vcl.hpp"
+#include "openvino/core/except.hpp"
+#include "openvino/runtime/tensor.hpp"
+
+using ::fake_vcl::FakeVcl;
+using ::intel_npu::VCLProfilingDecoder;
+
+namespace {
+
+ov::Tensor makeNetworkTensor() {
+ return ov::Tensor(ov::element::u8, ov::Shape{4});
+}
+
+} // namespace
+
+struct VCLProfilingDecoderTest : public ::testing::Test {
+ FakeVcl fake;
+
+ std::shared_ptr<VCLProfilingDecoder> makeDecoder() {
+ return std::make_shared<VCLProfilingDecoder>(fake.functions());
+ }
+};
+
+TEST_F(VCLProfilingDecoderTest, ConstructionDoesNotTriggerACompilerCreateGetDestroyCycle) {
+ // The whole point of the decoder: decoding never needs a compiler instance.
+ auto decoder = makeDecoder();
+ ASSERT_NE(decoder, nullptr);
+
+ EXPECT_FALSE(fake.called("vclCompilerCreate"));
+ EXPECT_FALSE(fake.called("vclCompilerGetProperties"));
+ EXPECT_EQ(fake.compilerDestroyCount, 0);
+}
+
+TEST_F(VCLProfilingDecoderTest, NullFunctionTableIsRejected) {
+ EXPECT_THROW(
+ {
+ auto decoder = std::make_shared<VCLProfilingDecoder>(nullptr);
+ (void)decoder;
+ },
+ ov::Exception);
+}
+
+TEST_F(VCLProfilingDecoderTest, UnwiredFunctionTableIsRejected) {
+ // A default-constructed table: every entry point is null.
+ auto unwired = std::make_shared<const intel_npu::VCLFunctionTable>();
+ EXPECT_THROW(
+ {
+ auto decoder = std::make_shared<VCLProfilingDecoder>(unwired);
+ (void)decoder;
+ },
+ ov::Exception);
+}
+
+TEST_F(VCLProfilingDecoderTest, MissingAProfilingEntryPointIsRejected) {
+ fake.mutableFunctions()->vclGetDecodedProfilingBuffer = nullptr;
+ EXPECT_THROW(makeDecoder(), ov::Exception);
+}
+
+TEST_F(VCLProfilingDecoderTest, UnrelatedMissingEntryPointsDoNotBlockConstruction) {
+ // The decoder only needs the profiling entry points, never the compiler/executable/query ones.
+ fake.mutableFunctions()->vclCompilerCreate = nullptr;
+ fake.mutableFunctions()->vclAllocatedExecutableCreate4 = nullptr;
+ fake.mutableFunctions()->vclQueryNetworkCreate = nullptr;
+ EXPECT_NO_THROW(makeDecoder());
+}
+
+TEST_F(VCLProfilingDecoderTest, DecodeFollowsCreateGetDestroyOrdering) {
+ fake.profilingPayload.assign(2 * sizeof(ze_profiling_layer_info), 0);
+ auto decoder = makeDecoder();
+
+ const std::vector<uint8_t> profData{1, 2, 3};
+ const ov::Tensor network = makeNetworkTensor();
+ const auto info = decoder->decode(profData, network);
+
+ EXPECT_EQ(fake.callCount("vclProfilingCreate"), 1u);
+ EXPECT_EQ(fake.callCount("vclProfilingGetProperties"), 1u);
+ EXPECT_EQ(fake.callCount("vclGetDecodedProfilingBuffer"), 1u);
+ EXPECT_EQ(fake.profilingDestroyCount, 1);
+
+ EXPECT_LT(fake.indexOf("vclProfilingCreate"), fake.indexOf("vclProfilingGetProperties"));
+ EXPECT_LT(fake.indexOf("vclProfilingGetProperties"), fake.indexOf("vclGetDecodedProfilingBuffer"));
+ EXPECT_LT(fake.indexOf("vclGetDecodedProfilingBuffer"), fake.indexOf("vclProfilingDestroy"));
+
+ // One entry per ze_profiling_layer_info in the returned buffer.
+ EXPECT_EQ(info.size(), 2u);
+}
+
+TEST_F(VCLProfilingDecoderTest, DecodeSizesByLayerInfoStride) {
+ fake.profilingPayload.assign(5 * sizeof(ze_profiling_layer_info), 0);
+ auto decoder = makeDecoder();
+ EXPECT_EQ(decoder->decode({1}, makeNetworkTensor()).size(), 5u);
+}
+
+TEST_F(VCLProfilingDecoderTest, DecodeThrowsOnNullData) {
+ fake.forceNullProfilingData = true;
+ auto decoder = makeDecoder();
+
+ try {
+ decoder->decode({1}, makeNetworkTensor());
+ FAIL() << "Expected a throw on NULL profiling data";
+ } catch (const ov::Exception& error) {
+ EXPECT_NE(std::string(error.what()).find("Failed to get VCL profiling output"), std::string::npos);
+ }
+ // The handle was created and must still be released even though destroy was never explicitly reached.
+ EXPECT_EQ(fake.profilingDestroyCount, 1);
+}
+
+TEST_F(VCLProfilingDecoderTest, DecodeCleansUpTheHandleWhenGetPropertiesFails) {
+ auto decoder = makeDecoder();
+ fake.failWith("vclProfilingGetProperties", VCL_RESULT_ERROR_UNKNOWN);
+
+ try {
+ decoder->decode({1}, makeNetworkTensor());
+ FAIL() << "Expected a throw on vclProfilingGetProperties failure";
+ } catch (const ov::Exception& error) {
+ EXPECT_NE(std::string(error.what()).find("vclProfilingGetProperties"), std::string::npos);
+ }
+ // The handle was created before this failure; it must still be released, not leaked.
+ EXPECT_EQ(fake.profilingDestroyCount, 1);
+}
+
+TEST_F(VCLProfilingDecoderTest, DecodeCleansUpTheHandleWhenGetDecodedProfilingBufferFails) {
+ auto decoder = makeDecoder();
+ fake.failWith("vclGetDecodedProfilingBuffer", VCL_RESULT_ERROR_UNKNOWN);
+
+ try {
+ decoder->decode({1}, makeNetworkTensor());
+ FAIL() << "Expected a throw on vclGetDecodedProfilingBuffer failure";
+ } catch (const ov::Exception& error) {
+ EXPECT_NE(std::string(error.what()).find("vclGetDecodedProfilingBuffer"), std::string::npos);
+ }
+ EXPECT_EQ(fake.profilingDestroyCount, 1);
+}
+
+TEST_F(VCLProfilingDecoderTest, DecodeThrowsOnMisalignedBufferSize) {
+ // One byte short of a whole ze_profiling_layer_info: integer division would otherwise silently
+ // truncate the vector while memcpy still copied the full, larger byte count into it.
+ fake.profilingPayload.assign(sizeof(ze_profiling_layer_info) - 1, 0);
+ auto decoder = makeDecoder();
+
+ EXPECT_THROW(decoder->decode({1}, makeNetworkTensor()), ov::Exception);
+ EXPECT_EQ(fake.profilingDestroyCount, 1);
+}
+
+TEST_F(VCLProfilingDecoderTest, DecodeThrowsWhenCreateFails) {
+ // A decodable payload, so the scripted vclProfilingCreate() failure is the only reason to throw.
+ fake.profilingPayload.assign(sizeof(ze_profiling_layer_info), 0);
+ auto decoder = makeDecoder();
+ fake.failWith("vclProfilingCreate", VCL_RESULT_ERROR_UNKNOWN);
+
+ try {
+ decoder->decode({1}, makeNetworkTensor());
+ FAIL() << "Expected a throw on vclProfilingCreate failure";
+ } catch (const ov::Exception& error) {
+ EXPECT_NE(std::string(error.what()).find("vclProfilingCreate"), std::string::npos);
+ }
+ // Nothing was created, so nothing must be destroyed.
+ EXPECT_EQ(fake.profilingDestroyCount, 0);
+}
+
+TEST_F(VCLProfilingDecoderTest, DecodeThrowsWhenDestroyFails) {
+ // The payload must decode successfully, otherwise the null-data guard throws first and the
+ // destroy-failure path is never reached.
+ fake.profilingPayload.assign(sizeof(ze_profiling_layer_info), 0);
+ auto decoder = makeDecoder();
+ fake.failWith("vclProfilingDestroy", VCL_RESULT_ERROR_UNKNOWN);
+
+ try {
+ decoder->decode({1}, makeNetworkTensor());
+ FAIL() << "Expected a throw on vclProfilingDestroy failure";
+ } catch (const ov::Exception& error) {
+ EXPECT_NE(std::string(error.what()).find("vclProfilingDestroy"), std::string::npos);
+ }
+ // The decode ran to completion before destroy was attempted.
+ EXPECT_EQ(fake.callCount("vclGetDecodedProfilingBuffer"), 1u);
+ EXPECT_EQ(fake.profilingDestroyCount, 1);
+}
diff --git a/src/plugins/intel_npu/tests/unit/npu/zero_profiling_test.cpp b/src/plugins/intel_npu/tests/unit/npu/zero_profiling_test.cpp
new file mode 100644
index 00000000000..28de425d4e4
--- /dev/null
+++ b/src/plugins/intel_npu/tests/unit/npu/zero_profiling_test.cpp
@@ -0,0 +1,110 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "zero_profiling.hpp"
+
+#include <gtest/gtest.h>
+
+#include <optional>
+#include <string>
+#include <vector>
+
+#include "intel_npu/common/igraph.hpp"
+#include "openvino/core/except.hpp"
+
+namespace {
+
+ov::ProfilingInfo makeProfilingInfo(const std::string& name) {
+ ov::ProfilingInfo info;
+ info.node_name = name;
+ return info;
+}
+
+class TestGraph final : public intel_npu::IGraph {
+public:
+ std::optional<bool> is_profiling_blob() const override {
+ return true;
+ }
+
+ bool has_profiling_decoder() const override {
+ return decoderAvailable;
+ }
+
+ std::vector<ov::ProfilingInfo> process_profiling_output(const std::vector<uint8_t>& data) const override {
+ receivedData = data;
+ if (!decoderAvailable) {
+ return intel_npu::IGraph::process_profiling_output(data);
+ }
+ if (throwOnDecode) {
+ OPENVINO_THROW("synthetic graph decoder failure");
+ }
+ return graphStatistics;
+ }
+
+ bool decoderAvailable = true;
+ bool throwOnDecode = false;
+ mutable std::vector<uint8_t> receivedData;
+ std::vector<ov::ProfilingInfo> graphStatistics;
+};
+
+struct TestQuery {
+ template <typename ProfilingData>
+ std::vector<ProfilingData> getData() const {
+ ++rawDataCalls;
+ return std::vector<ProfilingData>(rawData.begin(), rawData.end());
+ }
+
+ intel_npu::zeroProfiling::LayerStatistics getLayerStatistics() const {
+ ++layerStatisticsCalls;
+ return layerStatistics;
+ }
+
+ std::vector<uint8_t> rawData{4, 5, 6};
+ intel_npu::zeroProfiling::LayerStatistics layerStatistics{makeProfilingInfo("level-zero")};
+ mutable size_t rawDataCalls = 0;
+ mutable size_t layerStatisticsCalls = 0;
+};
+
+TEST(ZeroProfilingTest, PrefersGraphDecoderWhenItSucceeds) {
+ TestGraph graph;
+ graph.graphStatistics = {makeProfilingInfo("graph-decoded")};
+ TestQuery query;
+
+ const auto result = intel_npu::zeroProfiling::getModelLayerStatistics(graph, query);
+
+ ASSERT_EQ(result.size(), 1u);
+ EXPECT_EQ(result.front().node_name, "graph-decoded");
+ EXPECT_EQ(graph.receivedData, query.rawData);
+ EXPECT_EQ(query.rawDataCalls, 1u);
+ EXPECT_EQ(query.layerStatisticsCalls, 0u);
+}
+
+TEST(ZeroProfilingTest, FallsBackToLevelZeroStatisticsWhenGraphHasNoDecoder) {
+ TestGraph graph;
+ graph.decoderAvailable = false;
+ TestQuery query;
+
+ const auto result = intel_npu::zeroProfiling::getModelLayerStatistics(graph, query);
+
+ ASSERT_EQ(result.size(), 1u);
+ EXPECT_EQ(result.front().node_name, "level-zero");
+ // No decoder means the raw profiling buffer is never worth fetching.
+ EXPECT_TRUE(graph.receivedData.empty());
+ EXPECT_EQ(query.rawDataCalls, 0u);
+ EXPECT_EQ(query.layerStatisticsCalls, 1u);
+}
+
+TEST(ZeroProfilingTest, FallsBackToLevelZeroStatisticsWhenGraphDecoderThrows) {
+ TestGraph graph;
+ graph.throwOnDecode = true;
+ TestQuery query;
+
+ const auto result = intel_npu::zeroProfiling::getModelLayerStatistics(graph, query);
+
+ ASSERT_EQ(result.size(), 1u);
+ EXPECT_EQ(result.front().node_name, "level-zero");
+ EXPECT_EQ(query.layerStatisticsCalls, 1u);
+}
+
+} // namespace