[neurun] Move and split Plan.h (#2369)
author이한종/동작제어Lab(SR)/Engineer/삼성전자 <hanjoung.lee@samsung.com>
Mon, 20 Aug 2018 10:53:50 +0000 (19:53 +0900)
committer이춘석/동작제어Lab(SR)/Staff Engineer/삼성전자 <chunseok.lee@samsung.com>
Mon, 20 Aug 2018 10:53:50 +0000 (19:53 +0900)
Move and split classes in `internal/Plan.h` into separate files.

- `internal::Plan` to `neurun::codegen::Plan`
- `internal::operand::Context` to `neurun::codegen::operand::Context`
- `internal::op::Sequence` to `neurun::codegen::operation::Sequence`

Signed-off-by: Hanjoung Lee <hanjoung.lee@samsung.com>
20 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/codegen/Plan.cc [new file with mode: 0644]
runtimes/neurun/src/codegen/Plan.h [new file with mode: 0644]
runtimes/neurun/src/codegen/PlanBuilder.h
runtimes/neurun/src/codegen/operand/Context.cc [new file with mode: 0644]
runtimes/neurun/src/codegen/operand/Context.h [new file with mode: 0644]
runtimes/neurun/src/codegen/operation/Sequence.cc [new file with mode: 0644]
runtimes/neurun/src/codegen/operation/Sequence.h [new file with mode: 0644]
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 [deleted file]
runtimes/neurun/src/internal/Plan.h [deleted file]
runtimes/neurun/src/internal/common/TensorBuilder.cc
runtimes/neurun/src/internal/common/TensorBuilder.h

index 134e08f..818334c 100644 (file)
@@ -11,7 +11,7 @@ namespace backend
 namespace acl_cl
 {
 
-TensorBuilder::TensorBuilder(::internal::Plan &plan) : _plan(plan)
+TensorBuilder::TensorBuilder(codegen::Plan &plan) : _plan(plan)
 {
   // DO NOTHING
 }
index 1840b34..be96544 100644 (file)
@@ -2,7 +2,7 @@
 #define __NEURUN_BACKEND_ACL_CL_TENSOR_BUILDER_H__
 
 #include "backend/ITensorBuilder.h"
-#include "internal/Plan.h"
+#include "codegen/Plan.h"
 
 #include <unordered_map>
 #include <unordered_set>
@@ -21,7 +21,7 @@ class Plan;
 class TensorBuilder : public ITensorBuilder
 {
 public:
-  TensorBuilder(::internal::Plan &plan);
+  TensorBuilder(codegen::Plan &plan);
 
   virtual void mark(const ::neurun::graph::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 ::neurun::graph::operand::Index &ind);
 
 private:
-  ::internal::Plan &_plan;
+  codegen::Plan &_plan;
   std::unordered_set<int> _inds;
   std::unordered_map<int, std::shared_ptr<::arm_compute::CLTensor>> _tensors;
 };
index 0c23bdb..5e54815 100644 (file)
@@ -11,7 +11,7 @@ namespace backend
 namespace cpu
 {
 
-TensorBuilder::TensorBuilder(::internal::Plan &plan) : _plan(plan)
+TensorBuilder::TensorBuilder(codegen::Plan &plan) : _plan(plan)
 {
   // DO NOTHING
 }
index e43efe7..853c0e3 100644 (file)
@@ -6,7 +6,7 @@
 
 #include "backend/ITensorBuilder.h"
 #include "internal/cpu.h"
-#include "internal/Plan.h"
+#include "codegen/Plan.h"
 
 namespace neurun
 {
@@ -20,7 +20,7 @@ class Plan;
 class TensorBuilder : public ITensorBuilder
 {
 public:
-  TensorBuilder(::internal::Plan &plan);
+  TensorBuilder(codegen::Plan &plan);
 
   virtual void mark(const ::neurun::graph::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 ::neurun::graph::operand::Index &ind);
 
 private:
-  ::internal::Plan &_plan;
+  codegen::Plan &_plan;
   std::unordered_set<int> _inds;
   std::unordered_map<int, std::shared_ptr<::internal::cpu::Tensor>> _tensors;
 };
diff --git a/runtimes/neurun/src/codegen/Plan.cc b/runtimes/neurun/src/codegen/Plan.cc
new file mode 100644 (file)
index 0000000..91466e0
--- /dev/null
@@ -0,0 +1,11 @@
+#include "Plan.h"
+
+namespace neurun
+{
+namespace codegen
+{
+
+// NO IMPLEMENTATION YET
+
+} // namespace codegen
+} // namespace neurun
diff --git a/runtimes/neurun/src/codegen/Plan.h b/runtimes/neurun/src/codegen/Plan.h
new file mode 100644 (file)
index 0000000..03cbd06
--- /dev/null
@@ -0,0 +1,47 @@
+#ifndef __NEURUN_CODEGEN_PLAN_H__
+#define __NEURUN_CODEGEN_PLAN_H__
+
+#include "graph/Graph.h"
+#include "codegen/operand/Context.h"
+#include "codegen/operation/Sequence.h"
+
+namespace neurun
+{
+namespace codegen
+{
+
+class Plan
+{
+public:
+  Plan(const std::shared_ptr<neurun::graph::Graph> &model) : _model(model)
+  {
+    // DO NOTHING
+  }
+
+public:
+  neurun::graph::Graph &model(void) { return *_model; }
+  const neurun::graph::Graph &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:
+  operation::Sequence &operations(void) { return _ops; }
+  const operation::Sequence &operations(void) const { return _ops; }
+
+private:
+  std::shared_ptr<neurun::graph::Graph> _model;
+  operand::Context _operands;
+  operand::Context _common_operands;
+  operation::Sequence _ops;
+};
+
+} // namespace codegen
+} // namespace neurun
+
+#endif // __NEURUN_CODEGEN_PLAN_H__
index 9bc2e92..2f848e2 100644 (file)
@@ -2,7 +2,7 @@
 #define __NEURUN_CODEGEN_PLAN_BUILDER_H__
 
 #include "IPlanBuilder.h"
-#include "internal/Plan.h"
+#include "codegen/Plan.h"
 #include "codegen/BackendResolver.h"
 #include "backend/IStageGenerator.h"
 
@@ -14,7 +14,7 @@ namespace codegen
 class ExecutionBuilder final : public IExecutionBuilder
 {
 public:
-  ExecutionBuilder(::internal::Plan &plan) : _plan{plan}
+  ExecutionBuilder(codegen::Plan &plan) : _plan{plan}
   {
     // DO NOTHING
   }
@@ -26,13 +26,13 @@ public:
   }
 
 private:
-  ::internal::Plan &_plan;
+  codegen::Plan &_plan;
 };
 
 class PlanBuilder final : public IPlanBuilder
 {
 public:
-  PlanBuilder(::internal::Plan &plan) : _plan{plan}
+  PlanBuilder(codegen::Plan &plan) : _plan{plan}
   {
     // DO NOTHING
   }
@@ -55,7 +55,7 @@ public:
   const std::map<int, ::arm_compute::TensorInfo> &tensor_info_ctx() { return _tensor_info_ctx; }
 
 private:
-  ::internal::Plan &_plan;
+  codegen::Plan &_plan;
 
 private:
   std::map<int, ::arm_compute::TensorInfo> _tensor_info_ctx;
diff --git a/runtimes/neurun/src/codegen/operand/Context.cc b/runtimes/neurun/src/codegen/operand/Context.cc
new file mode 100644 (file)
index 0000000..5dbfdc7
--- /dev/null
@@ -0,0 +1,19 @@
+#include "Context.h"
+
+namespace neurun
+{
+namespace codegen
+{
+namespace operand
+{
+
+Context &Context::set(const graph::operand::Index &id,
+                      const std::shared_ptr<backend::operand::IObject> &object)
+{
+  _objects[id.value()].emplace_back(object);
+  return (*this);
+}
+
+} // namespace operand
+} // namespace codegen
+} // namespace neurun
diff --git a/runtimes/neurun/src/codegen/operand/Context.h b/runtimes/neurun/src/codegen/operand/Context.h
new file mode 100644 (file)
index 0000000..2c343d2
--- /dev/null
@@ -0,0 +1,48 @@
+#ifndef __NEURUN_CODEGEN_OPERAND_CONTEXT_H__
+#define __NEURUN_CODEGEN_OPERAND_CONTEXT_H__
+
+#include "backend/IObject.h"
+#include "graph/operand/Index.h"
+
+#include <map>
+
+namespace neurun
+{
+namespace codegen
+{
+namespace operand
+{
+
+class Context
+{
+public:
+  Context &set(const graph::operand::Index &ind,
+               const std::shared_ptr<backend::operand::IObject> &object);
+
+public:
+  bool exist(const ::neurun::graph::operand::Index &ind) const
+  {
+    return _objects.find(ind.asInt()) != _objects.end();
+  }
+
+public:
+  const std::vector<std::shared_ptr<backend::operand::IObject>> &
+  at(const graph::operand::Index &ind) const
+  {
+    return _objects.at(ind.asInt());
+  }
+
+  std::vector<std::shared_ptr<backend::operand::IObject>> &at(const graph::operand::Index &ind)
+  {
+    return _objects.at(ind.asInt());
+  }
+
+private:
+  std::map<int, std::vector<std::shared_ptr<backend::operand::IObject>>> _objects;
+};
+
+} // namespace operand
+} // namespace codegen
+} // namespace neurun
+
+#endif // __NEURUN_CODEGEN_OPERAND_CONTEXT_H__
diff --git a/runtimes/neurun/src/codegen/operation/Sequence.cc b/runtimes/neurun/src/codegen/operation/Sequence.cc
new file mode 100644 (file)
index 0000000..4985e86
--- /dev/null
@@ -0,0 +1,14 @@
+#include "Sequence.h"
+
+namespace neurun
+{
+namespace codegen
+{
+namespace operation
+{
+
+// NO IMPLEMENTATION YET
+
+} // namespace operation
+} // namespace codegen
+} // namespace neurun
diff --git a/runtimes/neurun/src/codegen/operation/Sequence.h b/runtimes/neurun/src/codegen/operation/Sequence.h
new file mode 100644 (file)
index 0000000..8a747d7
--- /dev/null
@@ -0,0 +1,39 @@
+#ifndef __NEURUN_CODEGEN_OPERATION_SEQUENCE_H__
+#define __NEURUN_CODEGEN_OPERATION_SEQUENCE_H__
+
+#include <stdint.h>
+#include <arm_compute/runtime/IFunction.h>
+#include <memory>
+#include <vector>
+
+namespace neurun
+{
+namespace codegen
+{
+namespace operation
+{
+
+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 operation
+} // namespace codegen
+} // namespace neurun
+
+#endif // __NEURUN_CODEGEN_OPERATION_SEQUENCE_H__
index 609d8a1..b2f3c05 100644 (file)
@@ -1,27 +1,27 @@
 #ifndef __COMPILATION_H__
 #define __COMPILATION_H__
 
-#include "internal/Plan.h"
+#include "codegen/Plan.h"
 #include "graph/Graph.h"
 
 struct ANeuralNetworksCompilation
 {
 public:
   ANeuralNetworksCompilation(const std::shared_ptr<neurun::graph::Graph> &model)
-      : _plan{new internal::Plan{model}}
+      : _plan{new neurun::codegen::Plan{model}}
   {
     // DO NOTHING
   }
 
 public:
-  internal::Plan &plan(void) { return *_plan; }
+  neurun::codegen::Plan &plan(void) { return *_plan; }
 
 public:
-  void publish(std::shared_ptr<const internal::Plan> &plan) { plan = _plan; }
+  void publish(std::shared_ptr<const neurun::codegen::Plan> &plan) { plan = _plan; }
   int finish();
 
 private:
-  std::shared_ptr<internal::Plan> _plan;
+  std::shared_ptr<neurun::codegen::Plan> _plan;
 };
 
 #endif
index 91b20a2..7ed1486 100644 (file)
@@ -1,24 +1,24 @@
 #ifndef __EXECUTION_H__
 #define __EXECUTION_H__
 
-#include "internal/Plan.h"
+#include "codegen/Plan.h"
 #include "internal/Source.h"
 #include "internal/Sink.h"
 
 struct ANeuralNetworksExecution
 {
 public:
-  ANeuralNetworksExecution(const std::shared_ptr<const internal::Plan> &plan) : _plan{plan}
+  ANeuralNetworksExecution(const std::shared_ptr<const neurun::codegen::Plan> &plan) : _plan{plan}
   {
     _sources.resize(_plan->model().inputs().size());
     _sinks.resize(_plan->model().outputs().size());
   }
 
 public:
-  const internal::Plan &plan(void) const { return *_plan; }
+  const neurun::codegen::Plan &plan(void) const { return *_plan; }
 
 private:
-  std::shared_ptr<const internal::Plan> _plan;
+  std::shared_ptr<const neurun::codegen::Plan> _plan;
 
 public:
   // TODO Use InputIndex instead of int
index 3ae189d..047c814 100644 (file)
@@ -20,7 +20,7 @@ int ANeuralNetworksExecution_create(ANeuralNetworksCompilation *compilation,
     return ANEURALNETWORKS_UNEXPECTED_NULL;
   }
 
-  std::shared_ptr<const ::internal::Plan> plan;
+  std::shared_ptr<const neurun::codegen::Plan> plan;
 
   compilation->publish(plan);
 
index a4a614e..ff1f15f 100644 (file)
@@ -10,7 +10,7 @@
 namespace internal
 {
 
-BackendManager::BackendManager(::internal::Plan &plan) : _plan(plan)
+BackendManager::BackendManager(neurun::codegen::Plan &plan) : _plan(plan)
 {
   const auto &operands = _plan.model().operands();
 
index 3af69d0..b6a1efc 100644 (file)
@@ -3,7 +3,7 @@
 
 #include <memory>
 
-#include "internal/Plan.h"
+#include "codegen/Plan.h"
 #include "backend/IInitializerGenerator.h"
 #include "backend/IStageGenerator.h"
 #include "backend/ITensorBuilder.h"
@@ -33,14 +33,14 @@ struct Backend
 class BackendManager
 {
 public:
-  BackendManager(::internal::Plan &plan);
+  BackendManager(neurun::codegen::Plan &plan);
 
   Backend get(const std::string &key);
 
   std::shared_ptr<::internal::common::TensorBuilder> getCommonTensorBuilder();
 
 private:
-  ::internal::Plan &_plan;
+  neurun::codegen::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
deleted file mode 100644 (file)
index 8dcbaf1..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-#include "Plan.h"
-
-namespace internal
-{
-namespace operand
-{
-
-Context &Context::set(const ::neurun::graph::operand::Index &id,
-                      const std::shared_ptr<neurun::backend::operand::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
deleted file mode 100644 (file)
index 3b02a98..0000000
+++ /dev/null
@@ -1,111 +0,0 @@
-#ifndef __INTERNAL_PLAN_H__
-#define __INTERNAL_PLAN_H__
-
-#include "graph/Graph.h"
-#include "backend/IObject.h"
-
-#include <map>
-
-namespace internal
-{
-namespace operand
-{
-
-class Context
-{
-public:
-  Context &set(const ::neurun::graph::operand::Index &ind,
-               const std::shared_ptr<neurun::backend::operand::IObject> &object);
-
-public:
-  bool exist(const ::neurun::graph::operand::Index &ind) const
-  {
-    return _objects.find(ind.asInt()) != _objects.end();
-  }
-
-public:
-  const std::vector<std::shared_ptr<neurun::backend::operand::IObject>> &
-  at(const ::neurun::graph::operand::Index &ind) const
-  {
-    return _objects.at(ind.asInt());
-  }
-
-  std::vector<std::shared_ptr<neurun::backend::operand::IObject>> &
-  at(const ::neurun::graph::operand::Index &ind)
-  {
-    return _objects.at(ind.asInt());
-  }
-
-private:
-  std::map<int, std::vector<std::shared_ptr<neurun::backend::operand::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<neurun::graph::Graph> &model) : _model(model)
-  {
-    // DO NOTHING
-  }
-
-public:
-  neurun::graph::Graph &model(void) { return *_model; }
-  const neurun::graph::Graph &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<neurun::graph::Graph> _model;
-  operand::Context _operands;
-  operand::Context _common_operands;
-  op::Sequence _ops;
-};
-
-} // namespace internal
-
-#endif // __INTERNAL_PLAN_H__
index e80d5e2..7b04a8d 100644 (file)
@@ -7,7 +7,7 @@ namespace internal
 namespace common
 {
 
-TensorBuilder::TensorBuilder(::internal::Plan &plan) : _plan(plan)
+TensorBuilder::TensorBuilder(neurun::codegen::Plan &plan) : _plan(plan)
 {
   // DO NOTHING
 }
index 2ba7833..d974c1e 100644 (file)
@@ -5,9 +5,9 @@
 #include <unordered_map>
 
 #include "backend/ITensorBuilder.h"
+#include "codegen/Plan.h"
 #include "internal/common/Tensor.h"
 #include "internal/common/common.h"
-#include "internal/Plan.h"
 
 namespace internal
 {
@@ -19,7 +19,7 @@ class Plan;
 class TensorBuilder : public neurun::backend::ITensorBuilder
 {
 public:
-  TensorBuilder(::internal::Plan &plan);
+  TensorBuilder(neurun::codegen::Plan &plan);
 
   virtual void mark(const ::neurun::graph::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 ::neurun::graph::operand::Index &ind);
 
 private:
-  ::internal::Plan &_plan;
+  neurun::codegen::Plan &_plan;
   std::unordered_set<int> _inds;
   std::unordered_map<int, std::shared_ptr<::internal::common::Tensor>> _tensors;
 };