From 2bb67ff67e030583d959354ffb60adfdb807e3c3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=98=A4=ED=98=95=EC=84=9D/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Staff=20Engineer/=EC=82=BC=EC=84=B1?= =?utf8?q?=EC=A0=84=EC=9E=90?= Date: Mon, 5 Nov 2018 17:01:56 +0900 Subject: [PATCH] Introduce registerTensorInfo (#3467) Introduce registerTensorInfo to - Divide tensor info register and use-def notify - Prepare subtensor information register Signed-off-by: Hyeongseok Oh --- .../neurun/src/backend/acl_cl/TensorBuilder.cc | 9 ++++-- runtimes/neurun/src/backend/acl_cl/TensorBuilder.h | 10 +++++-- runtimes/neurun/src/backend/cpu/TensorBuilder.cc | 10 +++++-- runtimes/neurun/src/backend/cpu/TensorBuilder.h | 11 ++++++-- .../neurun/src/backend/interface/ITensorBuilder.h | 8 +++++- runtimes/neurun/src/linear/Linear.cc | 33 +++++++++------------- 6 files changed, 52 insertions(+), 29 deletions(-) diff --git a/runtimes/neurun/src/backend/acl_cl/TensorBuilder.cc b/runtimes/neurun/src/backend/acl_cl/TensorBuilder.cc index c0cc2c8..b86c545 100644 --- a/runtimes/neurun/src/backend/acl_cl/TensorBuilder.cc +++ b/runtimes/neurun/src/backend/acl_cl/TensorBuilder.cc @@ -34,14 +34,19 @@ TensorBuilder::TensorBuilder() // DO NOTHING } -void TensorBuilder::notifyFirstUse(const graph::operand::Index &ind, - const ::arm_compute::TensorInfo &info) +void TensorBuilder::registerTensorInfo(const ::neurun::graph::operand::Index &ind, + const ::arm_compute::TensorInfo &info) { assert(_tensors.size() == 0); _tensor_info_map.insert({ind, info}); } +void TensorBuilder::notifyFirstUse(const graph::operand::Index &) +{ + // DO NOTHING +} + void TensorBuilder::notifyLastUse(const graph::operand::Index &) { // DO NOTHING diff --git a/runtimes/neurun/src/backend/acl_cl/TensorBuilder.h b/runtimes/neurun/src/backend/acl_cl/TensorBuilder.h index d57cb5c..1a1a984 100644 --- a/runtimes/neurun/src/backend/acl_cl/TensorBuilder.h +++ b/runtimes/neurun/src/backend/acl_cl/TensorBuilder.h @@ -35,8 +35,14 @@ class TensorBuilder : public ITensorBuilder public: TensorBuilder(); - virtual void notifyFirstUse(const graph::operand::Index &, - const ::arm_compute::TensorInfo &) override; + /** + * @brief Register tensor information to allocate on ACL-CL backend + * @param[in] ind Operand index + * @param[in] info Tensor information + */ + virtual void registerTensorInfo(const graph::operand::Index &ind, + const ::arm_compute::TensorInfo &info) override; + virtual void notifyFirstUse(const graph::operand::Index &) override; virtual void notifyLastUse(const graph::operand::Index &) override; virtual void prepare(void) override; diff --git a/runtimes/neurun/src/backend/cpu/TensorBuilder.cc b/runtimes/neurun/src/backend/cpu/TensorBuilder.cc index c349a67..6a71704 100644 --- a/runtimes/neurun/src/backend/cpu/TensorBuilder.cc +++ b/runtimes/neurun/src/backend/cpu/TensorBuilder.cc @@ -35,12 +35,18 @@ TensorBuilder::TensorBuilder() : _mem_alloc(std::make_shared()) // DO NOTHING } -void TensorBuilder::notifyFirstUse(const graph::operand::Index &ind, - const ::arm_compute::TensorInfo &info) +void TensorBuilder::registerTensorInfo(const graph::operand::Index &ind, + const ::arm_compute::TensorInfo &info) { assert(_mem_alloc); _tensor_info_map.insert({ind, info}); +} + +void TensorBuilder::notifyFirstUse(const graph::operand::Index &ind) +{ + assert(_tensor_info_map.find(ind) != _tensor_info_map.end()); + const auto &info = _tensor_info_map.at(ind); const auto size = info.total_size(); auto mem_blk = _mem_alloc->allocate(ind, size); diff --git a/runtimes/neurun/src/backend/cpu/TensorBuilder.h b/runtimes/neurun/src/backend/cpu/TensorBuilder.h index 768f6ab..168ee6e 100644 --- a/runtimes/neurun/src/backend/cpu/TensorBuilder.h +++ b/runtimes/neurun/src/backend/cpu/TensorBuilder.h @@ -36,10 +36,15 @@ class TensorBuilder : public ITensorBuilder public: TensorBuilder(); - virtual void notifyFirstUse(const graph::operand::Index &, - const ::arm_compute::TensorInfo &) override; + /** + * @brief Register tensor information to allocate on CPU backend + * @param[in] ind Operand index + * @param[in] info Tensor information + */ + virtual void registerTensorInfo(const graph::operand::Index &ind, + const ::arm_compute::TensorInfo &info) override; + virtual void notifyFirstUse(const graph::operand::Index &) override; virtual void notifyLastUse(const graph::operand::Index &) override; - virtual void prepare(void) override; virtual void allocate(void) override; diff --git a/runtimes/neurun/src/backend/interface/ITensorBuilder.h b/runtimes/neurun/src/backend/interface/ITensorBuilder.h index d968c47..bd8c407 100644 --- a/runtimes/neurun/src/backend/interface/ITensorBuilder.h +++ b/runtimes/neurun/src/backend/interface/ITensorBuilder.h @@ -34,7 +34,13 @@ struct ITensorBuilder virtual ~ITensorBuilder(void) = default; - virtual void notifyFirstUse(const graph::operand::Index &, const ::arm_compute::TensorInfo &) = 0; + // TODO Merge registerTensorInfo and registerSubTensorInfo using abstraction by internal class + /** + * @brief Register tensor information to allocate on backend + */ + virtual void registerTensorInfo(const graph::operand::Index &, + const ::arm_compute::TensorInfo &) = 0; + virtual void notifyFirstUse(const graph::operand::Index &) = 0; virtual void notifyLastUse(const graph::operand::Index &) = 0; // TODO Add an interface for adding subsumption info diff --git a/runtimes/neurun/src/linear/Linear.cc b/runtimes/neurun/src/linear/Linear.cc index 162477d..e2c3315 100644 --- a/runtimes/neurun/src/linear/Linear.cc +++ b/runtimes/neurun/src/linear/Linear.cc @@ -86,8 +86,10 @@ backend::TensorBuilderSet Linear::planTensors() } // Prepare tensor builders to be returned - iterTensorBuilders(ind, [&tensor_builders](const graph::operand::Index &, - ITensorBuilderPtr tensor_builder) { + const auto info = ::internal::asTensorInfo(obj.shape(), obj.typeInfo()); + iterTensorBuilders(ind, [&tensor_builders, &info](const graph::operand::Index &ind, + ITensorBuilderPtr tensor_builder) { + tensor_builder->registerTensorInfo(ind, info); tensor_builders.insert(tensor_builder); }); }); @@ -103,24 +105,18 @@ backend::TensorBuilderSet Linear::planTensors() VERBOSE(LINEAR) << "TENSORS as CONSTANT" << std::endl; for (const auto &ind : constants) { - const auto &obj = operands.at(ind); - const auto info = ::internal::asTensorInfo(obj.shape(), obj.typeInfo()); - iterTensorBuilders(ind, - [&info](const graph::operand::Index &ind, ITensorBuilderPtr tensor_builder) { - tensor_builder->notifyFirstUse(ind, info); - }); + iterTensorBuilders(ind, [](const graph::operand::Index &ind, ITensorBuilderPtr tensor_builder) { + tensor_builder->notifyFirstUse(ind); + }); } // Allocate Model's inputs VERBOSE(LINEAR) << "TENSORS as MODEL INPUT" << std::endl; for (const auto &ind : _graph.getInputs()) { - const auto &obj = operands.at(ind); - const auto info = ::internal::asTensorInfo(obj.shape(), obj.typeInfo()); - iterTensorBuilders(ind, - [&info](const graph::operand::Index &ind, ITensorBuilderPtr tensor_builder) { - tensor_builder->notifyFirstUse(ind, info); - }); + iterTensorBuilders(ind, [](const graph::operand::Index &ind, ITensorBuilderPtr tensor_builder) { + tensor_builder->notifyFirstUse(ind); + }); } // At each operation, @@ -134,11 +130,10 @@ backend::TensorBuilderSet Linear::planTensors() const auto &obj = operands.at(ind); if (obj.getDef().size()) { - const auto info = ::internal::asTensorInfo(obj.shape(), obj.typeInfo()); - iterTensorBuilders( - ind, [&info](const graph::operand::Index &ind, ITensorBuilderPtr tensor_builder) { - tensor_builder->notifyFirstUse(ind, info); - }); + iterTensorBuilders(ind, + [](const graph::operand::Index &ind, ITensorBuilderPtr tensor_builder) { + tensor_builder->notifyFirstUse(ind); + }); } } -- 2.7.4