Imported Upstream version 1.25.0
[platform/core/ml/nnfw.git] / runtime / onert / core / src / dumper / text / GraphDumper.cc
index 80cfbbc..6bd7904 100644 (file)
@@ -18,6 +18,9 @@
 
 #include "ir/Graph.h"
 #include "compiler/LoweredGraph.h"
+#ifdef ONERT_TRAIN
+#include "compiler/train/LoweredTrainableGraph.h"
+#endif // ONERT_TRAIN
 #include "util/logging.h"
 #include "misc/string_helpers.h"
 
@@ -34,7 +37,7 @@ namespace
 std::string formatOperandIndexSequence(const ir::OperandIndexSequence &seq)
 {
   std::vector<std::string> strs;
-  for (auto ind : seq)
+  for (auto &&ind : seq)
     strs.push_back(dumper::text::formatOperandBrief(ind));
   return nnfw::misc::join(strs.begin(), strs.end(), ", ");
 }
@@ -56,10 +59,9 @@ std::string formatOperand(const ir::Graph &, ir::OperandIndex ind)
   return ss.str();
 }
 
-std::string formatOperation(const ir::Graph &graph, ir::OperationIndex ind)
+std::string formatOperation(const ir::IOperation &op, ir::OperationIndex ind)
 {
   std::stringstream ss;
-  const auto &op = graph.operations().at(ind);
 
   ss << formatOperandIndexSequence(op.getOutputs());
   ss << " = ";
@@ -69,13 +71,21 @@ std::string formatOperation(const ir::Graph &graph, ir::OperationIndex ind)
   return ss.str();
 }
 
+std::string formatOperation(const ir::Graph &graph, ir::OperationIndex ind)
+{
+  std::stringstream ss;
+  const auto &op = graph.operations().at(ind);
+  return formatOperation(op, ind);
+}
+
 void dumpGraph(const ir::Graph &graph)
 {
   VERBOSE(GraphDumper) << "{\n";
   auto ops_topol = graph.topolSortOperations();
-  for (auto op_ind : ops_topol)
+  for (auto &&op_ind : ops_topol)
   {
-    VERBOSE(GraphDumper) << "  " << formatOperation(graph, op_ind) << "\n";
+    const auto &op = graph.operations().at(op_ind);
+    VERBOSE(GraphDumper) << "  " << formatOperation(op, op_ind) << "\n";
   }
   VERBOSE(GraphDumper) << "}\n";
   VERBOSE(GraphDumper) << std::endl;
@@ -87,6 +97,14 @@ void dumpLoweredGraph(const compiler::LoweredGraph &lgraph)
   dumpGraph(lgraph.graph());
 }
 
+#ifdef ONERT_TRAIN
+void dumpLoweredGraph(const compiler::train::LoweredTrainableGraph &lgraph)
+{
+  // TODO Graph dump with backend info
+  dumpGraph(lgraph.graph());
+}
+#endif // ONERT_TRAIN
+
 } // namespace text
 } // namespace dumper
 } // namespace onert