From: Inki Dae Date: Wed, 13 May 2020 06:45:04 +0000 (+0900) Subject: Add InitBackendEngine function for a new bind function X-Git-Tag: submit/tizen/20200602.011936~9 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ba0937e9ac08fe3efcb0a76a759c6c53e6db6bfb;p=platform%2Fcore%2Fmultimedia%2Finference-engine-interface.git Add InitBackendEngine function for a new bind function This patch introduces a new private function, InitBackendEngine which loads library file with a given backend library path. This function will be used by other bind function which passes backend type instead of name. Change-Id: I54b1970b72c8cee258c9d33e4bd2a32ff5132a2f Signed-off-by: Inki Dae --- diff --git a/include/inference_engine_common_impl.h b/include/inference_engine_common_impl.h index 4e3bd64..fb863fd 100755 --- a/include/inference_engine_common_impl.h +++ b/include/inference_engine_common_impl.h @@ -225,6 +225,7 @@ public: int SetBackendEngine(inference_backend_type_e backend); private: + int InitBackendEngine(std::string &backend_path); int CheckTensorBuffers(std::vector &buffers); int CheckLayerProperty(inference_engine_layer_property &property); diff --git a/src/inference_engine_common_impl.cpp b/src/inference_engine_common_impl.cpp index 8b7371b..f8634d9 100755 --- a/src/inference_engine_common_impl.cpp +++ b/src/inference_engine_common_impl.cpp @@ -167,6 +167,38 @@ int InferenceEngineCommon::DumpProfileToFile(const std::string filename) return INFERENCE_ENGINE_ERROR_NONE; } +int InferenceEngineCommon::InitBackendEngine(std::string &backend_path) +{ + LOGI("lib: %s", backend_path.c_str()); + mBackendModule = dlopen(backend_path.c_str(), RTLD_NOW); + LOGI("HANDLE : [%p]", mBackendModule); + + if (!mBackendModule) { + LOGE("Fail to dlopen %s", backend_path.c_str()); + LOGE("Error: %s\n", dlerror()); + return INFERENCE_ENGINE_ERROR_NOT_SUPPORTED; + } + + init_t* EngineInit = (init_t *)dlsym(mBackendModule, "EngineCommonInit"); + char *error = NULL; + if ((error = dlerror()) != NULL) { + LOGE("Error: %s\n", error); + dlclose(mBackendModule); + mBackendModule = nullptr; + return INFERENCE_ENGINE_ERROR_INTERNAL; + } + + mBackendHandle = EngineInit(); + if (mBackendHandle == NULL) { + LOGE("Fail to EngineInit"); + dlclose(mBackendModule); + mBackendModule = nullptr; + return INFERENCE_ENGINE_ERROR_INTERNAL; + } + + return INFERENCE_ENGINE_ERROR_NONE; +} + int InferenceEngineCommon::BindBackend(inference_engine_config *config) { LOGI("ENTER"); @@ -178,32 +210,10 @@ int InferenceEngineCommon::BindBackend(inference_engine_config *config) mBackendLibName = "libinference-engine-" + config->backend_name + ".so"; - char *error = NULL; - LOGI("lib: %s", mBackendLibName.c_str()); - mBackendModule = dlopen(mBackendLibName.c_str(), RTLD_NOW); - LOGI("HANDLE : [%p]", mBackendModule); - - if (!mBackendModule) { - LOGE("Fail to dlopen %s", mBackendLibName.c_str()); - LOGE("Error: %s\n", dlerror()); - return INFERENCE_ENGINE_ERROR_NOT_SUPPORTED; - } - - init_t* EngineInit = (init_t *)dlsym(mBackendModule, "EngineCommonInit"); - if ((error = dlerror()) != NULL) { - LOGE("Error: %s\n", error); - dlclose(mBackendModule); - mBackendModule = nullptr; - return INFERENCE_ENGINE_ERROR_INTERNAL; - } - - mBackendHandle = EngineInit(); - if (mBackendHandle == NULL) { - LOGE("Fail to EngineInit"); - dlclose(mBackendModule); - mBackendModule = nullptr; - return INFERENCE_ENGINE_ERROR_INTERNAL; - } + int ret = InitBackendEngine(mBackendLibName); + if (ret != INFERENCE_ENGINE_ERROR_NONE) { + return ret; + } if (mUseProfiler == true) { mProfiler->AddBackendName(config->backend_name);