[MemoryManager] Introduce interface apis of ITensorBuilder (#5469)
author김용섭/On-Device Lab(SR)/Engineer/삼성전자 <yons.kim@samsung.com>
Tue, 25 Jun 2019 06:52:33 +0000 (15:52 +0900)
committer이춘석/On-Device Lab(SR)/Staff Engineer/삼성전자 <chunseok.lee@samsung.com>
Tue, 25 Jun 2019 06:52:33 +0000 (15:52 +0900)
On arm_compute::Memory classes, constant should be allocated before
prepare() after configure(). To do this, below functions will be used.
- registerModelObject
- markConstant
- isConstant

Some acl_kernels support deallocating constants unused. To do this,
- deallocateConstants

For arm_compute::LifetimeManager class, we should track the
operands' lifetime. To do this,
- notifyFirstUseIf
- notifyLastUseIf

Signed-off-by: Yongseop Kim <yons.kim@samsung.com>
runtimes/neurun/backend/acl_common/TemplTensorBuilder.h
runtimes/neurun/backend/cpu/TensorBuilder.cc
runtimes/neurun/backend/cpu/TensorBuilder.h
runtimes/neurun/core/include/backend/ITensorBuilder.h
runtimes/neurun/format.patch [new file with mode: 0644]

index 206f5b8..1682603 100644 (file)
@@ -68,6 +68,15 @@ public:
   std::shared_ptr<backend::operand::IObject> wrapTensor(const model::OperandIndex &ind) override;
   void iterate(const IterateFunction &fn) override;
 
+  void registerModelObject(const model::OperandIndex &ind, const model::Operand &obj) override;
+  void markConstant(const model::OperandIndex &ind) override;
+  bool isConstant(const model::OperandIndex &ind) override;
+
+  void deallocateConstants(void) override;
+
+  void notifyFirstUseIf(const model::OperandIndex &ind) override;
+  void notifyLastUseIf(const model::OperandIndex &ind) override;
+
   std::unique_ptr<IMemoryManager> releaseMemoryManager(void) override;
 
   std::shared_ptr<T_ITensor> at(const ::neurun::model::OperandIndex &ind);
@@ -144,14 +153,14 @@ template <typename T_ITensor, typename T_Tensor, typename T_SubTensor, typename
 void TemplTensorBuilder<T_ITensor, T_Tensor, T_SubTensor, T_Object>::notifyFirstUse(
     const model::OperandIndex &)
 {
-  // DO NOTHING
+  // TODO FILL THIS
 }
 
 template <typename T_ITensor, typename T_Tensor, typename T_SubTensor, typename T_Object>
 void TemplTensorBuilder<T_ITensor, T_Tensor, T_SubTensor, T_Object>::notifyLastUse(
     const model::OperandIndex &)
 {
-  // DO NOTHING
+  // TODO FILL THIS
 }
 
 template <typename T_ITensor, typename T_Tensor, typename T_SubTensor, typename T_Object>
@@ -349,6 +358,54 @@ void TemplTensorBuilder<T_ITensor, T_Tensor, T_SubTensor, T_Object>::buildSubten
   }
 }
 
+template <typename T_ITensor, typename T_Tensor, typename T_SubTensor, typename T_Object>
+void TemplTensorBuilder<T_ITensor, T_Tensor, T_SubTensor, T_Object>::registerModelObject(
+    const model::OperandIndex &ind, const model::Operand &obj)
+{
+  // TODO Fill this
+  (void)ind;
+  (void)obj;
+}
+
+template <typename T_ITensor, typename T_Tensor, typename T_SubTensor, typename T_Object>
+void TemplTensorBuilder<T_ITensor, T_Tensor, T_SubTensor, T_Object>::markConstant(
+    const model::OperandIndex &ind)
+{
+  // TODO Fill this
+  (void)ind;
+}
+
+template <typename T_ITensor, typename T_Tensor, typename T_SubTensor, typename T_Object>
+bool TemplTensorBuilder<T_ITensor, T_Tensor, T_SubTensor, T_Object>::isConstant(
+    const model::OperandIndex &ind)
+{
+  // TODO Fill this
+  (void)ind;
+  return false;
+}
+
+template <typename T_ITensor, typename T_Tensor, typename T_SubTensor, typename T_Object>
+void TemplTensorBuilder<T_ITensor, T_Tensor, T_SubTensor, T_Object>::deallocateConstants()
+{
+  // TODO Fill this
+}
+
+template <typename T_ITensor, typename T_Tensor, typename T_SubTensor, typename T_Object>
+void TemplTensorBuilder<T_ITensor, T_Tensor, T_SubTensor, T_Object>::notifyFirstUseIf(
+    const model::OperandIndex &ind)
+{
+  // TODO Fill this
+  (void)ind;
+}
+
+template <typename T_ITensor, typename T_Tensor, typename T_SubTensor, typename T_Object>
+void TemplTensorBuilder<T_ITensor, T_Tensor, T_SubTensor, T_Object>::notifyLastUseIf(
+    const model::OperandIndex &ind)
+{
+  // TODO Fill this
+  (void)ind;
+}
+
 } // namespace acl_common
 } // namespace backend
 } // namespace neurun
index 4a6ebea..d6ac7f1 100644 (file)
@@ -95,6 +95,43 @@ std::unique_ptr<IMemoryManager> TensorBuilder::releaseMemoryManager(void)
   return std::move(_mem_mgr);
 }
 
+void TensorBuilder::registerModelObject(const model::OperandIndex &ind, const model::Operand &obj)
+{
+  // TODO Fill this
+  (void)ind;
+  (void)obj;
+}
+
+void TensorBuilder::markConstant(const model::OperandIndex &ind)
+{
+  // TODO Fill this
+  (void)ind;
+}
+
+bool TensorBuilder::isConstant(const model::OperandIndex &ind)
+{
+  // TODO Fill this
+  (void)ind;
+  return false;
+}
+
+void TensorBuilder::deallocateConstants(void)
+{
+  // DO NOTHING
+}
+
+void TensorBuilder::notifyFirstUseIf(const model::OperandIndex &ind)
+{
+  VERBOSE(CPU_TensorBuilder) << "notifyFirstUseIf()... skip operand #" << ind.value() << std::endl;
+  // DO NOTHING
+}
+
+void TensorBuilder::notifyLastUseIf(const model::OperandIndex &ind)
+{
+  VERBOSE(CPU_TensorBuilder) << "notifyLastUseIf()... skip operand #" << ind.value() << std::endl;
+  // DO NOTHING
+}
+
 } // namespace cpu
 } // namespace backend
 } // namespace neurun
index 72711c8..87c3a63 100644 (file)
@@ -68,6 +68,16 @@ public:
 
   void iterate(const IterateFunction &fn) override;
 
+  void registerModelObject(const model::OperandIndex &ind, const model::Operand &obj) override;
+  void markConstant(const model::OperandIndex &ind) override;
+  bool isConstant(const model::OperandIndex &ind) override;
+
+  void deallocateConstants(void) override;
+
+  // Only act on the linear executor on acl
+  void notifyFirstUseIf(const model::OperandIndex &) override;
+  void notifyLastUseIf(const model::OperandIndex &) override;
+
   std::unique_ptr<IMemoryManager> releaseMemoryManager(void) override;
 
   std::shared_ptr<operand::Tensor> at(const ::neurun::model::OperandIndex &ind);
index 683e1cc..cc5427c 100644 (file)
@@ -61,6 +61,15 @@ struct ITensorBuilder
   virtual std::shared_ptr<backend::operand::IObject> wrapTensor(const model::OperandIndex &ind) = 0;
   virtual void iterate(const IterateFunction &fn) = 0;
 
+  virtual void registerModelObject(const model::OperandIndex &, const model::Operand &) = 0;
+  virtual void markConstant(const model::OperandIndex &) = 0;
+  virtual bool isConstant(const model::OperandIndex &) = 0;
+
+  virtual void deallocateConstants(void) = 0;
+
+  virtual void notifyFirstUseIf(const model::OperandIndex &) = 0;
+  virtual void notifyLastUseIf(const model::OperandIndex &) = 0;
+
   virtual std::unique_ptr<IMemoryManager> releaseMemoryManager(void) = 0;
 };
 
diff --git a/runtimes/neurun/format.patch b/runtimes/neurun/format.patch
new file mode 100644 (file)
index 0000000..e69de29