[neurun] Introduce IO::Index (#2272)
author김수진/동작제어Lab(SR)/Engineer/삼성전자 <sjsujin.kim@samsung.com>
Mon, 13 Aug 2018 10:23:30 +0000 (19:23 +0900)
committer오형석/동작제어Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Mon, 13 Aug 2018 10:23:30 +0000 (19:23 +0900)
* [neurun] Introduce IOIndex/IOIndexSet

Close : #2257

This commit introduce IOIndex/IOIndexSet.
`IOIndex` is the indices for ANeuralNetworksModel_identifyInputsAndOutputs() API.
`IOIndexSet` is accessible only using with `IOIndex`.

Signed-off-by: sjsujinkim <sjsujin.kim@samsung.com>
* Revert some codes

runtimes/neurun/src/frontend/execution.cc
runtimes/neurun/src/graph/Index.h
runtimes/neurun/src/graph/operand/Index.h
runtimes/neurun/src/graph/operand/IndexSet.h
runtimes/neurun/src/graph/operation/Concat.cc
runtimes/neurun/test/graph/Graph.cc
runtimes/neurun/test/graph/operand/IndexSet.cc

index 0a4de81..8276ce3 100644 (file)
@@ -7,6 +7,7 @@
 #include "event.h"
 
 #include "internal/Source.h"
+#include "graph/operand/Index.h"
 
 //
 // NNAPI Implementation
@@ -51,7 +52,9 @@ int ANeuralNetworksExecution_setInput(ANeuralNetworksExecution *execution, int32
 
   // NOTE The current implemenation assumes that every input is a feature map.
   // TODO Remove this assumption
-  const auto operand_index = execution->plan().model().inputs().at(index);
+  neurun::graph::operand::IO::Index input_index{index};
+
+  const auto operand_index = execution->plan().model().inputs().at(input_index);
 
   if (operands.at(operand_index).shape().rank() == 2)
   {
@@ -95,7 +98,9 @@ int ANeuralNetworksExecution_setOutput(ANeuralNetworksExecution *execution, int3
 
   // NOTE The current implemenation assumes that every output is a feature map.
   // TODO Remove this assumption
-  const auto operand_index = execution->plan().model().outputs().list().at(index);
+  neurun::graph::operand::IO::Index output_index{index};
+
+  const auto operand_index = execution->plan().model().outputs().at(output_index);
 
   if (operands.at(operand_index).shape().rank() == 2)
   {
@@ -142,7 +147,9 @@ int ANeuralNetworksExecution_startCompute(ANeuralNetworksExecution *execution,
   {
     auto setter = [&](::arm_compute::ITensor &tensor) { execution->source(n).push(tensor); };
 
-    ::internal::tflite::operand::Index index{model.inputs().at(n).asInt()};
+    neurun::graph::operand::IO::Index input_index{n};
+
+    ::internal::tflite::operand::Index index{model.inputs().at(input_index).asInt()};
     auto objects = plan.operands().at(index);
 
     for (auto object : objects)
@@ -163,7 +170,9 @@ int ANeuralNetworksExecution_startCompute(ANeuralNetworksExecution *execution,
   {
     auto getter = [&](::arm_compute::ITensor &tensor) { execution->sink(n).pull(tensor); };
 
-    ::internal::tflite::operand::Index index{model.outputs().at(n).asInt()};
+    neurun::graph::operand::IO::Index output_index{n};
+
+    ::internal::tflite::operand::Index index{model.outputs().at(output_index).asInt()};
     auto objects = plan.operands().at(index);
 
     for (auto object : objects)
index 86e3901..e5345d6 100644 (file)
@@ -11,8 +11,8 @@ namespace graph
 template <typename T, typename DummyTag> class Index
 {
 public:
-  Index(T o) : _index{o} {}
-  Index(int32_t o) : _index{static_cast<T>(o)} {} // For legacy code compatibility
+  explicit Index(T o) : _index{o} {}
+  explicit Index(int32_t o) : _index{static_cast<T>(o)} {} // For legacy code compatibility
   Index(const Index<T, DummyTag> &o) : _index{o._index} {}
 
   Index<T, DummyTag> &operator=(T o)
index 5e4e892..1b5426e 100644 (file)
@@ -16,4 +16,20 @@ using Index = ::neurun::graph::Index<uint32_t, struct IndexTag>;
 } // namespace graph
 } // namespace neurun
 
+namespace neurun
+{
+namespace graph
+{
+namespace operand
+{
+namespace IO
+{
+
+using Index = ::neurun::graph::Index<uint32_t, struct IndexTag>;
+
+} // namespace IO
+} // namespace operand
+} // namespace graph
+} // namespace neurun
+
 #endif // __NEURUN_GRAPH_OPERAND_INDEX_H__
index df57b84..5deb805 100644 (file)
@@ -25,8 +25,11 @@ public:
 
 public:
   uint32_t size() const { return static_cast<uint32_t>(_set.size()); }
-  const Index &at(uint32_t set_index) const { return _set.at(set_index); }
   const std::vector<Index> &list() const { return _set; }
+  const Index &at(::neurun::graph::operand::IO::Index set_index) const
+  {
+    return _set.at(set_index.asInt());
+  }
 
 private:
   std::vector<Index> _set;
index 73b5e93..e52424c 100644 (file)
@@ -14,7 +14,8 @@ operand::IndexSet Node::inputs() const
   operand::IndexSet set;
   for (auto index : _op->param().ifm_indexes)
   {
-    set.append({index});
+    operand::Index ind{index};
+    set.append({ind});
   }
   return set;
 }
index 32f3a5e..d690e55 100644 (file)
@@ -6,13 +6,31 @@ TEST(Graph, inputs_and_outputs)
 {
   ::neurun::graph::Graph graph;
 
-  graph.addInput({0u});
-  graph.addInput({1u});
+  ::neurun::graph::operand::Index index0{0u};
+  ::neurun::graph::operand::Index index1{1u};
 
-  graph.addOutput({10u});
-  graph.addOutput({11u});
-  graph.addOutput({12u});
+  graph.addInput({index0});
+  graph.addInput({index1});
+
+  ::neurun::graph::operand::Index index10{10u};
+  ::neurun::graph::operand::Index index11{11u};
+  ::neurun::graph::operand::Index index12{12u};
+
+  graph.addOutput({index10});
+  graph.addOutput({index11});
+  graph.addOutput({index12});
 
   ASSERT_EQ(graph.inputs().size(), 2);
   ASSERT_EQ(graph.outputs().size(), 3);
+
+  ::neurun::graph::operand::IO::Index io_index0{0};
+  ::neurun::graph::operand::IO::Index io_index1{1};
+  ::neurun::graph::operand::IO::Index io_index2{2};
+
+  ASSERT_EQ(graph.inputs().at(io_index0), 0);
+  ASSERT_EQ(graph.inputs().at(io_index1), 1);
+
+  ASSERT_EQ(graph.outputs().at(io_index0), 10);
+  ASSERT_EQ(graph.outputs().at(io_index1), 11);
+  ASSERT_EQ(graph.outputs().at(io_index2), 12);
 }
index b9754fd..a533796 100644 (file)
@@ -7,14 +7,17 @@ using neurun::graph::operand::IndexSet;
 
 TEST(graph_operand_IndexSet, index_set_test)
 {
-  IndexSet iset{0, 1, 2, 3};
+  IndexSet iset{0, 2, 4, 8};
 
   ASSERT_EQ(iset.size(), 4);
 
-  iset.append(Index{4});
+  iset.append(Index{10});
 
   ASSERT_EQ(iset.size(), 5);
 
-  ASSERT_EQ(iset.at(0), 0);
-  ASSERT_EQ(iset.at(4), 4);
+  neurun::graph::operand::IO::Index index1{1};
+  neurun::graph::operand::IO::Index index2{4};
+
+  ASSERT_EQ(iset.at(index1), 2);
+  ASSERT_EQ(iset.at(index2), 10);
 }