2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "GraphDumper.h"
20 #include "compiler/LoweredGraph.h"
22 #include "compiler/train/LoweredTrainableGraph.h"
24 #include "util/logging.h"
25 #include "misc/string_helpers.h"
37 std::string formatOperandIndexSequence(const ir::OperandIndexSequence &seq)
39 std::vector<std::string> strs;
40 for (auto &&ind : seq)
41 strs.push_back(dumper::text::formatOperandBrief(ind));
42 return nnfw::misc::join(strs.begin(), strs.end(), ", ");
47 std::string formatOperandBrief(ir::OperandIndex ind)
54 std::string formatOperand(const ir::Graph &, ir::OperandIndex ind)
58 // TODO Print shape, type and maybe more
62 std::string formatOperation(const ir::IOperation &op, ir::OperationIndex ind)
66 ss << formatOperandIndexSequence(op.getOutputs());
68 ss << ind << "_" << op.name() << "(";
69 ss << formatOperandIndexSequence(op.getInputs());
74 std::string formatOperation(const ir::Graph &graph, ir::OperationIndex ind)
77 const auto &op = graph.operations().at(ind);
78 return formatOperation(op, ind);
81 void dumpGraph(const ir::Graph &graph)
83 VERBOSE(GraphDumper) << "{\n";
84 auto ops_topol = graph.topolSortOperations();
85 for (auto &&op_ind : ops_topol)
87 const auto &op = graph.operations().at(op_ind);
88 VERBOSE(GraphDumper) << " " << formatOperation(op, op_ind) << "\n";
90 VERBOSE(GraphDumper) << "}\n";
91 VERBOSE(GraphDumper) << std::endl;
94 void dumpLoweredGraph(const compiler::LoweredGraph &lgraph)
96 // TODO Graph dump with backend info
97 dumpGraph(lgraph.graph());
101 void dumpLoweredGraph(const compiler::train::LoweredTrainableGraph &lgraph)
103 // TODO Graph dump with backend info
104 dumpGraph(lgraph.graph());
106 #endif // ONERT_TRAIN
109 } // namespace dumper