From: 김수진/동작제어Lab(SR)/Engineer/삼성전자 Date: Thu, 2 Aug 2018 07:32:44 +0000 (+0900) Subject: [neurun] Introduce Common Operands in Plan (#2144) X-Git-Tag: 0.2~352 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=59f6cebd7c80d3c995dafd30dd6baab10a92a48a;p=platform%2Fcore%2Fml%2Fnnfw.git [neurun] Introduce Common Operands in Plan (#2144) Related : #2142 This commit introduces common operands in Plan, since we should set input/output as Common Tensor. Signed-off-by: sjsujinkim --- diff --git a/runtimes/neurun/src/internal/BackendManager.cc b/runtimes/neurun/src/internal/BackendManager.cc index e8fd286..5a21bcc 100644 --- a/runtimes/neurun/src/internal/BackendManager.cc +++ b/runtimes/neurun/src/internal/BackendManager.cc @@ -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 { diff --git a/runtimes/neurun/src/internal/arm_compute.h b/runtimes/neurun/src/internal/arm_compute.h index 9e2706b..1e7a340 100644 --- a/runtimes/neurun/src/internal/arm_compute.h +++ b/runtimes/neurun/src/internal/arm_compute.h @@ -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; }; diff --git a/runtimes/neurun/src/internal/common/Tensor.h b/runtimes/neurun/src/internal/common/Tensor.h index a5a1b96..f27cdc7 100644 --- a/runtimes/neurun/src/internal/common/Tensor.h +++ b/runtimes/neurun/src/internal/common/Tensor.h @@ -4,6 +4,8 @@ #include #include +#include "internal/IObject.h" + namespace internal { namespace common diff --git a/runtimes/neurun/src/internal/common/TensorBuilder.cc b/runtimes/neurun/src/internal/common/TensorBuilder.cc index 2be0b09..61bc618 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() +TensorBuilder::TensorBuilder(::internal::arm_compute::Plan &plan) : _plan(plan) { // DO NOTHING } @@ -45,6 +45,7 @@ void TensorBuilder::prepare(const std::map &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; } } diff --git a/runtimes/neurun/src/internal/common/TensorBuilder.h b/runtimes/neurun/src/internal/common/TensorBuilder.h index dd184b1..ac37112 100644 --- a/runtimes/neurun/src/internal/common/TensorBuilder.h +++ b/runtimes/neurun/src/internal/common/TensorBuilder.h @@ -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 _inds; std::unordered_map> _tensors; }; diff --git a/runtimes/neurun/src/internal/common/common.cc b/runtimes/neurun/src/internal/common/common.cc new file mode 100644 index 0000000..f9f8064 --- /dev/null +++ b/runtimes/neurun/src/internal/common/common.cc @@ -0,0 +1,14 @@ +#include "common.h" + +namespace internal +{ +namespace common +{ + +void Object::access(const std::function &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 index 0000000..9651ac1 --- /dev/null +++ b/runtimes/neurun/src/internal/common/common.h @@ -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} + { + // DO NOTHING + } + +public: + Tensor *ptr(void) const override { return _tensor.get(); } + +private: + std::shared_ptr _tensor; + +public: + void access(const std::function &fn) const override; +}; + +} // common +} // internal + +#endif // __INTERNAL_COMMON_H__