From: 이한종/동작제어Lab(SR)/Engineer/삼성전자 Date: Mon, 20 Aug 2018 10:53:50 +0000 (+0900) Subject: [neurun] Move and split Plan.h (#2369) X-Git-Tag: 0.2~232 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=641dfeb6efd1355a67630e8882a57483fed3ee0f;p=platform%2Fcore%2Fml%2Fnnfw.git [neurun] Move and split Plan.h (#2369) 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 --- diff --git a/runtimes/neurun/src/backend/acl_cl/TensorBuilder.cc b/runtimes/neurun/src/backend/acl_cl/TensorBuilder.cc index 134e08f..818334c 100644 --- a/runtimes/neurun/src/backend/acl_cl/TensorBuilder.cc +++ b/runtimes/neurun/src/backend/acl_cl/TensorBuilder.cc @@ -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 } diff --git a/runtimes/neurun/src/backend/acl_cl/TensorBuilder.h b/runtimes/neurun/src/backend/acl_cl/TensorBuilder.h index 1840b34..be96544 100644 --- a/runtimes/neurun/src/backend/acl_cl/TensorBuilder.h +++ b/runtimes/neurun/src/backend/acl_cl/TensorBuilder.h @@ -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 #include @@ -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 _inds; std::unordered_map> _tensors; }; diff --git a/runtimes/neurun/src/backend/cpu/TensorBuilder.cc b/runtimes/neurun/src/backend/cpu/TensorBuilder.cc index 0c23bdb..5e54815 100644 --- a/runtimes/neurun/src/backend/cpu/TensorBuilder.cc +++ b/runtimes/neurun/src/backend/cpu/TensorBuilder.cc @@ -11,7 +11,7 @@ namespace backend namespace cpu { -TensorBuilder::TensorBuilder(::internal::Plan &plan) : _plan(plan) +TensorBuilder::TensorBuilder(codegen::Plan &plan) : _plan(plan) { // DO NOTHING } diff --git a/runtimes/neurun/src/backend/cpu/TensorBuilder.h b/runtimes/neurun/src/backend/cpu/TensorBuilder.h index e43efe7..853c0e3 100644 --- a/runtimes/neurun/src/backend/cpu/TensorBuilder.h +++ b/runtimes/neurun/src/backend/cpu/TensorBuilder.h @@ -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 _inds; std::unordered_map> _tensors; }; diff --git a/runtimes/neurun/src/codegen/Plan.cc b/runtimes/neurun/src/codegen/Plan.cc new file mode 100644 index 0000000..91466e0 --- /dev/null +++ b/runtimes/neurun/src/codegen/Plan.cc @@ -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 index 0000000..03cbd06 --- /dev/null +++ b/runtimes/neurun/src/codegen/Plan.h @@ -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 &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 _model; + operand::Context _operands; + operand::Context _common_operands; + operation::Sequence _ops; +}; + +} // namespace codegen +} // namespace neurun + +#endif // __NEURUN_CODEGEN_PLAN_H__ diff --git a/runtimes/neurun/src/codegen/PlanBuilder.h b/runtimes/neurun/src/codegen/PlanBuilder.h index 9bc2e92..2f848e2 100644 --- a/runtimes/neurun/src/codegen/PlanBuilder.h +++ b/runtimes/neurun/src/codegen/PlanBuilder.h @@ -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 &tensor_info_ctx() { return _tensor_info_ctx; } private: - ::internal::Plan &_plan; + codegen::Plan &_plan; private: std::map _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 index 0000000..5dbfdc7 --- /dev/null +++ b/runtimes/neurun/src/codegen/operand/Context.cc @@ -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 &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 index 0000000..2c343d2 --- /dev/null +++ b/runtimes/neurun/src/codegen/operand/Context.h @@ -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 + +namespace neurun +{ +namespace codegen +{ +namespace operand +{ + +class Context +{ +public: + Context &set(const graph::operand::Index &ind, + const std::shared_ptr &object); + +public: + bool exist(const ::neurun::graph::operand::Index &ind) const + { + return _objects.find(ind.asInt()) != _objects.end(); + } + +public: + const std::vector> & + at(const graph::operand::Index &ind) const + { + return _objects.at(ind.asInt()); + } + + std::vector> &at(const graph::operand::Index &ind) + { + return _objects.at(ind.asInt()); + } + +private: + std::map>> _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 index 0000000..4985e86 --- /dev/null +++ b/runtimes/neurun/src/codegen/operation/Sequence.cc @@ -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 index 0000000..8a747d7 --- /dev/null +++ b/runtimes/neurun/src/codegen/operation/Sequence.h @@ -0,0 +1,39 @@ +#ifndef __NEURUN_CODEGEN_OPERATION_SEQUENCE_H__ +#define __NEURUN_CODEGEN_OPERATION_SEQUENCE_H__ + +#include +#include +#include +#include + +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> _functions; +}; + +} // namespace operation +} // namespace codegen +} // namespace neurun + +#endif // __NEURUN_CODEGEN_OPERATION_SEQUENCE_H__ diff --git a/runtimes/neurun/src/compilation.h b/runtimes/neurun/src/compilation.h index 609d8a1..b2f3c05 100644 --- a/runtimes/neurun/src/compilation.h +++ b/runtimes/neurun/src/compilation.h @@ -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 &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 &plan) { plan = _plan; } + void publish(std::shared_ptr &plan) { plan = _plan; } int finish(); private: - std::shared_ptr _plan; + std::shared_ptr _plan; }; #endif diff --git a/runtimes/neurun/src/execution.h b/runtimes/neurun/src/execution.h index 91b20a2..7ed1486 100644 --- a/runtimes/neurun/src/execution.h +++ b/runtimes/neurun/src/execution.h @@ -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 &plan) : _plan{plan} + ANeuralNetworksExecution(const std::shared_ptr &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 _plan; + std::shared_ptr _plan; public: // TODO Use InputIndex instead of int diff --git a/runtimes/neurun/src/frontend/execution.cc b/runtimes/neurun/src/frontend/execution.cc index 3ae189d..047c814 100644 --- a/runtimes/neurun/src/frontend/execution.cc +++ b/runtimes/neurun/src/frontend/execution.cc @@ -20,7 +20,7 @@ int ANeuralNetworksExecution_create(ANeuralNetworksCompilation *compilation, return ANEURALNETWORKS_UNEXPECTED_NULL; } - std::shared_ptr plan; + std::shared_ptr plan; compilation->publish(plan); diff --git a/runtimes/neurun/src/internal/BackendManager.cc b/runtimes/neurun/src/internal/BackendManager.cc index a4a614e..ff1f15f 100644 --- a/runtimes/neurun/src/internal/BackendManager.cc +++ b/runtimes/neurun/src/internal/BackendManager.cc @@ -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(); diff --git a/runtimes/neurun/src/internal/BackendManager.h b/runtimes/neurun/src/internal/BackendManager.h index 3af69d0..b6a1efc 100644 --- a/runtimes/neurun/src/internal/BackendManager.h +++ b/runtimes/neurun/src/internal/BackendManager.h @@ -3,7 +3,7 @@ #include -#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 _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 index 8dcbaf1..0000000 --- a/runtimes/neurun/src/internal/Plan.cc +++ /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 &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 index 3b02a98..0000000 --- a/runtimes/neurun/src/internal/Plan.h +++ /dev/null @@ -1,111 +0,0 @@ -#ifndef __INTERNAL_PLAN_H__ -#define __INTERNAL_PLAN_H__ - -#include "graph/Graph.h" -#include "backend/IObject.h" - -#include - -namespace internal -{ -namespace operand -{ - -class Context -{ -public: - Context &set(const ::neurun::graph::operand::Index &ind, - const std::shared_ptr &object); - -public: - bool exist(const ::neurun::graph::operand::Index &ind) const - { - return _objects.find(ind.asInt()) != _objects.end(); - } - -public: - const std::vector> & - at(const ::neurun::graph::operand::Index &ind) const - { - return _objects.at(ind.asInt()); - } - - std::vector> & - at(const ::neurun::graph::operand::Index &ind) - { - return _objects.at(ind.asInt()); - } - -private: - std::map>> _objects; -}; - -} // namespace operand -} // namespace internal - -#include - -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> _functions; -}; - -} // namespace op -} // namespace internal - -namespace internal -{ - -class Plan -{ -public: - Plan(const std::shared_ptr &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 _model; - operand::Context _operands; - operand::Context _common_operands; - op::Sequence _ops; -}; - -} // namespace internal - -#endif // __INTERNAL_PLAN_H__ diff --git a/runtimes/neurun/src/internal/common/TensorBuilder.cc b/runtimes/neurun/src/internal/common/TensorBuilder.cc index e80d5e2..7b04a8d 100644 --- a/runtimes/neurun/src/internal/common/TensorBuilder.cc +++ b/runtimes/neurun/src/internal/common/TensorBuilder.cc @@ -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 } diff --git a/runtimes/neurun/src/internal/common/TensorBuilder.h b/runtimes/neurun/src/internal/common/TensorBuilder.h index 2ba7833..d974c1e 100644 --- a/runtimes/neurun/src/internal/common/TensorBuilder.h +++ b/runtimes/neurun/src/internal/common/TensorBuilder.h @@ -5,9 +5,9 @@ #include #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 _inds; std::unordered_map> _tensors; };