[neurun] Graph holds Model as pointer (#3663)
author이한종/동작제어Lab(SR)/Engineer/삼성전자 <hanjoung.lee@samsung.com>
Wed, 21 Nov 2018 08:00:55 +0000 (17:00 +0900)
committer오형석/동작제어Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Wed, 21 Nov 2018 08:00:55 +0000 (17:00 +0900)
Graph holds Model as pointer. This is for the next work that `_model` is moved
to Linear.

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

index d263fed..cf2d00c 100644 (file)
@@ -42,32 +42,32 @@ Graph::~Graph(void) = default;
 
 operand::Index Graph::addOperand(const operand::Shape &shape, const operand::TypeInfo &type)
 {
-  return _model.operands.append(shape, type);
+  return _model->operands.append(shape, type);
 }
 
 operation::Index Graph::addOperation(std::unique_ptr<operation::Node> &&node)
 {
   assert(isBuildingPhase());
-  return _model.operations.append(std::move(node));
+  return _model->operations.append(std::move(node));
 }
 
 void Graph::setOperandValue(const operand::Index &ind, std::unique_ptr<operand::Data> &&data)
 {
   assert(isBuildingPhase());
-  assert(_model.operands.exist(ind));
-  _model.operands.at(ind).data(std::move(data));
+  assert(_model->operands.exist(ind));
+  _model->operands.at(ind).data(std::move(data));
 }
 
 void Graph::addInput(const operand::Index &ind)
 {
   assert(isBuildingPhase());
-  _model.inputs.append(ind);
+  _model->inputs.append(ind);
 }
 
 void Graph::addOutput(const operand::Index &ind)
 {
   assert(isBuildingPhase());
-  _model.outputs.append(ind);
+  _model->outputs.append(ind);
 }
 
 void Graph::finishBuilding(void)
@@ -94,14 +94,14 @@ void Graph::lower(void)
     // operand::LowerInfo holder
     std::unordered_map<operand::Index, std::unique_ptr<operand::LowerInfo>> operands_lower_info;
 
-    _model.operands.iterate([&](const operand::Index &index, const operand::Object &object) {
+    _model->operands.iterate([&](const operand::Index &index, const operand::Object &object) {
       operands_lower_info[index] =
           nnfw::make_unique<operand::LowerInfo>(operand::asShape4D(object.shape()));
     });
 
-    _backend_resolver = nnfw::make_unique<codegen::BackendResolver>(_model.operands);
+    _backend_resolver = nnfw::make_unique<codegen::BackendResolver>(_model->operands);
 
-    _model.operations.iterate([&](const operation::Index &, operation::Node &node) {
+    _model->operations.iterate([&](const operation::Index &, operation::Node &node) {
       auto backend = _backend_resolver->getBackend(typeid(node));
 
       // Operation LowerInfo
@@ -135,7 +135,7 @@ void Graph::lower(void)
 
     // Add DefBackend constants same as UseBackend
     // NOTE This assumes a constant operand is used by only one operation
-    _model.operations.iterate([&](const operation::Index &, operation::Node &node) {
+    _model->operations.iterate([&](const operation::Index &, operation::Node &node) {
       // LowerInfo for input operands
       for (auto operand : node.getInputs())
       {
@@ -148,7 +148,7 @@ void Graph::lower(void)
     });
 
     // Set LowerInfo for each operand from the operand::LowerInfo holder
-    _model.operands.iterate([&](const operand::Index &index, operand::Object &object) {
+    _model->operands.iterate([&](const operand::Index &index, operand::Object &object) {
       object.lower_info(std::move(operands_lower_info[index]));
 
       // Dump operand LowerInfo
index e5ca1ec..3b82a6c 100644 (file)
@@ -114,18 +114,18 @@ private:
 
   // Accessors
 public:
-  const operand::IndexSet &getInputs() const { return _model.inputs; }
-  const operand::IndexSet &getOutputs() const { return _model.outputs; }
-  operand::IndexSet &getOutputs() { return _model.outputs; }
-  const operand::Set &operands() const { return _model.operands; }
-  operand::Set &operands() { return _model.operands; } // TODO Remove this non-const accessor
-  const operation::Set &operations() const { return _model.operations; }
-  operation::Set &operations() { return _model.operations; }
+  const operand::IndexSet &getInputs() const { return _model->inputs; }
+  const operand::IndexSet &getOutputs() const { return _model->outputs; }
+  operand::IndexSet &getOutputs() { return _model->outputs; }
+  const operand::Set &operands() const { return _model->operands; }
+  operand::Set &operands() { return _model->operands; } // TODO Remove this non-const accessor
+  const operation::Set &operations() const { return _model->operations; }
+  operation::Set &operations() { return _model->operations; }
   const codegen::BackendResolver *backend_resolver() const { return _backend_resolver.get(); }
 
 private:
   Phase _phase{Phase::BUILDING};
-  Model _model;
+  std::unique_ptr<Model> _model{new Model};
 
   // For LOWERED phase
 private: