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"
21 #include "util/logging.h"
22 #include "misc/string_helpers.h"
34 std::string formatOperandIndexSequence(const ir::OperandIndexSequence &seq)
36 std::vector<std::string> strs;
38 strs.push_back(dumper::text::formatOperandBrief(ind));
39 return nnfw::misc::join(strs.begin(), strs.end(), ", ");
44 std::string formatOperandBrief(ir::OperandIndex ind)
51 std::string formatOperand(const ir::Graph &, ir::OperandIndex ind)
55 // TODO Print shape, type and maybe more
59 std::string formatOperation(const ir::Graph &graph, ir::OperationIndex ind)
62 const auto &op = graph.operations().at(ind);
64 ss << formatOperandIndexSequence(op.getOutputs());
66 ss << ind << "_" << op.name() << "(";
67 ss << formatOperandIndexSequence(op.getInputs());
72 void dumpGraph(const ir::Graph &graph)
74 VERBOSE(GraphDumper) << "{\n";
75 auto ops_topol = graph.topolSortOperations();
76 for (auto op_ind : ops_topol)
78 VERBOSE(GraphDumper) << " " << formatOperation(graph, op_ind) << "\n";
80 VERBOSE(GraphDumper) << "}\n";
81 VERBOSE(GraphDumper) << std::endl;
84 void dumpLoweredGraph(const compiler::LoweredGraph &lgraph)
86 // TODO Graph dump with backend info
87 dumpGraph(lgraph.graph());