Imported Upstream version 1.7.0
[platform/core/ml/nnfw.git] / runtime / onert / core / src / dumper / dot / DotDumper.cc
index 9bd8ed0..118057f 100644 (file)
@@ -19,7 +19,7 @@
 
 #include "DotDumper.h"
 #include "DotBuilder.h"
-#include "DotOpSequenceInfo.h"
+#include "DotSubgraphInfo.h"
 #include "ir/OpSequence.h"
 #include "ir/OperationIndexMap.h"
 #include "backend/Backend.h"
@@ -48,19 +48,6 @@ void DotDumper::dump(const std::string &tag)
   ir::OperationIndexMap<std::unique_ptr<Operation>> operation_nodes;
   std::unordered_map<ir::OperandIndex, std::unique_ptr<Operand>> operand_nodes;
 
-  operations.iterate([&](const ir::OperationIndex &index, const ir::Operation &op) {
-    auto node = std::make_unique<Operation>(index, op);
-
-    for (auto output : op.getOutputs())
-    {
-      using onert::dumper::dot::Operand;
-      auto child = std::make_shared<Operand>(output, Operand::Type::MODEL_OUTPUT);
-      node->addEdge(child);
-    }
-
-    operation_nodes.emplace(index, std::move(node));
-  });
-
   auto backend_to_fillcolor = [](const backend::Backend *backend) {
     static const auto map = []() {
       std::unordered_map<const backend::Backend *, std::string> ret;
@@ -136,17 +123,35 @@ void DotDumper::dump(const std::string &tag)
         node->setAttribute("fillcolor", fillcolor);
       }
 
-      for (auto operation_index : object.getUses().list())
-      {
-        auto &operation = operations.at(operation_index);
-        auto child = std::make_shared<Operation>(operation_index, operation);
-        node->addEdge(child);
-      }
-
       operand_nodes.emplace(index, std::move(node));
     }
   });
 
+  operations.iterate([&](const ir::OperationIndex &index, const ir::Operation &op) {
+    auto node = std::make_unique<Operation>(index, op);
+
+    for (auto input : op.getInputs())
+    {
+      using onert::dumper::dot::Operand;
+
+      // Constant input and dump level is ALL_BUT_CONSTANTS
+      if (operand_nodes.find(input) == operand_nodes.end())
+        continue;
+
+      auto &input_node = operand_nodes.at(input);
+      input_node->addOutEdge(node.get());
+    }
+
+    for (auto output : op.getOutputs())
+    {
+      using onert::dumper::dot::Operand;
+      auto &output_node = operand_nodes.at(output);
+      node->addOutEdge(output_node.get());
+    }
+
+    operation_nodes.emplace(index, std::move(node));
+  });
+
   if (_lowered_graph)
   {
     const auto &op_seqs = _lowered_graph->op_seqs();
@@ -155,15 +160,15 @@ void DotDumper::dump(const std::string &tag)
       auto fillcolor = backend_to_fillcolor(lower_info->backend());
       std::string label =
           std::to_string(index.value()) + " [" + lower_info->backend()->config()->id() + "]";
-      DotOpSequenceInfo op_sequence_info{index, op_seq, shown_operand_set};
-      op_sequence_info.label(label);
-      op_sequence_info.fillcolor(fillcolor);
-      dot_builder.addOpSequence(op_sequence_info);
+      DotSubgraphInfo subgraph_info{index, op_seq, shown_operand_set, _graph.operations()};
+      subgraph_info.label(label);
+      subgraph_info.fillcolor(fillcolor);
+      dot_builder.addOpSequence(subgraph_info);
 
       // Set fillcolor of all operations in the op_seq
-      for (const auto &op : op_seq.operations())
+      for (const auto &op_idx : op_seq.operations())
       {
-        auto found = operation_nodes.find(op.index);
+        auto found = operation_nodes.find(op_idx);
         if (found != operation_nodes.end())
         {
           auto &&op = found->second;