[enco] Support subnet in/out identification (#1234)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Thu, 30 Aug 2018 01:02:25 +0000 (10:02 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Thu, 30 Aug 2018 01:02:25 +0000 (10:02 +0900)
This commit introduces identifyInputs and identifyOutputs method which
allows Backend to record android NN subnet's input and output.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
contrib/enco/core/src/ANN/Binder.h

index 16b69e5..bbae045 100644 (file)
@@ -102,12 +102,68 @@ public:
     _module->operation()->create(code, inputs, outputs);
   }
 
+public:
+  // @brief Identify a sequence of coco::Bag * as subnet's inputs
+  //
+  // NOTE 1. This method takes input iterator over coco::Bag * values
+  // NOTE 2. All the identifyInputs class except the last one will be ignored if there are
+  //         multiple identifyInputs calls
+  template <typename It> void identifyInputs(It beg, It end)
+  {
+    _inputs.clear();
+    _module->input()->clear();
+
+    for (auto it = beg; it != end; ++it)
+    {
+      auto const bag = *it;
+      _inputs.emplace_back(*it);
+      _module->input()->emplace_back(_operands.at(bag));
+    }
+  }
+
+  template <typename T> void identifyInputs(T &&values)
+  {
+    identifyInputs(std::begin(values), std::end(values));
+  }
+
+public:
+  // @brief Identify a sequence of coco::Bag * as subnet's outputs
+  //
+  // NOTE 1. This method takes input iterator over coco::Bag * values
+  // NOTE 2. All the identifyOutputs class except the last one will be ignored if there are
+  //         multiple identifyOutputs calls
+  template <typename It> void identifyOutputs(It beg, It end)
+  {
+    _outputs.clear();
+    _module->output()->clear();
+
+    for (auto it = beg; it != end; ++it)
+    {
+      auto const bag = *it;
+      _outputs.emplace_back(bag);
+      _module->output()->emplace_back(_operands.at(bag));
+    }
+  }
+
+  template <typename T> void identifyOutputs(T &&values)
+  {
+    identifyOutputs(std::begin(values), std::end(values));
+  }
+
+public:
+  coco::Bag *input(uint32_t n) const { return _inputs.at(n); }
+  coco::Bag *output(uint32_t n) const { return _outputs.at(n); }
+
 private:
   uint32_t const _id;
   coco::Block *const _block;
   std::unique_ptr<ann::Module> _module;
 
 private:
+  std::vector<coco::Bag *> _inputs;
+  std::vector<coco::Bag *> _outputs;
+
+private:
   // @brief Operand ID assigned for each coco::Bag
   std::map<const coco::Bag *, ann::OperandID> _operands;
 };