mv_inference: Check for inference target devices
authorInki Dae <inki.dae@samsung.com>
Mon, 10 Feb 2020 06:26:35 +0000 (15:26 +0900)
committerInki Dae <inki.dae@samsung.com>
Tue, 14 Apr 2020 00:40:31 +0000 (09:40 +0900)
This patch checks if a given backend engine supports a given
interface target device/devices for the inference by calling
GetBackendCapacity callback.

Change-Id: Ifd5eaa2fbbc5aeb9af0769fb5f7bfb16c2525dbe
Signed-off-by: Inki Dae <inki.dae@samsung.com>
mv_inference/inference/include/Inference.h
mv_inference/inference/src/Inference.cpp

index d66cb83e03512c63ce3dcdad3e218b07d91c11aa..3c82d1fce9a3a4c6aed9f50d55fcf267ec214133 100755 (executable)
@@ -265,6 +265,7 @@ private:
 
        InferenceConfig mConfig;
        mv_engine_config_h engine_config;
+       inference_engine_capacity mBackendCapacity;
 
        InferenceEngineVision * mBackend;
 
index 16b65b49e09cba03fc5876c42a80069b7bfa24f2..e201cac406f752a03883d6ebc34842684dbcff7e 100755 (executable)
@@ -52,6 +52,7 @@ InferenceConfig::InferenceConfig() :
 Inference::Inference() :
        mCanRun(),
        mConfig(),
+       mBackendCapacity(),
        mSupportedInferenceBackend()
 {
        LOGI("ENTER");
@@ -271,6 +272,13 @@ int Inference::Bind(void)
                return MEDIA_VISION_ERROR_INVALID_OPERATION;
        }
 
+       // Get capacity information from a backend.
+       ret = mBackend->GetBackendCapacity(&mBackendCapacity);
+       if (ret != MEDIA_VISION_ERROR_NONE) {
+               LOGE("Fail to get backend capacity.");
+               return ret;
+       }
+
        LOGI("LEAVE");
 
        return MEDIA_VISION_ERROR_NONE;
@@ -297,6 +305,28 @@ int Inference::Prepare(void)
 
        mBackend->SetOutputTensorParamNodes(mConfig.mOutputNodeNames);
 
+       // Check if backend supports a given target device/devices or not.
+       if (mConfig.mTargetTypes & MV_INFERENCE_TARGET_CPU) {
+               if (!(mBackendCapacity.supported_accel_devices & INFERENCE_TARGET_CPU)) {
+                       LOGE("Backend doesn't support CPU device as an accelerator.");
+                       return MEDIA_VISION_ERROR_INVALID_PARAMETER;
+               }
+       }
+
+       if (mConfig.mTargetTypes & MV_INFERENCE_TARGET_GPU) {
+               if (!(mBackendCapacity.supported_accel_devices & INFERENCE_TARGET_GPU)) {
+                       LOGE("Backend doesn't support CPU device as an accelerator.");
+                       return MEDIA_VISION_ERROR_INVALID_PARAMETER;
+               }
+       }
+
+       if (mConfig.mTargetTypes & MV_INFERENCE_TARGET_CUSTOM) {
+               if (!(mBackendCapacity.supported_accel_devices & INFERENCE_TARGET_CUSTOM)) {
+                       LOGE("Backend doesn't support CPU device as an accelerator.");
+                       return MEDIA_VISION_ERROR_INVALID_PARAMETER;
+               }
+       }
+
        mBackend->SetTargetDevices(ConvertTargetTypes(mConfig.mTargetTypes));
 
        LOGI("LEAVE");