From: 이한종/동작제어Lab(SR)/Engineer/삼성전자 Date: Mon, 3 Sep 2018 07:10:56 +0000 (+0900) Subject: [neurun] Range-based loop for operand::IndexSet (#2554) X-Git-Tag: 0.2~113 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c313028a9b5a3fcc77a65b4c9d5d4a6d91b2b1e2;p=platform%2Fcore%2Fml%2Fnnfw.git [neurun] Range-based loop for operand::IndexSet (#2554) Support and apply range-based loop for operand::IndexSet and remove `list()` method. Signed-off-by: Hanjoung Lee --- diff --git a/runtimes/neurun/src/backend/acl_cl/StageGenerator.cc b/runtimes/neurun/src/backend/acl_cl/StageGenerator.cc index 0a6969e..2fda73f 100644 --- a/runtimes/neurun/src/backend/acl_cl/StageGenerator.cc +++ b/runtimes/neurun/src/backend/acl_cl/StageGenerator.cc @@ -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()); } diff --git a/runtimes/neurun/src/backend/cpu/StageGenerator.cc b/runtimes/neurun/src/backend/cpu/StageGenerator.cc index 96686d2..def1e3c 100644 --- a/runtimes/neurun/src/backend/cpu/StageGenerator.cc +++ b/runtimes/neurun/src/backend/cpu/StageGenerator.cc @@ -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))); } diff --git a/runtimes/neurun/src/codegen/Dumper.cc b/runtimes/neurun/src/codegen/Dumper.cc index d6beb7c..5f7e061 100644 --- a/runtimes/neurun/src/codegen/Dumper.cc +++ b/runtimes/neurun/src/codegen/Dumper.cc @@ -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()) + ","; } diff --git a/runtimes/neurun/src/codegen/Planner.cc b/runtimes/neurun/src/codegen/Planner.cc index 0e7f8c4..53facf4 100644 --- a/runtimes/neurun/src/codegen/Planner.cc +++ b/runtimes/neurun/src/codegen/Planner.cc @@ -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(); diff --git a/runtimes/neurun/src/graph/Graph.cc b/runtimes/neurun/src/graph/Graph.cc index 5db6e5c..04e08ff 100644 --- a/runtimes/neurun/src/graph/Graph.cc +++ b/runtimes/neurun/src/graph/Graph.cc @@ -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::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) { diff --git a/runtimes/neurun/src/graph/operand/IndexSet.h b/runtimes/neurun/src/graph/operand/IndexSet.h index 077e70b..780acc7 100644 --- a/runtimes/neurun/src/graph/operand/IndexSet.h +++ b/runtimes/neurun/src/graph/operand/IndexSet.h @@ -26,11 +26,14 @@ public: public: uint32_t size() const { return static_cast(_set.size()); } - const std::vector &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::const_iterator begin(void) const { return _set.begin(); } + std::vector::const_iterator end(void) const { return _set.end(); } + private: std::vector _set; }; diff --git a/runtimes/neurun/src/graph/verifier/IVerifier.cc b/runtimes/neurun/src/graph/verifier/IVerifier.cc index 461084e..ee5ae42 100644 --- a/runtimes/neurun/src/graph/verifier/IVerifier.cc +++ b/runtimes/neurun/src/graph/verifier/IVerifier.cc @@ -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) { diff --git a/runtimes/neurun/src/linear/Linear.cc b/runtimes/neurun/src/linear/Linear.cc index 3d56228..a07ceda 100644 --- a/runtimes/neurun/src/linear/Linear.cc +++ b/runtimes/neurun/src/linear/Linear.cc @@ -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); }