mv_inference: Fix target device configuration
authorInki Dae <inki.dae@samsung.com>
Fri, 6 Nov 2020 06:21:13 +0000 (15:21 +0900)
committerInki Dae <inki.dae@samsung.com>
Tue, 10 Nov 2020 06:57:08 +0000 (15:57 +0900)
Fixed an issue that target device type isn't updated correctly
when binding a backend engine.

This patch makes the target device configuration to be done
before a backend engine binding is completed because actual target device
configuration to the backend engine is done at binding time.

Change-Id: I24b5779f294abdf8944d4ec0339f1c1282e2156b
Signed-off-by: Inki Dae <inki.dae@samsung.com>
mv_inference/inference/src/mv_inference_open.cpp

index 10f9ca65dc00a3a48fbc2805f72cacb6763defcb..713d8b787a12d37e7d167816c2120617a7f892a8 100755 (executable)
@@ -129,7 +129,6 @@ int mv_inference_configure_model_open(mv_inference_h infer,
        char *modelUserFilePath = NULL;
        double modelMeanValue = 0.0;
        int backendType = 0;
-       int targetTypes = 0;
        size_t userFileLength = 0;
 
        ret = mv_engine_config_get_string_attribute(
@@ -170,13 +169,6 @@ int mv_inference_configure_model_open(mv_inference_h infer,
                goto _ERROR_;
        }
 
-       ret = mv_engine_config_get_int_attribute(
-                       engine_config, MV_INFERENCE_TARGET_DEVICE_TYPE, &targetTypes);
-       if (ret != MEDIA_VISION_ERROR_NONE) {
-               LOGE("Fail to get inference target type");
-               goto _ERROR_;
-       }
-
        if (access(modelWeightFilePath, F_OK)) {
                LOGE("weightFilePath in [%s] ", modelWeightFilePath);
                ret = MEDIA_VISION_ERROR_INVALID_PATH;
@@ -202,34 +194,6 @@ int mv_inference_configure_model_open(mv_inference_h infer,
                goto _ERROR_;
        }
 
-       bool is_new_version;
-
-       // Check if new inference engine framework or old one.
-       // new inference engine framework has different mv_inference_target_type_e enumeration values
-       // to support multiple inference target devices. So in case of old version,
-       // enumeration value given by user should be converted to new value, which
-       // will be done at ConfigureTargetTypes callback internally.
-       // Ps. this function will be dropped with deprecated code version-after-next of Tizen.
-       ret = check_mv_inference_engine_version(engine_config, &is_new_version);
-       if (ret != MEDIA_VISION_ERROR_NONE)
-               goto _ERROR_;
-
-       if (is_new_version) {
-               // Use new type.
-               if (pInfer->ConfigureTargetDevices(targetTypes) !=
-                       MEDIA_VISION_ERROR_NONE) {
-                       LOGE("Tried to configure invalid target types.");
-                       goto _ERROR_;
-               }
-       } else {
-               // Convert old type to new one and then use it.
-               if (pInfer->ConfigureTargetTypes(targetTypes) !=
-                       MEDIA_VISION_ERROR_NONE) {
-                       LOGE("Tried to configure invalid target types.");
-                       goto _ERROR_;
-               }
-       }
-
        pInfer->ConfigureModelFiles(std::string(modelConfigFilePath),
                                                                std::string(modelWeightFilePath),
                                                                std::string(modelUserFilePath));
@@ -396,6 +360,7 @@ int mv_inference_configure_engine_open(mv_inference_h infer,
 
        Inference *pInfer = static_cast<Inference *>(infer);
        int backendType = 0;
+       int targetTypes = 0;
        int ret = MEDIA_VISION_ERROR_NONE;
 
        pInfer->SetEngineConfig(engine_config);
@@ -407,6 +372,13 @@ int mv_inference_configure_engine_open(mv_inference_h infer,
                goto _ERROR_;
        }
 
+       ret = mv_engine_config_get_int_attribute(
+                       engine_config, MV_INFERENCE_TARGET_DEVICE_TYPE, &targetTypes);
+       if (ret != MEDIA_VISION_ERROR_NONE) {
+               LOGE("Fail to get inference target type");
+               goto _ERROR_;
+       }
+
        ret = pInfer->ConfigureBackendType(
                        (mv_inference_backend_type_e) backendType);
        if (ret != MEDIA_VISION_ERROR_NONE) {
@@ -414,6 +386,34 @@ int mv_inference_configure_engine_open(mv_inference_h infer,
                goto _ERROR_;
        }
 
+       bool is_new_version;
+
+       // Check if new inference engine framework or old one.
+       // new inference engine framework has different mv_inference_target_type_e enumeration values
+       // to support multiple inference target devices. So in case of old version,
+       // enumeration value given by user should be converted to new value, which
+       // will be done at ConfigureTargetTypes callback internally.
+       // Ps. this function will be dropped with deprecated code version-after-next of Tizen.
+       ret = check_mv_inference_engine_version(engine_config, &is_new_version);
+       if (ret != MEDIA_VISION_ERROR_NONE)
+               goto _ERROR_;
+
+       if (is_new_version) {
+               // Use new type.
+               if (pInfer->ConfigureTargetDevices(targetTypes) !=
+                       MEDIA_VISION_ERROR_NONE) {
+                       LOGE("Tried to configure invalid target types.");
+                       goto _ERROR_;
+               }
+       } else {
+               // Convert old type to new one and then use it.
+               if (pInfer->ConfigureTargetTypes(targetTypes) !=
+                       MEDIA_VISION_ERROR_NONE) {
+                       LOGE("Tried to configure invalid target types.");
+                       goto _ERROR_;
+               }
+       }
+
        // Create a inference-engine-common class object and load its corresponding library.
        ret = pInfer->Bind();
        if (ret != MEDIA_VISION_ERROR_NONE) {