[neurun] Define use & def in operand (#2541)
author오형석/동작제어Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Fri, 31 Aug 2018 06:21:49 +0000 (15:21 +0900)
committer박세희/동작제어Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>
Fri, 31 Aug 2018 06:21:49 +0000 (15:21 +0900)
- Define use & def in operand
- Define base methods to append & remove

Signed-off-by: Hyeongseok Oh <hseok82.oh@samsung.com>
runtimes/neurun/src/graph/operand/Object.cc
runtimes/neurun/src/graph/operand/Object.h

index cc054a7..625cb78 100644 (file)
@@ -57,6 +57,38 @@ bool Object::setUsage(const OperandUsage usage)
   return true;
 }
 
+void Object::appendUse(const ::neurun::graph::operation::Index &idx)
+{
+  assert(_usage != OperandUsage::NOT_DEFINED);
+  assert(!_uses.contains(idx));
+
+  _uses.append(idx);
+}
+
+void Object::removeUse(const ::neurun::graph::operation::Index &idx)
+{
+  assert(_usage != OperandUsage::NOT_DEFINED);
+  assert(_uses.contains(idx));
+
+  _uses.remove(idx);
+}
+
+void Object::appendDef(const ::neurun::graph::operation::Index &idx)
+{
+  assert(_usage != OperandUsage::NOT_DEFINED && _usage != OperandUsage::CONSTANT);
+  assert(_def.size() == 0);
+
+  _def.append(idx);
+}
+
+void Object::removeDef(const ::neurun::graph::operation::Index &idx)
+{
+  assert(_usage != OperandUsage::NOT_DEFINED);
+  assert(_def.contains(idx));
+
+  _def.remove(idx);
+}
+
 } // namespace operand
 } // namespace graph
 } // namespace neurun
index fc5bd01..59110fd 100644 (file)
@@ -9,6 +9,7 @@
 #include "Shape.h"
 #include "Data.h"
 #include "TypeInfo.h"
+#include "graph/operation/IndexList.h"
 
 namespace neurun
 {
@@ -45,6 +46,13 @@ public:
   bool usageIsDefined(void) const { return _usage != OperandUsage::NOT_DEFINED; }
   bool isModelInput(void) const { return _usage == OperandUsage::MODEL_INPUT; }
 
+  const operation::IndexList &getUses() const { return _uses; }
+  const operation::IndexList &getDef() const { return _def; }
+  void appendUse(const operation::Index &idx);
+  void removeUse(const operation::Index &idx);
+  void appendDef(const operation::Index &idx);
+  void removeDef(const operation::Index &idx);
+
 private:
   bool setUsage(OperandUsage usage);
 
@@ -73,6 +81,9 @@ private:
   const TypeInfo _type;
   std::unique_ptr<Data> _data;
   OperandUsage _usage;
+
+  operation::IndexList _uses;
+  operation::IndexList _def; // size is 0 (constant) or 1 (from def operation)
 };
 
 } // namespace operand