[neurun] Enhance DotDumper backend color assign (#6368)
author이한종/On-Device Lab(SR)/Engineer/삼성전자 <hanjoung.lee@samsung.com>
Thu, 8 Aug 2019 02:27:18 +0000 (11:27 +0900)
committer이성재/On-Device Lab(SR)/Principal Engineer/삼성전자 <sj925.lee@samsung.com>
Thu, 8 Aug 2019 02:27:18 +0000 (11:27 +0900)
Enhance DotDumper backend color assignment. Each Backend will have its
unique color up to 8 of them. Before it was assigned based on hard-coded
Backend ID.

Signed-off-by: Hanjoung Lee <hanjoung.lee@samsung.com>
runtimes/neurun/core/src/dumper/dot/DotDumper.cc

index f20713d..bf147b7 100644 (file)
@@ -23,6 +23,7 @@
 #include "model/Subgraph.h"
 #include "model/OperationIndexMap.h"
 #include "backend/Backend.h"
+#include "backend/BackendManager.h"
 #include "backend/IConfig.h"
 
 namespace neurun
@@ -62,20 +63,26 @@ void DotDumper::dump(const std::string &tag)
     operation_nodes.emplace(index, std::move(node));
   });
 
-  auto backend_to_fillcolor = [](const neurun::backend::Backend *backend) {
-    std::string backend_id = backend->config()->id();
-    // TODO : This is just workaround it can be made more efficient.
-    if (backend_id == "acl_cl")
-    {
-      return OperandNode::BG_COLORS[BLUE];
-    }
-    else if (backend_id == "cpu")
+  auto backend_to_fillcolor = [](const backend::Backend *backend) {
+    static const auto map = []() {
+      std::unordered_map<const backend::Backend *, std::string> ret;
+      uint32_t index = 1; // Start from 1 to avoid 0(red) which is too dark :(
+      for (const auto backend : backend::BackendManager::instance().getAll())
+      {
+        ret.emplace(backend, OperandNode::BG_COLORS[index]);
+        index = (index + 1) % (sizeof(Node::BG_COLORS) / sizeof(Node::BG_COLORS[0]));
+      }
+      return ret;
+    }();
+
+    auto itr = map.find(backend);
+    if (itr == map.end())
     {
-      return OperandNode::BG_COLORS[GREEN];
+      return Node::DEFAULT_FILLCOLOR;
     }
     else
     {
-      return Node::DEFAULT_FILLCOLOR;
+      return itr->second;
     }
   };