Skip to content

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

[HETERO] Add perf logging for compile_model and subgraph collection (#36463)

guozhong wang48f3f6360d64
diff --git a/docs/articles_en/openvino-workflow/running-inference/inference-devices-and-modes/hetero-execution.rst b/docs/articles_en/openvino-workflow/running-inference/inference-devices-and-modes/hetero-execution.rst
index 3235f3515db..46489a0797e 100644
--- a/docs/articles_en/openvino-workflow/running-inference/inference-devices-and-modes/hetero-execution.rst
+++ b/docs/articles_en/openvino-workflow/running-inference/inference-devices-and-modes/hetero-execution.rst
@@ -208,6 +208,29 @@ You can use the GraphViz utility or a file converter to view the images. On the
* ``sudo apt-get install xdot``
* ``xdot hetero_subgraphs.dot``
+For HETERO compilation-time diagnostics, you can also enable internal performance logging with the
+``OPENVINO_HETERO_PERF`` environment variable:
+
+* ``OPENVINO_HETERO_PERF=1`` enables high-level compilation timing for:
+
+ * ``Plugin::compile_model`` - top-level HETERO compilation flow.
+ * ``CompiledModel::compile_model`` - submodel compilation and overall HETERO compiled-model construction.
+ * ``CompiledModel::compile_model submodel[...]`` - per-subgraph compile time on the target device.
+ * ``Plugin::query_model_update`` - overall multi-device query and graph-partition update time.
+
+* ``OPENVINO_HETERO_PERF=2`` enables all level-1 logs and per-device query/update breakdown for:
+
+ * ``Plugin::query_model_update device timing`` - per-device summary including query, mask, clone, and device-subgraph state.
+
+* ``OPENVINO_HETERO_PERF=3`` enables all level-2 logs and additional subgraph-splitting diagnostics for:
+
+ * ``SubgraphCollector::SubgraphCollector`` - subgraph collector setup.
+ * ``SubgraphCollector::split_cyclic_dependencies`` - affinity-boundary and cycle-resolution work during graph splitting.
+ * ``partition_and_rewrite_model`` - subgraph collection and model rewrite time per partition pass.
+
+These logs are intended for HETERO-specific compilation analysis and are separate from runtime layer profiling such as
+sample application ``-pc`` output.
+
You can use performance data (in sample applications, it is the option ``-pc``) to get the performance data on each subgraph.
Here is an example of the output for Googlenet v1 running on HDDL (device no longer supported) with fallback to CPU:
diff --git a/src/plugins/hetero/src/compiled_model.cpp b/src/plugins/hetero/src/compiled_model.cpp
index 2325ef3dc6a..828facb509b 100644
--- a/src/plugins/hetero/src/compiled_model.cpp
+++ b/src/plugins/hetero/src/compiled_model.cpp
@@ -4,6 +4,7 @@
#include "compiled_model.hpp"
+#include <chrono>
#include <memory>
#include "async_infer_request.hpp"
@@ -17,6 +18,7 @@
#include "openvino/runtime/properties.hpp"
#include "openvino/util/common_util.hpp"
#include "openvino/util/xml_parse_utils.hpp"
+#include "perf_log.hpp"
#include "properties.hpp"
ov::hetero::CompiledModel::CompiledModel(const std::shared_ptr<ov::Model>& model,
@@ -40,6 +42,17 @@ ov::hetero::CompiledModel::CompiledModel(const std::shared_ptr<ov::Model>& model
}
void ov::hetero::CompiledModel::compile_model(const std::vector<ov::hetero::SubmodelInfo>& submodels) {
+ using clock = std::chrono::steady_clock;
+ const auto to_ms = [](clock::duration d) {
+ return std::chrono::duration_cast<std::chrono::milliseconds>(d).count();
+ };
+ const bool perf_logging_enabled = perf_log_enabled(PerfLogLevel::Summary);
+ clock::time_point t0{};
+ clock::duration submodel_total_time{};
+ if (perf_logging_enabled) {
+ t0 = clock::now();
+ }
+
const bool add_exclusive = submodels.size() > 1;
const auto& hetero_plugin = get_hetero_plugin();
const auto& core = hetero_plugin->get_core();
@@ -48,7 +61,15 @@ void ov::hetero::CompiledModel::compile_model(const std::vector<ov::hetero::Subm
m_compiled_submodels.clear();
m_compiled_submodels.reserve(submodels.size());
+ size_t submodel_index = 0;
for (const auto& [device, sub_model] : submodels) {
+ clock::time_point t_submodel_start{};
+ clock::time_point t_compile_start{};
+ clock::time_point t_compile_end{};
+ clock::time_point t_submodel_end{};
+ if (perf_logging_enabled) {
+ t_submodel_start = clock::now();
+ }
// get meta devices properties for the target device
auto meta_devices = hetero_plugin->get_properties_per_device(device, device_properties);
@@ -71,10 +92,53 @@ void ov::hetero::CompiledModel::compile_model(const std::vector<ov::hetero::Subm
CompiledModelDesc desc;
desc.device = device;
desc.model = sub_model;
+ if (perf_logging_enabled) {
+ t_compile_start = clock::now();
+ }
desc.compiled_model = core->compile_model(sub_model, device, device_config);
+ if (perf_logging_enabled) {
+ t_compile_end = clock::now();
+ }
m_compiled_submodels.emplace_back(std::move(desc));
+
+ if (perf_logging_enabled) {
+ t_submodel_end = clock::now();
+ submodel_total_time += t_submodel_end - t_submodel_start;
+ HETERO_PERF_LOG_LEVEL(PerfLogLevel::Summary,
+ "CompiledModel::compile_model submodel[",
+ submodel_index,
+ "] device=",
+ device,
+ " ops=",
+ sub_model ? sub_model->get_ops().size() : 0,
+ " total=",
+ to_ms(t_submodel_end - t_submodel_start),
+ " ms, core_compile=",
+ to_ms(t_compile_end - t_compile_start),
+ " ms");
+ }
+ ++submodel_index;
+ }
+
+ clock::time_point t_set_io_start{};
+ clock::time_point t_set_io_end{};
+ if (perf_logging_enabled) {
+ t_set_io_start = clock::now();
}
set_inputs_and_outputs();
+ if (perf_logging_enabled) {
+ t_set_io_end = clock::now();
+ HETERO_PERF_LOG_LEVEL(PerfLogLevel::Summary,
+ "CompiledModel::compile_model timing: total=",
+ to_ms(t_set_io_end - t0),
+ " ms, submodels=",
+ submodels.size(),
+ ", submodel_total=",
+ to_ms(submodel_total_time),
+ " ms, set_inputs_and_outputs=",
+ to_ms(t_set_io_end - t_set_io_start),
+ " ms");
+ }
}
ov::hetero::CompiledModel::CompiledModel(std::istream& model,
diff --git a/src/plugins/hetero/src/perf_log.hpp b/src/plugins/hetero/src/perf_log.hpp
new file mode 100644
index 00000000000..0a643a99b21
--- /dev/null
+++ b/src/plugins/hetero/src/perf_log.hpp
@@ -0,0 +1,78 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include <cstdlib>
+#include <utility>
+
+#include "openvino/util/log.hpp"
+
+namespace ov::hetero {
+
+enum class PerfLogLevel {
+ Off = 0,
+ Summary = 1,
+ DeviceBreakdown = 2,
+ PartitionDetails = 3,
+};
+
+inline PerfLogLevel perf_log_level() {
+ static const PerfLogLevel cached = []() {
+ const char* value = std::getenv("OPENVINO_HETERO_PERF");
+ if (value == nullptr || *value == '\0') {
+ return PerfLogLevel::Off;
+ }
+
+ char* end = nullptr;
+ const long parsed = std::strtol(value, &end, 10);
+ if (end == value || *end != '\0') {
+ return PerfLogLevel::Off;
+ }
+
+ if (parsed <= 0) {
+ return PerfLogLevel::Off;
+ }
+
+ if (parsed >= static_cast<long>(PerfLogLevel::PartitionDetails)) {
+ return PerfLogLevel::PartitionDetails;
+ }
+
+ if (parsed >= static_cast<long>(PerfLogLevel::DeviceBreakdown)) {
+ return PerfLogLevel::DeviceBreakdown;
+ }
+
+ return PerfLogLevel::Summary;
+ }();
+
+ return cached;
+}
+
+inline bool perf_log_enabled() {
+ return perf_log_level() != PerfLogLevel::Off;
+}
+
+inline bool perf_log_enabled(PerfLogLevel level) {
+ if (level == PerfLogLevel::Off) {
+ return false;
+ }
+ return static_cast<int>(perf_log_level()) >= static_cast<int>(level);
+}
+
+template <typename... Args>
+inline void perf_log_impl(const char* file, int line, Args&&... args) {
+ ov::util::LogHelper helper(ov::util::LOG_TYPE::_LOG_TYPE_DEBUG_EMPTY, file, line);
+ auto& stream = helper.stream();
+ (stream << ... << std::forward<Args>(args));
+}
+
+} // namespace ov::hetero
+
+#define HETERO_PERF_LOG_LEVEL(level, ...) \
+ do { \
+ if (::ov::hetero::perf_log_enabled(level)) { \
+ ::ov::hetero::perf_log_impl(__FILE__, __LINE__, __VA_ARGS__); \
+ } \
+ } while (0)
+#define HETERO_PERF_LOG(...) HETERO_PERF_LOG_LEVEL(::ov::hetero::PerfLogLevel::Summary, __VA_ARGS__)
\ No newline at end of file
diff --git a/src/plugins/hetero/src/plugin.cpp b/src/plugins/hetero/src/plugin.cpp
index 6703610d7cb..589a2b40255 100644
--- a/src/plugins/hetero/src/plugin.cpp
+++ b/src/plugins/hetero/src/plugin.cpp
@@ -4,6 +4,7 @@
#include "plugin.hpp"
+#include <chrono>
#include <fstream>
#include <map>
#include <memory>
@@ -23,7 +24,9 @@
#include "openvino/runtime/internal_properties.hpp"
#include "openvino/runtime/properties.hpp"
#include "openvino/runtime/shared_buffer.hpp"
+#include "openvino/util/common_util.hpp"
#include "openvino/util/container_util.hpp"
+#include "perf_log.hpp"
#include "properties.hpp"
#include "remote_context.hpp"
@@ -54,7 +57,7 @@ std::pair<ov::hetero::SubgraphsMappingInfo, std::vector<ov::hetero::SubmodelInfo
// All affinities must be defined by user
ov::hetero::SubgraphsVector ordered_subgraphs;
std::tie(ordered_subgraphs, mapping_info) =
- get_model_subgraphs(model, query_model_result, true, m_cfg.dump_dot_files());
+ get_model_subgraphs(model, query_model_result, true, m_cfg.dump_dot_files(), "", "user_affinity_partition");
submodels.resize(ordered_subgraphs.size());
for (size_t i = 0; i < ordered_subgraphs.size(); ++i) {
@@ -102,12 +105,49 @@ std::shared_ptr<ov::ICompiledModel> ov::hetero::Plugin::compile_model(const std:
const ov::AnyMap& properties) const {
OV_ITT_SCOPED_TASK(itt::domains::Hetero, "Plugin::compile_model");
+ using clock = std::chrono::steady_clock;
+ const auto to_ms = [](clock::duration d) {
+ return std::chrono::duration_cast<std::chrono::milliseconds>(d).count();
+ };
+
+ const bool perf_logging_enabled = perf_log_enabled(PerfLogLevel::Summary);
+ clock::time_point t0{};
+ clock::time_point t_clone_start{};
+ clock::time_point t_clone_end{};
+ clock::time_point t_split_start{};
+ clock::time_point t_split_end{};
+ clock::time_point t_context_start{};
+ clock::time_point t_context_end{};
+ clock::time_point t_compiled_model_start{};
+ clock::time_point t_compiled_model_end{};
+ if (perf_logging_enabled) {
+ t0 = clock::now();
+ }
+
auto config = Configuration{properties, m_cfg};
+
+ if (perf_logging_enabled) {
+ t_clone_start = clock::now();
+ }
auto cloned_model = model->clone();
+ if (perf_logging_enabled) {
+ t_clone_end = clock::now();
+ }
+
SubgraphsMappingInfo mapping_info;
std::vector<ov::hetero::SubmodelInfo> submodels;
+ if (perf_logging_enabled) {
+ t_split_start = clock::now();
+ }
std::tie(mapping_info, submodels) = split_graph(cloned_model, config);
+ if (perf_logging_enabled) {
+ t_split_end = clock::now();
+ }
+
ov::hetero::RemoteContext::Ptr remote_context;
+ if (perf_logging_enabled) {
+ t_context_start = clock::now();
+ }
try {
std::map<std::string, ov::SoPtr<ov::IRemoteContext>> contexts_map;
for (const auto& [device_name, _] : submodels) {
@@ -116,12 +156,36 @@ std::shared_ptr<ov::ICompiledModel> ov::hetero::Plugin::compile_model(const std:
remote_context = std::make_shared<ov::hetero::RemoteContext>(std::move(contexts_map));
} catch (const ov::Exception&) {
}
- return std::make_shared<CompiledModel>(cloned_model,
- submodels,
- mapping_info,
- shared_from_this(),
- remote_context,
- config);
+ if (perf_logging_enabled) {
+ t_context_end = clock::now();
+ t_compiled_model_start = t_context_end;
+ }
+
+ auto compiled_model = std::make_shared<CompiledModel>(cloned_model,
+ submodels,
+ mapping_info,
+ shared_from_this(),
+ remote_context,
+ config);
+ if (perf_logging_enabled) {
+ t_compiled_model_end = clock::now();
+ HETERO_PERF_LOG_LEVEL(PerfLogLevel::Summary,
+ "Plugin::compile_model timing: total=",
+ to_ms(t_compiled_model_end - t0),
+ " ms, submodels=",
+ submodels.size(),
+ ", clone_model=",
+ to_ms(t_clone_end - t_clone_start),
+ " ms, split_graph=",
+ to_ms(t_split_end - t_split_start),
+ " ms, create_remote_context=",
+ to_ms(t_context_end - t_context_start),
+ " ms, construct_compiled_model=",
+ to_ms(t_compiled_model_end - t_compiled_model_start),
+ " ms");
+ }
+
+ return compiled_model;
}
std::shared_ptr<ov::ICompiledModel> ov::hetero::Plugin::compile_model(
@@ -202,7 +266,20 @@ std::pair<ov::SupportedOpsMap, ov::hetero::SubgraphsMappingInfo> ov::hetero::Plu
std::shared_ptr<ov::Model>& model,
const ov::AnyMap& properties,
bool allow_exception) const {
+ using clock = std::chrono::steady_clock;
+ const auto to_ms = [](clock::duration d) {
+ return std::chrono::duration_cast<std::chrono::milliseconds>(d).count();
+ };
+ const bool perf_logging_enabled = perf_log_enabled(PerfLogLevel::Summary);
+ const bool detailed_perf_logging_enabled = perf_log_enabled(PerfLogLevel::DeviceBreakdown);
+ const bool partition_details_logging_enabled = perf_log_enabled(PerfLogLevel::PartitionDetails);
std::map<std::string, size_t> available_device_mem_map;
+ clock::time_point t0{};
+ clock::duration query_model_total_time{};
+ clock::duration mask_total_time{};
+ if (perf_logging_enabled) {
+ t0 = clock::now();
+ }
Configuration full_config{properties, m_cfg};
DeviceProperties properties_per_device =
get_properties_per_device(full_config.device_priorities, full_config.get_device_properties());
@@ -223,6 +300,25 @@ std::pair<ov::SupportedOpsMap, ov::hetero::SubgraphsMappingInfo> ov::hetero::Plu
final_results.emplace(layer_query_result);
};
+ const auto mask_model_subgraphs_with_optional_context = [&](std::shared_ptr<ov::Model>& target_model,
+ ov::SupportedOpsMap& target_supported_ops,
+ const bool dump_dot_files,
+ const std::string& default_device,
+ const char* stage_prefix,
+ const std::string& device_name) {
+ if (partition_details_logging_enabled) {
+ return ov::hetero::mask_model_subgraphs_by_ops(target_model,
+ target_supported_ops,
+ dump_dot_files,
+ default_device,
+ std::string{stage_prefix} + device_name);
+ }
+ return ov::hetero::mask_model_subgraphs_by_ops(target_model,
+ target_supported_ops,
+ dump_dot_files,
+ default_device);
+ };
+
auto has_subgraph_ops = [](std::shared_ptr<ov::Model>& model) {
for (auto& op : model->get_ordered_ops()) {
if (ov::as_type_ptr<ov::hetero::op::DeviceSubgraph>(op)) {
@@ -296,48 +392,162 @@ std::pair<ov::SupportedOpsMap, ov::hetero::SubgraphsMappingInfo> ov::hetero::Plu
}
model->add_results(new_outputs);
for (const auto& device_name : device_names) {
+ clock::time_point device_start{};
+ clock::duration device_query_time{};
+ clock::duration device_mask_time{};
+ clock::duration device_clone_time{};
+ if (detailed_perf_logging_enabled) {
+ device_start = clock::now();
+ }
// If there are some unsupported operations and it is a last device
// exception should be raised when allowed
bool fallback_device = (device_name == device_names.back());
const auto& default_device = (!allow_exception || !fallback_device) ? get_device_name() : "";
auto& device_config = properties_per_device.at(device_name);
- if (!has_subgraph_ops(model)) {
+ const bool model_has_subgraph_ops = has_subgraph_ops(model);
+ if (!model_has_subgraph_ops) {
if (hetero_query_model_by_device)
update_config(device_config, model, device_name, fallback_device);
+ clock::time_point t_query_start{};
+ if (perf_logging_enabled) {
+ t_query_start = clock::now();
+ }
query_results[device_name] = get_core()->query_model(model, device_name, device_config);
+ if (perf_logging_enabled) {
+ const auto t_query_end = clock::now();
+ const auto elapsed = t_query_end - t_query_start;
+ query_model_total_time += elapsed;
+ if (detailed_perf_logging_enabled) {
+ device_query_time += elapsed;
+ }
+ }
update_supported_ops(supported_ops_temp, query_results[device_name]);
update_supported_ops(supported_ops_final, query_results[device_name]);
- mapping_info = ov::hetero::mask_model_subgraphs_by_ops(model,
- supported_ops_temp,
- m_cfg.dump_dot_files(),
- default_device);
+ clock::time_point t_mask_start{};
+ if (perf_logging_enabled) {
+ t_mask_start = clock::now();
+ }
+ mapping_info = mask_model_subgraphs_with_optional_context(model,
+ supported_ops_temp,
+ m_cfg.dump_dot_files(),
+ default_device,
+ "initial_partition stage_device=",
+ device_name);
+ if (perf_logging_enabled) {
+ const auto t_mask_end = clock::now();
+ const auto elapsed = t_mask_end - t_mask_start;
+ mask_total_time += elapsed;
+ if (detailed_perf_logging_enabled) {
+ device_mask_time += elapsed;
+ }
+ }
} else {
// Mask supported nodes and left nodes to Subgraph in graph, and query model use subgraph, keep the
// model in query_model same as compile
+ clock::time_point t_clone_start{};
+ if (detailed_perf_logging_enabled) {
+ t_clone_start = clock::now();
+ }
auto temp_model = model->clone();
+ if (detailed_perf_logging_enabled) {
+ device_clone_time += clock::now() - t_clone_start;
+ }
update_supported_ops(supported_ops_temp_1, supported_ops_temp);
for (auto&& node : temp_model->get_ops()) {
supported_ops_temp_1.emplace(node->get_friendly_name(), "HETERO-TEMP");
}
- auto mapping_info_temp =
- ov::hetero::mask_model_subgraphs_by_ops(temp_model, supported_ops_temp_1, false, default_device);
+ clock::time_point t_temp_mask_start{};
+ if (perf_logging_enabled) {
+ t_temp_mask_start = clock::now();
+ }
+ auto mapping_info_temp = mask_model_subgraphs_with_optional_context(temp_model,
+ supported_ops_temp_1,
+ false,
+ default_device,
+ "temp_partition stage_device=",
+ device_name);
+ if (perf_logging_enabled) {
+ const auto t_temp_mask_end = clock::now();
+ const auto elapsed = t_temp_mask_end - t_temp_mask_start;
+ mask_total_time += elapsed;
+ if (detailed_perf_logging_enabled) {
+ device_mask_time += elapsed;
+ }
+ }
+ (void)mapping_info_temp;
for (const auto& op : temp_model->get_ordered_ops()) {
if (const auto& subgraph = ov::as_type_ptr<ov::hetero::op::DeviceSubgraph>(op)) {
if (subgraph->get_affinity() == "HETERO-TEMP") {
if (hetero_query_model_by_device)
update_config(device_config, subgraph->get_function(), device_name, fallback_device);
+ clock::time_point t_query_start{};
+ if (perf_logging_enabled) {
+ t_query_start = clock::now();
+ }
query_results[device_name] =
get_core()->query_model(subgraph->get_function(), device_name, device_config);
+ if (perf_logging_enabled) {
+ const auto t_query_end = clock::now();
+ const auto elapsed = t_query_end - t_query_start;
+ query_model_total_time += elapsed;
+ if (detailed_perf_logging_enabled) {
+ device_query_time += elapsed;
+ }
+ }
update_supported_ops(supported_ops_temp, query_results[device_name]);
update_supported_ops(supported_ops_final, query_results[device_name]);
}
}
}
- mapping_info = ov::hetero::mask_model_subgraphs_by_ops(model,
- supported_ops_temp,
- m_cfg.dump_dot_files(),
- default_device);
+ clock::time_point t_final_mask_start{};
+ if (perf_logging_enabled) {
+ t_final_mask_start = clock::now();
+ }
+ mapping_info = mask_model_subgraphs_with_optional_context(model,
+ supported_ops_temp,
+ m_cfg.dump_dot_files(),
+ default_device,
+ "final_partition stage_device=",
+ device_name);
+ if (perf_logging_enabled) {
+ const auto t_final_mask_end = clock::now();
+ const auto elapsed = t_final_mask_end - t_final_mask_start;
+ mask_total_time += elapsed;
+ if (detailed_perf_logging_enabled) {
+ device_mask_time += elapsed;
+ }
+ }
}
+ if (detailed_perf_logging_enabled) {
+ const bool final_has_subgraph_ops = has_subgraph_ops(model);
+ const auto device_end = clock::now();
+ HETERO_PERF_LOG_LEVEL(PerfLogLevel::DeviceBreakdown,
+ "Plugin::query_model_update device timing: stage_device=",
+ device_name,
+ ", total=",
+ to_ms(device_end - device_start),
+ " ms, query_supported_ops=",
+ to_ms(device_query_time),
+ " ms, partition_and_rewrite_model=",
+ to_ms(device_mask_time),
+ " ms, temp_model_clone=",
+ to_ms(device_clone_time),
+ " ms, has_device_subgraphs=",
+ final_has_subgraph_ops ? 1 : 0);
+ }
+ }
+ if (perf_logging_enabled) {
+ const auto t_end = clock::now();
+ HETERO_PERF_LOG_LEVEL(PerfLogLevel::Summary,
+ "Plugin::query_model_update timing: total=",
+ to_ms(t_end - t0),
+ " ms, devices=",
+ device_names.size(),
+ ", query_supported_ops_total=",
+ to_ms(query_model_total_time),
+ " ms, partition_and_rewrite_model_total=",
+ to_ms(mask_total_time),
+ " ms");
}
return {supported_ops_final, mapping_info};
}
diff --git a/src/plugins/hetero/src/subgraph_collector.cpp b/src/plugins/hetero/src/subgraph_collector.cpp
index 6f944176fe7..ee11d99abcc 100644
--- a/src/plugins/hetero/src/subgraph_collector.cpp
+++ b/src/plugins/hetero/src/subgraph_collector.cpp
@@ -5,6 +5,7 @@
#include "subgraph_collector.hpp"
#include <algorithm>
+#include <chrono>
#include <cstdint>
#include <functional>
#include <iterator>
@@ -26,8 +27,11 @@
#include "openvino/op/paged_attention.hpp"
#include "openvino/op/reshape.hpp"
#include "openvino/op/util/op_types.hpp"
+#include "openvino/util/common_util.hpp"
#include "openvino/util/container_util.hpp"
+#include "perf_log.hpp"
#include "transformations/utils/utils.hpp"
+
namespace {
template <typename T>
@@ -59,7 +63,8 @@ std::shared_ptr<ov::Node> ov::hetero::SubgraphCollector::input_node(
}
ov::hetero::SubgraphCollector::SubgraphCollector(const std::shared_ptr<ov::Model>& model,
- const AffinitiesMap& affinities)
+ const AffinitiesMap& affinities,
+ std::string log_context)
: _ordered_ops{model->get_ordered_ops()},
_origin_parameters(model->get_parameters()),
_origin_results(model->get_results()),
@@ -68,9 +73,53 @@ ov::hetero::SubgraphCollector::SubgraphCollector(const std::shared_ptr<ov::Model
_intermediate_results(),
_affinities{affinities},
_subgraph_inputs{},
- _subgraph_parameter_to_prev_result{} {
+ _subgraph_parameter_to_prev_result{},
+ _log_context{std::move(log_context)} {
+ using clock = std::chrono::steady_clock;
+ const bool perf_logging_enabled = perf_log_enabled(PerfLogLevel::PartitionDetails);
+ const auto& model_name = model->get_friendly_name();
+ const auto node_count = _ordered_ops.size();
+ clock::time_point t0{};
+ clock::time_point t_init_start{};
+ clock::time_point t_init_end{};
+ clock::time_point t_split_start{};
+ clock::time_point t_split_end{};
+ if (perf_logging_enabled) {
+ t0 = clock::now();
+ t_init_start = t0;
+ }
init();
+ if (perf_logging_enabled) {
+ t_init_end = clock::now();
+ t_split_start = t_init_end;
+ }
_subgraph_ids = split_cyclic_dependencies();
+ if (perf_logging_enabled) {
+ t_split_end = clock::now();
+ }
+
+ const auto to_ms = [](clock::duration d) {
+ return std::chrono::duration_cast<std::chrono::milliseconds>(d).count();
+ };
+ if (perf_logging_enabled) {
+ const auto total_ms = to_ms(t_split_end - t0);
+ if (total_ms > 0) {
+ HETERO_PERF_LOG_LEVEL(PerfLogLevel::PartitionDetails,
+ "SubgraphCollector::SubgraphCollector timing: stage=",
+ _log_context,
+ ", model=",
+ model_name,
+ ", nodes=",
+ node_count,
+ ", total=",
+ total_ms,
+ " ms, init=",
+ to_ms(t_init_end - t_init_start),
+ " ms, split_cyclic_dependencies=",
+ to_ms(t_split_end - t_split_start),
+ " ms");
+ }
+ }
}
bool ov::hetero::SubgraphCollector::is_graph_input_node(const ov::Node* node) const {
@@ -100,6 +149,20 @@ void ov::hetero::SubgraphCollector::init() {
}
ov::hetero::SubgraphCollector::SubgraphIdsMap ov::hetero::SubgraphCollector::split_cyclic_dependencies() {
+ using clock = std::chrono::steady_clock;
+ const auto to_ms = [](clock::duration d) {
+ return std::chrono::duration_cast<std::chrono::milliseconds>(d).count();
+ };
+ const bool perf_logging_enabled = perf_log_enabled(PerfLogLevel::PartitionDetails);
+ clock::time_point t0{};
+ clock::duration collect_ids_time{};
+ size_t node_scan_iterations = 0;
+ size_t scc_iterations = 0;
+ size_t scc_promoted_edges = 0;
+ if (perf_logging_enabled) {
+ t0 = clock::now();
+ }
+
// Iteratively detect cross-subgraph cycles (subgraph A feeds B and B feeds A) and break them
// by promoting offending edges into _subgraph_inputs until no new boundaries are added.
//
@@ -193,11 +256,24 @@ ov::hetero::SubgraphCollector::SubgraphIdsMap ov::hetero::SubgraphCollector::spl
std::vector<SubgraphId> subgraph_id_by_index(nodes_count);
// Split cyclic dependencies.
+ clock::time_point t_per_node_start{};
+ clock::time_point t_per_node_end{};
+ if (perf_logging_enabled) {
+ t_per_node_start = clock::now();
+ }
for (size_t prev_subgraphs = 0, cyclic_split_step = 0; prev_subgraphs != _subgraph_inputs.size();
++cyclic_split_step) {
OPENVINO_ASSERT(cyclic_split_step < _ordered_ops.size(), "Cannot resolve cycles during submodels split!");
+ clock::time_point t_collect_start{};
+ if (perf_logging_enabled) {
+ ++node_scan_iterations;
+ t_collect_start = clock::now();
+ }
prev_subgraphs = _subgraph_inputs.size();
subgraph_ids = collect_subgraphs_ids();
+ if (perf_logging_enabled) {
+ collect_ids_time += clock::now() - t_collect_start;
+ }
for (const auto& node : _ordered_ops) {
const auto index = get_index_by_node(node.get());
@@ -350,6 +426,10 @@ ov::hetero::SubgraphCollector::SubgraphIdsMap ov::hetero::SubgraphCollector::spl
}
}
+ if (perf_logging_enabled) {
+ t_per_node_end = clock::now();
+ }
+
// === Subgraph-level SCC fallback. ===========================================================
// The per-node heuristic above only detects cycles whose re-entry point sits on a node whose
// own cyc_dep bitset is non-empty (same-sg data flows back through a foreign sg into that
@@ -649,11 +729,23 @@ ov::hetero::SubgraphCollector::SubgraphIdsMap ov::hetero::SubgraphCollector::spl
// so the ids it computed at the top of that final iteration are still in sync. Recompute
// only after the SCC step actually modifies _subgraph_inputs.
bool ids_valid = true;
+ clock::time_point t_scc_start{};
+ clock::time_point t_scc_end{};
+ if (perf_logging_enabled) {
+ t_scc_start = clock::now();
+ }
for (size_t scc_step = 0;; ++scc_step) {
OPENVINO_ASSERT(scc_step < total_node_inputs + 1,
"Subgraph SCC fallback did not converge: exceeded node-input edge budget");
if (!ids_valid) {
+ clock::time_point t_collect_start{};
+ if (perf_logging_enabled) {
+ t_collect_start = clock::now();
+ }
subgraph_ids = collect_subgraphs_ids();
+ if (perf_logging_enabled) {
+ collect_ids_time += clock::now() - t_collect_start;
+ }
for (size_t i = 0; i < nodes_count; ++i) {
subgraph_id_by_index[i] = subgraph_ids.at(_ordered_ops[i]);
}
@@ -668,6 +760,9 @@ ov::hetero::SubgraphCollector::SubgraphIdsMap ov::hetero::SubgraphCollector::spl
if (scc_members.empty()) {
break; // subgraph DAG is acyclic, fix-point reached.
}
+ if (perf_logging_enabled) {
+ ++scc_iterations;
+ }
// Isolate one Union-Find node from any SCC member by promoting ALL its same-sg input
// edges. See isolate_one_scc_node for why a single-edge cut diverges, why entry/exit
@@ -677,6 +772,9 @@ ov::hetero::SubgraphCollector::SubgraphIdsMap ov::hetero::SubgraphCollector::spl
OPENVINO_ASSERT(promoted > 0,
"Subgraph SCC fallback found a cyclic subgraph DAG but the chosen node "
"had no same-subgraph inputs to promote; helper invariant violated.");
+ if (perf_logging_enabled) {
+ scc_promoted_edges += promoted;
+ }
// Defensive: each iteration must grow _subgraph_inputs strictly. If insert() ever found
// all promoted edges already present (logic bug), surface it here instead of looping
// silently until the edge budget runs out.
@@ -684,11 +782,48 @@ ov::hetero::SubgraphCollector::SubgraphIdsMap ov::hetero::SubgraphCollector::spl
"Subgraph SCC fallback promoted edges but _subgraph_inputs did not grow");
ids_valid = false; // _subgraph_inputs grew; next iteration must rebuild ids.
}
+ if (perf_logging_enabled) {
+ t_scc_end = clock::now();
+ }
// Edge case: if init() produced no _subgraph_inputs at all, the per-node loop never ran and
// subgraph_ids is empty. Materialize the final mapping in that case.
if (subgraph_ids.empty()) {
+ clock::time_point t_collect_start{};
+ if (perf_logging_enabled) {
+ t_collect_start = clock::now();
+ }
subgraph_ids = collect_subgraphs_ids();
+ if (perf_logging_enabled) {
+ collect_ids_time += clock::now() - t_collect_start;
+ }
+ }
+ if (perf_logging_enabled) {
+ const auto t_end = clock::now();
+ const auto total_ms = to_ms(t_end - t0);
+ if (total_ms > 0) {
+ HETERO_PERF_LOG_LEVEL(PerfLogLevel::PartitionDetails,
+ "SubgraphCollector::split_cyclic_dependencies timing: stage=",
+ _log_context,
+ ", nodes=",
+ nodes_count,
+ ", total=",
+ total_ms,
+ " ms, node_scan_total=",
+ to_ms(t_per_node_end - t_per_node_start),
+ " ms, node_scan_nodes_per_iteration=",
+ nodes_count,
+ ", node_scan_iterations=",
+ node_scan_iterations,
+ ", collect_subgraphs_ids=",
+ to_ms(collect_ids_time),
+ " ms, scc_fallback=",
+ to_ms(t_scc_end - t_scc_start),
+ " ms, scc_iterations=",
+ scc_iterations,
+ ", scc_promoted_edges=",
+ scc_promoted_edges);
+ }
}
return subgraph_ids;
}
@@ -1087,7 +1222,8 @@ std::pair<ov::hetero::SubgraphsVector, ov::hetero::SubgraphsMappingInfo> ov::het
ov::SupportedOpsMap& supported_ops,
const bool user_set_affinities,
const bool dump_dot_files,
- const std::string default_device) {
+ const std::string default_device,
+ const std::string log_context) {
std::unordered_set<std::string> devices;
ov::hetero::SubgraphCollector::AffinitiesMap affinities;
ov::SupportedOpsMap debug_supported_ops{supported_ops};
@@ -1139,7 +1275,7 @@ std::pair<ov::hetero::SubgraphsVector, ov::hetero::SubgraphsMappingInfo> ov::het
}
// Init subgraph collector
- ov::hetero::SubgraphCollector subgraph_collector(model, affinities);
+ ov::hetero::SubgraphCollector subgraph_collector(model, affinities, log_context);
if (dump_dot_files) {
auto subgraph_ids = subgraph_collector.get_subgraph_ids();
@@ -1202,16 +1338,36 @@ void ov::hetero::fix_submodel_with_paged_attention(std::shared_ptr<ov::Model>& m
ov::hetero::SubgraphsMappingInfo ov::hetero::mask_model_subgraphs_by_ops(std::shared_ptr<ov::Model>& model,
ov::SupportedOpsMap& supported_ops,
const bool dump_dot_files,
- const std::string default_device) {
+ const std::string default_device,
+ const std::string log_context) {
+ using clock = std::chrono::steady_clock;
+ const auto to_ms = [](clock::duration d) {
+ return std::chrono::duration_cast<std::chrono::milliseconds>(d).count();
+ };
+ const bool perf_logging_enabled = perf_log_enabled(PerfLogLevel::PartitionDetails);
const std::string subgraph_id_rt_info_name = "HETERO_SUBGRAPH_ID";
const std::string input_id_rt_info_name = "HETERO_INPUT_ID";
const std::string output_id_rt_info_name = "HETERO_OUTPUT_ID";
const auto& name = model->get_friendly_name();
+ const auto original_nodes = model->get_ops().size();
+ clock::time_point t0{};
+ clock::time_point t_collect_start{};
+ clock::time_point t_collect_end{};
+ clock::time_point t_rewrite_start{};
+ clock::time_point t_rewrite_end{};
+ if (perf_logging_enabled) {
+ t0 = clock::now();
+ t_collect_start = t0;
+ }
SubgraphsVector ordered_subgraphs;
SubgraphsMappingInfo mapping_info;
std::tie(ordered_subgraphs, mapping_info) =
- get_model_subgraphs(model, supported_ops, false, dump_dot_files, default_device);
+ get_model_subgraphs(model, supported_ops, false, dump_dot_files, default_device, log_context);
+ if (perf_logging_enabled) {
+ t_collect_end = clock::now();
+ t_rewrite_start = t_collect_end;
+ }
SubmodelsVector submodels{ordered_subgraphs.size()};
for (size_t i = 0; i < ordered_subgraphs.size(); i++) {
@@ -1280,6 +1436,27 @@ ov::hetero::SubgraphsMappingInfo ov::hetero::mask_model_subgraphs_by_ops(std::sh
}
}
}
+ if (perf_logging_enabled) {
+ t_rewrite_end = clock::now();
+ const auto total_ms = to_ms(t_rewrite_end - t0);
+ if (total_ms > 0) {
+ HETERO_PERF_LOG_LEVEL(PerfLogLevel::PartitionDetails,
+ "partition_and_rewrite_model timing: stage=",
+ log_context,
+ ", model=",
+ name,
+ ", nodes=",
+ original_nodes,
+ ", total=",
+ total_ms,
+ " ms, collect_subgraphs=",
+ to_ms(t_collect_end - t_collect_start),
+ " ms, rewrite_subgraph_model=",
+ to_ms(t_rewrite_end - t_rewrite_start),
+ " ms, subgraph_count=",
+ ordered_subgraphs.size());
+ }
+ }
merge_submodels(submodels, mapping_info._submodels_input_to_prev_output);
diff --git a/src/plugins/hetero/src/subgraph_collector.hpp b/src/plugins/hetero/src/subgraph_collector.hpp
index 428e87e1f70..7bc19aac9d8 100644
--- a/src/plugins/hetero/src/subgraph_collector.hpp
+++ b/src/plugins/hetero/src/subgraph_collector.hpp
@@ -46,7 +46,9 @@ public:
using OutputSet = std::set<Output>;
using InputVector = std::vector<Input>;
using OutputVector = std::vector<Output>;
- SubgraphCollector(const std::shared_ptr<ov::Model>& model, const AffinitiesMap& affinities);
+ SubgraphCollector(const std::shared_ptr<ov::Model>& model,
+ const AffinitiesMap& affinities,
+ std::string log_context = {});
SubgraphIdsMap get_subgraph_ids() {
return _subgraph_ids;
}
@@ -75,6 +77,7 @@ private:
InputSet _subgraph_inputs;
SubgraphIdsMap _subgraph_ids;
ParameterResultMap _subgraph_parameter_to_prev_result;
+ std::string _log_context;
};
void merge_submodels(SubmodelsVector& submodels, const std::map<NodeInfo, NodeInfo>& submodels_input_to_prev_output);
@@ -83,12 +86,14 @@ std::pair<SubgraphsVector, SubgraphsMappingInfo> get_model_subgraphs(const std::
ov::SupportedOpsMap& supported_ops,
const bool user_set_affinities = false,
const bool dump_dot_files = false,
- const std::string default_device = "");
+ const std::string default_device = "",
+ const std::string log_context = "");
SubgraphsMappingInfo mask_model_subgraphs_by_ops(std::shared_ptr<ov::Model>& model,
ov::SupportedOpsMap& supported_ops,
const bool dump_dot_files = false,
- const std::string default_device = "");
+ const std::string default_device = "",
+ const std::string log_context = "");
void fix_submodel_with_paged_attention(std::shared_ptr<ov::Model>& model);