Add InitBackendEngine function for a new bind function 33/233233/3
authorInki Dae <inki.dae@samsung.com>
Wed, 13 May 2020 06:45:04 +0000 (15:45 +0900)
committerInki Dae <inki.dae@samsung.com>
Wed, 13 May 2020 08:54:13 +0000 (17:54 +0900)
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 <inki.dae@samsung.com>
include/inference_engine_common_impl.h
src/inference_engine_common_impl.cpp

index 4e3bd6460817c6249bc66c195b9a3fc05d3dbef6..fb863fd15907d09d687754d9e3ba95164ea71ac7 100755 (executable)
@@ -225,6 +225,7 @@ public:
     int SetBackendEngine(inference_backend_type_e backend);
 
 private:
+       int InitBackendEngine(std::string &backend_path);
        int CheckTensorBuffers(std::vector<inference_engine_tensor_buffer> &buffers);
        int CheckLayerProperty(inference_engine_layer_property &property);
 
index 8b7371b6c3116ccc6ee35f7e8a4710e98edf496b..f8634d9e963d6a152519e9a55632c3f478f9c36b 100755 (executable)
@@ -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);