From f3ac3bfa3ab220a6ac243f9d73d894cd26fb7797 Mon Sep 17 00:00:00 2001 From: sfatimar Date: Thu, 21 Aug 2025 21:49:36 +0530 Subject: [PATCH 1/5] Changed fix --- .../openvino/ov_versions/capability.cc | 52 ++++++++----------- .../providers/openvino/ov_versions/utils.cc | 20 +++++++ .../providers/openvino/ov_versions/utils.h | 4 ++ 3 files changed, 47 insertions(+), 29 deletions(-) diff --git a/onnxruntime/core/providers/openvino/ov_versions/capability.cc b/onnxruntime/core/providers/openvino/ov_versions/capability.cc index 4ad8f8dd85f4d..a0771db744bf6 100644 --- a/onnxruntime/core/providers/openvino/ov_versions/capability.cc +++ b/onnxruntime/core/providers/openvino/ov_versions/capability.cc @@ -166,33 +166,25 @@ std::vector> GetCapability::Execute() { auto connected_clusters = GetConnectedClusters(graph_viewer_, ng_clusters); int no_of_clusters = 0; - std::vector prev_cluster; - bool try_next_cluster = false; - + int cluster_index = 0; for (auto this_cluster : connected_clusters) { bool omit_subgraph = false; - if (try_next_cluster) { - // no need to check previous cluster - for (auto idx : prev_cluster) { - if ((std::find(this_cluster.begin(), this_cluster.end(), idx)) == this_cluster.end()) { - this_cluster.emplace_back(idx); - } - } - try_next_cluster = false; - } - // If subgraph has less then three, graph is considered trivial unless its an epctx cluster - if (!try_next_cluster && this_cluster.size() < 3) { - bool is_epctx_node = false; - for (auto node_idx : this_cluster) { - if (graph_viewer_.GetNode(node_idx)->OpType() == "EPContext") - is_epctx_node = true; - } - if (!is_epctx_node) { - omit_subgraph = true; - prev_cluster = this_cluster; - try_next_cluster = true; - } + auto id = this_cluster.at(0); + std::cout << graph_viewer_.GetNode(id)->Name() << "\n"; + + if (this_cluster.size() == 1) { + //check next cluster + auto index = this_cluster.at(0); + if (graph_viewer_.GetNode(index)->OpType() != "EPContext") { + bool append_node = AddTrivialClusterToNextClusterIfConnected(graph_viewer_, index, connected_clusters[cluster_index+1]); + if(append_node) { + connected_clusters[cluster_index+1].emplace_back(index); + } + omit_subgraph=true; + } else if (graph_viewer_.GetNode(index)->OpType() == "EPContext") { + omit_subgraph=false; + } } std::vector cluster_graph_inputs, cluster_inputs, cluster_outputs; @@ -233,15 +225,17 @@ std::vector> GetCapability::Execute() { } } } - if (omit_subgraph) - continue; /* In scenarios, when there are no inputs or all inputs being initializers, ConstantFolding optimization in onnxruntime pre-computes the value.*/ - if (!cluster_inputs.empty()) { - AppendClusterToSubGraph(this_cluster, cluster_inputs, cluster_outputs, result); - no_of_clusters++; + if (!omit_subgraph) { + if (!cluster_inputs.empty()) { + AppendClusterToSubGraph(this_cluster, cluster_inputs, cluster_outputs, result); + no_of_clusters++; + } } + + cluster_index = cluster_index+1; } LOGS_DEFAULT(INFO) << "[OpenVINO-EP] Supported subgraphs on OpenVINO: " << no_of_clusters; } diff --git a/onnxruntime/core/providers/openvino/ov_versions/utils.cc b/onnxruntime/core/providers/openvino/ov_versions/utils.cc index f924fa0c8205c..814378eab47d5 100644 --- a/onnxruntime/core/providers/openvino/ov_versions/utils.cc +++ b/onnxruntime/core/providers/openvino/ov_versions/utils.cc @@ -153,6 +153,26 @@ GetConnectedClusters(const GraphViewer& graph_viewer, const std::vector& search_cluster) { + + for(auto index: search_cluster) { + auto curr_node = graph_viewer.GetNode(index); + for (auto node = curr_node->InputNodesBegin(); node != curr_node->InputNodesEnd(); ++node) { + if((*node).Index() == curr_node_index) + return true; + } + + for (auto node = curr_node->OutputNodesBegin(); node != curr_node->OutputNodesEnd(); ++node) { + if((*node).Index() == curr_node_index) + return true; + } + } + return false; +} + + void GetInputsOutputsOfCluster(const GraphViewer& graph_viewer, const std::vector& cluster, const std::unordered_set& ng_required_initializers, diff --git a/onnxruntime/core/providers/openvino/ov_versions/utils.h b/onnxruntime/core/providers/openvino/ov_versions/utils.h index 34aa762ba9b67..bdad047a422c1 100644 --- a/onnxruntime/core/providers/openvino/ov_versions/utils.h +++ b/onnxruntime/core/providers/openvino/ov_versions/utils.h @@ -40,6 +40,10 @@ void IdentifyConnectedNodes( std::vector> GetConnectedClusters(const GraphViewer& graph_viewer, const std::vector>& clusters); +bool AddTrivialClusterToNextClusterIfConnected(const GraphViewer& graph_viewer, + const NodeIndex index, + const std::vector& search_cluster); + void GetInputsOutputsOfCluster(const GraphViewer& graph_viewer, const std::vector& cluster, const std::unordered_set& ng_required_initializers, From 83ee65f8fafadbf82015f729d8d7b37695cc0fee Mon Sep 17 00:00:00 2001 From: sfatimar Date: Fri, 22 Aug 2025 11:56:54 +0530 Subject: [PATCH 2/5] Fix to omit subgraph --- .../core/providers/openvino/ov_versions/capability.cc | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/onnxruntime/core/providers/openvino/ov_versions/capability.cc b/onnxruntime/core/providers/openvino/ov_versions/capability.cc index a0771db744bf6..ead5779e8effb 100644 --- a/onnxruntime/core/providers/openvino/ov_versions/capability.cc +++ b/onnxruntime/core/providers/openvino/ov_versions/capability.cc @@ -171,19 +171,17 @@ std::vector> GetCapability::Execute() { bool omit_subgraph = false; auto id = this_cluster.at(0); - std::cout << graph_viewer_.GetNode(id)->Name() << "\n"; - if (this_cluster.size() == 1) { //check next cluster auto index = this_cluster.at(0); - if (graph_viewer_.GetNode(index)->OpType() != "EPContext") { + if (graph_viewer_.GetNode(index)->OpType() == "EPContext") { + omit_subgraph=false; + } else if(cluster_index < this_cluster.size()-1) { bool append_node = AddTrivialClusterToNextClusterIfConnected(graph_viewer_, index, connected_clusters[cluster_index+1]); if(append_node) { connected_clusters[cluster_index+1].emplace_back(index); } omit_subgraph=true; - } else if (graph_viewer_.GetNode(index)->OpType() == "EPContext") { - omit_subgraph=false; } } From ac4b8d4058da779b3313b4b84c76da2786ef9481 Mon Sep 17 00:00:00 2001 From: sfatimar Date: Fri, 22 Aug 2025 12:44:49 +0530 Subject: [PATCH 3/5] Commit a fix for cluster index len --- onnxruntime/core/providers/openvino/ov_versions/capability.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/onnxruntime/core/providers/openvino/ov_versions/capability.cc b/onnxruntime/core/providers/openvino/ov_versions/capability.cc index ead5779e8effb..559a66a5f228b 100644 --- a/onnxruntime/core/providers/openvino/ov_versions/capability.cc +++ b/onnxruntime/core/providers/openvino/ov_versions/capability.cc @@ -170,13 +170,13 @@ std::vector> GetCapability::Execute() { for (auto this_cluster : connected_clusters) { bool omit_subgraph = false; - auto id = this_cluster.at(0); + //auto id = this_cluster.at(0); if (this_cluster.size() == 1) { //check next cluster auto index = this_cluster.at(0); if (graph_viewer_.GetNode(index)->OpType() == "EPContext") { omit_subgraph=false; - } else if(cluster_index < this_cluster.size()-1) { + } else if(cluster_index < connected_clusters.size()-1) { bool append_node = AddTrivialClusterToNextClusterIfConnected(graph_viewer_, index, connected_clusters[cluster_index+1]); if(append_node) { connected_clusters[cluster_index+1].emplace_back(index); From eaf1dac081b9b54c7053f26f54aa08aacc605cf8 Mon Sep 17 00:00:00 2001 From: sfatimar Date: Mon, 25 Aug 2025 13:13:21 +0530 Subject: [PATCH 4/5] Fixing the Warning with size_t on clusters --- .../core/providers/openvino/ov_versions/capability.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/onnxruntime/core/providers/openvino/ov_versions/capability.cc b/onnxruntime/core/providers/openvino/ov_versions/capability.cc index 559a66a5f228b..4be4bff039df4 100644 --- a/onnxruntime/core/providers/openvino/ov_versions/capability.cc +++ b/onnxruntime/core/providers/openvino/ov_versions/capability.cc @@ -166,7 +166,8 @@ std::vector> GetCapability::Execute() { auto connected_clusters = GetConnectedClusters(graph_viewer_, ng_clusters); int no_of_clusters = 0; - int cluster_index = 0; + size_t cluster_index = 0; + size_t total_clusters = connected_clusters.size(); for (auto this_cluster : connected_clusters) { bool omit_subgraph = false; @@ -176,7 +177,7 @@ std::vector> GetCapability::Execute() { auto index = this_cluster.at(0); if (graph_viewer_.GetNode(index)->OpType() == "EPContext") { omit_subgraph=false; - } else if(cluster_index < connected_clusters.size()-1) { + } else if(cluster_index < total_clusters-1) { bool append_node = AddTrivialClusterToNextClusterIfConnected(graph_viewer_, index, connected_clusters[cluster_index+1]); if(append_node) { connected_clusters[cluster_index+1].emplace_back(index); From a0fa81640beb16dcb6cc6d7fb0cb17f53b2261b7 Mon Sep 17 00:00:00 2001 From: sfatimar Date: Mon, 25 Aug 2025 15:06:58 +0530 Subject: [PATCH 5/5] Loop Test fix --- onnxruntime/test/providers/cpu/controlflow/loop_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/onnxruntime/test/providers/cpu/controlflow/loop_test.cc b/onnxruntime/test/providers/cpu/controlflow/loop_test.cc index a5fd37361a255..a92c1ed47f69b 100644 --- a/onnxruntime/test/providers/cpu/controlflow/loop_test.cc +++ b/onnxruntime/test/providers/cpu/controlflow/loop_test.cc @@ -1162,7 +1162,7 @@ TEST(Loop, SequenceAsLoopCarriedDependency) { test.AddSeqOutput("loop_var_0_final", seq_output); // Disable TensorRT on unsupported data type BOOL - test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider}); + test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider, kOpenVINOExecutionProvider}); } #if !defined(DISABLE_OPTIONAL_TYPE)