From: 김수진/동작제어Lab(SR)/Engineer/삼성전자 Date: Mon, 13 Aug 2018 10:23:30 +0000 (+0900) Subject: [neurun] Introduce IO::Index (#2272) X-Git-Tag: 0.2~284 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=df33a3001de7f1f5ad806197d3f04f271e1cc055;p=platform%2Fcore%2Fml%2Fnnfw.git [neurun] Introduce IO::Index (#2272) * [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 * Revert some codes --- diff --git a/runtimes/neurun/src/frontend/execution.cc b/runtimes/neurun/src/frontend/execution.cc index 0a4de81..8276ce3 100644 --- a/runtimes/neurun/src/frontend/execution.cc +++ b/runtimes/neurun/src/frontend/execution.cc @@ -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) diff --git a/runtimes/neurun/src/graph/Index.h b/runtimes/neurun/src/graph/Index.h index 86e3901..e5345d6 100644 --- a/runtimes/neurun/src/graph/Index.h +++ b/runtimes/neurun/src/graph/Index.h @@ -11,8 +11,8 @@ namespace graph template class Index { public: - Index(T o) : _index{o} {} - Index(int32_t o) : _index{static_cast(o)} {} // For legacy code compatibility + explicit Index(T o) : _index{o} {} + explicit Index(int32_t o) : _index{static_cast(o)} {} // For legacy code compatibility Index(const Index &o) : _index{o._index} {} Index &operator=(T o) diff --git a/runtimes/neurun/src/graph/operand/Index.h b/runtimes/neurun/src/graph/operand/Index.h index 5e4e892..1b5426e 100644 --- a/runtimes/neurun/src/graph/operand/Index.h +++ b/runtimes/neurun/src/graph/operand/Index.h @@ -16,4 +16,20 @@ using Index = ::neurun::graph::Index; } // namespace graph } // namespace neurun +namespace neurun +{ +namespace graph +{ +namespace operand +{ +namespace IO +{ + +using Index = ::neurun::graph::Index; + +} // namespace IO +} // namespace operand +} // namespace graph +} // namespace neurun + #endif // __NEURUN_GRAPH_OPERAND_INDEX_H__ diff --git a/runtimes/neurun/src/graph/operand/IndexSet.h b/runtimes/neurun/src/graph/operand/IndexSet.h index df57b84..5deb805 100644 --- a/runtimes/neurun/src/graph/operand/IndexSet.h +++ b/runtimes/neurun/src/graph/operand/IndexSet.h @@ -25,8 +25,11 @@ public: public: uint32_t size() const { return static_cast(_set.size()); } - const Index &at(uint32_t set_index) const { return _set.at(set_index); } const std::vector &list() const { return _set; } + const Index &at(::neurun::graph::operand::IO::Index set_index) const + { + return _set.at(set_index.asInt()); + } private: std::vector _set; diff --git a/runtimes/neurun/src/graph/operation/Concat.cc b/runtimes/neurun/src/graph/operation/Concat.cc index 73b5e93..e52424c 100644 --- a/runtimes/neurun/src/graph/operation/Concat.cc +++ b/runtimes/neurun/src/graph/operation/Concat.cc @@ -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; } diff --git a/runtimes/neurun/test/graph/Graph.cc b/runtimes/neurun/test/graph/Graph.cc index 32f3a5e..d690e55 100644 --- a/runtimes/neurun/test/graph/Graph.cc +++ b/runtimes/neurun/test/graph/Graph.cc @@ -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); } diff --git a/runtimes/neurun/test/graph/operand/IndexSet.cc b/runtimes/neurun/test/graph/operand/IndexSet.cc index b9754fd..a533796 100644 --- a/runtimes/neurun/test/graph/operand/IndexSet.cc +++ b/runtimes/neurun/test/graph/operand/IndexSet.cc @@ -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); }