[neurun] Introduce Common Operands in Plan (#2144)
author김수진/동작제어Lab(SR)/Engineer/삼성전자 <sjsujin.kim@samsung.com>
Thu, 2 Aug 2018 07:32:44 +0000 (16:32 +0900)
committer박세희/동작제어Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>
Thu, 2 Aug 2018 07:32:44 +0000 (16:32 +0900)
Related : #2142

This commit introduces common operands in Plan, since we should set input/output as Common Tensor.

Signed-off-by: sjsujinkim <sjsujin.kim@samsung.com>
runtimes/neurun/src/internal/BackendManager.cc
runtimes/neurun/src/internal/arm_compute.h
runtimes/neurun/src/internal/common/Tensor.h
runtimes/neurun/src/internal/common/TensorBuilder.cc
runtimes/neurun/src/internal/common/TensorBuilder.h
runtimes/neurun/src/internal/common/common.cc [new file with mode: 0644]
runtimes/neurun/src/internal/common/common.h [new file with mode: 0644]

index e8fd286..5a21bcc 100644 (file)
@@ -14,7 +14,7 @@ BackendManager::BackendManager(::internal::arm_compute::Plan &plan) : _plan(plan
 {
   const auto &operands = _plan.model().operands();
 
-  _common_tensor_builder = std::make_shared<::internal::common::TensorBuilder>();
+  _common_tensor_builder = std::make_shared<::internal::common::TensorBuilder>(_plan);
 
   // Add arm_compute backend
   {
index 9e2706b..1e7a340 100644 (file)
@@ -134,12 +134,17 @@ public:
   const operand::Context &operands(void) const { return _operands; }
 
 public:
+  operand::Context &common_operands(void) { return _common_operands; }
+  const operand::Context &common_operands(void) const { return _common_operands; }
+
+public:
   op::Sequence &operations(void) { return _ops; }
   const op::Sequence &operations(void) const { return _ops; }
 
 private:
   std::shared_ptr<::internal::tflite::Model> _model;
   operand::Context _operands;
+  operand::Context _common_operands;
   op::Sequence _ops;
 };
 
index a5a1b96..f27cdc7 100644 (file)
@@ -4,6 +4,8 @@
 #include <arm_compute/core/ITensor.h>
 #include <arm_compute/core/TensorInfo.h>
 
+#include "internal/IObject.h"
+
 namespace internal
 {
 namespace common
index 2be0b09..61bc618 100644 (file)
@@ -7,7 +7,7 @@ namespace internal
 namespace common
 {
 
-TensorBuilder::TensorBuilder()
+TensorBuilder::TensorBuilder(::internal::arm_compute::Plan &plan) : _plan(plan)
 {
   // DO NOTHING
 }
@@ -45,6 +45,7 @@ void TensorBuilder::prepare(const std::map<int, ::arm_compute::TensorInfo> &tens
   {
     ::internal::tflite::operand::Index ind{ind_int};
     auto tensor = std::make_shared<::internal::common::Tensor>(tensor_info_ctx.at(ind.asInt()));
+    _plan.common_operands().set(ind, std::make_shared<::internal::common::Object>(tensor));
     _tensors[ind.asInt()] = tensor;
   }
 }
index dd184b1..ac37112 100644 (file)
@@ -6,6 +6,8 @@
 
 #include "internal/ITensorBuilder.h"
 #include "internal/common/Tensor.h"
+#include "internal/common/common.h"
+#include "internal/arm_compute.h"
 
 namespace internal
 {
@@ -17,7 +19,7 @@ class Plan;
 class TensorBuilder : public ::internal::ITensorBuilder
 {
 public:
-  TensorBuilder();
+  TensorBuilder(::internal::arm_compute::Plan &plan);
 
   virtual void mark(const ::internal::tflite::operand::Index &ind) override;
   virtual void markFromCommon(const ::internal::tflite::op::Node &op, int32_t ind) override;
@@ -29,6 +31,7 @@ public:
   std::shared_ptr<::internal::common::Tensor> at(const ::internal::tflite::operand::Index &ind);
 
 private:
+  ::internal::arm_compute::Plan &_plan;
   std::unordered_set<int> _inds;
   std::unordered_map<int, std::shared_ptr<::internal::common::Tensor>> _tensors;
 };
diff --git a/runtimes/neurun/src/internal/common/common.cc b/runtimes/neurun/src/internal/common/common.cc
new file mode 100644 (file)
index 0000000..f9f8064
--- /dev/null
@@ -0,0 +1,14 @@
+#include "common.h"
+
+namespace internal
+{
+namespace common
+{
+
+void Object::access(const std::function<void(::arm_compute::ITensor &tensor)> &fn) const
+{
+  fn(*_tensor);
+}
+
+} // common
+} // internal
diff --git a/runtimes/neurun/src/internal/common/common.h b/runtimes/neurun/src/internal/common/common.h
new file mode 100644 (file)
index 0000000..9651ac1
--- /dev/null
@@ -0,0 +1,36 @@
+#ifndef __INTERNAL_COMMON_H__
+#define __INTERNAL_COMMON_H__
+
+#include "internal/IObject.h"
+#include "Tensor.h"
+
+namespace internal
+{
+namespace common
+{
+
+class Object : public ::internal::IObject
+{
+public:
+  Object() = default;
+
+public:
+  Object(const std::shared_ptr<Tensor> &tensor) : _tensor{tensor}
+  {
+    // DO NOTHING
+  }
+
+public:
+  Tensor *ptr(void) const override { return _tensor.get(); }
+
+private:
+  std::shared_ptr<Tensor> _tensor;
+
+public:
+  void access(const std::function<void(::arm_compute::ITensor &tensor)> &fn) const override;
+};
+
+} // common
+} // internal
+
+#endif // __INTERNAL_COMMON_H__