[filter] Independency on order of the properties
authorParichay Kapoor <pk.kapoor@samsung.com>
Fri, 14 Aug 2020 12:51:01 +0000 (21:51 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Sat, 5 Sep 2020 12:26:35 +0000 (21:26 +0900)
This patch adds independence on the order of setting the properties
Properties of tensor filter which depends on the framework can now be set before setting the framework as well
When setting the framework, these properties are set again from the cache

Resolves #2650

**Self evaluation:**
1. Build test: [x]Passed [ ]Failed [ ]Skipped
2. Run test: [x]Passed [ ]Failed [ ]Skipped

Signed-off-by: Parichay Kapoor <pk.kapoor@samsung.com>
gst/nnstreamer/tensor_filter/tensor_filter_common.c
tests/nnstreamer_filter_tensorflow_lite/runTest.sh

index c86b83a..d6dc81a 100644 (file)
@@ -95,6 +95,10 @@ static const gchar *regex_accl_elem_utils[] = {
  */
 static GList *parse_accl_hw_all (const gchar * accelerators,
     const gchar ** supported_accelerators);
+static gint _gtfc_setprop_IS_UPDATABLE (GstTensorFilterPrivate * priv,
+    GstTensorFilterProperties * prop, const GValue * value);
+static gint _gtfc_setprop_ACCELERATOR (GstTensorFilterPrivate * priv,
+    GstTensorFilterProperties * prop, const GValue * value);
 
 /**
  * @brief GstTensorFilter properties.
@@ -1005,7 +1009,9 @@ static gint
 _gtfc_setprop_FRAMEWORK (GstTensorFilterPrivate * priv,
     GstTensorFilterProperties * prop, const GValue * value)
 {
+  gint status;
   const gchar *fw_name = g_value_get_string (value);
+  GValue val = G_VALUE_INIT;
 
   if (priv->fw != NULL) {
     if (g_strcmp0 (priv->prop.fwname, fw_name) != 0) {
@@ -1019,6 +1025,29 @@ _gtfc_setprop_FRAMEWORK (GstTensorFilterPrivate * priv,
   }
 
   gst_tensor_filter_get_available_framework (priv, fw_name);
+
+  /** set PROP_IS_UPDATABLE in case it was set before framework */
+  g_value_init (&val, G_TYPE_BOOLEAN);
+  g_value_set_boolean (&val, priv->is_updatable);
+  status = _gtfc_setprop_IS_UPDATABLE (priv, prop, &val);
+  g_value_unset (&val);
+  if (status != 0) {
+    g_warning ("Set propery is-updatable failed with error: %d", status);
+    return status;
+  }
+
+  /** set PROP_ACCELERATOR in case it was set before framework */
+  if (prop->accl_str) {
+    g_value_init (&val, G_TYPE_STRING);
+    g_value_set_string (&val, prop->accl_str);
+    status = _gtfc_setprop_ACCELERATOR (priv, prop, &val);
+    g_value_unset (&val);
+    if (status != 0) {
+      g_warning ("Set propery accelerator failed with error: %d", status);
+      return status;
+    }
+  }
+
   return 0;
 }
 
@@ -1318,11 +1347,15 @@ _gtfc_setprop_ACCELERATOR (GstTensorFilterPrivate * priv,
     return 0;
   }
 
-  if (GST_TF_FW_V0 (priv->fw)) {
-    g_free_const (prop->accl_str);
+  if (priv->fw) {
+    if (GST_TF_FW_V0 (priv->fw)) {
+      g_free_const (prop->accl_str);
+      prop->accl_str = g_strdup (accelerators);
+    } else if (GST_TF_FW_V1 (priv->fw)) {
+      gst_tensor_filter_parse_accelerator (priv, &priv->prop, accelerators);
+    }
+  } else {
     prop->accl_str = g_strdup (accelerators);
-  } else if (GST_TF_FW_V1 (priv->fw)) {
-    gst_tensor_filter_parse_accelerator (priv, &priv->prop, accelerators);
   }
   return 0;
 }
@@ -1332,13 +1365,17 @@ static gint
 _gtfc_setprop_IS_UPDATABLE (GstTensorFilterPrivate * priv,
     GstTensorFilterProperties * prop, const GValue * value)
 {
-  if (GST_TF_FW_V0 (priv->fw) && priv->fw->reloadModel == NULL) {
-    return 0;
-  } else if (GST_TF_FW_V1 (priv->fw) &&
-      priv->fw->eventHandler (priv->fw, prop, priv->privateData, RELOAD_MODEL,
-          NULL)
-      == -ENOENT) {
-    return 0;
+  if (priv->fw) {
+    if (GST_TF_FW_V0 (priv->fw) && priv->fw->reloadModel == NULL) {
+      priv->is_updatable = FALSE;
+      return 0;
+    } else if (GST_TF_FW_V1 (priv->fw) &&
+        priv->fw->eventHandler (priv->fw, prop, priv->privateData, RELOAD_MODEL,
+            NULL)
+        == -ENOENT) {
+      priv->is_updatable = FALSE;
+      return 0;
+    }
   }
 
   priv->is_updatable = g_value_get_boolean (value);
index 47cff44..27081e3 100644 (file)
@@ -96,7 +96,7 @@ function run_pipeline() {
 }
 
 arch=$(uname -m)
-if [ "$arch" = "armv7l" ]; then
+if [ "$arch" = "aarch64" ] || [ "$arch" = "armv7l" ]; then
   auto_accl="cpu.neon"
 elif [ "$arch" = "x86_64" ]; then
   auto_accl="cpu.simd"
@@ -189,6 +189,11 @@ run_pipeline true:${auto_accl},cpu
 cat info | grep "nnapi = 1, accl = ${auto_accl}$"
 testResult $? 2-17 "NNAPI activation test" 0 1
 
+# Property reading test for nnapi before setting the framework (analogous test is 2-3)
+gst-launch-1.0 --gst-plugin-path=${PATH_TO_PLUGIN} filesrc location=${PATH_TO_IMAGE} ! pngdec ! videoscale ! imagefreeze ! videoconvert ! video/x-raw,format=RGB,framerate=0/1 ! tensor_converter ! tensor_filter accelerator=true:!npu,gpu framework=tensorflow-lite model=${PATH_TO_MODEL} ! filesink location=tensorfilter.out.log 2>info
+cat info | grep "nnapi = 1, accl = gpu$"
+testResult $? 2-18 "NNAPI activation test" 0 1
+
 # Cleanup
 rm info