From 3929ecba491ba27d445576533163d4a127b0f5f4 Mon Sep 17 00:00:00 2001 From: Jaeyun Date: Mon, 10 Feb 2020 16:37:38 +0900 Subject: [PATCH] [C-Api] add function to get subplugin name Add new function to get sub-plugin name and conditions to validate the nnfw is available. TODO : add condition to check the nnfw availability. Signed-off-by: Jaeyun --- api/capi/include/nnstreamer-capi-private.h | 5 +++ api/capi/src/nnstreamer-capi-single.c | 38 ++-------------- api/capi/src/nnstreamer-capi-util.c | 70 ++++++++++++++++-------------- 3 files changed, 47 insertions(+), 66 deletions(-) diff --git a/api/capi/include/nnstreamer-capi-private.h b/api/capi/include/nnstreamer-capi-private.h index 1ab6394..b07d574 100644 --- a/api/capi/include/nnstreamer-capi-private.h +++ b/api/capi/include/nnstreamer-capi-private.h @@ -356,6 +356,11 @@ int ml_validate_model_file (const char *model, ml_nnfw_type_e * nnfw); */ int ml_check_plugin_availability (const char *plugin_name, const char *element_name); +/** + * @brief Internal function to get the sub-plugin name. + */ +const char* ml_get_nnfw_subplugin_name (ml_nnfw_type_e nnfw); + #if defined (__TIZEN__) /** * @brief Checks whether machine_learning.inference feature is enabled or not. diff --git a/api/capi/src/nnstreamer-capi-single.c b/api/capi/src/nnstreamer-capi-single.c index e05f24f..d7921d1 100644 --- a/api/capi/src/nnstreamer-capi-single.c +++ b/api/capi/src/nnstreamer-capi-single.c @@ -465,6 +465,7 @@ ml_single_open_custom (ml_single_h * single, ml_single_preset * info) ml_tensors_info_s *in_tensors_info, *out_tensors_info; ml_nnfw_type_e nnfw; ml_nnfw_hw_e hw; + const char *fw_name; check_feature_state (); @@ -567,40 +568,9 @@ ml_single_open_custom (ml_single_h * single, ml_single_preset * info) } } - switch (nnfw) { - case ML_NNFW_TYPE_CUSTOM_FILTER: - g_object_set (filter_obj, "framework", "custom", NULL); - break; - case ML_NNFW_TYPE_TENSORFLOW_LITE: - /* We can get the tensor meta from tf-lite model. */ - g_object_set (filter_obj, "framework", "tensorflow-lite", NULL); - break; - case ML_NNFW_TYPE_TENSORFLOW: - g_object_set (filter_obj, "framework", "tensorflow", NULL); - break; - case ML_NNFW_TYPE_MVNC: - /** @todo Verify this! (this code is not tested) */ - g_object_set (filter_obj, "framework", "movidius-ncsdk2", NULL); - break; - case ML_NNFW_TYPE_NNFW: - /* We can get the tensor meta from tf-lite model. */ - g_object_set (filter_obj, "framework", "nnfw", NULL); - break; - case ML_NNFW_TYPE_SNAP: - g_object_set (filter_obj, "framework", "snap", NULL); - break; - case ML_NNFW_TYPE_ARMNN: - g_object_set (filter_obj, "framework", "armnn", NULL); - break; - default: - /** @todo Add other fw later. */ - ml_loge ("The given nnfw is not supported."); - status = ML_ERROR_NOT_SUPPORTED; - goto error; - } - - /* set model files and custom option */ - g_object_set (filter_obj, "model", info->models, NULL); + /* set framework, model files and custom option */ + fw_name = ml_get_nnfw_subplugin_name (nnfw); + g_object_set (filter_obj, "framework", fw_name, "model", info->models, NULL); if (info->custom_option) { g_object_set (filter_obj, "custom", info->custom_option, NULL); diff --git a/api/capi/src/nnstreamer-capi-util.c b/api/capi/src/nnstreamer-capi-util.c index 647ea9f..db61643 100644 --- a/api/capi/src/nnstreamer-capi-util.c +++ b/api/capi/src/nnstreamer-capi-util.c @@ -971,11 +971,18 @@ ml_validate_model_file (const char *model, ml_nnfw_type_e * nnfw) break; } case ML_NNFW_TYPE_MVNC: - /** @todo Need to check method for NCSDK2 */ - ml_loge ("Intel Movidius NCSDK2 is not supported."); + case ML_NNFW_TYPE_OPENVINO: + case ML_NNFW_TYPE_VIVANTE: + case ML_NNFW_TYPE_EDGE_TPU: + /** @todo Need to check method to validate model */ + ml_loge ("Given NNFW is not supported yet."); status = ML_ERROR_NOT_SUPPORTED; break; case ML_NNFW_TYPE_SNAP: +#if !defined(__ANDROID__) + ml_loge ("SNAP only can be included in Android (arm64-v8a only)."); + status = ML_ERROR_NOT_SUPPORTED; +#endif /* SNAP requires multiple files, set supported if model file exists. */ break; case ML_NNFW_TYPE_ARMNN: @@ -1031,6 +1038,30 @@ ml_nnfw_to_accl_hw (const ml_nnfw_hw_e hw) } /** + * @brief Internal function to get the sub-plugin name. + */ +const char * +ml_get_nnfw_subplugin_name (ml_nnfw_type_e nnfw) +{ + static const char *nnfw_subplugin_name[] = { + [ML_NNFW_TYPE_ANY] = "any", /* DO NOT use this name ('any') to get the sub-plugin */ + [ML_NNFW_TYPE_CUSTOM_FILTER] = "custom", + [ML_NNFW_TYPE_TENSORFLOW_LITE] = "tensorflow-lite", + [ML_NNFW_TYPE_TENSORFLOW] = "tensorflow", + [ML_NNFW_TYPE_NNFW] = "nnfw", + [ML_NNFW_TYPE_MVNC] = "movidius-ncsdk2", + [ML_NNFW_TYPE_OPENVINO] = "openvino", + [ML_NNFW_TYPE_VIVANTE] = "vivante", + [ML_NNFW_TYPE_EDGE_TPU] = "edgetpu", + [ML_NNFW_TYPE_ARMNN] = "armnn", + [ML_NNFW_TYPE_SNAP] = "snap", + NULL + }; + + return nnfw_subplugin_name[nnfw]; +} + +/** * @brief Checks the availability of the given execution environments. */ int @@ -1038,7 +1069,7 @@ ml_check_nnfw_availability (ml_nnfw_type_e nnfw, ml_nnfw_hw_e hw, bool * available) { const GstTensorFilterFramework *fw; - gchar *fw_name = NULL; + const char *fw_name = NULL; check_feature_state (); @@ -1048,33 +1079,10 @@ ml_check_nnfw_availability (ml_nnfw_type_e nnfw, ml_nnfw_hw_e hw, /* init false */ *available = false; - switch (nnfw) { - case ML_NNFW_TYPE_CUSTOM_FILTER: - fw_name = g_strdup ("custom"); - break; - case ML_NNFW_TYPE_TENSORFLOW_LITE: - fw_name = g_strdup ("tensorflow-lite"); - break; - case ML_NNFW_TYPE_TENSORFLOW: - fw_name = g_strdup ("tensorflow"); - break; - case ML_NNFW_TYPE_NNFW: - fw_name = g_strdup ("nnfw"); - break; - case ML_NNFW_TYPE_MVNC: - /** @todo Condition to support Movidius NCSDK2 */ - fw_name = g_strdup ("movidius-ncsdk2"); - break; - case ML_NNFW_TYPE_SNAP: - fw_name = g_strdup ("snap"); - break; - case ML_NNFW_TYPE_ARMNN: - fw_name = g_strdup ("armnn"); - break; - default: - /* Default = "Not available!" */ - break; - } + if (nnfw == ML_NNFW_TYPE_ANY) + return ML_ERROR_INVALID_PARAMETER; + + fw_name = ml_get_nnfw_subplugin_name (nnfw); if (fw_name) { if ((fw = nnstreamer_filter_find (fw_name)) != NULL) { @@ -1086,8 +1094,6 @@ ml_check_nnfw_availability (ml_nnfw_type_e nnfw, ml_nnfw_hw_e hw, } else { ml_logw ("%s is not supported.", fw_name); } - - g_free (fw_name); } return ML_ERROR_NONE; -- 2.7.4