[neurun] Range-based loop for operand::IndexSet (#2554)
author이한종/동작제어Lab(SR)/Engineer/삼성전자 <hanjoung.lee@samsung.com>
Mon, 3 Sep 2018 07:10:56 +0000 (16:10 +0900)
committer오형석/동작제어Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Mon, 3 Sep 2018 07:10:56 +0000 (16:10 +0900)
Support and apply range-based loop for operand::IndexSet and remove
`list()` method.

Signed-off-by: Hanjoung Lee <hanjoung.lee@samsung.com>
runtimes/neurun/src/backend/acl_cl/StageGenerator.cc
runtimes/neurun/src/backend/cpu/StageGenerator.cc
runtimes/neurun/src/codegen/Dumper.cc
runtimes/neurun/src/codegen/Planner.cc
runtimes/neurun/src/graph/Graph.cc
runtimes/neurun/src/graph/operand/IndexSet.h
runtimes/neurun/src/graph/verifier/IVerifier.cc
runtimes/neurun/src/linear/Linear.cc

index 0a6969e..2fda73f 100644 (file)
@@ -374,7 +374,7 @@ Stage StageGenerator::generate(const graph::operation::Concat::Node &node)
   Param param;
 
   param.output_index = ofm_index.asInt();
-  for (const auto &e : node.getInputs().list())
+  for (const auto &e : node.getInputs())
   {
     param.input_indexes.emplace_back(e.asInt());
   }
index 96686d2..def1e3c 100644 (file)
@@ -334,7 +334,7 @@ Stage StageGenerator::generate(const graph::operation::Concat::Node &node)
   Param param;
 
   param.output_index = ofm_index.asInt();
-  for (const auto &e : node.getInputs().list())
+  for (const auto &e : node.getInputs())
   {
     param.input_indexes.emplace_back(e.asInt());
   }
@@ -342,7 +342,7 @@ Stage StageGenerator::generate(const graph::operation::Concat::Node &node)
 
   param.ofm_shape = ::neurun::kernel::cpu::getShape(_ctx.at(ofm_index));
 
-  for (auto e : node.getInputs().list())
+  for (auto e : node.getInputs())
   {
     param.ifm_shapes.emplace_back(::neurun::kernel::cpu::getShape(_ctx.at(e)));
   }
index d6beb7c..5f7e061 100644 (file)
@@ -38,7 +38,7 @@ void Dumper::visit(const Concat::Node &node)
 {
   VERBOSE(LIR) << "* Concat" << std::endl;
   std::string inputs;
-  for (auto i : node.getInputs().list())
+  for (auto i : node.getInputs())
   {
     inputs += std::to_string(i.value()) + ",";
   }
@@ -76,12 +76,12 @@ void Dumper::visit(const NOP::Node &node)
 {
   VERBOSE(LIR) << "* NOP" << std::endl;
   std::string inputs, outputs;
-  for (auto i : node.getInputs().list())
+  for (auto i : node.getInputs())
   {
     inputs += std::to_string(i.value()) + ",";
   }
   VERBOSE(LIR) << "  - Inputs : IFM(" << inputs << ")" << std::endl;
-  for (auto i : node.getOutputs().list())
+  for (auto i : node.getOutputs())
   {
     outputs += std::to_string(i.value()) + ",";
   }
index 0e7f8c4..53facf4 100644 (file)
@@ -92,7 +92,7 @@ void Planner::visit(const graph::operation::Concat::Node &node)
   _builder.addShapeConstr(ofm_index, ::internal::asTensorInfo(ofm_shape));
 
   // Set Shape Constraints (for input)
-  for (const auto &index : node.getInputs().list())
+  for (const auto &index : node.getInputs())
   {
     const ::neurun::graph::operand::Index ifm_index{index};
     const auto ifm_shape = _ctx.at(ifm_index).shape().asFeature();
index 5db6e5c..04e08ff 100644 (file)
@@ -53,7 +53,7 @@ operation::Index Graph::insertOperation(const operand::Index &prev_operand_index
   auto cur_output_indexes = node->getOutputs();
   assert(cur_output_indexes.size() == 1); // Assume output of inserted node size always 1
   // TODO : If the API for setting input one by one is introduced, it would be changed to simple.
-  for (auto next_input_index : next_input_indexes.list())
+  for (auto next_input_index : next_input_indexes)
   {
     if (prev_operand_index == next_input_index)
     {
@@ -142,13 +142,13 @@ void Graph::initializeUseDef()
 {
   operations().iterate([&](const operation::Index &index, const operation::Node &node) -> void {
     auto outputs = node.getOutputs();
-    for (auto output : outputs.list())
+    for (auto output : outputs)
     {
       operands().at(output).appendDef(index);
     }
 
     auto inputs = node.getInputs();
-    for (auto input : inputs.list())
+    for (auto input : inputs)
     {
       operands().at(input).appendUse(index);
     }
@@ -197,14 +197,14 @@ void Graph::PostDfsIterator<is_const>::iterate(GraphRef graph, const IterFn &fn)
     visited[index.asInt()] = true;
 
     auto outputs = node.getOutputs();
-    for (auto output : outputs.list())
+    for (auto output : outputs)
     {
       // TODO Fix traversing algorithm
       //      Every time need to search for operations that has `outgoing` as incoming from all
       //      operations but we can hold that info cached
       graph._operations.iterate([&](const operation::Index &cand_index, NodeRef cand_node) -> void {
         auto inputs = cand_node.getInputs();
-        for (auto input : inputs.list())
+        for (auto input : inputs)
         {
           if (output == input)
           {
index 077e70b..780acc7 100644 (file)
@@ -26,11 +26,14 @@ public:
 
 public:
   uint32_t size() const { return static_cast<uint32_t>(_set.size()); }
-  const std::vector<Index> &list() const { return _set; }
   const Index &at(IO::Index set_index) const { return _set.at(set_index.asInt()); }
   const Index &at(uint32_t index) const { return _set.at(index); }
   bool contains(const Index &index) const;
 
+public:
+  std::vector<Index>::const_iterator begin(void) const { return _set.begin(); }
+  std::vector<Index>::const_iterator end(void) const { return _set.end(); }
+
 private:
   std::vector<Index> _set;
 };
index 461084e..ee5ae42 100644 (file)
@@ -26,14 +26,14 @@ bool DAGChecker::verify(const Graph &graph) const
     on_stack[index.value()] = true;
 
     auto outputs = node.getOutputs();
-    for (auto output : outputs.list())
+    for (auto output : outputs)
     {
       // TODO Fix traversing algorithm
       //      Every time need to search for operations that has `outgoing` as incoming from all
       //      operations but we can hold that info cached
       operations.iterate([&](const operation::Index &cand_index, const operation::Node &cand_node) {
         auto inputs = cand_node.getInputs();
-        for (auto input : inputs.list())
+        for (auto input : inputs)
         {
           if (output == input)
           {
index 3d56228..a07ceda 100644 (file)
@@ -37,11 +37,11 @@ void Linear::markTensors(neurun::codegen::BackendResolver &resolver) const
   for (const auto op : _operations)
   {
     auto tensor_builder = resolver.getTensorBuilder(typeid(*op));
-    for (const auto &ind : op->getInputs().list())
+    for (const auto &ind : op->getInputs())
     {
       tensor_builder->mark(ind);
     }
-    for (const auto &ind : op->getOutputs().list())
+    for (const auto &ind : op->getOutputs())
     {
       tensor_builder->mark(ind);
     }