From 762b66ffb06e498288ddfca02f7fb62f5bb97cdc Mon Sep 17 00:00:00 2001 From: Parichay Kapoor Date: Fri, 15 May 2020 15:58:47 +0530 Subject: [PATCH] [subplugins] Update subplugins accl support Update subplugin's accelerators support as per updated rules for auto/default Signed-off-by: Parichay Kapoor --- ext/nnstreamer/tensor_filter/tensor_filter_armnn.cc | 8 +------- ext/nnstreamer/tensor_filter/tensor_filter_caffe2.cc | 6 +----- ext/nnstreamer/tensor_filter/tensor_filter_edgetpu.cc | 4 +--- .../tensor_filter/tensor_filter_mediapipe.cc | 19 +++++++++---------- .../tensor_filter/tensor_filter_movidius_ncsdk2.c | 2 -- ext/nnstreamer/tensor_filter/tensor_filter_nnfw.c | 16 +++++++++------- .../tensor_filter/tensor_filter_openvino.cc | 11 +++++------ .../tensor_filter/tensor_filter_openvino.hh | 5 ++--- ext/nnstreamer/tensor_filter/tensor_filter_python.cc | 7 +------ .../tensor_filter/tensor_filter_tensorflow.cc | 6 +----- gst/nnstreamer/tensor_filter/tensor_filter_common.c | 3 +++ 11 files changed, 33 insertions(+), 54 deletions(-) diff --git a/ext/nnstreamer/tensor_filter/tensor_filter_armnn.cc b/ext/nnstreamer/tensor_filter/tensor_filter_armnn.cc index 362f8e3..55e53a8 100644 --- a/ext/nnstreamer/tensor_filter/tensor_filter_armnn.cc +++ b/ext/nnstreamer/tensor_filter/tensor_filter_armnn.cc @@ -40,9 +40,7 @@ #include static const gchar *armnn_accl_support[] = { - ACCL_AUTO_STR, - ACCL_DEFAULT_STR, - ACCL_CPU_NEON_STR, + ACCL_CPU_NEON_STR, /** ACCL for default and auto config */ ACCL_CPU_STR, ACCL_GPU_STR, NULL @@ -327,10 +325,6 @@ armnn::Compute ArmNNCore::getBackend (const accl_hw hw) case ACCL_CPU: return armnn::Compute::CpuRef; case ACCL_CPU_NEON: - return armnn::Compute::CpuAcc; - case ACCL_AUTO: - /** intended */ - case ACCL_DEFAULT: /** intended */ default: return armnn::Compute::CpuAcc; diff --git a/ext/nnstreamer/tensor_filter/tensor_filter_caffe2.cc b/ext/nnstreamer/tensor_filter/tensor_filter_caffe2.cc index 215ed84..407ec5c 100644 --- a/ext/nnstreamer/tensor_filter/tensor_filter_caffe2.cc +++ b/ext/nnstreamer/tensor_filter/tensor_filter_caffe2.cc @@ -43,11 +43,7 @@ #define DBG FALSE #endif -static const gchar *caffe2_accl_support[] = { - ACCL_AUTO_STR, - ACCL_DEFAULT_STR, - NULL -}; +static const gchar *caffe2_accl_support[] = { NULL }; using namespace caffe2; diff --git a/ext/nnstreamer/tensor_filter/tensor_filter_edgetpu.cc b/ext/nnstreamer/tensor_filter/tensor_filter_edgetpu.cc index 658baf4..aa328ef 100644 --- a/ext/nnstreamer/tensor_filter/tensor_filter_edgetpu.cc +++ b/ext/nnstreamer/tensor_filter/tensor_filter_edgetpu.cc @@ -63,7 +63,6 @@ private: BuildEdgeTpuInterpreter(const tflite::FlatBufferModel &model, edgetpu::EdgeTpuContext* edgetpu_context); - /** Internal Utility Functions & Properties ***************************/ void cleanup (); static void setTensorProp (tflite::Interpreter *interpreter, @@ -92,8 +91,7 @@ public: }; const char *edgetpu_subplugin::name = "edgetpu"; -const accl_hw edgetpu_subplugin::hw_list[] = { ACCL_NPU_EDGE_TPU, - ACCL_DEFAULT, ACCL_AUTO }; +const accl_hw edgetpu_subplugin::hw_list[] = { ACCL_NPU_EDGE_TPU }; edgetpu_subplugin::edgetpu_subplugin () : tensor_filter_subplugin (), diff --git a/ext/nnstreamer/tensor_filter/tensor_filter_mediapipe.cc b/ext/nnstreamer/tensor_filter/tensor_filter_mediapipe.cc index bdab84e..4a70519 100644 --- a/ext/nnstreamer/tensor_filter/tensor_filter_mediapipe.cc +++ b/ext/nnstreamer/tensor_filter/tensor_filter_mediapipe.cc @@ -61,7 +61,7 @@ private: int loadMediapipeGraph (const GstTensorFilterProperties * prop); static const char *name; static const accl_hw hw_list[]; - static const int num_hw = 1; + static const int num_hw = 0; static mediapipe_subplugin *registeredRepresentation; public: @@ -81,8 +81,7 @@ public: }; const char *mediapipe_subplugin::name = "mediapipe"; -const accl_hw mediapipe_subplugin::hw_list[] = { - ACCL_DEFAULT, ACCL_AUTO }; +const accl_hw mediapipe_subplugin::hw_list[] = { }; /** * @brief mediapipe_subplugin Constructor @@ -237,7 +236,7 @@ void mediapipe_subplugin::invoke (const GstTensorMemory *input, GstTensorMemory mediapipe::Status status; /* TODO to make it better, start the graph at init or previous step */ - mediapipe::OutputStreamPoller poller = + mediapipe::OutputStreamPoller poller = graph.AddOutputStreamPoller (outputInfo.info[0].name).ValueOrDie (); status = graph.StartRun ({}); if (!status.ok ()) { @@ -247,8 +246,8 @@ void mediapipe_subplugin::invoke (const GstTensorMemory *input, GstTensorMemory // Wrap Mat into an ImageFrame. auto input_frame = absl::make_unique ( - mediapipe::ImageFormat::SRGB, - input_width, + mediapipe::ImageFormat::SRGB, + input_width, input_height, input_widthStep, (uint8_t *) input->data, @@ -257,7 +256,7 @@ void mediapipe_subplugin::invoke (const GstTensorMemory *input, GstTensorMemory // Send image packet status = graph.AddPacketToInputStream ( - inputInfo.info[0].name, + inputInfo.info[0].name, mediapipe::Adopt (input_frame.release ()).At ( mediapipe::Timestamp (frame_timestamp++) ) @@ -300,7 +299,7 @@ void mediapipe_subplugin::getFrameworkInfo (GstTensorFilterFrameworkInfo &info) info.num_hw = num_hw; } -/** +/** * @brief there is no model info available from the mediapipe. * For this reason, the acquired properties gotten at configuration will be filled. * @return 0 if OK. non-zero if error. @@ -339,7 +338,7 @@ void _init_filter_mediapipe () mediapipe_subplugin::init_filter_mediapipe (); } -/** +/** * @brief Destruct the subplugin */ void mediapipe_subplugin::fini_filter_mediapipe (void) @@ -348,7 +347,7 @@ void mediapipe_subplugin::fini_filter_mediapipe (void) tensor_filter_subplugin::unregister_subplugin (registeredRepresentation); } -/** +/** * @brief fin */ void _fini_filter_mediapipe () diff --git a/ext/nnstreamer/tensor_filter/tensor_filter_movidius_ncsdk2.c b/ext/nnstreamer/tensor_filter/tensor_filter_movidius_ncsdk2.c index 89d78da..537658c 100644 --- a/ext/nnstreamer/tensor_filter/tensor_filter_movidius_ncsdk2.c +++ b/ext/nnstreamer/tensor_filter/tensor_filter_movidius_ncsdk2.c @@ -37,8 +37,6 @@ #include static const gchar *mvncsdk2_accl_support[] = { - ACCL_AUTO_STR, - ACCL_DEFAULT_STR, ACCL_NPU_STR, ACCL_NPU_MOVIDIUS_STR, NULL diff --git a/ext/nnstreamer/tensor_filter/tensor_filter_nnfw.c b/ext/nnstreamer/tensor_filter/tensor_filter_nnfw.c index e3380a9..b15ec02 100644 --- a/ext/nnstreamer/tensor_filter/tensor_filter_nnfw.c +++ b/ext/nnstreamer/tensor_filter/tensor_filter_nnfw.c @@ -47,8 +47,6 @@ #define NNFW_TENSOR_RANK_LIMIT 6 static const gchar *nnfw_accl_support[] = { - ACCL_AUTO_STR, - ACCL_DEFAULT_STR, ACCL_CPU_NEON_STR, ACCL_CPU_STR, ACCL_GPU_STR, @@ -57,6 +55,13 @@ static const gchar *nnfw_accl_support[] = { NULL }; +#if defined(__aarch64__) || defined(__arm__) +static const gchar *nnfw_accl_auto = ACCL_CPU_NEON_STR; +#else +static const gchar *nnfw_accl_auto = ACCL_CPU_STR; +#endif +static const gchar *nnfw_accl_default = ACCL_CPU_STR; + void init_filter_nnfw (void) __attribute__ ((constructor)); void fini_filter_nnfw (void) __attribute__ ((destructor)); @@ -88,7 +93,8 @@ static int nnfw_tensor_type_from_gst (const tensor_type type, static const char * nnfw_get_accelerator (nnfw_pdata * pdata, const char *accelerators) { - pdata->accelerator = parse_accl_hw (accelerators, nnfw_accl_support); + pdata->accelerator = parse_accl_hw (accelerators, nnfw_accl_support, + nnfw_accl_auto, nnfw_accl_default); switch (pdata->accelerator) { case ACCL_NPU: @@ -101,8 +107,6 @@ nnfw_get_accelerator (nnfw_pdata * pdata, const char *accelerators) return NNFW_GPU_BACKEND; case ACCL_CPU: return NNFW_CPU_BACKEND; - case ACCL_DEFAULT: - /** intended */ default: return NNFW_DEFAULT_BACKEND; } @@ -303,7 +307,6 @@ nnfw_close (const GstTensorFilterProperties * prop, void **private_data) *private_data = NULL; } - /** * @brief Convert from nnfw type to gst tensor type * @param[in] nnfw_type type given in nnfw format @@ -334,7 +337,6 @@ nnfw_tensor_type_to_gst (const NNFW_TYPE nnfw_type, tensor_type * type) return err; } - /** * @brief Copy nnfw format info of tensor to gst format info * @param[in] nnfw_info info give in gst format diff --git a/ext/nnstreamer/tensor_filter/tensor_filter_openvino.cc b/ext/nnstreamer/tensor_filter/tensor_filter_openvino.cc index c4134f2..482716d 100644 --- a/ext/nnstreamer/tensor_filter/tensor_filter_openvino.cc +++ b/ext/nnstreamer/tensor_filter/tensor_filter_openvino.cc @@ -37,7 +37,6 @@ #include #include "tensor_filter_openvino.hh" - void init_filter_openvino (void) __attribute__ ((constructor)); void fini_filter_openvino (void) __attribute__ ((destructor)); @@ -449,7 +448,6 @@ TensorFilterOpenvino::invoke (const GstTensorFilterProperties * prop, return RetSuccess; } - /** * @brief The mandatory callback for GstTensorFilterFramework * @param prop property of tensor_filter instance @@ -541,14 +539,15 @@ ov_open (const GstTensorFilterProperties * prop, void **private_data) return TensorFilterOpenvino::RetEInval; } #endif - if (accelerator == ACCL_NONE || accelerator == ACCL_AUTO - || accelerator == ACCL_DEFAULT) { + if (accelerator == ACCL_NONE) { if (prop->accl_str != NULL) { ml_loge("'%s' is not valid value for the 'accelerator' property", prop->accl_str); + } else { + ml_loge("Invalid value for the 'accelerator' property"); } - ml_loge ("The 'accelerator' property is mandatory to use the tensor filter for OpenVino.\n" - "An acceptable format is as follows: 'true:[cpu|npu.movidius]'. Note that 'cpu' is only for the x86_64 architecture."); + ml_loge ("An acceptable format is as follows: 'true:[cpu|npu.movidius]'." + "Note that 'cpu' is only for the x86_64 architecture."); return TensorFilterOpenvino::RetEInval; } diff --git a/ext/nnstreamer/tensor_filter/tensor_filter_openvino.hh b/ext/nnstreamer/tensor_filter/tensor_filter_openvino.hh index 8652a04..2025aed 100644 --- a/ext/nnstreamer/tensor_filter/tensor_filter_openvino.hh +++ b/ext/nnstreamer/tensor_filter/tensor_filter_openvino.hh @@ -44,11 +44,10 @@ #include #include - const gchar *openvino_accl_support[] = { - ACCL_CPU_STR, + ACCL_NPU_MOVIDIUS_STR, /** ACCL for default and auto config */ ACCL_NPU_STR, - ACCL_NPU_MOVIDIUS_STR, + ACCL_CPU_STR, NULL }; diff --git a/ext/nnstreamer/tensor_filter/tensor_filter_python.cc b/ext/nnstreamer/tensor_filter/tensor_filter_python.cc index b3fce01..f2469e0 100644 --- a/ext/nnstreamer/tensor_filter/tensor_filter_python.cc +++ b/ext/nnstreamer/tensor_filter/tensor_filter_python.cc @@ -81,11 +81,7 @@ #define Py_ERRMSG(...) do {PyErr_Print(); ml_loge (__VA_ARGS__);} while (0); -static const gchar *python_accl_support[] = { - ACCL_AUTO_STR, - ACCL_DEFAULT_STR, - NULL -}; +static const gchar *python_accl_support[] = { NULL }; /** @brief Callback type for custom filter */ typedef enum _cb_type @@ -578,7 +574,6 @@ PYCore::parseOutputTensors(PyObject* result, GstTensorsInfo * info) if (nullptr == shape_type) throw std::runtime_error ("parseOutputTensors() has failed (3)."); - /** convert numpy type to tensor type */ info->info[i].type = getTensorType((NPY_TYPES)(((PyArray_Descr*) shape_type)->type_num)); for (int j = 0; j < PyList_Size(shape_dims); j++) diff --git a/ext/nnstreamer/tensor_filter/tensor_filter_tensorflow.cc b/ext/nnstreamer/tensor_filter/tensor_filter_tensorflow.cc index b7febdf..3fa7695 100644 --- a/ext/nnstreamer/tensor_filter/tensor_filter_tensorflow.cc +++ b/ext/nnstreamer/tensor_filter/tensor_filter_tensorflow.cc @@ -46,11 +46,7 @@ #define DBG FALSE #endif -static const gchar *tf_accl_support[] = { - ACCL_AUTO_STR, - ACCL_DEFAULT_STR, - NULL -}; +static const gchar *tf_accl_support[] = { NULL }; /** * @brief Internal data structure for tensorflow diff --git a/gst/nnstreamer/tensor_filter/tensor_filter_common.c b/gst/nnstreamer/tensor_filter/tensor_filter_common.c index c2730c4..2c2b5e1 100644 --- a/gst/nnstreamer/tensor_filter/tensor_filter_common.c +++ b/gst/nnstreamer/tensor_filter/tensor_filter_common.c @@ -754,6 +754,9 @@ gst_tensor_filter_parse_accelerator (GstTensorFilterPrivate * priv, } } + if (info->num_hw == 0) + return; + /** * Convert the list to string format * Extra 2 entries for basic accelerators : auto and default -- 2.7.4