From 5a5e926130ac654fbfebb3ac2ab6f46f6fdb13f5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=9D=B4=ED=95=9C=EC=A2=85/On-Device=20Lab=28SR=29/Enginee?= =?utf8?q?r/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Fri, 9 Aug 2019 16:06:02 +0900 Subject: [PATCH] [neurun] Do not wrap vector with unique_ptr (#6431) As `std::vector` has move constructor, without wrapping it with `unique_ptr` works efficiently as well. Signed-off-by: Hanjoung Lee --- runtimes/neurun/core/src/compiler/Linear.cc | 14 ++++++-------- runtimes/neurun/core/src/compiler/Linear.h | 4 ++-- runtimes/neurun/core/src/exec/LinearExecutor.h | 4 ++-- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/runtimes/neurun/core/src/compiler/Linear.cc b/runtimes/neurun/core/src/compiler/Linear.cc index 83efb96..dfeb89e 100644 --- a/runtimes/neurun/core/src/compiler/Linear.cc +++ b/runtimes/neurun/core/src/compiler/Linear.cc @@ -44,8 +44,6 @@ Linear::Linear(const std::shared_ptr &model, { assert(_model && _subgraphs && _lower_info_map); - _elements = nnfw::cpp14::make_unique>(); - // Get SubgraphSequence by topological sorting { // _subgraphs can't access a subgraph by an operand so that input_to_subgs can offer it @@ -113,7 +111,7 @@ Linear::Linear(const std::shared_ptr &model, } } - _elements->emplace_back(&_subgraphs->at(index), getLowerInfo(index)); + _elements.emplace_back(&_subgraphs->at(index), getLowerInfo(index)); }; _subgraphs->iterate(dfs_recursive); @@ -124,7 +122,7 @@ Linear::Linear(const std::shared_ptr &model, [](const std::pair &v) { return v.second; })); // NOTE. Now these subgraph are on the reverse order - std::reverse(_elements->begin(), _elements->end()); + std::reverse(_elements.begin(), _elements.end()); } { @@ -137,7 +135,7 @@ Linear::Linear(const std::shared_ptr &model, }; VERBOSE(Linear) << "Final SubgraphSequence" << std::endl; - for (const auto &element : *_elements) + for (const auto &element : _elements) { const auto subg = element.subgraph; const auto lower_info = element.lower_info; @@ -150,7 +148,7 @@ Linear::Linear(const std::shared_ptr &model, void Linear::accept(model::OperationVisitor &&visitor) const { - for (const auto &e : *_elements) + for (const auto &e : _elements) { e.subgraph->accept(visitor); } @@ -257,7 +255,7 @@ backend::TensorBuilderSet Linear::planTensors() // 1. Scan DEF of outputs. If the DEF, allocate it // 2. Scan USE of inputs. Decrease the USE and deallocate if the USE is 0 VERBOSE(LINEAR) << "TENSORS" << std::endl; - for (const auto &e : *_elements) + for (const auto &e : _elements) { for (const auto &op : e.subgraph->operations()) { @@ -314,7 +312,7 @@ backend::TensorBuilderSet Linear::planTensors() void Linear::iterate(const std::function &fn) const { - for (const auto &e : *_elements) + for (const auto &e : _elements) { fn(e); } diff --git a/runtimes/neurun/core/src/compiler/Linear.h b/runtimes/neurun/core/src/compiler/Linear.h index 5f87aae..16b1f40 100644 --- a/runtimes/neurun/core/src/compiler/Linear.h +++ b/runtimes/neurun/core/src/compiler/Linear.h @@ -81,7 +81,7 @@ public: std::unique_ptr releaseSubgraphs() { return std::move(_subgraphs); } - std::unique_ptr> releaseElements() { return std::move(_elements); } + std::vector &&releaseElements() { return std::move(_elements); } const backend::BackendContext *getBackendContext(const backend::Backend *backend) { @@ -97,7 +97,7 @@ private: std::shared_ptr _model; std::unique_ptr _subgraphs; std::unique_ptr _lower_info_map; - std::unique_ptr> _elements; + std::vector _elements; std::unique_ptr _backend_resolver; }; diff --git a/runtimes/neurun/core/src/exec/LinearExecutor.h b/runtimes/neurun/core/src/exec/LinearExecutor.h index 42cbad4..6c4e977 100644 --- a/runtimes/neurun/core/src/exec/LinearExecutor.h +++ b/runtimes/neurun/core/src/exec/LinearExecutor.h @@ -47,7 +47,7 @@ public: const std::shared_ptr &operand_context, std::unique_ptr lower_info, std::unique_ptr mem_mgrs, - std::unique_ptr> elements, + std::vector &&elements, const std::shared_ptr &plan) : ExecutorBase{model, std::move(subgraphs), operand_context, std::move(lower_info), std::move(mem_mgrs)}, @@ -60,7 +60,7 @@ public: private: std::shared_ptr _plan; - std::unique_ptr> _elements; + std::vector _elements; }; } // namespace exec -- 2.7.4