From: Parichay Kapoor Date: Tue, 11 Feb 2020 10:22:55 +0000 (+0900) Subject: [ncsdk2/hw] Added supported accelerators X-Git-Tag: accepted/tizen/unified/20200318.130449~30 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=68f57e4394b1e8555f51d36d1d6da318b9dab38d;p=platform%2Fupstream%2Fnnstreamer.git [ncsdk2/hw] Added supported accelerators Added supported accelerators for ncsdk2 extension and corresponding unit-tests with single API Signed-off-by: Parichay Kapoor --- diff --git a/ext/nnstreamer/tensor_filter/meson.build b/ext/nnstreamer/tensor_filter/meson.build index 3bcc444..a6ae4c3 100644 --- a/ext/nnstreamer/tensor_filter/meson.build +++ b/ext/nnstreamer/tensor_filter/meson.build @@ -228,39 +228,31 @@ if have_python3 ) endif -if get_option('enable-movidius-ncsdk2') - # Explicitly checks mvnc.h in the ncsdk2 directory - nns_mvncsdk2_dep = cc.find_library('mvnc', required: false) - if not nns_mvncsdk2_dep.found() - warning('Failed to find \'libmvnc.so\' despite setting enable-movidius-ncsdk2. This option be ignored.') - elif not cc.check_header('mvnc2/mvnc.h') - warning('Failed to find \'mvnc2/mvnc.h\' despite setting enable-movidius-ncsdk2. This option be ignored.') - else - filter_sub_mvncsdk2_sources = [ - 'tensor_filter_movidius_ncsdk2.c' - ] +if have_movidius_ncsdk2 + filter_sub_mvncsdk2_sources = [ + 'tensor_filter_movidius_ncsdk2.c' + ] - nnstreamer_filter_mvncsdk2_sources = [] - foreach s : filter_sub_mvncsdk2_sources - nnstreamer_filter_mvncsdk2_sources += join_paths(meson.current_source_dir(), s) - endforeach + nnstreamer_filter_mvncsdk2_sources = [] + foreach s : filter_sub_mvncsdk2_sources + nnstreamer_filter_mvncsdk2_sources += join_paths(meson.current_source_dir(), s) + endforeach - nnstreamer_filter_mvncsdk2_deps = [glib_dep, gst_dep, nnstreamer_dep, nns_mvncsdk2_dep] + nnstreamer_filter_mvncsdk2_deps = [glib_dep, gst_dep, nnstreamer_dep, nns_mvncsdk2_dep] - shared_library('nnstreamer_filter_movidius-ncsdk2', - nnstreamer_filter_mvncsdk2_sources, - dependencies: nnstreamer_filter_mvncsdk2_deps, - install: true, - install_dir: filter_subplugin_install_dir - ) + shared_library('nnstreamer_filter_movidius-ncsdk2', + nnstreamer_filter_mvncsdk2_sources, + dependencies: nnstreamer_filter_mvncsdk2_deps, + install: true, + install_dir: filter_subplugin_install_dir + ) - static_library('nnstreamer_filter_movidius-ncsdk2', - nnstreamer_filter_mvncsdk2_sources, - dependencies: nnstreamer_filter_mvncsdk2_deps, - install: true, - install_dir: nnstreamer_libdir - ) - endif + static_library('nnstreamer_filter_movidius-ncsdk2', + nnstreamer_filter_mvncsdk2_sources, + dependencies: nnstreamer_filter_mvncsdk2_deps, + install: true, + install_dir: nnstreamer_libdir + ) endif if get_option('enable-cppfilter') diff --git a/ext/nnstreamer/tensor_filter/tensor_filter_movidius_ncsdk2.c b/ext/nnstreamer/tensor_filter/tensor_filter_movidius_ncsdk2.c index d0558cc..f611cf3 100644 --- a/ext/nnstreamer/tensor_filter/tensor_filter_movidius_ncsdk2.c +++ b/ext/nnstreamer/tensor_filter/tensor_filter_movidius_ncsdk2.c @@ -35,6 +35,14 @@ #include #include +static const gchar *mvncsdk2_accl_support[] = { + ACCL_AUTO_STR, + ACCL_DEFAULT_STR, + ACCL_NPU_STR, + ACCL_NPU_MOVIDIUS_STR, + NULL +}; + void init_filter_mvncsdk2 (void) __attribute__ ((constructor)); void fini_filter_mvncsdk2 (void) __attribute__ ((destructor)); @@ -381,7 +389,6 @@ _mvncsdk2_getInputDim (const GstTensorFilterProperties * prop, * @param prop : property of tensor_filter instance * @param private_data : tensorflow lite plugin's private data * @param[out] info : The dimesions and types of output tensors - * @todo : fill this function */ static int _mvncsdk2_getOutputDim (const GstTensorFilterProperties * prop, @@ -409,12 +416,27 @@ _mvncsdk2_getOutputDim (const GstTensorFilterProperties * prop, return 0; } +/** + * @brief The optional callback for GstTensorFilterFramework + * @param[in] hw backend accelerator hardware + * @return 0 if supported. -errno if not supported. + */ +static int +_mvncsdk2_checkAvailability (accl_hw hw) +{ + if (g_strv_contains (mvncsdk2_accl_support, get_accl_hw_str (hw))) + return 0; + + return -ENOENT; +} + static gchar filter_subplugin_movidius_ncsdk2[] = "movidius-ncsdk2"; static GstTensorFilterFramework NNS_support_movidius_ncsdk2 = { .version = GST_TENSOR_FILTER_FRAMEWORK_V0, .open = _mvncsdk2_open, .close = _mvncsdk2_close, + .checkAvailability = _mvncsdk2_checkAvailability, }; /** @brief Initialize this object for tensor_filter subplugin runtime register */ diff --git a/meson.build b/meson.build index c5b5a2b..c329103 100644 --- a/meson.build +++ b/meson.build @@ -257,6 +257,21 @@ if get_option('enable-armnn') add_project_arguments('-DENABLE_ARMNN=1', language: ['c', 'cpp']) endif +# Movidius NCSDK2 +have_movidius_ncsdk2 = false +if get_option('enable-movidius-ncsdk2') + # Explicitly checks mvnc.h in the ncsdk2 directory + nns_mvncsdk2_dep = cc.find_library('mvnc', required: false) + if not nns_mvncsdk2_dep.found() + warning('Failed to find \'libmvnc.so\' despite setting enable-movidius-ncsdk2. This option be ignored.') + elif not cc.check_header('mvnc2/mvnc.h') + warning('Failed to find \'mvnc2/mvnc.h\' despite setting enable-movidius-ncsdk2. This option be ignored.') + else + have_movidius_ncsdk2 = true + add_project_arguments('-DENABLE_MOVIDIUS_NCSDK2=1', language: ['c', 'cpp']) + endif +endif + # Set configuration to install .ini nnstreamer_install_conf = configuration_data() nnstreamer_install_conf.merge_from(nnstreamer_conf) diff --git a/tests/meson.build b/tests/meson.build index fbb8fa5..e7bdaef 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -156,7 +156,7 @@ if get_option('enable-tensorflow-lite') and get_option('enable-edgetpu') subdir('nnstreamer_filter_edgetpu') endif -if get_option('enable-movidius-ncsdk2') +if have_movidius_ncsdk2 subdir('nnstreamer_filter_mvncsdk2') endif diff --git a/tests/tizen_capi/unittest_tizen_capi.cc b/tests/tizen_capi/unittest_tizen_capi.cc index eecedc1..cfe8e0b 100644 --- a/tests/tizen_capi/unittest_tizen_capi.cc +++ b/tests/tizen_capi/unittest_tizen_capi.cc @@ -1463,6 +1463,50 @@ TEST (nnstreamer_capi_util, availability_fail_04_n) } #endif /** ENABLE_NNFW_RUNTIME */ +#ifdef ENABLE_MOVIDIUS_NCSDK2 +/** + * @brief Test NNStreamer Utility for checking availability of custom backend + */ +TEST (nnstreamer_capi_util, availability_05) +{ + bool result; + int status; + + status = ml_check_nnfw_availability (ML_NNFW_TYPE_MVNC, ML_NNFW_HW_ANY, &result); + EXPECT_EQ (status, ML_ERROR_NONE); + EXPECT_EQ (result, true); + + status = ml_check_nnfw_availability (ML_NNFW_TYPE_MVNC, ML_NNFW_HW_AUTO, &result); + EXPECT_EQ (status, ML_ERROR_NONE); + EXPECT_EQ (result, true); + + status = ml_check_nnfw_availability (ML_NNFW_TYPE_MVNC, ML_NNFW_HW_NPU, &result); + EXPECT_EQ (status, ML_ERROR_NONE); + EXPECT_EQ (result, true); + + status = ml_check_nnfw_availability (ML_NNFW_TYPE_MVNC, ML_NNFW_HW_NPU_MOVIDIUS, &result); + EXPECT_EQ (status, ML_ERROR_NONE); + EXPECT_EQ (result, true); +} + +/** + * @brief Test NNStreamer Utility for checking availability of custom backend + */ +TEST (nnstreamer_capi_util, availability_fail_05_n) +{ + bool result; + int status; + + status = ml_check_nnfw_availability (ML_NNFW_TYPE_MVNC, ML_NNFW_HW_CPU, &result); + EXPECT_EQ (status, ML_ERROR_NONE); + EXPECT_EQ (result, false); + + status = ml_check_nnfw_availability (ML_NNFW_TYPE_MVNC, ML_NNFW_HW_GPU, &result); + EXPECT_EQ (status, ML_ERROR_NONE); + EXPECT_EQ (result, false); +} +#endif /** ENABLE_MOVIDIUS_NCSDK2 */ + /** * @brief Test NNStreamer Utility for checking tensors info handle */