[neurun] Dump Operand in order of OperandIndex (#9254)
author이한종/On-Device Lab(SR)/Engineer/삼성전자 <hanjoung.lee@samsung.com>
Thu, 28 Nov 2019 01:57:31 +0000 (10:57 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Thu, 28 Nov 2019 01:57:31 +0000 (10:57 +0900)
`Graph::lower` dumps operands but its order is random since it iterates
over the unordered container. This commit makes it to dump in the order
of operand index.

Signed-off-by: Hanjoung Lee <hanjoung.lee@samsung.com>
runtime/neurun/core/src/graph/Graph.cc

index 585e8fe..89ff907 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <algorithm>
 #include <bitset>
+#include <sstream>
 
 #include "util/logging.h"
 #include "verifier/Verifier.h"
@@ -425,9 +426,10 @@ void Graph::dumpLowerInfo()
   if (::neurun::util::logging::ctx.enabled() == false)
     return;
 
+  std::map<uint32_t, std::string> dumps;
+
   _model->operands.iterate([&](const model::OperandIndex &index, model::Operand &object) {
-    // Dump operand LowerInfo
-    // TODO Extract this dumping procedure to be reusable
+    std::stringstream sstream;
     if (!getLowerInfo(index)->def_factors().empty() || !getLowerInfo(index)->use_factors().empty())
     {
       auto factors_to_string = [](const operand::PermuteFactorSet &factors) {
@@ -458,22 +460,31 @@ void Graph::dumpLowerInfo()
       std::string use_ops = operation_index_to_string(object.getUses());
       std::string def_layouts = factors_to_string(lower_info->def_factors());
       std::string use_layouts = factors_to_string(lower_info->use_factors());
-      VERBOSE(Lower) << "* Operand #" << index.value() << " LowerInfo" << std::endl;
-      VERBOSE(Lower) << "  - Shape           : { " << (shape.rank() > 0 ? shape.dim(0) : 0) << " "
-                     << (shape.rank() > 1 ? shape.dim(1) : 0) << " "
-                     << (shape.rank() > 2 ? shape.dim(2) : 0) << " "
-                     << (shape.rank() > 3 ? shape.dim(3) : 0) << " "
-                     << "}" << std::endl;
-      VERBOSE(Lower) << "  - Def Operations  : " << def_ops << std::endl;
-      VERBOSE(Lower) << "  - Use Operations  : " << use_ops << std::endl;
-      VERBOSE(Lower) << "  - Lower Info" << std::endl;
-      VERBOSE(Lower) << "    - 4D Shape (NHWC) : { " << lower_shape.n() << " " << lower_shape.h()
-                     << " " << lower_shape.w() << " " << lower_shape.c() << " "
-                     << "}" << std::endl;
-      VERBOSE(Lower) << "    - Def Backends    : " << def_layouts << std::endl;
-      VERBOSE(Lower) << "    - Use Backends    : " << use_layouts << std::endl;
+      sstream << "Operand #" << index.value() << " LowerInfo" << std::endl;
+      sstream << "  - Shape           : { " << (shape.rank() > 0 ? shape.dim(0) : 0) << " "
+              << (shape.rank() > 1 ? shape.dim(1) : 0) << " "
+              << (shape.rank() > 2 ? shape.dim(2) : 0) << " "
+              << (shape.rank() > 3 ? shape.dim(3) : 0) << " "
+              << "}" << std::endl;
+      sstream << "  - Def Operations  : " << def_ops << std::endl;
+      sstream << "  - Use Operations  : " << use_ops << std::endl;
+      sstream << "  - Lower Info" << std::endl;
+      sstream << "    - 4D Shape (NHWC) : { " << lower_shape.n() << " " << lower_shape.h() << " "
+              << lower_shape.w() << " " << lower_shape.c() << " "
+              << "}" << std::endl;
+      sstream << "    - Def Backends    : " << def_layouts << std::endl;
+      sstream << "    - Use Backends    : " << use_layouts << std::endl;
     }
+    dumps.emplace(index.value(), sstream.str());
   });
+
+  for (const auto &e : dumps)
+  {
+    if (!e.second.empty())
+    {
+      VERBOSE(Lower) << e.second;
+    }
+  }
 }
 
 bool Graph::mergeable(const model::SubgraphIndex &subg_index,