From f02f6f37db3baf0b648543a95c2dba44e6501e3b Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EA=B9=80=EC=88=98=EC=A7=84/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Engineer/=EC=82=BC=EC=84=B1=EC=A0=84?= =?utf8?q?=EC=9E=90?= Date: Wed, 8 Aug 2018 11:19:20 +0900 Subject: [PATCH] [neurun] Allow to have multi objects in an one index. (#2182) This commit allows to have multi objects in an one index. It's for objects of heterogeneous backends in an one index. Signed-off-by: sjsujinkim --- runtimes/neurun/src/compilation.cc | 7 ++++++- runtimes/neurun/src/frontend/execution.cc | 14 ++++++++++++-- runtimes/neurun/src/internal/arm_compute.cc | 4 +--- runtimes/neurun/src/internal/arm_compute.h | 11 ++++++----- 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/runtimes/neurun/src/compilation.cc b/runtimes/neurun/src/compilation.cc index eff8b32..f8a583f 100644 --- a/runtimes/neurun/src/compilation.cc +++ b/runtimes/neurun/src/compilation.cc @@ -646,7 +646,12 @@ void PlanBuilder::finalize(BackendResolver &backend_resolver) for (auto it = _initializer_ctx.begin(); it != _initializer_ctx.end(); ++it) { const ::internal::tflite::operand::Index operand_index{it->first}; - _plan.operands().at(operand_index).access(it->second); + auto objects = _plan.operands().at(operand_index); + + for (auto object : objects) + { + object->access(it->second); + } } } diff --git a/runtimes/neurun/src/frontend/execution.cc b/runtimes/neurun/src/frontend/execution.cc index 0a331c1..13e4f51 100644 --- a/runtimes/neurun/src/frontend/execution.cc +++ b/runtimes/neurun/src/frontend/execution.cc @@ -142,7 +142,12 @@ int ANeuralNetworksExecution_startCompute(ANeuralNetworksExecution *execution, { auto setter = [&](::arm_compute::ITensor &tensor) { execution->source(n).push(tensor); }; - plan.operands().at(model.inputs.at(n)).access(setter); + auto objects = plan.operands().at(model.inputs.at(n)); + + for (auto object : objects) + { + object->access(setter); + } } const auto &operations = execution->plan().operations(); @@ -157,7 +162,12 @@ int ANeuralNetworksExecution_startCompute(ANeuralNetworksExecution *execution, { auto getter = [&](::arm_compute::ITensor &tensor) { execution->sink(n).pull(tensor); }; - plan.operands().at(model.outputs.at(n)).access(getter); + auto objects = plan.operands().at(model.outputs.at(n)); + + for (auto object : objects) + { + object->access(getter); + } } return ANEURALNETWORKS_NO_ERROR; diff --git a/runtimes/neurun/src/internal/arm_compute.cc b/runtimes/neurun/src/internal/arm_compute.cc index 1e0097b..1bfb0dd 100644 --- a/runtimes/neurun/src/internal/arm_compute.cc +++ b/runtimes/neurun/src/internal/arm_compute.cc @@ -34,9 +34,7 @@ namespace operand Context &Context::set(const ::internal::tflite::operand::Index &id, const std::shared_ptr<::internal::IObject> &object) { - assert(_objects.find(id.asInt()) == _objects.end()); - - _objects[id.asInt()] = object; + _objects[id.asInt()].emplace_back(object); return (*this); } diff --git a/runtimes/neurun/src/internal/arm_compute.h b/runtimes/neurun/src/internal/arm_compute.h index 1e7a340..db9b007 100644 --- a/runtimes/neurun/src/internal/arm_compute.h +++ b/runtimes/neurun/src/internal/arm_compute.h @@ -61,18 +61,19 @@ public: } public: - const ::internal::IObject &at(const ::internal::tflite::operand::Index &ind) const + const std::vector> & + at(const ::internal::tflite::operand::Index &ind) const { - return *_objects.at(ind.asInt()); + return _objects.at(ind.asInt()); } - ::internal::IObject &at(const ::internal::tflite::operand::Index &ind) + std::vector> &at(const ::internal::tflite::operand::Index &ind) { - return *_objects.at(ind.asInt()); + return _objects.at(ind.asInt()); } private: - std::map> _objects; + std::map>> _objects; }; } // namespace operand -- 2.7.4