diff --git a/onnxruntime/core/providers/shared_library/provider_interfaces.h b/onnxruntime/core/providers/shared_library/provider_interfaces.h index 74c67cc79d..d560527978 100644 --- a/onnxruntime/core/providers/shared_library/provider_interfaces.h +++ b/onnxruntime/core/providers/shared_library/provider_interfaces.h @@ -848,7 +848,7 @@ struct ProviderHost { virtual bool GraphViewer__GetInitializedTensor(const GraphViewer* p, const std::string& tensor_name, const ONNX_NAMESPACE::TensorProto*& value) = 0; virtual const std::unordered_map& GraphViewer__DomainToVersionMap(const GraphViewer* p) = 0; - virtual const std::vector& GraphViewer__GetNodesInTopologicalOrder(const GraphViewer* p) = 0; + virtual const std::vector& GraphViewer__GetNodesInTopologicalOrder(const GraphViewer* p, int execution_order) = 0; virtual const std::vector& GraphViewer__GetInputsIncludingInitializers(const GraphViewer* p) noexcept = 0; virtual void GraphViewer__ToProto(const GraphViewer* p, diff --git a/onnxruntime/core/providers/shared_library/provider_wrappedtypes.h b/onnxruntime/core/providers/shared_library/provider_wrappedtypes.h index b86c3b2ba5..a74630cdf7 100644 --- a/onnxruntime/core/providers/shared_library/provider_wrappedtypes.h +++ b/onnxruntime/core/providers/shared_library/provider_wrappedtypes.h @@ -884,7 +884,7 @@ class GraphViewer final { const std::unordered_map& DomainToVersionMap() const noexcept { return g_host->GraphViewer__DomainToVersionMap(this); } - const std::vector& GetNodesInTopologicalOrder() const { return g_host->GraphViewer__GetNodesInTopologicalOrder(this); } + const std::vector& GetNodesInTopologicalOrder(int execution_order = 0) const { return g_host->GraphViewer__GetNodesInTopologicalOrder(this, execution_order); } const std::vector& GetInputsIncludingInitializers() const noexcept { return g_host->GraphViewer__GetInputsIncludingInitializers(this); } void ToProto(ONNX_NAMESPACE::GraphProto& graph_proto, diff --git a/onnxruntime/core/providers/tensorrt/tensorrt_execution_provider.cc b/onnxruntime/core/providers/tensorrt/tensorrt_execution_provider.cc index 5e2da4990c..bfd464c700 100644 --- a/onnxruntime/core/providers/tensorrt/tensorrt_execution_provider.cc +++ b/onnxruntime/core/providers/tensorrt/tensorrt_execution_provider.cc @@ -1783,7 +1783,7 @@ bool TensorrtExecutionProvider::AllNodesAssignedToSpecificEP(const GraphViewer& const int number_of_ort_nodes = graph.NumberOfNodes(); std::vector nodes_vector(number_of_ort_nodes); std::iota(std::begin(nodes_vector), std::end(nodes_vector), 0); - const std::vector& node_index = graph.GetNodesInTopologicalOrder(); + const std::vector& node_index = graph.GetNodesInTopologicalOrder(1 /*priority-based topological sort*/); for (const auto& index : nodes_vector) { const auto& node = graph.GetNode(node_index[index]); if (node->GetExecutionProviderType() != provider_type) { @@ -1807,7 +1807,7 @@ bool TensorrtExecutionProvider::IsSubGraphFullySupported(SubGraphCollection_t su } std::unique_ptr TensorrtExecutionProvider::GetSubGraph(SubGraph_t graph_nodes_index, const GraphViewer& graph, const HashValue& model_hash, int subgraph_index) const { - const std::vector& node_index = graph.GetNodesInTopologicalOrder(); + const std::vector& node_index = graph.GetNodesInTopologicalOrder(1 /*priority-based topological sort*/); std::unordered_set node_set; node_set.reserve(graph_nodes_index.first.size()); for (const auto& index : graph_nodes_index.first) { @@ -1971,7 +1971,7 @@ SubGraphCollection_t TensorrtExecutionProvider::GetSupportedList(SubGraphCollect } iterations++; - const std::vector& node_index = graph.GetNodesInTopologicalOrder(); + const std::vector& node_index = graph.GetNodesInTopologicalOrder(1 /*priority-based topological sort*/); for (const auto& group : nodes_vector_input) { // Construct subgraph if (!group.first.empty()) { @@ -2135,7 +2135,7 @@ SubGraphCollection_t TensorrtExecutionProvider::GetSupportedList(SubGraphCollect trt_parser->supportsModel(string_buf.data(), string_buf.size(), parser_nodes_list, model_path_); SubGraphCollection_t next_nodes_list; - const std::vector& subgraph_node_index = graph_viewer->GetNodesInTopologicalOrder(); + const std::vector& subgraph_node_index = graph_viewer->GetNodesInTopologicalOrder(1 /*priority-based topological sort*/); next_nodes_list = GetSupportedList(parser_nodes_list, iterations, max_iterations, *graph_viewer, early_termination); for (size_t i = 0, end = next_nodes_list.size(); i < end; ++i) { for (size_t j = 0, end = next_nodes_list[i].first.size(); j < end; ++j) { @@ -2151,7 +2151,7 @@ SubGraphCollection_t TensorrtExecutionProvider::GetSupportedList(SubGraphCollect // Detect and remove cycles from supported node list bool TensorrtExecutionProvider::DetectTensorRTGraphCycles(SubGraphCollection_t& supported_nodes_vector, const GraphViewer& graph, const HashValue& model_hash, bool remove_cycles) const { - const std::vector& node_index = graph.GetNodesInTopologicalOrder(); + const std::vector& node_index = graph.GetNodesInTopologicalOrder(1 /*priority-based topological sort*/); bool trt_cycle = true, cycle_detected = false; while (trt_cycle) { trt_cycle = false; @@ -2299,7 +2299,7 @@ TensorrtExecutionProvider::GetCapability(const GraphViewer& graph, std::iota(std::begin(nodes_vector), std::end(nodes_vector), 0); std::vector filtered_nodes_vector; - const std::vector& node_index = graph.GetNodesInTopologicalOrder(); + const std::vector& node_index = graph.GetNodesInTopologicalOrder(1 /*priority-based topological sort*/); for (const auto& index : nodes_vector) { const auto& node = graph.GetNode(node_index[index]); @@ -2374,7 +2374,7 @@ TensorrtExecutionProvider::GetCapability(const GraphViewer& graph, // The purpose is to make control flow op as well as its subgraphs run on TRT. // Here we need to check whether subgraph is fully supported by TRT and don't fuse the nodes of the subgraph until control flow op level. if (IsSubGraphOfControlFlowOp(graph) && IsSubGraphFullySupported(supported_nodes_vector, number_of_ort_nodes)) { - const std::vector& node_index = graph.GetNodesInTopologicalOrder(); + const std::vector& node_index = graph.GetNodesInTopologicalOrder(1 /*priority-based topological sort*/); bool all_subgraphs_are_supported = true; // "If" control flow op has two subgraph bodies, "then" body and "else" body respectively. diff --git a/onnxruntime/core/session/provider_bridge_ort.cc b/onnxruntime/core/session/provider_bridge_ort.cc index 6bd277ec96..80bd301c20 100644 --- a/onnxruntime/core/session/provider_bridge_ort.cc +++ b/onnxruntime/core/session/provider_bridge_ort.cc @@ -1086,7 +1086,9 @@ struct ProviderHostImpl : ProviderHost { const std::unordered_map& GraphViewer__DomainToVersionMap(const GraphViewer* p) override { return p->DomainToVersionMap(); } - const std::vector& GraphViewer__GetNodesInTopologicalOrder(const GraphViewer* p) override { return p->GetNodesInTopologicalOrder(); } + const std::vector& GraphViewer__GetNodesInTopologicalOrder(const GraphViewer* p, int execution_order) override { + return p->GetNodesInTopologicalOrder(static_cast(execution_order)); + } const std::vector& GraphViewer__GetInputsIncludingInitializers(const GraphViewer* p) noexcept override { return p->GetInputsIncludingInitializers(); } void GraphViewer__ToProto(const GraphViewer* p, ONNX_NAMESPACE::GraphProto& graph_proto,