From 2989fbfc88f0edec35d18356859e75dadcd347e5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=98=A4=ED=98=95=EC=84=9D/On-Device=20Lab=28SR=29/Staff?= =?utf8?q?=20Engineer/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Mon, 9 Dec 2019 12:35:03 +0900 Subject: [PATCH] [neurun] Check backend initialization success (#9454) Backend initialize() function return boolean to check initialization success/fail Signed-off-by: Hyeongseok Oh --- runtime/neurun/backend/acl_cl/Config.cc | 8 +++++++- runtime/neurun/backend/acl_cl/Config.h | 2 +- runtime/neurun/backend/acl_neon/Config.cc | 5 +---- runtime/neurun/backend/acl_neon/Config.h | 2 +- runtime/neurun/backend/cpu/Config.cc | 5 +---- runtime/neurun/backend/cpu/Config.h | 2 +- runtime/neurun/backend/srcn/Config.cc | 5 +---- runtime/neurun/backend/srcn/Config.h | 2 +- runtime/neurun/core/include/backend/IConfig.h | 2 +- runtime/neurun/core/src/backend/BackendManager.cc | 9 ++++++++- runtime/neurun/test/core/backend/ExecTime.test.cc | 2 +- runtime/neurun/test/core/compiler/Scheduler.cc | 6 +++--- 12 files changed, 27 insertions(+), 23 deletions(-) diff --git a/runtime/neurun/backend/acl_cl/Config.cc b/runtime/neurun/backend/acl_cl/Config.cc index 0c07691..36bf836 100644 --- a/runtime/neurun/backend/acl_cl/Config.cc +++ b/runtime/neurun/backend/acl_cl/Config.cc @@ -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 diff --git a/runtime/neurun/backend/acl_cl/Config.h b/runtime/neurun/backend/acl_cl/Config.h index ae527dd..a7ceaac 100644 --- a/runtime/neurun/backend/acl_cl/Config.h +++ b/runtime/neurun/backend/acl_cl/Config.h @@ -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 timer() override { return nnfw::cpp14::make_unique(); } diff --git a/runtime/neurun/backend/acl_neon/Config.cc b/runtime/neurun/backend/acl_neon/Config.cc index 8f4a8e7..352bc0b 100644 --- a/runtime/neurun/backend/acl_neon/Config.cc +++ b/runtime/neurun/backend/acl_neon/Config.cc @@ -23,10 +23,7 @@ namespace backend namespace acl_neon { -void Config::initialize() -{ - // DO NOTHING -} +bool Config::initialize() { return true; } } // namespace acl_neon } // namespace backend diff --git a/runtime/neurun/backend/acl_neon/Config.h b/runtime/neurun/backend/acl_neon/Config.h index 13f6c83..430c194 100644 --- a/runtime/neurun/backend/acl_neon/Config.h +++ b/runtime/neurun/backend/acl_neon/Config.h @@ -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; } diff --git a/runtime/neurun/backend/cpu/Config.cc b/runtime/neurun/backend/cpu/Config.cc index 1a487f7..3912740 100644 --- a/runtime/neurun/backend/cpu/Config.cc +++ b/runtime/neurun/backend/cpu/Config.cc @@ -23,10 +23,7 @@ namespace backend namespace cpu { -void Config::initialize() -{ - // DO NOTHING -} +bool Config::initialize() { return true; } } // namespace cpu } // namespace backend diff --git a/runtime/neurun/backend/cpu/Config.h b/runtime/neurun/backend/cpu/Config.h index 262d477..be303b5 100644 --- a/runtime/neurun/backend/cpu/Config.h +++ b/runtime/neurun/backend/cpu/Config.h @@ -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 { diff --git a/runtime/neurun/backend/srcn/Config.cc b/runtime/neurun/backend/srcn/Config.cc index e69136f..6865657 100644 --- a/runtime/neurun/backend/srcn/Config.cc +++ b/runtime/neurun/backend/srcn/Config.cc @@ -23,10 +23,7 @@ namespace backend namespace srcn { -void Config::initialize() -{ - // DO NOTHING -} +bool Config::initialize() { return true; } } // namespace srcn } // namespace backend diff --git a/runtime/neurun/backend/srcn/Config.h b/runtime/neurun/backend/srcn/Config.h index fbe2f09..efc77fd 100644 --- a/runtime/neurun/backend/srcn/Config.h +++ b/runtime/neurun/backend/srcn/Config.h @@ -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 { diff --git a/runtime/neurun/core/include/backend/IConfig.h b/runtime/neurun/core/include/backend/IConfig.h index e6c2235..855f31e 100644 --- a/runtime/neurun/core/include/backend/IConfig.h +++ b/runtime/neurun/core/include/backend/IConfig.h @@ -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 diff --git a/runtime/neurun/core/src/backend/BackendManager.cc b/runtime/neurun/core/src/backend/BackendManager.cc index 6cc1deb..3db3b24 100644 --- a/runtime/neurun/core/src/backend/BackendManager.cc +++ b/runtime/neurun/core/src/backend/BackendManager.cc @@ -90,7 +90,14 @@ void BackendManager::loadBackend(const std::string &backend) auto backend_object = std::unique_ptr(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); } diff --git a/runtime/neurun/test/core/backend/ExecTime.test.cc b/runtime/neurun/test/core/backend/ExecTime.test.cc index b0065d3..b5471c8 100644 --- a/runtime/neurun/test/core/backend/ExecTime.test.cc +++ b/runtime/neurun/test/core/backend/ExecTime.test.cc @@ -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; } }; diff --git a/runtime/neurun/test/core/compiler/Scheduler.cc b/runtime/neurun/test/core/compiler/Scheduler.cc index 72350f4..cf653b1 100644 --- a/runtime/neurun/test/core/compiler/Scheduler.cc +++ b/runtime/neurun/test/core/compiler/Scheduler.cc @@ -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; } }; -- 2.7.4