From: Inki Dae Date: Mon, 10 Feb 2020 06:26:35 +0000 (+0900) Subject: mv_inference: Check for inference target devices X-Git-Tag: submit/tizen/20200423.063253~40 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a5a1eb180428b970268c6c69b28da8f5cb2f177c;p=platform%2Fcore%2Fapi%2Fmediavision.git mv_inference: Check for inference target devices 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 --- diff --git a/mv_inference/inference/include/Inference.h b/mv_inference/inference/include/Inference.h index d66cb83e..3c82d1fc 100755 --- a/mv_inference/inference/include/Inference.h +++ b/mv_inference/inference/include/Inference.h @@ -265,6 +265,7 @@ private: InferenceConfig mConfig; mv_engine_config_h engine_config; + inference_engine_capacity mBackendCapacity; InferenceEngineVision * mBackend; diff --git a/mv_inference/inference/src/Inference.cpp b/mv_inference/inference/src/Inference.cpp index 16b65b49..e201cac4 100755 --- a/mv_inference/inference/src/Inference.cpp +++ b/mv_inference/inference/src/Inference.cpp @@ -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");