Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 22 additions & 29 deletions onnxruntime/core/providers/openvino/ov_versions/capability.cc
Original file line number Diff line number Diff line change
Expand Up @@ -166,33 +166,24 @@ std::vector<std::unique_ptr<ComputeCapability>> GetCapability::Execute() {
auto connected_clusters = GetConnectedClusters(graph_viewer_, ng_clusters);

int no_of_clusters = 0;
std::vector<NodeIndex> prev_cluster;
bool try_next_cluster = false;

size_t cluster_index = 0;
size_t total_clusters = connected_clusters.size();
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);
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 < 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);
}
omit_subgraph=true;
}
}

std::vector<std::string> cluster_graph_inputs, cluster_inputs, cluster_outputs;
Expand Down Expand Up @@ -233,15 +224,17 @@ std::vector<std::unique_ptr<ComputeCapability>> 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;
}
Expand Down
20 changes: 20 additions & 0 deletions onnxruntime/core/providers/openvino/ov_versions/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,26 @@ GetConnectedClusters(const GraphViewer& graph_viewer, const std::vector<std::vec
return connected_clusters;
}

bool AddTrivialClusterToNextClusterIfConnected(const GraphViewer& graph_viewer,
const NodeIndex curr_node_index,
const std::vector<NodeIndex>& 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<NodeIndex>& cluster,
const std::unordered_set<std::string>& ng_required_initializers,
Expand Down
4 changes: 4 additions & 0 deletions onnxruntime/core/providers/openvino/ov_versions/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ void IdentifyConnectedNodes(
std::vector<std::vector<NodeIndex>>
GetConnectedClusters(const GraphViewer& graph_viewer, const std::vector<std::vector<NodeIndex>>& clusters);

bool AddTrivialClusterToNextClusterIfConnected(const GraphViewer& graph_viewer,
const NodeIndex index,
const std::vector<NodeIndex>& search_cluster);

void GetInputsOutputsOfCluster(const GraphViewer& graph_viewer,
const std::vector<NodeIndex>& cluster,
const std::unordered_set<std::string>& ng_required_initializers,
Expand Down
2 changes: 1 addition & 1 deletion onnxruntime/test/providers/cpu/controlflow/loop_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading