From 85414e43a9ac886400fefed6b4a340478dfe513d Mon Sep 17 00:00:00 2001 From: Lei Cao Date: Wed, 18 Sep 2024 23:17:39 +0000 Subject: [PATCH] dump Graph topology in allocation_planner.cc --- .../core/framework/allocation_planner.cc | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/onnxruntime/core/framework/allocation_planner.cc b/onnxruntime/core/framework/allocation_planner.cc index eae152b180c89..e445b0ddc81b5 100644 --- a/onnxruntime/core/framework/allocation_planner.cc +++ b/onnxruntime/core/framework/allocation_planner.cc @@ -2205,6 +2205,51 @@ Status PlannerImpl::CreatePlan( // TODO: enable verification // VerifyMemoryTimeSchedule(); + // dump Graph topology + const std::vector& graph_inputs = graph_viewer_.GetInputs(); + std::cout<<"\n\ngraph inputs:\n"; + for (size_t i = 0; i < graph_inputs.size(); i++) { + std::cout<Name()<<"\n"; + } + const std::vector& graph_inputs_initializers = graph_viewer_.GetInputsIncludingInitializers(); + std::cout<<"\n\ngraph inputs including initializers:\n"; + for (size_t i = 0; i < graph_inputs_initializers.size(); i++) { + std::cout<Name()<<"\n"; + } + const std::vector& graph_outputs = graph_viewer_.GetOutputs(); + std::cout<<"\n\ngraph outputs:\n"; + for (size_t i = 0; i < graph_outputs.size(); i++) { + std::cout<Name()<<"\n"; + } + const std::unordered_set& graph_value_info = graph_viewer_.GetValueInfo(); + std::cout<<"\n\ngraph value infos:\n"; + for (const auto& elem : graph_value_info) { + std::cout<Name()<<"\n"; + } + const InitializedTensorSet& initialized_set = graph_viewer_.GetAllInitializedTensors(); + std::cout<<"\n\ngraph initialized tensors:\n"; + for (const auto& elem : initialized_set) { + std::cout<& topo_sort = graph_viewer_.GetNodesInTopologicalOrder(); + for (size_t i = 0; i < topo_sort.size(); i++) { + const Node* node = graph_viewer_.GetNode(topo_sort[i]); + std::cout<<"Node:"<Name()<<", type:"<OpType()<<"\n"; + std::cout<<" Inputs:\n"; + for (size_t j = 0; j < node->InputDefs().size(); j++) { + std::cout<<" "<InputDefs()[j]->Name()<<"\n"; + } + std::cout<<" Implicit Inputs:\n"; + for (size_t j = 0; j < node->ImplicitInputDefs().size(); j++) { + std::cout<<" "<ImplicitInputDefs()[j]->Name()<<"\n"; + } + std::cout<<" Outputs:\n"; + for (size_t j = 0; j < node->OutputDefs().size(); j++) { + std::cout<<" "<OutputDefs()[j]->Name()<<"\n"; + } + } + return Status::OK(); }