From 97531ca951a57d9968741ab01636a9fc015797b8 Mon Sep 17 00:00:00 2001 From: Sergei Barannikov/AI Tools Lab /SRR/Engineer/Samsung Electronics Date: Wed, 4 Dec 2019 09:37:39 +0300 Subject: [PATCH] [neurun] Remove wrapTensor methods (#9358) Remove `wrapTensor` methods of TensorBuilder and TensorManager. Signed-off-by: Sergei Barannikov --- .../neurun/backend/acl_common/AclMemoryManager.h | 22 ---------------------- .../neurun/backend/acl_common/AclTensorManager.h | 12 ------------ .../neurun/backend/acl_common/TemplTensorBuilder.h | 9 --------- runtime/neurun/backend/cpu/MemoryManager.cc | 12 ------------ runtime/neurun/backend/cpu/MemoryManager.h | 3 --- runtime/neurun/backend/cpu/TensorBuilder.cc | 5 ----- runtime/neurun/backend/cpu/TensorBuilder.h | 2 -- runtime/neurun/backend/cpu/TensorManager.cc | 6 ------ runtime/neurun/backend/cpu/TensorManager.h | 1 - runtime/neurun/backend/srcn/ConstantInitializer.cc | 6 +++--- runtime/neurun/backend/srcn/MemoryManager.cc | 12 ------------ runtime/neurun/backend/srcn/MemoryManager.h | 3 --- runtime/neurun/backend/srcn/TensorBuilder.cc | 5 ----- runtime/neurun/backend/srcn/TensorBuilder.h | 2 -- runtime/neurun/backend/srcn/TensorManager.cc | 6 ------ runtime/neurun/backend/srcn/TensorManager.h | 1 - .../neurun/core/include/backend/ITensorBuilder.h | 1 - 17 files changed, 3 insertions(+), 105 deletions(-) diff --git a/runtime/neurun/backend/acl_common/AclMemoryManager.h b/runtime/neurun/backend/acl_common/AclMemoryManager.h index 076a3f4..60d2c5f 100644 --- a/runtime/neurun/backend/acl_common/AclMemoryManager.h +++ b/runtime/neurun/backend/acl_common/AclMemoryManager.h @@ -82,35 +82,13 @@ public: _subtensors[child_ind] = subtensor; } - std::shared_ptr wrapTensor(const model::OperandIndex &ind) - { - if (_objects.find(ind) != _objects.end()) - { - return _objects.at(ind); - } - else - { - if (_tensors.find(ind) != _tensors.end()) - { - return _objects[ind] = std::make_shared(_tensors.at(ind)); - } - else - { - return _objects[ind] = std::make_shared(_subtensors.at(ind)); - } - } - } - model::OperandIndexMap> &tensors(void) { return _tensors; } model::OperandIndexMap> &subtensors(void) { return _subtensors; } - model::OperandIndexMap> &objects(void) { return _objects; } - private: model::OperandIndexMap> _tensors; model::OperandIndexMap> _subtensors; - model::OperandIndexMap> _objects; }; } // namespace acl_common diff --git a/runtime/neurun/backend/acl_common/AclTensorManager.h b/runtime/neurun/backend/acl_common/AclTensorManager.h index 63918ff..8729663 100644 --- a/runtime/neurun/backend/acl_common/AclTensorManager.h +++ b/runtime/neurun/backend/acl_common/AclTensorManager.h @@ -62,7 +62,6 @@ public: void startLifetime(const model::OperandIndex &ind); void finishLifetime(const model::OperandIndex &ind); - std::shared_ptr wrapTensor(const model::OperandIndex &ind); std::shared_ptr at(const ::neurun::model::OperandIndex &ind); model::OperandIndexMap> &constTensors(void); @@ -215,15 +214,6 @@ void AclTensorManager::finishLifetim } template -std::shared_ptr -AclTensorManager::wrapTensor( - const model::OperandIndex &ind) -{ - assert(_ind_to_mgr.find(ind) != _ind_to_mgr.end()); - return _ind_to_mgr.at(ind).wrapTensor(ind); -} - -template std::shared_ptr AclTensorManager::at( const ::neurun::model::OperandIndex &ind) { @@ -286,7 +276,6 @@ template ::tryDeallocConstants(void) { auto &tensors = _const_mgr->tensors(); - auto &objects = _const_mgr->objects(); for (auto it = tensors.begin(); it != tensors.end();) { @@ -299,7 +288,6 @@ void AclTensorManager::tryDeallocCon tensor->allocator()->free(); tensor.reset(); it = tensors.erase(it); - objects.erase(ind); } else { diff --git a/runtime/neurun/backend/acl_common/TemplTensorBuilder.h b/runtime/neurun/backend/acl_common/TemplTensorBuilder.h index e3a4d72..ef70ee2 100644 --- a/runtime/neurun/backend/acl_common/TemplTensorBuilder.h +++ b/runtime/neurun/backend/acl_common/TemplTensorBuilder.h @@ -77,7 +77,6 @@ public: std::shared_ptr<::neurun::backend::operand::ITensor> tensorAt(const model::OperandIndex &ind) override; - std::shared_ptr wrapTensor(const model::OperandIndex &ind) override; void iterate(const IterateFunction &fn) override; void preVisit(const model::Operation &node) override; @@ -261,14 +260,6 @@ TemplTensorBuilder::tensorAt( } template -std::shared_ptr -TemplTensorBuilder::wrapTensor( - const model::OperandIndex &ind) -{ - return _tensor_mgr->wrapTensor(ind); -} - -template void TemplTensorBuilder::iterate( const IterateFunction &fn) { diff --git a/runtime/neurun/backend/cpu/MemoryManager.cc b/runtime/neurun/backend/cpu/MemoryManager.cc index 33f1ddc..ac0cc29 100644 --- a/runtime/neurun/backend/cpu/MemoryManager.cc +++ b/runtime/neurun/backend/cpu/MemoryManager.cc @@ -76,18 +76,6 @@ void MemoryManager::allocate(void) } } -std::shared_ptr MemoryManager::wrapTensor(const model::OperandIndex &ind) -{ - if (_objects.find(ind) != _objects.end()) - { - return _objects.at(ind); - } - else - { - return _objects[ind] = std::make_shared<::neurun::backend::operand::Object>(_tensors.at(ind)); - } -} - } // namespace cpu } // namespace backend } // namespace neurun diff --git a/runtime/neurun/backend/cpu/MemoryManager.h b/runtime/neurun/backend/cpu/MemoryManager.h index 6b225ed..9dad266 100644 --- a/runtime/neurun/backend/cpu/MemoryManager.h +++ b/runtime/neurun/backend/cpu/MemoryManager.h @@ -45,14 +45,11 @@ public: model::OperandIndexMap> &tensors(void) { return _tensors; } - std::shared_ptr wrapTensor(const model::OperandIndex &ind); - private: IMemoryPlanner *createMemoryPlanner(); private: model::OperandIndexMap> _tensors; - model::OperandIndexMap> _objects; model::OperandIndexMap _tensor_mem_map; std::shared_ptr _mem_planner; std::shared_ptr _mem_alloc; diff --git a/runtime/neurun/backend/cpu/TensorBuilder.cc b/runtime/neurun/backend/cpu/TensorBuilder.cc index 208e712..8ff3ce7 100644 --- a/runtime/neurun/backend/cpu/TensorBuilder.cc +++ b/runtime/neurun/backend/cpu/TensorBuilder.cc @@ -88,11 +88,6 @@ TensorBuilder::tensorAt(const model::OperandIndex &ind) return _tensor_mgr->at(ind); } -std::shared_ptr TensorBuilder::wrapTensor(const model::OperandIndex &ind) -{ - return _tensor_mgr->wrapTensor(ind); -} - void TensorBuilder::iterate(const IterateFunction &fn) { _tensor_mgr->iterate(fn); } std::shared_ptr TensorBuilder::at(const ::neurun::model::OperandIndex &ind) diff --git a/runtime/neurun/backend/cpu/TensorBuilder.h b/runtime/neurun/backend/cpu/TensorBuilder.h index 52b85d6..157978c 100644 --- a/runtime/neurun/backend/cpu/TensorBuilder.h +++ b/runtime/neurun/backend/cpu/TensorBuilder.h @@ -67,8 +67,6 @@ public: std::shared_ptr<::neurun::backend::operand::ITensor> tensorAt(const model::OperandIndex &ind) override; - std::shared_ptr wrapTensor(const model::OperandIndex &ind) override; - void iterate(const IterateFunction &fn) override; void preVisit(const model::Operation &) override { /* DO NOTHING */} diff --git a/runtime/neurun/backend/cpu/TensorManager.cc b/runtime/neurun/backend/cpu/TensorManager.cc index 22d874b..90751c7 100644 --- a/runtime/neurun/backend/cpu/TensorManager.cc +++ b/runtime/neurun/backend/cpu/TensorManager.cc @@ -64,12 +64,6 @@ void TensorManager::releasePlan(const model::OperandIndex &ind) _ind_to_mgr.at(ind).releasePlan(ind); } -std::shared_ptr TensorManager::wrapTensor(const model::OperandIndex &ind) -{ - assert(_ind_to_mgr.find(ind) != _ind_to_mgr.end()); - return _ind_to_mgr.at(ind).wrapTensor(ind); -} - std::shared_ptr TensorManager::at(const ::neurun::model::OperandIndex &ind) { assert(_ind_to_mgr.find(ind) != _ind_to_mgr.end()); diff --git a/runtime/neurun/backend/cpu/TensorManager.h b/runtime/neurun/backend/cpu/TensorManager.h index c1f4a00..22cf446 100644 --- a/runtime/neurun/backend/cpu/TensorManager.h +++ b/runtime/neurun/backend/cpu/TensorManager.h @@ -45,7 +45,6 @@ public: void claimPlan(const model::OperandIndex &ind, uint32_t size); void releasePlan(const model::OperandIndex &ind); - std::shared_ptr wrapTensor(const model::OperandIndex &ind); std::shared_ptr at(const ::neurun::model::OperandIndex &ind); model::OperandIndexMap> &constTensors(void); diff --git a/runtime/neurun/backend/srcn/ConstantInitializer.cc b/runtime/neurun/backend/srcn/ConstantInitializer.cc index b97342c..592e0df 100644 --- a/runtime/neurun/backend/srcn/ConstantInitializer.cc +++ b/runtime/neurun/backend/srcn/ConstantInitializer.cc @@ -129,7 +129,7 @@ void ConstantInitializer::visit(const model::operation::Conv2D &node) const auto &kernel_obj = _operands.at(kernel_index); util::Coordinates permutation{0, 1, 2, 3}; const auto frontend_layout = _current_subg_layout; - const auto backend_layout = _tensor_builder->wrapTensor(kernel_index)->ptr()->layout(); + const auto backend_layout = _tensor_builder->tensorAt(kernel_index)->layout(); assert(frontend_layout == neurun::model::Layout::NHWC || frontend_layout == neurun::model::Layout::NCHW); assert(backend_layout == neurun::model::Layout::NHWC || @@ -151,7 +151,7 @@ void ConstantInitializer::visit(const model::operation::DepthwiseConv2D &node) const auto &kernel_obj = _operands.at(kernel_index); util::Coordinates permutation{0, 1, 2, 3}; const auto frontend_layout = _current_subg_layout; - const auto backend_layout = _tensor_builder->wrapTensor(kernel_index)->ptr()->layout(); + const auto backend_layout = _tensor_builder->tensorAt(kernel_index)->layout(); assert(frontend_layout == neurun::model::Layout::NHWC || frontend_layout == neurun::model::Layout::NCHW); assert(backend_layout == neurun::model::Layout::NHWC || @@ -179,7 +179,7 @@ void ConstantInitializer::visit(const model::operation::TransposeConv &node) const auto &kernel_index = node.getInputs().at(model::operation::TransposeConv::KERNEL); const auto &kernel_obj = _operands.at(kernel_index); const auto frontend_layout = _current_subg_layout; - const auto backend_layout = _tensor_builder->wrapTensor(kernel_index)->ptr()->layout(); + const auto backend_layout = _tensor_builder->tensorAt(kernel_index)->layout(); assert(frontend_layout == neurun::model::Layout::NHWC || frontend_layout == neurun::model::Layout::NCHW); assert(backend_layout == neurun::model::Layout::NHWC || diff --git a/runtime/neurun/backend/srcn/MemoryManager.cc b/runtime/neurun/backend/srcn/MemoryManager.cc index d05dd2f..65d841b 100644 --- a/runtime/neurun/backend/srcn/MemoryManager.cc +++ b/runtime/neurun/backend/srcn/MemoryManager.cc @@ -77,18 +77,6 @@ void MemoryManager::allocate(void) } } -std::shared_ptr MemoryManager::wrapTensor(const model::OperandIndex &ind) -{ - if (_objects.find(ind) != _objects.end()) - { - return _objects.at(ind); - } - else - { - return _objects[ind] = std::make_shared<::neurun::backend::operand::Object>(_tensors.at(ind)); - } -} - } // namespace srcn } // namespace backend } // namespace neurun diff --git a/runtime/neurun/backend/srcn/MemoryManager.h b/runtime/neurun/backend/srcn/MemoryManager.h index edfcbd7..f425abe 100644 --- a/runtime/neurun/backend/srcn/MemoryManager.h +++ b/runtime/neurun/backend/srcn/MemoryManager.h @@ -46,14 +46,11 @@ public: model::OperandIndexMap> &tensors(void) { return _tensors; } - std::shared_ptr wrapTensor(const model::OperandIndex &ind); - private: IMemoryPlanner *createMemoryPlanner(); private: model::OperandIndexMap> _tensors; - model::OperandIndexMap> _objects; model::OperandIndexMap _tensor_mem_map; std::shared_ptr _mem_planner; std::shared_ptr _mem_alloc; diff --git a/runtime/neurun/backend/srcn/TensorBuilder.cc b/runtime/neurun/backend/srcn/TensorBuilder.cc index a384f45..dd440e3 100644 --- a/runtime/neurun/backend/srcn/TensorBuilder.cc +++ b/runtime/neurun/backend/srcn/TensorBuilder.cc @@ -91,11 +91,6 @@ TensorBuilder::tensorAt(const model::OperandIndex &ind) return _tensor_mgr->at(ind); } -std::shared_ptr TensorBuilder::wrapTensor(const model::OperandIndex &ind) -{ - return _tensor_mgr->wrapTensor(ind); -} - void TensorBuilder::iterate(const IterateFunction &fn) { _tensor_mgr->iterate(fn); } std::shared_ptr TensorBuilder::at(const ::neurun::model::OperandIndex &ind) diff --git a/runtime/neurun/backend/srcn/TensorBuilder.h b/runtime/neurun/backend/srcn/TensorBuilder.h index 074ba3c..3fd023d 100644 --- a/runtime/neurun/backend/srcn/TensorBuilder.h +++ b/runtime/neurun/backend/srcn/TensorBuilder.h @@ -67,8 +67,6 @@ public: std::shared_ptr<::neurun::backend::operand::ITensor> tensorAt(const model::OperandIndex &ind) override; - std::shared_ptr wrapTensor(const model::OperandIndex &ind) override; - void iterate(const IterateFunction &fn) override; void preVisit(const model::Operation &) override { /* DO NOTHING */} diff --git a/runtime/neurun/backend/srcn/TensorManager.cc b/runtime/neurun/backend/srcn/TensorManager.cc index 1014ce1..b32b030 100644 --- a/runtime/neurun/backend/srcn/TensorManager.cc +++ b/runtime/neurun/backend/srcn/TensorManager.cc @@ -65,12 +65,6 @@ void TensorManager::releasePlan(const model::OperandIndex &ind) _ind_to_mgr.at(ind).releasePlan(ind); } -std::shared_ptr TensorManager::wrapTensor(const model::OperandIndex &ind) -{ - assert(_ind_to_mgr.find(ind) != _ind_to_mgr.end()); - return _ind_to_mgr.at(ind).wrapTensor(ind); -} - std::shared_ptr TensorManager::at(const ::neurun::model::OperandIndex &ind) { assert(_ind_to_mgr.find(ind) != _ind_to_mgr.end()); diff --git a/runtime/neurun/backend/srcn/TensorManager.h b/runtime/neurun/backend/srcn/TensorManager.h index 37559fe..5bdeaff 100644 --- a/runtime/neurun/backend/srcn/TensorManager.h +++ b/runtime/neurun/backend/srcn/TensorManager.h @@ -45,7 +45,6 @@ public: void claimPlan(const model::OperandIndex &ind, uint32_t size); void releasePlan(const model::OperandIndex &ind); - std::shared_ptr wrapTensor(const model::OperandIndex &ind); std::shared_ptr at(const ::neurun::model::OperandIndex &ind); model::OperandIndexMap> &constTensors(void); diff --git a/runtime/neurun/core/include/backend/ITensorBuilder.h b/runtime/neurun/core/include/backend/ITensorBuilder.h index 413050d..88866f7 100644 --- a/runtime/neurun/core/include/backend/ITensorBuilder.h +++ b/runtime/neurun/core/include/backend/ITensorBuilder.h @@ -64,7 +64,6 @@ struct ITensorBuilder virtual std::shared_ptr<::neurun::backend::operand::ITensor> tensorAt(const model::OperandIndex &ind) = 0; - virtual std::shared_ptr wrapTensor(const model::OperandIndex &ind) = 0; virtual void iterate(const IterateFunction &fn) = 0; virtual void preVisit(const model::Operation &) = 0; -- 2.7.4