Support assigning backends to instances of operations (#5167)
authorДилшоджон Умронхонович Пошшоев/AI Tools Lab /SRR/Engineer/삼성전자 <d.poshshoev@samsung.com>
Mon, 13 May 2019 01:13:06 +0000 (04:13 +0300)
committer오형석/On-Device Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Mon, 13 May 2019 01:13:06 +0000 (10:13 +0900)
* Support assigning backends to instances of operations

This is needed for HE scheduling

Signed-off-by: Poshshoev Dilshodzhon <d.poshshoev@samsung.com>
* Remove unrelated changes

Signed-off-by: Poshshoev Dilshodzhon <d.poshshoev@samsung.com>
runtimes/neurun/core/src/compiler/BackendResolver.h

index 5399115..bb0105a 100644 (file)
@@ -43,11 +43,11 @@ public:
     if (backend_all_str.compare("none") != 0)
     {
       VERBOSE(BackendResolver) << "Use backend for all ops: " << backend_all_str << std::endl;
-#define OP(InternalName, IsNnApi)                               \
-  if (IsNnApi)                                                  \
-  {                                                             \
-    auto backend = _backend_manager->get(backend_all_str);      \
-    _gen_map[typeid(model::operation::InternalName)] = backend; \
+#define OP(InternalName, IsNnApi)                                          \
+  if (IsNnApi)                                                             \
+  {                                                                        \
+    auto backend = _backend_manager->get(backend_all_str);                 \
+    _gen_map_deprecated[typeid(model::operation::InternalName)] = backend; \
   }
 #include "model/Operations.lst"
 #undef OP
@@ -62,7 +62,7 @@ public:
     auto backend = _backend_manager->get(backend_str);                                         \
     VERBOSE(BackendResolver) << "backend for " << #InternalName << ": " << backend_str         \
                              << std::endl;                                                     \
-    _gen_map[typeid(model::operation::InternalName)] = backend;                                \
+    _gen_map_deprecated[typeid(model::operation::InternalName)] = backend;                     \
   }
 
 #include "model/Operations.lst"
@@ -71,15 +71,30 @@ public:
   }
 
 public:
-  const backend::Backend *getBackend(const std::type_index &type) { return _gen_map[type]; }
+  const backend::Backend *getBackend(const std::type_index &type)
+  {
+    return _gen_map_deprecated[type];
+  }
   const backend::Backend *getDefaultBackend() const
   {
     backend::Backend *default_backend = _backend_manager->get("cpu");
     return default_backend;
   }
 
+  const backend::Backend *getBackend(const model::OperationIndex &index)
+  {
+    return _gen_map.at(index);
+  }
+
+  void setBackend(const model::OperationIndex &index, const backend::Backend *backend)
+  {
+    _gen_map[index] = backend;
+  }
+
 private:
-  std::unordered_map<std::type_index, backend::Backend *> _gen_map;
+  // TODO: remove all usage of _gen_map_deprecated
+  std::unordered_map<std::type_index, backend::Backend *> _gen_map_deprecated;
+  std::unordered_map<model::OperationIndex, const backend::Backend *> _gen_map;
   std::shared_ptr<backend::BackendManager> _backend_manager;
 };