Move Plan and related codes into compiler (#3676)
author오형석/동작제어Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Thu, 22 Nov 2018 09:25:26 +0000 (18:25 +0900)
committer박세희/동작제어Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>
Thu, 22 Nov 2018 09:25:26 +0000 (18:25 +0900)
Move Plan and related codes into compiler
Update namespace and comments

Signed-off-by: Hyeongseok Oh <hseok82.oh@samsung.com>
15 files changed:
runtimes/neurun/CMakeLists.txt
runtimes/neurun/src/compiler/Compiler.h
runtimes/neurun/src/compiler/ConstantInitializer.cc
runtimes/neurun/src/compiler/ConstantInitializer.h
runtimes/neurun/src/compiler/Plan.cc [moved from runtimes/neurun/src/codegen/Plan.cc with 100% similarity]
runtimes/neurun/src/compiler/Plan.h [moved from runtimes/neurun/src/codegen/Plan.h with 92% similarity]
runtimes/neurun/src/compiler/PlanBuilder.h
runtimes/neurun/src/compiler/operand/Context.cc [moved from runtimes/neurun/src/codegen/operand/Context.cc with 96% similarity]
runtimes/neurun/src/compiler/operand/Context.h [moved from runtimes/neurun/src/codegen/operand/Context.h with 89% similarity]
runtimes/neurun/src/compiler/operation/Sequence.cc [moved from runtimes/neurun/src/codegen/operation/Sequence.cc with 94% similarity]
runtimes/neurun/src/compiler/operation/Sequence.h [moved from runtimes/neurun/src/codegen/operation/Sequence.h with 86% similarity]
runtimes/neurun/src/frontend/execution.cc
runtimes/neurun/src/frontend/wrapper/compilation.h
runtimes/neurun/src/frontend/wrapper/execution.h
runtimes/neurun/src/kernel/cpu/PermuteLayer.cc

index 0458fb8..4407f38 100644 (file)
@@ -18,13 +18,12 @@ file(GLOB SOURCES_BACKEND "src/backend/*.cc")
 file(GLOB_RECURSE SOURCES_INTERNAL "src/internal/*.cc")
 file(GLOB_RECURSE SOURCES_GRAPH "src/graph/*.cc")
 file(GLOB_RECURSE SOURCES_LINEAR "src/linear/*.cc")
-file(GLOB_RECURSE SOURCES_CODEGEN "src/codegen/*.cc")
 file(GLOB_RECURSE SOURCES_DUMPER "src/dumper/*.cc")
 file(GLOB_RECURSE SOURCES_COMPILER "src/compiler/*.cc")
 file(GLOB_RECURSE SOURCES_VERIFIER "src/verifier/*.cc")
 file(GLOB_RECURSE SOURCES_VERIFIER "src/util/*.cc")
 
-set(SOURCES ${SOURCES} ${SOURCES_FRONTEND} ${SOURCES_BACKEND} ${SOURCES_INTERNAL} ${SOURCES_GRAPH} ${SOURCES_LINEAR} ${SOURCES_CODEGEN} ${SOURCES_DUMPER} ${SOURCES_COMPILER} ${SOURCES_VERIFIER})
+set(SOURCES ${SOURCES} ${SOURCES_FRONTEND} ${SOURCES_BACKEND} ${SOURCES_INTERNAL} ${SOURCES_GRAPH} ${SOURCES_LINEAR} ${SOURCES_DUMPER} ${SOURCES_COMPILER} ${SOURCES_VERIFIER})
 
 # NOTE For now ARMCompute is necessary
 # TODO Remove required package below(should be optional)
index 2fa2588..d8f620a 100644 (file)
@@ -23,7 +23,7 @@
 #define __NEURUN_COMPILER_COMPILE_H_
 
 #include "graph/Graph.h"
-#include "codegen/Plan.h"
+#include "Plan.h"
 
 namespace neurun
 {
@@ -41,7 +41,7 @@ public:
    * @brief     Construct a new Compiler object
    * @param[in] model Graph model
    */
-  Compiler(const std::shared_ptr<graph::Graph> &model) : _plan{new codegen::Plan{model}}
+  Compiler(const std::shared_ptr<graph::Graph> &model) : _plan{new Plan{model}}
   {
     // DO NOTHING
   }
@@ -51,7 +51,7 @@ public:
    * @brief   Return plan
    * @return  Plan
    */
-  codegen::Plan &plan(void) { return *_plan; }
+  Plan &plan(void) { return *_plan; }
   /**
    * @brief   Run compilation
    */
@@ -60,10 +60,10 @@ public:
    * @brief       Pass plan reference
    * @param[out]  plan  Plan reference to return
    */
-  void release(std::shared_ptr<const codegen::Plan> &plan) { plan = _plan; }
+  void release(std::shared_ptr<const Plan> &plan) { plan = _plan; }
 
 private:
-  std::shared_ptr<codegen::Plan> _plan;
+  std::shared_ptr<Plan> _plan;
 };
 
 } // namespace compiler
index acc4dae..b1a465b 100644 (file)
@@ -33,7 +33,7 @@ namespace neurun
 namespace compiler
 {
 
-ConstantInitializer::ConstantInitializer(const graph::Graph &graph, codegen::Plan &plan)
+ConstantInitializer::ConstantInitializer(const graph::Graph &graph, Plan &plan)
     : _graph{graph}, _plan{plan}
 {
 }
index d3ecdd2..7d92319 100644 (file)
@@ -18,7 +18,7 @@
 #define __NEURUN_COMPILER_CONSTANT_INITIALIZER_H__
 
 #include "graph/Graph.h"
-#include "codegen/Plan.h"
+#include "Plan.h"
 
 namespace neurun
 {
@@ -28,13 +28,13 @@ namespace compiler
 class ConstantInitializer
 {
 public:
-  ConstantInitializer(const graph::Graph &graph, codegen::Plan &plan);
+  ConstantInitializer(const graph::Graph &graph, Plan &plan);
 
   void operator()();
 
 private:
   const graph::Graph &_graph;
-  codegen::Plan &_plan;
+  Plan &_plan;
 };
 
 } // namespace compiler
similarity index 92%
rename from runtimes/neurun/src/codegen/Plan.h
rename to runtimes/neurun/src/compiler/Plan.h
index 47624ed..b5fb4d5 100644 (file)
 #define __NEURUN_CODEGEN_PLAN_H__
 
 #include "graph/Graph.h"
-#include "codegen/operand/Context.h"
-#include "codegen/operation/Sequence.h"
+#include "compiler/operand/Context.h"
+#include "compiler/operation/Sequence.h"
 
 namespace neurun
 {
-namespace codegen
+namespace compiler
 {
 
 class Plan
@@ -52,7 +52,7 @@ private:
   operation::Sequence _ops;
 };
 
-} // namespace codegen
+} // namespace compiler
 } // namespace neurun
 
 #endif // __NEURUN_CODEGEN_PLAN_H__
index 68caae8..3231906 100644 (file)
@@ -17,7 +17,7 @@
 #ifndef __NEURUN_COMPILER_PLAN_BUILDER_H__
 #define __NEURUN_COMPILER_PLAN_BUILDER_H__
 
-#include "codegen/Plan.h"
+#include "Plan.h"
 #include "backend/interface/IStageGenerator.h"
 #include "backend/interface/ITensorBuilder.h"
 
@@ -29,7 +29,7 @@ namespace compiler
 class ExecutionBuilder final : public IExecutionBuilder
 {
 public:
-  ExecutionBuilder(codegen::Plan &plan) : _plan{plan}
+  ExecutionBuilder(Plan &plan) : _plan{plan}
   {
     // DO NOTHING
   }
@@ -41,13 +41,13 @@ public:
   }
 
 private:
-  codegen::Plan &_plan;
+  Plan &_plan;
 };
 
 class PlanBuilder
 {
 public:
-  PlanBuilder(codegen::Plan &plan) : _plan{plan}
+  PlanBuilder(Plan &plan) : _plan{plan}
   {
     // DO NOTHING
   }
@@ -60,7 +60,7 @@ public:
   void finalize(const backend::TensorBuilderSet &tensor_builders);
 
 private:
-  codegen::Plan &_plan;
+  Plan &_plan;
 
 private:
   std::vector<Stage> _stages;
@@ -20,7 +20,7 @@
 
 namespace neurun
 {
-namespace codegen
+namespace compiler
 {
 namespace operand
 {
@@ -43,5 +43,5 @@ void Context::iterate(const std::function<void(int, backend::operand::IObject &)
 }
 
 } // namespace operand
-} // namespace codegen
+} // namespace compiler
 } // namespace neurun
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef __NEURUN_CODEGEN_OPERAND_CONTEXT_H__
-#define __NEURUN_CODEGEN_OPERAND_CONTEXT_H__
+#ifndef __NEURUN_COMPILER_OPERAND_CONTEXT_H__
+#define __NEURUN_COMPILER_OPERAND_CONTEXT_H__
 
 #include "backend/interface/operand/IObject.h"
 #include "graph/operand/Index.h"
@@ -24,7 +24,7 @@
 
 namespace neurun
 {
-namespace codegen
+namespace compiler
 {
 namespace operand
 {
@@ -59,7 +59,7 @@ private:
 };
 
 } // namespace operand
-} // namespace codegen
+} // namespace compiler
 } // namespace neurun
 
-#endif // __NEURUN_CODEGEN_OPERAND_CONTEXT_H__
+#endif // __NEURUN_COMPILER_OPERAND_CONTEXT_H__
@@ -18,7 +18,7 @@
 
 namespace neurun
 {
-namespace codegen
+namespace compiler
 {
 namespace operation
 {
@@ -26,5 +26,5 @@ namespace operation
 // NO IMPLEMENTATION YET
 
 } // namespace operation
-} // namespace codegen
+} // namespace compiler
 } // namespace neurun
@@ -14,9 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef __NEURUN_CODEGEN_OPERATION_SEQUENCE_H__
-#define __NEURUN_CODEGEN_OPERATION_SEQUENCE_H__
-
+#ifndef __NEURUN_COMPILER_OPERATION_SEQUENCE_H__
+#define __NEURUN_COMPILER_OPERATION_SEQUENCE_H__
 #include <stdint.h>
 #include "exec/interface/IFunction.h"
 #include <memory>
@@ -24,7 +23,7 @@
 
 namespace neurun
 {
-namespace codegen
+namespace compiler
 {
 namespace operation
 {
@@ -49,7 +48,7 @@ private:
 };
 
 } // namespace operation
-} // namespace codegen
+} // namespace compiler
 } // namespace neurun
 
-#endif // __NEURUN_CODEGEN_OPERATION_SEQUENCE_H__
+#endif // __NEURUN_COMPILER_OPERATION_SEQUENCE_H__
index 2464769..bba792e 100644 (file)
@@ -98,7 +98,7 @@ int ANeuralNetworksExecution_create(ANeuralNetworksCompilation *compilation,
     return ANEURALNETWORKS_UNEXPECTED_NULL;
   }
 
-  std::shared_ptr<const neurun::codegen::Plan> plan;
+  std::shared_ptr<const neurun::compiler::Plan> plan;
 
   compilation->publish(plan);
 
index bfa3439..d4ba32e 100644 (file)
@@ -17,9 +17,8 @@
 #ifndef __COMPILATION_H__
 #define __COMPILATION_H__
 
-#include "codegen/Plan.h"
-#include "graph/Graph.h"
 #include "compiler/Compiler.h"
+#include "graph/Graph.h"
 
 struct ANeuralNetworksCompilation
 {
@@ -31,10 +30,10 @@ public:
   }
 
 public:
-  neurun::codegen::Plan &plan(void) { return _compiler->plan(); }
+  neurun::compiler::Plan &plan(void) { return _compiler->plan(); }
 
 public:
-  void publish(std::shared_ptr<const neurun::codegen::Plan> &plan) { _compiler->release(plan); }
+  void publish(std::shared_ptr<const neurun::compiler::Plan> &plan) { _compiler->release(plan); }
   int finish();
 
 private:
index 0bef1a5..b68a7b9 100644 (file)
 #ifndef __EXECUTION_H__
 #define __EXECUTION_H__
 
-#include "codegen/Plan.h"
+#include "compiler/Plan.h"
 #include "exec/Source.h"
 #include "exec/Sink.h"
 
 struct ANeuralNetworksExecution
 {
 public:
-  ANeuralNetworksExecution(const std::shared_ptr<const neurun::codegen::Plan> &plan) : _plan{plan}
+  ANeuralNetworksExecution(const std::shared_ptr<const neurun::compiler::Plan> &plan) : _plan{plan}
   {
     _sources.resize(_plan->model().getInputs().size());
     _sinks.resize(_plan->model().getOutputs().size());
   }
 
 public:
-  const neurun::codegen::Plan &plan(void) const { return *_plan; }
+  const neurun::compiler::Plan &plan(void) const { return *_plan; }
 
 private:
-  std::shared_ptr<const neurun::codegen::Plan> _plan;
+  std::shared_ptr<const neurun::compiler::Plan> _plan;
 
 public:
   // TODO Use InputIndex instead of int
index e63b445..503d49e 100644 (file)
@@ -56,6 +56,7 @@ void PermuteLayer::run()
   {
     case Type::NHWC_TO_NCHW:
     {
+      // TODO Fix this workaround (We may need backend::operand::IObject instead of ITensor)
       auto &queue = ::arm_compute::CLScheduler::get().queue();
       auto _output_cl = dynamic_cast<::arm_compute::ICLTensor *>(_output);
       _output_cl->map(queue);
@@ -120,7 +121,6 @@ void PermuteLayer::run()
               feature, reinterpret_cast<const float *>(input_buffer), input_size};
           util::feature::nchw::View<float> into{_output};
 
-          // TODO Fix this workaround (We may need codegen::operand::Object instead of ITensor)
           ::nnfw::util::feature::iterate(feature)
               << [&](uint32_t batch, uint32_t ch, uint32_t row, uint32_t col) {
                    const auto value = from.at(batch, ch, row, col);
@@ -138,6 +138,7 @@ void PermuteLayer::run()
     }
     case Type::NCHW_TO_NHWC:
     {
+      // TODO Fix this workaround (We may need backend::operand::IObject instead of ITensor)
       auto &queue = ::arm_compute::CLScheduler::get().queue();
       auto _input_cl = dynamic_cast<::arm_compute::ICLTensor *>(_input);
       _input_cl->map(queue);
@@ -198,7 +199,6 @@ void PermuteLayer::run()
         {
           auto feature = _shape.asFeature();
 
-          // TODO Fix this workaround (We may need codegen::operand::Object instead of ITensor)
           const util::feature::nchw::View<float> from{_input};
           util::feature::nhwc::View<float> into{feature, reinterpret_cast<float *>(output_buffer),
                                                 output_size};