[neurun] Remove wrapTensor methods (#9358)
authorSergei Barannikov/AI Tools Lab /SRR/Engineer/Samsung Electronics <s.barannikov@samsung.com>
Wed, 4 Dec 2019 06:37:39 +0000 (09:37 +0300)
committer이한종/On-Device Lab(SR)/Engineer/삼성전자 <hanjoung.lee@samsung.com>
Wed, 4 Dec 2019 06:37:39 +0000 (15:37 +0900)
Remove `wrapTensor` methods of TensorBuilder and TensorManager.

Signed-off-by: Sergei Barannikov <s.barannikov@samsung.com>
17 files changed:
runtime/neurun/backend/acl_common/AclMemoryManager.h
runtime/neurun/backend/acl_common/AclTensorManager.h
runtime/neurun/backend/acl_common/TemplTensorBuilder.h
runtime/neurun/backend/cpu/MemoryManager.cc
runtime/neurun/backend/cpu/MemoryManager.h
runtime/neurun/backend/cpu/TensorBuilder.cc
runtime/neurun/backend/cpu/TensorBuilder.h
runtime/neurun/backend/cpu/TensorManager.cc
runtime/neurun/backend/cpu/TensorManager.h
runtime/neurun/backend/srcn/ConstantInitializer.cc
runtime/neurun/backend/srcn/MemoryManager.cc
runtime/neurun/backend/srcn/MemoryManager.h
runtime/neurun/backend/srcn/TensorBuilder.cc
runtime/neurun/backend/srcn/TensorBuilder.h
runtime/neurun/backend/srcn/TensorManager.cc
runtime/neurun/backend/srcn/TensorManager.h
runtime/neurun/core/include/backend/ITensorBuilder.h

index 076a3f4..60d2c5f 100644 (file)
@@ -82,35 +82,13 @@ public:
     _subtensors[child_ind] = subtensor;
   }
 
-  std::shared_ptr<T_Object> 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<T_Object>(_tensors.at(ind));
-      }
-      else
-      {
-        return _objects[ind] = std::make_shared<T_Object>(_subtensors.at(ind));
-      }
-    }
-  }
-
   model::OperandIndexMap<std::shared_ptr<T_Tensor>> &tensors(void) { return _tensors; }
 
   model::OperandIndexMap<std::shared_ptr<T_SubTensor>> &subtensors(void) { return _subtensors; }
 
-  model::OperandIndexMap<std::shared_ptr<T_Object>> &objects(void) { return _objects; }
-
 private:
   model::OperandIndexMap<std::shared_ptr<T_Tensor>> _tensors;
   model::OperandIndexMap<std::shared_ptr<T_SubTensor>> _subtensors;
-  model::OperandIndexMap<std::shared_ptr<T_Object>> _objects;
 };
 
 } // namespace acl_common
index 63918ff..8729663 100644 (file)
@@ -62,7 +62,6 @@ public:
   void startLifetime(const model::OperandIndex &ind);
   void finishLifetime(const model::OperandIndex &ind);
 
-  std::shared_ptr<backend::operand::IObject> wrapTensor(const model::OperandIndex &ind);
   std::shared_ptr<T_ITensor> at(const ::neurun::model::OperandIndex &ind);
 
   model::OperandIndexMap<std::shared_ptr<T_Tensor>> &constTensors(void);
@@ -215,15 +214,6 @@ void AclTensorManager<T_ITensor, T_Tensor, T_SubTensor, T_Object>::finishLifetim
 }
 
 template <typename T_ITensor, typename T_Tensor, typename T_SubTensor, typename T_Object>
-std::shared_ptr<backend::operand::IObject>
-AclTensorManager<T_ITensor, T_Tensor, T_SubTensor, T_Object>::wrapTensor(
-    const model::OperandIndex &ind)
-{
-  assert(_ind_to_mgr.find(ind) != _ind_to_mgr.end());
-  return _ind_to_mgr.at(ind).wrapTensor(ind);
-}
-
-template <typename T_ITensor, typename T_Tensor, typename T_SubTensor, typename T_Object>
 std::shared_ptr<T_ITensor> AclTensorManager<T_ITensor, T_Tensor, T_SubTensor, T_Object>::at(
     const ::neurun::model::OperandIndex &ind)
 {
@@ -286,7 +276,6 @@ template <typename T_ITensor, typename T_Tensor, typename T_SubTensor, typename
 void AclTensorManager<T_ITensor, T_Tensor, T_SubTensor, T_Object>::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<T_ITensor, T_Tensor, T_SubTensor, T_Object>::tryDeallocCon
       tensor->allocator()->free();
       tensor.reset();
       it = tensors.erase(it);
-      objects.erase(ind);
     }
     else
     {
index e3a4d72..ef70ee2 100644 (file)
@@ -77,7 +77,6 @@ public:
 
   std::shared_ptr<::neurun::backend::operand::ITensor>
   tensorAt(const model::OperandIndex &ind) override;
-  std::shared_ptr<backend::operand::IObject> wrapTensor(const model::OperandIndex &ind) override;
   void iterate(const IterateFunction &fn) override;
 
   void preVisit(const model::Operation &node) override;
@@ -261,14 +260,6 @@ TemplTensorBuilder<T_ITensor, T_Tensor, T_SubTensor, T_Object>::tensorAt(
 }
 
 template <typename T_ITensor, typename T_Tensor, typename T_SubTensor, typename T_Object>
-std::shared_ptr<backend::operand::IObject>
-TemplTensorBuilder<T_ITensor, T_Tensor, T_SubTensor, T_Object>::wrapTensor(
-    const model::OperandIndex &ind)
-{
-  return _tensor_mgr->wrapTensor(ind);
-}
-
-template <typename T_ITensor, typename T_Tensor, typename T_SubTensor, typename T_Object>
 void TemplTensorBuilder<T_ITensor, T_Tensor, T_SubTensor, T_Object>::iterate(
     const IterateFunction &fn)
 {
index 33f1ddc..ac0cc29 100644 (file)
@@ -76,18 +76,6 @@ void MemoryManager::allocate(void)
   }
 }
 
-std::shared_ptr<backend::operand::IObject> 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
index 6b225ed..9dad266 100644 (file)
@@ -45,14 +45,11 @@ public:
 
   model::OperandIndexMap<std::shared_ptr<operand::Tensor>> &tensors(void) { return _tensors; }
 
-  std::shared_ptr<backend::operand::IObject> wrapTensor(const model::OperandIndex &ind);
-
 private:
   IMemoryPlanner *createMemoryPlanner();
 
 private:
   model::OperandIndexMap<std::shared_ptr<operand::Tensor>> _tensors;
-  model::OperandIndexMap<std::shared_ptr<::neurun::backend::operand::Object>> _objects;
   model::OperandIndexMap<Block> _tensor_mem_map;
   std::shared_ptr<IMemoryPlanner> _mem_planner;
   std::shared_ptr<Allocator> _mem_alloc;
index 208e712..8ff3ce7 100644 (file)
@@ -88,11 +88,6 @@ TensorBuilder::tensorAt(const model::OperandIndex &ind)
   return _tensor_mgr->at(ind);
 }
 
-std::shared_ptr<backend::operand::IObject> TensorBuilder::wrapTensor(const model::OperandIndex &ind)
-{
-  return _tensor_mgr->wrapTensor(ind);
-}
-
 void TensorBuilder::iterate(const IterateFunction &fn) { _tensor_mgr->iterate(fn); }
 
 std::shared_ptr<operand::Tensor> TensorBuilder::at(const ::neurun::model::OperandIndex &ind)
index 52b85d6..157978c 100644 (file)
@@ -67,8 +67,6 @@ public:
   std::shared_ptr<::neurun::backend::operand::ITensor>
   tensorAt(const model::OperandIndex &ind) override;
 
-  std::shared_ptr<backend::operand::IObject> wrapTensor(const model::OperandIndex &ind) override;
-
   void iterate(const IterateFunction &fn) override;
 
   void preVisit(const model::Operation &) override { /* DO NOTHING */}
index 22d874b..90751c7 100644 (file)
@@ -64,12 +64,6 @@ void TensorManager::releasePlan(const model::OperandIndex &ind)
   _ind_to_mgr.at(ind).releasePlan(ind);
 }
 
-std::shared_ptr<backend::operand::IObject> 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<operand::Tensor> TensorManager::at(const ::neurun::model::OperandIndex &ind)
 {
   assert(_ind_to_mgr.find(ind) != _ind_to_mgr.end());
index c1f4a00..22cf446 100644 (file)
@@ -45,7 +45,6 @@ public:
   void claimPlan(const model::OperandIndex &ind, uint32_t size);
   void releasePlan(const model::OperandIndex &ind);
 
-  std::shared_ptr<backend::operand::IObject> wrapTensor(const model::OperandIndex &ind);
   std::shared_ptr<operand::Tensor> at(const ::neurun::model::OperandIndex &ind);
 
   model::OperandIndexMap<std::shared_ptr<operand::Tensor>> &constTensors(void);
index b97342c..592e0df 100644 (file)
@@ -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 ||
index d05dd2f..65d841b 100644 (file)
@@ -77,18 +77,6 @@ void MemoryManager::allocate(void)
   }
 }
 
-std::shared_ptr<backend::operand::IObject> 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
index edfcbd7..f425abe 100644 (file)
@@ -46,14 +46,11 @@ public:
 
   model::OperandIndexMap<std::shared_ptr<operand::Tensor>> &tensors(void) { return _tensors; }
 
-  std::shared_ptr<backend::operand::IObject> wrapTensor(const model::OperandIndex &ind);
-
 private:
   IMemoryPlanner *createMemoryPlanner();
 
 private:
   model::OperandIndexMap<std::shared_ptr<operand::Tensor>> _tensors;
-  model::OperandIndexMap<std::shared_ptr<::neurun::backend::operand::Object>> _objects;
   model::OperandIndexMap<Block> _tensor_mem_map;
   std::shared_ptr<IMemoryPlanner> _mem_planner;
   std::shared_ptr<Allocator> _mem_alloc;
index a384f45..dd440e3 100644 (file)
@@ -91,11 +91,6 @@ TensorBuilder::tensorAt(const model::OperandIndex &ind)
   return _tensor_mgr->at(ind);
 }
 
-std::shared_ptr<backend::operand::IObject> TensorBuilder::wrapTensor(const model::OperandIndex &ind)
-{
-  return _tensor_mgr->wrapTensor(ind);
-}
-
 void TensorBuilder::iterate(const IterateFunction &fn) { _tensor_mgr->iterate(fn); }
 
 std::shared_ptr<operand::Tensor> TensorBuilder::at(const ::neurun::model::OperandIndex &ind)
index 074ba3c..3fd023d 100644 (file)
@@ -67,8 +67,6 @@ public:
   std::shared_ptr<::neurun::backend::operand::ITensor>
   tensorAt(const model::OperandIndex &ind) override;
 
-  std::shared_ptr<backend::operand::IObject> wrapTensor(const model::OperandIndex &ind) override;
-
   void iterate(const IterateFunction &fn) override;
 
   void preVisit(const model::Operation &) override { /* DO NOTHING */}
index 1014ce1..b32b030 100644 (file)
@@ -65,12 +65,6 @@ void TensorManager::releasePlan(const model::OperandIndex &ind)
   _ind_to_mgr.at(ind).releasePlan(ind);
 }
 
-std::shared_ptr<backend::operand::IObject> 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<operand::Tensor> TensorManager::at(const ::neurun::model::OperandIndex &ind)
 {
   assert(_ind_to_mgr.find(ind) != _ind_to_mgr.end());
index 37559fe..5bdeaff 100644 (file)
@@ -45,7 +45,6 @@ public:
   void claimPlan(const model::OperandIndex &ind, uint32_t size);
   void releasePlan(const model::OperandIndex &ind);
 
-  std::shared_ptr<backend::operand::IObject> wrapTensor(const model::OperandIndex &ind);
   std::shared_ptr<operand::Tensor> at(const ::neurun::model::OperandIndex &ind);
 
   model::OperandIndexMap<std::shared_ptr<operand::Tensor>> &constTensors(void);
index 413050d..88866f7 100644 (file)
@@ -64,7 +64,6 @@ struct ITensorBuilder
 
   virtual std::shared_ptr<::neurun::backend::operand::ITensor>
   tensorAt(const model::OperandIndex &ind) = 0;
-  virtual std::shared_ptr<backend::operand::IObject> wrapTensor(const model::OperandIndex &ind) = 0;
   virtual void iterate(const IterateFunction &fn) = 0;
 
   virtual void preVisit(const model::Operation &) = 0;