[nnc] Update constant support in Graph (#2620)
authorVladimir Plazun/AI Tools Lab /SRR/Engineer/삼성전자 <v.plazun@samsung.com>
Wed, 12 Dec 2018 10:13:56 +0000 (13:13 +0300)
committerEfimov Alexander/AI Tools Lab/./Samsung Electronics <a.efimov@samsung.com>
Wed, 12 Dec 2018 10:13:56 +0000 (13:13 +0300)
Do not list constants as inputs
Mark inputs resolved before running visitor
Register constant automatically, no need to keep track in importers

Signed-off-by: Vladimir Plazun <v.plazun@partner.samsung.com>
contrib/nnc/core/modelIR/Graph.cpp
contrib/nnc/include/core/modelIR/Graph.h

index 4e18187..fd9eb87 100644 (file)
@@ -77,6 +77,11 @@ void Graph::accept(IVisitor* visitor) {
     known_ops.insert(e.second); //Consider all input _ops resolved by default
   }
 
+  for (const auto& e : _constants) {
+    q.push_back(e);
+    known_ops.insert(e); //Consider all input _ops resolved by default
+  }
+
   //BFS
   while (!q.empty()) {
     auto n = q.front();
@@ -120,9 +125,6 @@ std::vector<Operation*> Graph::collectInputs() const {
   for (auto& e : _inputs) {
     res.emplace_back(e.second);
   }
-  for (auto c : _constants) {
-    res.emplace_back(c);
-  }
   return res;
 }
 
index 95b10c0..edd227d 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "core/modelIR/Operation.h"
 #include "core/modelIR/operations/VariableOp.h"
+#include "core/modelIR/operations/ConstantOp.h"
 
 namespace nnc {
 namespace mir {
@@ -115,7 +116,13 @@ class Graph {
     _inputs.insert(it, {op->getName(), op});
     _ops.push_back(op);
   }
-  
+
+
+  void registerOp(ops::ConstantOp* op) {
+    _constants.insert(op);
+    _ops.push_back(op);
+  }
+
   std::vector<Operation*> _ops;
   size_t _lastNodeId = 0;
   std::unordered_map<std::string, Operation*> _inputs;