[neurun] Allow to have multi objects in an one index. (#2182)
author김수진/동작제어Lab(SR)/Engineer/삼성전자 <sjsujin.kim@samsung.com>
Wed, 8 Aug 2018 02:19:20 +0000 (11:19 +0900)
committer박세희/동작제어Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>
Wed, 8 Aug 2018 02:19:20 +0000 (11:19 +0900)
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 <sjsujin.kim@samsung.com>
runtimes/neurun/src/compilation.cc
runtimes/neurun/src/frontend/execution.cc
runtimes/neurun/src/internal/arm_compute.cc
runtimes/neurun/src/internal/arm_compute.h

index eff8b32..f8a583f 100644 (file)
@@ -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);
+    }
   }
 }
 
index 0a331c1..13e4f51 100644 (file)
@@ -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;
index 1e0097b..1bfb0dd 100644 (file)
@@ -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);
 }
 
index 1e7a340..db9b007 100644 (file)
@@ -61,18 +61,19 @@ public:
   }
 
 public:
-  const ::internal::IObject &at(const ::internal::tflite::operand::Index &ind) const
+  const std::vector<std::shared_ptr<IObject>> &
+  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<std::shared_ptr<IObject>> &at(const ::internal::tflite::operand::Index &ind)
   {
-    return *_objects.at(ind.asInt());
+    return _objects.at(ind.asInt());
   }
 
 private:
-  std::map<int, std::shared_ptr<IObject>> _objects;
+  std::map<int, std::vector<std::shared_ptr<IObject>>> _objects;
 };
 
 } // namespace operand