[neurun] Check backend initialization success (#9454)
author오형석/On-Device Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Mon, 9 Dec 2019 03:35:03 +0000 (12:35 +0900)
committer이한종/On-Device Lab(SR)/Engineer/삼성전자 <hanjoung.lee@samsung.com>
Mon, 9 Dec 2019 03:35:03 +0000 (12:35 +0900)
Backend initialize() function return boolean to check initialization success/fail

Signed-off-by: Hyeongseok Oh <hseok82.oh@samsung.com>
12 files changed:
runtime/neurun/backend/acl_cl/Config.cc
runtime/neurun/backend/acl_cl/Config.h
runtime/neurun/backend/acl_neon/Config.cc
runtime/neurun/backend/acl_neon/Config.h
runtime/neurun/backend/cpu/Config.cc
runtime/neurun/backend/cpu/Config.h
runtime/neurun/backend/srcn/Config.cc
runtime/neurun/backend/srcn/Config.h
runtime/neurun/core/include/backend/IConfig.h
runtime/neurun/core/src/backend/BackendManager.cc
runtime/neurun/test/core/backend/ExecTime.test.cc
runtime/neurun/test/core/compiler/Scheduler.cc

index 0c07691..36bf836 100644 (file)
@@ -30,13 +30,19 @@ namespace backend
 namespace acl_cl
 {
 
-void Config::initialize()
+bool Config::initialize()
 {
+  if (!arm_compute::opencl_is_available())
+  {
+    return false;
+  }
   arm_compute::CLScheduler::get().default_init();
   // NOTE CLKernelLibraryEx must use the same context as CLScheduler
   // It did not check whether another device is available.
   arm_compute::CLKernelLibraryEx::get().init(
       "./cl_kernels/", arm_compute::CLScheduler::get().context(), cl::Device::getDefault());
+
+  return true;
 }
 
 } // namespace acl_cl
index ae527dd..a7ceaac 100644 (file)
@@ -32,7 +32,7 @@ class Config : public IConfig
 {
 public:
   std::string id() override { return "acl_cl"; }
-  void initialize() override;
+  bool initialize() override;
   bool SupportPermutation() override { return true; }
   bool SupportSubTensorAlloc() override { return true; }
   std::unique_ptr<util::ITimer> timer() override { return nnfw::cpp14::make_unique<CLTimer>(); }
index 8f4a8e7..352bc0b 100644 (file)
@@ -23,10 +23,7 @@ namespace backend
 namespace acl_neon
 {
 
-void Config::initialize()
-{
-  // DO NOTHING
-}
+bool Config::initialize() { return true; }
 
 } // namespace acl_neon
 } // namespace backend
index 13f6c83..430c194 100644 (file)
@@ -32,7 +32,7 @@ class Config : public IConfig
 {
 public:
   std::string id() override { return "acl_neon"; }
-  void initialize() override;
+  bool initialize() override;
   bool SupportPermutation() override { return true; }
   bool SupportSubTensorAlloc() override { return true; }
 
index 1a487f7..3912740 100644 (file)
@@ -23,10 +23,7 @@ namespace backend
 namespace cpu
 {
 
-void Config::initialize()
-{
-  // DO NOTHING
-}
+bool Config::initialize() { return true; }
 
 } // namespace cpu
 } // namespace backend
index 262d477..be303b5 100644 (file)
@@ -32,7 +32,7 @@ class Config : public IConfig
 {
 public:
   std::string id() override { return "cpu"; }
-  void initialize() override;
+  bool initialize() override;
   bool SupportPermutation() override { return true; }
   bool SupportSubTensorAlloc() override
   {
index e69136f..6865657 100644 (file)
@@ -23,10 +23,7 @@ namespace backend
 namespace srcn
 {
 
-void Config::initialize()
-{
-  // DO NOTHING
-}
+bool Config::initialize() { return true; }
 
 } // namespace srcn
 } // namespace backend
index fbe2f09..efc77fd 100644 (file)
@@ -30,7 +30,7 @@ class Config : public IConfig
 {
 public:
   std::string id() override { return "srcn"; }
-  void initialize() override;
+  bool initialize() override;
   bool SupportPermutation() override { return false; }
   bool SupportSubTensorAlloc() override
   {
index e6c2235..855f31e 100644 (file)
@@ -31,7 +31,7 @@ struct IConfig
   virtual ~IConfig() = default;
 
   virtual std::string id() = 0;
-  virtual void initialize() = 0;
+  virtual bool initialize() = 0;
   // Support permute kernel
   virtual bool SupportPermutation() = 0;
   // Support subtensor allocation
index 6cc1deb..3db3b24 100644 (file)
@@ -90,7 +90,14 @@ void BackendManager::loadBackend(const std::string &backend)
     auto backend_object =
         std::unique_ptr<backend::Backend, backend_destroy_t>(backend_create(), backend_destroy);
     auto backend_object_raw = backend_object.get();
-    backend_object->config()->initialize(); // Call initialize here?
+    bool initialized = backend_object->config()->initialize(); // Call initialize here?
+    if (!initialized)
+    {
+      VERBOSE(BackendManager::loadBackend)
+          << backend.c_str() << " backend initialization failed. Don't use this backend"
+          << std::endl;
+      return;
+    }
     _gen_map.emplace(backend_object->config()->id(), std::move(backend_object));
     _available_backends.push_back(backend_object_raw);
   }
index b0065d3..b5471c8 100644 (file)
@@ -28,7 +28,7 @@ using namespace backend;
 struct MockConfig : public IConfig
 {
   std::string id() override { return "b1"; }
-  void initialize() override{};
+  bool initialize() override { return true; };
   bool SupportPermutation() override { return false; }
   bool SupportSubTensorAlloc() override { return false; }
 };
index 72350f4..cf653b1 100644 (file)
@@ -55,7 +55,7 @@ struct MockShapeFixer : IShapeFixer
 struct MockConfigCPU : public IConfig
 {
   std::string id() override { return "cpu"; }
-  void initialize() override{};
+  bool initialize() override { return true; };
   bool SupportPermutation() override { return false; }
   bool SupportSubTensorAlloc() override { return false; }
 };
@@ -74,7 +74,7 @@ struct MockBackendCPU : public Backend
 struct MockConfigGPU : public IConfig
 {
   std::string id() override { return "gpu"; }
-  void initialize() override{};
+  bool initialize() override { return true; };
   bool SupportPermutation() override { return false; }
   bool SupportSubTensorAlloc() override { return false; }
 };
@@ -93,7 +93,7 @@ struct MockBackendGPU : public Backend
 struct MockConfigNPU : public IConfig
 {
   std::string id() override { return "npu"; }
-  void initialize() override{};
+  bool initialize() override { return true; };
   bool SupportPermutation() override { return false; }
   bool SupportSubTensorAlloc() override { return false; }
 };