[neurun] Extract Plan and related classes from arm_compute namespace (#2239)
author김수진/동작제어Lab(SR)/Engineer/삼성전자 <sjsujin.kim@samsung.com>
Thu, 9 Aug 2018 09:59:59 +0000 (18:59 +0900)
committer이춘석/동작제어Lab(SR)/Staff Engineer/삼성전자 <chunseok.lee@samsung.com>
Thu, 9 Aug 2018 09:59:59 +0000 (18:59 +0900)
This commit extracts Plan and related classes from arm_compute namespace into ::internal.

16 files changed:
runtimes/neurun/src/backend/acl_cl/TensorBuilder.cc
runtimes/neurun/src/backend/acl_cl/TensorBuilder.h
runtimes/neurun/src/backend/cpu/TensorBuilder.cc
runtimes/neurun/src/backend/cpu/TensorBuilder.h
runtimes/neurun/src/compilation.cc
runtimes/neurun/src/compilation.h
runtimes/neurun/src/execution.h
runtimes/neurun/src/frontend/execution.cc
runtimes/neurun/src/internal/BackendManager.cc
runtimes/neurun/src/internal/BackendManager.h
runtimes/neurun/src/internal/Plan.cc [new file with mode: 0644]
runtimes/neurun/src/internal/Plan.h [new file with mode: 0644]
runtimes/neurun/src/internal/arm_compute.cc
runtimes/neurun/src/internal/arm_compute.h
runtimes/neurun/src/internal/common/TensorBuilder.cc
runtimes/neurun/src/internal/common/TensorBuilder.h

index 5354139..092835d 100644 (file)
@@ -11,7 +11,7 @@ namespace backend
 namespace acl_cl
 {
 
-TensorBuilder::TensorBuilder(::internal::arm_compute::Plan &plan) : _plan(plan)
+TensorBuilder::TensorBuilder(::internal::Plan &plan) : _plan(plan)
 {
   // DO NOTHING
 }
index e0fce48..a886bbc 100644 (file)
@@ -2,7 +2,7 @@
 #define __NEURUN_BACKEND_ACL_CL_TENSOR_BUILDER_H__
 
 #include "internal/ITensorBuilder.h"
-#include "internal/arm_compute.h"
+#include "internal/Plan.h"
 
 #include <unordered_map>
 #include <unordered_set>
@@ -21,7 +21,7 @@ class Plan;
 class TensorBuilder : public ::internal::ITensorBuilder
 {
 public:
-  TensorBuilder(::internal::arm_compute::Plan &plan);
+  TensorBuilder(::internal::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;
@@ -33,7 +33,7 @@ public:
   std::shared_ptr<::arm_compute::CLTensor> at(const ::internal::tflite::operand::Index &ind);
 
 private:
-  ::internal::arm_compute::Plan &_plan;
+  ::internal::Plan &_plan;
   std::unordered_set<int> _inds;
   std::unordered_map<int, std::shared_ptr<::arm_compute::CLTensor>> _tensors;
 };
index b907586..d0a4664 100644 (file)
@@ -11,7 +11,7 @@ namespace backend
 namespace cpu
 {
 
-TensorBuilder::TensorBuilder(::internal::arm_compute::Plan &plan) : _plan(plan)
+TensorBuilder::TensorBuilder(::internal::Plan &plan) : _plan(plan)
 {
   // DO NOTHING
 }
index de252e1..171f4e7 100644 (file)
@@ -6,7 +6,7 @@
 
 #include "internal/ITensorBuilder.h"
 #include "internal/cpu.h"
-#include "internal/arm_compute.h"
+#include "internal/Plan.h"
 
 namespace neurun
 {
@@ -20,7 +20,7 @@ class Plan;
 class TensorBuilder : public ::internal::ITensorBuilder
 {
 public:
-  TensorBuilder(::internal::arm_compute::Plan &plan);
+  TensorBuilder(::internal::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;
@@ -32,7 +32,7 @@ public:
   std::shared_ptr<::internal::cpu::Tensor> at(const ::internal::tflite::operand::Index &ind);
 
 private:
-  ::internal::arm_compute::Plan &_plan;
+  ::internal::Plan &_plan;
   std::unordered_set<int> _inds;
   std::unordered_map<int, std::shared_ptr<::internal::cpu::Tensor>> _tensors;
 };
index ad2def0..c9efb42 100644 (file)
@@ -541,7 +541,7 @@ void TensorMarker::visit(const ::internal::tflite::op::TensorConvert::AclToCommo
 class ExecutionBuilder final : public IExecutionBuilder
 {
 public:
-  ExecutionBuilder(::internal::arm_compute::Plan &plan) : _plan{plan}
+  ExecutionBuilder(::internal::Plan &plan) : _plan{plan}
   {
     // DO NOTHING
   }
@@ -553,13 +553,13 @@ public:
   }
 
 private:
-  ::internal::arm_compute::Plan &_plan;
+  ::internal::Plan &_plan;
 };
 
 class PlanBuilder final : public IPlanBuilder
 {
 public:
-  PlanBuilder(::internal::arm_compute::Plan &plan) : _plan{plan}
+  PlanBuilder(::internal::Plan &plan) : _plan{plan}
   {
     // DO NOTHING
   }
@@ -582,7 +582,7 @@ public:
   const std::map<int, ::arm_compute::TensorInfo> &tensor_info_ctx() { return _tensor_info_ctx; }
 
 private:
-  ::internal::arm_compute::Plan &_plan;
+  ::internal::Plan &_plan;
 
 private:
   std::map<int, ::arm_compute::TensorInfo> _tensor_info_ctx;
index 0209798..dc7e00b 100644 (file)
@@ -2,26 +2,26 @@
 #define __COMPILATION_H__
 
 #include "internal/Model.h"
-#include "internal/arm_compute.h"
+#include "internal/Plan.h"
 
 struct ANeuralNetworksCompilation
 {
 public:
   ANeuralNetworksCompilation(const std::shared_ptr<internal::tflite::Model> &model)
-      : _plan{new internal::arm_compute::Plan{model}}
+      : _plan{new internal::Plan{model}}
   {
     // DO NOTHING
   }
 
 public:
-  internal::arm_compute::Plan &plan(void) { return *_plan; }
+  internal::Plan &plan(void) { return *_plan; }
 
 public:
-  void publish(std::shared_ptr<const internal::arm_compute::Plan> &plan) { plan = _plan; }
+  void publish(std::shared_ptr<const internal::Plan> &plan) { plan = _plan; }
   int finish();
 
 private:
-  std::shared_ptr<internal::arm_compute::Plan> _plan;
+  std::shared_ptr<internal::Plan> _plan;
 };
 
 #endif
index ec1d364..45d2011 100644 (file)
@@ -1,25 +1,24 @@
 #ifndef __EXECUTION_H__
 #define __EXECUTION_H__
 
-#include "internal/arm_compute.h"
+#include "internal/Plan.h"
 #include "internal/Source.h"
 #include "internal/Sink.h"
 
 struct ANeuralNetworksExecution
 {
 public:
-  ANeuralNetworksExecution(const std::shared_ptr<const internal::arm_compute::Plan> &plan)
-      : _plan{plan}
+  ANeuralNetworksExecution(const std::shared_ptr<const internal::Plan> &plan) : _plan{plan}
   {
     _sources.resize(_plan->model().inputs.size());
     _sinks.resize(_plan->model().outputs.size());
   }
 
 public:
-  const internal::arm_compute::Plan &plan(void) const { return *_plan; }
+  const internal::Plan &plan(void) const { return *_plan; }
 
 private:
-  std::shared_ptr<const internal::arm_compute::Plan> _plan;
+  std::shared_ptr<const internal::Plan> _plan;
 
 public:
   // TODO Use InputIndex instead of int
index 6ea274e..a3d4ced 100644 (file)
@@ -19,7 +19,7 @@ int ANeuralNetworksExecution_create(ANeuralNetworksCompilation *compilation,
     return ANEURALNETWORKS_UNEXPECTED_NULL;
   }
 
-  std::shared_ptr<const ::internal::arm_compute::Plan> plan;
+  std::shared_ptr<const ::internal::Plan> plan;
 
   compilation->publish(plan);
 
index 5a21bcc..a4a614e 100644 (file)
@@ -10,7 +10,7 @@
 namespace internal
 {
 
-BackendManager::BackendManager(::internal::arm_compute::Plan &plan) : _plan(plan)
+BackendManager::BackendManager(::internal::Plan &plan) : _plan(plan)
 {
   const auto &operands = _plan.model().operands();
 
index 1946a04..45b6efa 100644 (file)
@@ -3,7 +3,7 @@
 
 #include <memory>
 
-#include "internal/arm_compute.h"
+#include "internal/Plan.h"
 #include "internal/IInitializerGenerator.h"
 #include "internal/IStageGenerator.h"
 #include "internal/ITensorBuilder.h"
@@ -33,14 +33,14 @@ struct Backend
 class BackendManager
 {
 public:
-  BackendManager(::internal::arm_compute::Plan &plan);
+  BackendManager(::internal::Plan &plan);
 
   Backend get(const std::string &key);
 
   std::shared_ptr<::internal::common::TensorBuilder> getCommonTensorBuilder();
 
 private:
-  ::internal::arm_compute::Plan &_plan;
+  ::internal::Plan &_plan;
   std::map<std::string, Backend> _gen_map;
   std::shared_ptr<::internal::common::TensorBuilder> _common_tensor_builder;
 };
diff --git a/runtimes/neurun/src/internal/Plan.cc b/runtimes/neurun/src/internal/Plan.cc
new file mode 100644 (file)
index 0000000..e79b28c
--- /dev/null
@@ -0,0 +1,16 @@
+#include "Plan.h"
+
+namespace internal
+{
+namespace operand
+{
+
+Context &Context::set(const ::internal::tflite::operand::Index &id,
+                      const std::shared_ptr<::internal::IObject> &object)
+{
+  _objects[id.asInt()].emplace_back(object);
+  return (*this);
+}
+
+} // namespace operand
+} // namespace internal
diff --git a/runtimes/neurun/src/internal/Plan.h b/runtimes/neurun/src/internal/Plan.h
new file mode 100644 (file)
index 0000000..547b7e7
--- /dev/null
@@ -0,0 +1,110 @@
+#ifndef __INTERNAL_PLAN_H__
+#define __INTERNAL_PLAN_H__
+
+#include "internal/Model.h"
+#include "internal/IObject.h"
+
+#include <map>
+
+namespace internal
+{
+namespace operand
+{
+
+class Context
+{
+public:
+  Context &set(const ::internal::tflite::operand::Index &ind,
+               const std::shared_ptr<::internal::IObject> &object);
+
+public:
+  bool exist(const ::internal::tflite::operand::Index &ind) const
+  {
+    return _objects.find(ind.asInt()) != _objects.end();
+  }
+
+public:
+  const std::vector<std::shared_ptr<IObject>> &
+  at(const ::internal::tflite::operand::Index &ind) const
+  {
+    return _objects.at(ind.asInt());
+  }
+
+  std::vector<std::shared_ptr<IObject>> &at(const ::internal::tflite::operand::Index &ind)
+  {
+    return _objects.at(ind.asInt());
+  }
+
+private:
+  std::map<int, std::vector<std::shared_ptr<IObject>>> _objects;
+};
+
+} // namespace operand
+} // namespace internal
+
+#include <arm_compute/runtime/IFunction.h>
+
+namespace internal
+{
+namespace op
+{
+
+class Sequence
+{
+public:
+  uint32_t size(void) const { return _functions.size(); }
+
+public:
+  Sequence &append(std::unique_ptr<::arm_compute::IFunction> &&func)
+  {
+    _functions.emplace_back(std::move(func));
+    return (*this);
+  }
+
+public:
+  ::arm_compute::IFunction &at(uint32_t n) const { return *(_functions.at(n)); }
+
+private:
+  std::vector<std::unique_ptr<::arm_compute::IFunction>> _functions;
+};
+
+} // namespace op
+} // namespace internal
+
+namespace internal
+{
+
+class Plan
+{
+public:
+  Plan(const std::shared_ptr<::internal::tflite::Model> &model) : _model(model)
+  {
+    // DO NOTHING
+  }
+
+public:
+  ::internal::tflite::Model &model(void) { return *_model; }
+  const ::internal::tflite::Model &model(void) const { return *_model; }
+
+public:
+  operand::Context &operands(void) { return _operands; }
+  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;
+};
+
+} // namespace internal
+
+#endif // __INTERNAL_PLAN_H__
index 1bfb0dd..8a6aa1c 100644 (file)
@@ -23,21 +23,3 @@ void Object::access(const std::function<void(::arm_compute::ITensor &tensor)> &f
 } // namespace operand
 } // namepsace arm_compute
 } // namespace internal
-
-namespace internal
-{
-namespace arm_compute
-{
-namespace operand
-{
-
-Context &Context::set(const ::internal::tflite::operand::Index &id,
-                      const std::shared_ptr<::internal::IObject> &object)
-{
-  _objects[id.asInt()].emplace_back(object);
-  return (*this);
-}
-
-} // namespace operand
-} // namepsace arm_compute
-} // namespace internal
index db9b007..0a34eee 100644 (file)
@@ -37,119 +37,4 @@ public:
 } // namepsace arm_compute
 } // namespace internal
 
-#include "internal/Model.h"
-
-#include <map>
-
-namespace internal
-{
-namespace arm_compute
-{
-namespace operand
-{
-
-class Context
-{
-public:
-  Context &set(const ::internal::tflite::operand::Index &ind,
-               const std::shared_ptr<::internal::IObject> &object);
-
-public:
-  bool exist(const ::internal::tflite::operand::Index &ind) const
-  {
-    return _objects.find(ind.asInt()) != _objects.end();
-  }
-
-public:
-  const std::vector<std::shared_ptr<IObject>> &
-  at(const ::internal::tflite::operand::Index &ind) const
-  {
-    return _objects.at(ind.asInt());
-  }
-
-  std::vector<std::shared_ptr<IObject>> &at(const ::internal::tflite::operand::Index &ind)
-  {
-    return _objects.at(ind.asInt());
-  }
-
-private:
-  std::map<int, std::vector<std::shared_ptr<IObject>>> _objects;
-};
-
-} // namespace operand
-} // namepsace arm_compute
-} // namespace internal
-
-#include <arm_compute/runtime/IFunction.h>
-
-namespace internal
-{
-namespace arm_compute
-{
-namespace op
-{
-
-class Sequence
-{
-public:
-  uint32_t size(void) const { return _functions.size(); }
-
-public:
-  Sequence &append(std::unique_ptr<::arm_compute::IFunction> &&func)
-  {
-    _functions.emplace_back(std::move(func));
-    return (*this);
-  }
-
-public:
-  ::arm_compute::IFunction &at(uint32_t n) const { return *(_functions.at(n)); }
-
-private:
-  std::vector<std::unique_ptr<::arm_compute::IFunction>> _functions;
-};
-
-} // namespace op
-} // namepsace arm_compute
-} // namespace internal
-
-namespace internal
-{
-namespace arm_compute
-{
-
-// TODO class Plan should not be in `::internal::arm_compute`, we should put it in `::internal`
-class Plan
-{
-public:
-  Plan(const std::shared_ptr<::internal::tflite::Model> &model) : _model(model)
-  {
-    // DO NOTHING
-  }
-
-public:
-  ::internal::tflite::Model &model(void) { return *_model; }
-  const ::internal::tflite::Model &model(void) const { return *_model; }
-
-public:
-  operand::Context &operands(void) { return _operands; }
-  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;
-};
-
-} // namepsace arm_compute
-} // namespace internal
-
 #endif // __INTERNAL_ARM_COMPUTE_H__
index 31ac71c..9ee06ec 100644 (file)
@@ -7,7 +7,7 @@ namespace internal
 namespace common
 {
 
-TensorBuilder::TensorBuilder(::internal::arm_compute::Plan &plan) : _plan(plan)
+TensorBuilder::TensorBuilder(::internal::Plan &plan) : _plan(plan)
 {
   // DO NOTHING
 }
index ac37112..de7af25 100644 (file)
@@ -7,7 +7,7 @@
 #include "internal/ITensorBuilder.h"
 #include "internal/common/Tensor.h"
 #include "internal/common/common.h"
-#include "internal/arm_compute.h"
+#include "internal/Plan.h"
 
 namespace internal
 {
@@ -19,7 +19,7 @@ class Plan;
 class TensorBuilder : public ::internal::ITensorBuilder
 {
 public:
-  TensorBuilder(::internal::arm_compute::Plan &plan);
+  TensorBuilder(::internal::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;
@@ -31,7 +31,7 @@ public:
   std::shared_ptr<::internal::common::Tensor> at(const ::internal::tflite::operand::Index &ind);
 
 private:
-  ::internal::arm_compute::Plan &_plan;
+  ::internal::Plan &_plan;
   std::unordered_set<int> _inds;
   std::unordered_map<int, std::shared_ptr<::internal::common::Tensor>> _tensors;
 };