Introduce optional operand set on frontent (#3751)
author오형석/동작제어Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Fri, 30 Nov 2018 04:13:08 +0000 (13:13 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Fri, 30 Nov 2018 04:13:08 +0000 (13:13 +0900)
Introduce unordered_set field for optional operand
Define API to insert optional operand
Introduce process to handle optional operand at model finish (cannot handle yet)

Signed-off-by: Hyeongseok Oh <hseok82.oh@samsung.com>
runtimes/neurun/src/frontend/wrapper/model.cc
runtimes/neurun/src/frontend/wrapper/model.h

index c7ccbc6..b731bb5 100644 (file)
@@ -21,7 +21,8 @@
 //
 // ANeuralNetworksModel
 //
-ANeuralNetworksModel::ANeuralNetworksModel() : _model{new neurun::graph::Graph}
+ANeuralNetworksModel::ANeuralNetworksModel()
+    : _model{new neurun::graph::Graph}, _optional_operands{}
 {
   // DO NOTHING
 }
@@ -34,7 +35,24 @@ ResultCode ANeuralNetworksModel::finish()
     return ANEURALNETWORKS_BAD_STATE;
   }
 
+  fillOptionalOperand();
+
   _model->finishBuilding();
 
   return ANEURALNETWORKS_NO_ERROR;
 }
+
+void ANeuralNetworksModel::fillOptionalOperand(void)
+{
+  _model->operations().iterate(
+      [&](const ::neurun::graph::operation::Index &, ::neurun::graph::operation::Node &node) {
+        for (auto input : node.getInputs())
+        {
+          // TODO fill default value for optional operands
+          if (_optional_operands.find(input) != _optional_operands.end())
+          {
+            throw std::runtime_error{"Optional operand is not supported yet"};
+          }
+        }
+      });
+}
index 3c7b027..c505f20 100644 (file)
@@ -30,12 +30,18 @@ public:
   neurun::graph::Graph &deref(void) { return *_model; }
   ResultCode finish();
   bool isFinished() { return !_model->isBuildingPhase(); }
-
-public:
   void release(std::shared_ptr<neurun::graph::Graph> &model) { model = _model; }
+  void setOptionalOperand(const neurun::graph::operand::Index idx)
+  {
+    _optional_operands.insert(idx);
+  }
+
+private:
+  void fillOptionalOperand(void);
 
 private:
   std::shared_ptr<neurun::graph::Graph> _model;
+  std::unordered_set<neurun::graph::operand::Index> _optional_operands;
 };
 
 #endif // __MODEL_H__