[C-Api] use tensor-info struct from nns
authorJaeyun Jung <jy1210.jung@samsung.com>
Tue, 21 Nov 2023 07:23:36 +0000 (16:23 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Fri, 1 Dec 2023 04:46:38 +0000 (13:46 +0900)
Use gst-info struct and util functions from nnstreamer.
Remove unnecessary functions for ml-info.

Signed-off-by: Jaeyun Jung <jy1210.jung@samsung.com>
c/src/ml-api-common.c
c/src/ml-api-inference-internal.c
c/src/ml-api-inference-internal.h
c/src/ml-api-internal.h
java/android/nnstreamer/src/main/jni/nnstreamer-native-api.c
tests/capi/unittest_capi_inference.cc

index 71a8ad3..427bcaa 100644 (file)
@@ -14,7 +14,7 @@
 #include <stdio.h>
 #include <stdarg.h>
 #include <glib.h>
-
+#include <nnstreamer_plugin_api_util.h>
 #include "nnstreamer.h"
 #include "nnstreamer-tizen-internal.h"
 #include "ml-api-internal.h"
@@ -76,6 +76,41 @@ ml_api_get_version (unsigned int *major, unsigned int *minor,
 }
 
 /**
+ * @brief Convert the type from ml_tensor_type_e to tensor_type.
+ * @note This code is based on the same order between NNS type and ML type.
+ * The index should be the same in case of adding a new type.
+ */
+static tensor_type
+convert_tensor_type_from (ml_tensor_type_e type)
+{
+  if (type < ML_TENSOR_TYPE_INT32 || type >= ML_TENSOR_TYPE_UNKNOWN) {
+    _ml_error_report
+        ("Failed to convert the type. Input ml_tensor_type_e %d is invalid.",
+        type);
+    return _NNS_END;
+  }
+
+  return (tensor_type) type;
+}
+
+/**
+ * @brief Convert the type from tensor_type to ml_tensor_type_e.
+ * @note This code is based on the same order between NNS type and ML type.
+ * The index should be the same in case of adding a new type.
+ */
+static ml_tensor_type_e
+convert_ml_tensor_type_from (tensor_type type)
+{
+  if (type < _NNS_INT32 || type >= _NNS_END) {
+    _ml_error_report
+        ("Failed to convert the type. Input tensor_type %d is invalid.", type);
+    return ML_TENSOR_TYPE_UNKNOWN;
+  }
+
+  return (ml_tensor_type_e) type;
+}
+
+/**
  * @brief Gets the version string of machine-learning API.
  */
 char *
@@ -155,248 +190,12 @@ ml_tensors_info_destroy (ml_tensors_info_h info)
 }
 
 /**
- * @brief Allocates memory in given tensors_info for extra tensor infos.
- */
-gboolean
-_ml_tensors_info_create_extra (ml_tensors_info_s * ml_info)
-{
-  ml_tensor_info_s *new;
-  guint i;
-
-  if (!ml_info)
-    _ml_error_report_return (FALSE, "The parameter, ml_info, is NULL.");
-
-  if (ml_info->extra) {
-    return TRUE;
-  }
-
-  new = g_try_new0 (ml_tensor_info_s, ML_TENSOR_SIZE_EXTRA_LIMIT);
-  if (!new) {
-    _ml_loge ("Failed to allocate memory for extra tensors info.");
-    return FALSE;
-  }
-
-  for (i = 0; i < ML_TENSOR_SIZE_EXTRA_LIMIT; i++) {
-    if (_ml_tensor_info_initialize (&new[i]) != ML_ERROR_NONE) {
-      _ml_loge ("Failed to initialize extra tensors info.");
-      g_free (new);
-      return FALSE;
-    }
-  }
-
-  ml_info->extra = new;
-
-  return TRUE;
-}
-
-/**
- * @brief Initializes given tensor_info with default value.
- */
-int
-_ml_tensor_info_initialize (ml_tensor_info_s * info)
-{
-  guint i;
-
-  if (!info)
-    _ml_error_report_return (ML_ERROR_INVALID_PARAMETER,
-        "The parameter, info, is NULL. Provide a valid pointer.");
-
-  info->name = NULL;
-  info->type = ML_TENSOR_TYPE_UNKNOWN;
-  for (i = 0; i < ML_TENSOR_RANK_LIMIT; i++) {
-    info->dimension[i] = 0;
-  }
-
-  return ML_ERROR_NONE;
-}
-
-/**
- * @brief Initializes the tensors information with default value.
- */
-int
-_ml_tensors_info_initialize (ml_tensors_info_s * info)
-{
-  guint i;
-
-  if (!info)
-    _ml_error_report_return (ML_ERROR_INVALID_PARAMETER,
-        "The parameter, info, is NULL. Provide a valid pointer.");
-
-  info->num_tensors = 0;
-
-  for (i = 0; i < ML_TENSOR_SIZE_LIMIT_STATIC; i++) {
-    _ml_tensor_info_initialize (&info->info[i]);
-  }
-
-  info->extra = NULL;
-
-  return ML_ERROR_NONE;
-}
-
-/**
- * @brief Get the pointer of nth tensor info.
- */
-ml_tensor_info_s *
-ml_tensors_info_get_nth_info (ml_tensors_info_s * info, guint nth)
-{
-  if (!info)
-    return NULL;
-
-  if (nth >= ML_TENSOR_SIZE_LIMIT) {
-    _ml_loge ("The given nth is out of range. It should be less than %d.",
-        ML_TENSOR_SIZE_LIMIT);
-    return NULL;
-  }
-
-  if (nth < ML_TENSOR_SIZE_LIMIT_STATIC)
-    return &info->info[nth];
-
-  if (!_ml_tensors_info_create_extra (info))
-    return NULL;
-
-  return &info->extra[nth - ML_TENSOR_SIZE_LIMIT_STATIC];
-}
-
-/**
- * @brief Get the rank of tensor dimension.
- */
-static guint
-_ml_tensor_dimension_get_rank (const ml_tensor_dimension dim)
-{
-  guint i;
-
-  for (i = 0; i < ML_TENSOR_RANK_LIMIT; i++) {
-    if (dim[i] == 0)
-      break;
-  }
-
-  return i;
-}
-
-/**
- * @brief Check the tensor dimension is valid
- */
-static gboolean
-_ml_tensor_dimension_is_valid (const ml_tensor_dimension dim)
-{
-  guint i;
-  gboolean is_valid = FALSE;
-
-  i = _ml_tensor_dimension_get_rank (dim);
-  if (i == 0)
-    goto done;
-
-  for (; i < ML_TENSOR_RANK_LIMIT; i++) {
-    if (dim[i] > 0)
-      goto done;
-  }
-
-  is_valid = TRUE;
-
-done:
-  if (!is_valid) {
-    _ml_error_report
-        ("Failed to validate tensor dimension. The dimension string should be in the form of d1:...:d8, d1:d2:d3:d4, d1:d2:d3, d1:d2, or d1. Here, dN is a positive integer.");
-  }
-
-  return is_valid;
-}
-
-/**
- * @brief Compares the given tensor info.
- */
-static gboolean
-ml_tensor_info_compare (const ml_tensor_info_s * i1,
-    const ml_tensor_info_s * i2)
-{
-  guint i;
-
-  if (i1 == NULL || i2 == NULL)
-    return FALSE;
-
-  if (i1->type != i2->type)
-    return FALSE;
-
-  if (!_ml_tensor_dimension_is_valid (i1->dimension)
-      || !_ml_tensor_dimension_is_valid (i2->dimension))
-    return FALSE;
-
-  for (i = 0; i < ML_TENSOR_RANK_LIMIT; i++) {
-    if (i1->dimension[i] != i2->dimension[i]) {
-      /* Supposed dimension is same if remained dimension is 1. */
-      if (i1->dimension[i] > 1 || i2->dimension[i] > 1)
-        return FALSE;
-    }
-  }
-
-  return TRUE;
-}
-
-/**
- * @brief Validates the given tensor info is valid.
- * @note info should be locked by caller if nolock == 0.
- */
-static gboolean
-ml_tensor_info_validate (const ml_tensor_info_s * info, bool is_extended)
-{
-  guint i;
-
-  if (!info)
-    return FALSE;
-
-  if (info->type < 0 || info->type >= ML_TENSOR_TYPE_UNKNOWN)
-    return FALSE;
-
-  if (!is_extended) {
-    for (i = ML_TENSOR_RANK_LIMIT_PREV; i < ML_TENSOR_RANK_LIMIT; i++) {
-      if (info->dimension[i] > 1)
-        return FALSE;
-    }
-  }
-
-  return TRUE;
-}
-
-/**
- * @brief Validates the given tensors info is valid without acquiring lock
- * @note This function assumes that lock on ml_tensors_info_h has already been acquired
- */
-static int
-_ml_tensors_info_validate_nolock (const ml_tensors_info_s * info, bool *valid)
-{
-  guint i;
-
-  G_VERIFYLOCK_UNLESS_NOLOCK (*info);
-  /* init false */
-  *valid = false;
-
-  if (info->num_tensors < 1) {
-    _ml_error_report_return (ML_ERROR_INVALID_PARAMETER,
-        "The given tensors_info to be validated has invalid num_tensors (%u). It should be 1 or more.",
-        info->num_tensors);
-  }
-
-  for (i = 0; i < info->num_tensors; i++) {
-    ml_tensor_info_s *tensor_info =
-        ml_tensors_info_get_nth_info ((ml_tensors_info_s *) info, i);
-    if (!ml_tensor_info_validate (tensor_info, info->is_extended))
-      goto done;
-  }
-
-  *valid = true;
-
-done:
-  return ML_ERROR_NONE;
-}
-
-/**
  * @brief Validates the given tensors info is valid.
  */
 int
 ml_tensors_info_validate (const ml_tensors_info_h info, bool *valid)
 {
   ml_tensors_info_s *tensors_info;
-  int ret = ML_ERROR_NONE;
 
   check_feature_state (ML_FEATURE);
 
@@ -411,11 +210,10 @@ ml_tensors_info_validate (const ml_tensors_info_h info, bool *valid)
         "The input parameter, tensors_info, is NULL. It should be a valid ml_tensors_info_h, which is usually created by ml_tensors_info_create().");
 
   G_LOCK_UNLESS_NOLOCK (*tensors_info);
-
-  ret = _ml_tensors_info_validate_nolock (info, valid);
-
+  *valid = gst_tensors_info_validate (&tensors_info->info);
   G_UNLOCK_UNLESS_NOLOCK (*tensors_info);
-  return ret;
+
+  return ML_ERROR_NONE;
 }
 
 /**
@@ -426,7 +224,6 @@ _ml_tensors_info_compare (const ml_tensors_info_h info1,
     const ml_tensors_info_h info2, bool *equal)
 {
   ml_tensors_info_s *i1, *i2;
-  guint i;
 
   check_feature_state (ML_FEATURE);
 
@@ -445,22 +242,8 @@ _ml_tensors_info_compare (const ml_tensors_info_h info1,
   i2 = (ml_tensors_info_s *) info2;
   G_LOCK_UNLESS_NOLOCK (*i2);
 
-  /* init false */
-  *equal = false;
-
-  if (i1->num_tensors != i2->num_tensors)
-    goto done;
+  *equal = gst_tensors_info_is_equal (&i1->info, &i2->info);
 
-  for (i = 0; i < i1->num_tensors; i++) {
-    ml_tensor_info_s *ti1 = ml_tensors_info_get_nth_info (i1, i);
-    ml_tensor_info_s *ti2 = ml_tensors_info_get_nth_info (i2, i);
-    if (!ml_tensor_info_compare (ti1, ti2))
-      goto done;
-  }
-
-  *equal = true;
-
-done:
   G_UNLOCK_UNLESS_NOLOCK (*i2);
   G_UNLOCK_UNLESS_NOLOCK (*i1);
   return ML_ERROR_NONE;
@@ -487,7 +270,7 @@ ml_tensors_info_set_count (ml_tensors_info_h info, unsigned int count)
   tensors_info = (ml_tensors_info_s *) info;
 
   /* This is atomic. No need for locks */
-  tensors_info->num_tensors = count;
+  tensors_info->info.num_tensors = count;
 
   return ML_ERROR_NONE;
 }
@@ -511,7 +294,7 @@ ml_tensors_info_get_count (ml_tensors_info_h info, unsigned int *count)
 
   tensors_info = (ml_tensors_info_s *) info;
   /* This is atomic. No need for locks */
-  *count = tensors_info->num_tensors;
+  *count = tensors_info->info.num_tensors;
 
   return ML_ERROR_NONE;
 }
@@ -524,7 +307,7 @@ ml_tensors_info_set_tensor_name (ml_tensors_info_h info,
     unsigned int index, const char *name)
 {
   ml_tensors_info_s *tensors_info;
-  ml_tensor_info_s *_tensor_info;
+  GstTensorInfo *_info;
 
   check_feature_state (ML_FEATURE);
 
@@ -535,26 +318,21 @@ ml_tensors_info_set_tensor_name (ml_tensors_info_h info,
   tensors_info = (ml_tensors_info_s *) info;
   G_LOCK_UNLESS_NOLOCK (*tensors_info);
 
-  if (tensors_info->num_tensors <= index) {
+  if (tensors_info->info.num_tensors <= index) {
     G_UNLOCK_UNLESS_NOLOCK (*tensors_info);
     _ml_error_report_return (ML_ERROR_INVALID_PARAMETER,
         "The number of tensors in 'info' parameter is %u, which is not larger than the given 'index' %u. Thus, we cannot get %u'th tensor from 'info'. Please set the number of tensors of 'info' correctly or check the value of the given 'index'.",
-        tensors_info->num_tensors, index, index);
+        tensors_info->info.num_tensors, index, index);
   }
 
-  _tensor_info = ml_tensors_info_get_nth_info (tensors_info, index);
-  if (!_tensor_info) {
+  _info = gst_tensors_info_get_nth_info (&tensors_info->info, index);
+  if (!_info) {
     G_UNLOCK_UNLESS_NOLOCK (*tensors_info);
     return ML_ERROR_INVALID_PARAMETER;
   }
 
-  if (_tensor_info->name) {
-    g_free (_tensor_info->name);
-    _tensor_info->name = NULL;
-  }
-
-  if (name)
-    _tensor_info->name = g_strdup (name);
+  g_free (_info->name);
+  _info->name = g_strdup (name);
 
   G_UNLOCK_UNLESS_NOLOCK (*tensors_info);
   return ML_ERROR_NONE;
@@ -568,7 +346,7 @@ ml_tensors_info_get_tensor_name (ml_tensors_info_h info,
     unsigned int index, char **name)
 {
   ml_tensors_info_s *tensors_info;
-  ml_tensor_info_s *_tensor_info;
+  GstTensorInfo *_info;
 
   check_feature_state (ML_FEATURE);
 
@@ -582,21 +360,20 @@ ml_tensors_info_get_tensor_name (ml_tensors_info_h info,
   tensors_info = (ml_tensors_info_s *) info;
   G_LOCK_UNLESS_NOLOCK (*tensors_info);
 
-  if (tensors_info->num_tensors <= index) {
+  if (tensors_info->info.num_tensors <= index) {
     G_UNLOCK_UNLESS_NOLOCK (*tensors_info);
     _ml_error_report_return (ML_ERROR_INVALID_PARAMETER,
         "The number of tensors in 'info' parameter is %u, which is not larger than the given 'index' %u. Thus, we cannot get %u'th tensor from 'info'. Please set the number of tensors of 'info' correctly or check the value of the given 'index'.",
-        tensors_info->num_tensors, index, index);
+        tensors_info->info.num_tensors, index, index);
   }
 
-  _tensor_info = ml_tensors_info_get_nth_info (tensors_info, index);
-  if (!_tensor_info) {
+  _info = gst_tensors_info_get_nth_info (&tensors_info->info, index);
+  if (!_info) {
     G_UNLOCK_UNLESS_NOLOCK (*tensors_info);
     return ML_ERROR_INVALID_PARAMETER;
   }
 
-  *name = g_strdup (_tensor_info->name);
-
+  *name = g_strdup (_info->name);
 
   G_UNLOCK_UNLESS_NOLOCK (*tensors_info);
   return ML_ERROR_NONE;
@@ -610,7 +387,7 @@ ml_tensors_info_set_tensor_type (ml_tensors_info_h info,
     unsigned int index, const ml_tensor_type_e type)
 {
   ml_tensors_info_s *tensors_info;
-  ml_tensor_info_s *_tensor_info;
+  GstTensorInfo *_info;
 
   check_feature_state (ML_FEATURE);
 
@@ -633,20 +410,20 @@ ml_tensors_info_set_tensor_type (ml_tensors_info_h info,
   tensors_info = (ml_tensors_info_s *) info;
   G_LOCK_UNLESS_NOLOCK (*tensors_info);
 
-  if (tensors_info->num_tensors <= index) {
+  if (tensors_info->info.num_tensors <= index) {
     G_UNLOCK_UNLESS_NOLOCK (*tensors_info);
     _ml_error_report_return (ML_ERROR_INVALID_PARAMETER,
         "The number of tensors in 'info' parameter is %u, which is not larger than the given 'index' %u. Thus, we cannot get %u'th tensor from 'info'. Please set the number of tensors of 'info' correctly or check the value of the given 'index'.",
-        tensors_info->num_tensors, index, index);
+        tensors_info->info.num_tensors, index, index);
   }
 
-  _tensor_info = ml_tensors_info_get_nth_info (tensors_info, index);
-  if (!_tensor_info) {
+  _info = gst_tensors_info_get_nth_info (&tensors_info->info, index);
+  if (!_info) {
     G_UNLOCK_UNLESS_NOLOCK (*tensors_info);
     return ML_ERROR_INVALID_PARAMETER;
   }
 
-  _tensor_info->type = type;
+  _info->type = convert_tensor_type_from (type);
 
   G_UNLOCK_UNLESS_NOLOCK (*tensors_info);
   return ML_ERROR_NONE;
@@ -660,7 +437,7 @@ ml_tensors_info_get_tensor_type (ml_tensors_info_h info,
     unsigned int index, ml_tensor_type_e * type)
 {
   ml_tensors_info_s *tensors_info;
-  ml_tensor_info_s *_tensor_info;
+  GstTensorInfo *_info;
 
   check_feature_state (ML_FEATURE);
 
@@ -674,19 +451,20 @@ ml_tensors_info_get_tensor_type (ml_tensors_info_h info,
   tensors_info = (ml_tensors_info_s *) info;
   G_LOCK_UNLESS_NOLOCK (*tensors_info);
 
-  if (tensors_info->num_tensors <= index) {
+  if (tensors_info->info.num_tensors <= index) {
     G_UNLOCK_UNLESS_NOLOCK (*tensors_info);
     _ml_error_report_return (ML_ERROR_INVALID_PARAMETER,
         "The number of tensors in 'info' parameter is %u, which is not larger than the given 'index' %u. Thus, we cannot get %u'th tensor from 'info'. Please set the number of tensors of 'info' correctly or check the value of the given 'index'.",
-        tensors_info->num_tensors, index, index);
+        tensors_info->info.num_tensors, index, index);
   }
 
-  _tensor_info = ml_tensors_info_get_nth_info (tensors_info, index);
-  if (!_tensor_info) {
+  _info = gst_tensors_info_get_nth_info (&tensors_info->info, index);
+  if (!_info) {
     G_UNLOCK_UNLESS_NOLOCK (*tensors_info);
     return ML_ERROR_INVALID_PARAMETER;
   }
-  *type = _tensor_info->type;
+
+  *type = convert_ml_tensor_type_from (_info->type);
 
   G_UNLOCK_UNLESS_NOLOCK (*tensors_info);
   return ML_ERROR_NONE;
@@ -700,7 +478,7 @@ ml_tensors_info_set_tensor_dimension (ml_tensors_info_h info,
     unsigned int index, const ml_tensor_dimension dimension)
 {
   ml_tensors_info_s *tensors_info;
-  ml_tensor_info_s *_tensor_info;
+  GstTensorInfo *_info;
   guint i;
 
   check_feature_state (ML_FEATURE);
@@ -712,25 +490,25 @@ ml_tensors_info_set_tensor_dimension (ml_tensors_info_h info,
   tensors_info = (ml_tensors_info_s *) info;
   G_LOCK_UNLESS_NOLOCK (*tensors_info);
 
-  if (tensors_info->num_tensors <= index) {
+  if (tensors_info->info.num_tensors <= index) {
     G_UNLOCK_UNLESS_NOLOCK (*tensors_info);
     _ml_error_report_return (ML_ERROR_INVALID_PARAMETER,
         "The number of tensors in 'info' parameter is %u, which is not larger than the given 'index' %u. Thus, we cannot get %u'th tensor from 'info'. Please set the number of tensors of 'info' correctly or check the value of the given 'index'.",
-        tensors_info->num_tensors, index, index);
+        tensors_info->info.num_tensors, index, index);
   }
 
-  _tensor_info = ml_tensors_info_get_nth_info (tensors_info, index);
-  if (!_tensor_info) {
+  _info = gst_tensors_info_get_nth_info (&tensors_info->info, index);
+  if (!_info) {
     G_UNLOCK_UNLESS_NOLOCK (*tensors_info);
     return ML_ERROR_INVALID_PARAMETER;
   }
 
   for (i = 0; i < ML_TENSOR_RANK_LIMIT_PREV; i++) {
-    _tensor_info->dimension[i] = dimension[i];
+    _info->dimension[i] = dimension[i];
   }
 
   for (i = ML_TENSOR_RANK_LIMIT_PREV; i < ML_TENSOR_RANK_LIMIT; i++) {
-    _tensor_info->dimension[i] = (tensors_info->is_extended ? dimension[i] : 0);
+    _info->dimension[i] = (tensors_info->is_extended ? dimension[i] : 0);
   }
 
   G_UNLOCK_UNLESS_NOLOCK (*tensors_info);
@@ -745,7 +523,7 @@ ml_tensors_info_get_tensor_dimension (ml_tensors_info_h info,
     unsigned int index, ml_tensor_dimension dimension)
 {
   ml_tensors_info_s *tensors_info;
-  ml_tensor_info_s *_tensor_info;
+  GstTensorInfo *_info;
   guint i, valid_rank = ML_TENSOR_RANK_LIMIT;
 
   check_feature_state (ML_FEATURE);
@@ -757,15 +535,15 @@ ml_tensors_info_get_tensor_dimension (ml_tensors_info_h info,
   tensors_info = (ml_tensors_info_s *) info;
   G_LOCK_UNLESS_NOLOCK (*tensors_info);
 
-  if (tensors_info->num_tensors <= index) {
+  if (tensors_info->info.num_tensors <= index) {
     G_UNLOCK_UNLESS_NOLOCK (*tensors_info);
     _ml_error_report_return (ML_ERROR_INVALID_PARAMETER,
         "The number of tensors in 'info' parameter is %u, which is not larger than the given 'index' %u. Thus, we cannot get %u'th tensor from 'info'. Please set the number of tensors of 'info' correctly or check the value of the given 'index'.",
-        tensors_info->num_tensors, index, index);
+        tensors_info->info.num_tensors, index, index);
   }
 
-  _tensor_info = ml_tensors_info_get_nth_info (tensors_info, index);
-  if (!_tensor_info) {
+  _info = gst_tensors_info_get_nth_info (&tensors_info->info, index);
+  if (!_info) {
     G_UNLOCK_UNLESS_NOLOCK (*tensors_info);
     return ML_ERROR_INVALID_PARAMETER;
   }
@@ -774,7 +552,7 @@ ml_tensors_info_get_tensor_dimension (ml_tensors_info_h info,
     valid_rank = ML_TENSOR_RANK_LIMIT_PREV;
 
   for (i = 0; i < valid_rank; i++) {
-    dimension[i] = _tensor_info->dimension[i];
+    dimension[i] = _info->dimension[i];
   }
 
   for (; i < ML_TENSOR_RANK_LIMIT; i++)
@@ -785,55 +563,6 @@ ml_tensors_info_get_tensor_dimension (ml_tensors_info_h info,
 }
 
 /**
- * @brief Gets the byte size of the given tensor info.
- */
-size_t
-_ml_tensor_info_get_size (const ml_tensor_info_s * info, bool is_extended)
-{
-  size_t tensor_size;
-  gint i, valid_rank = ML_TENSOR_RANK_LIMIT;
-
-  if (!info)
-    return 0;
-
-  switch (info->type) {
-    case ML_TENSOR_TYPE_INT8:
-    case ML_TENSOR_TYPE_UINT8:
-      tensor_size = 1;
-      break;
-    case ML_TENSOR_TYPE_INT16:
-    case ML_TENSOR_TYPE_UINT16:
-    case ML_TENSOR_TYPE_FLOAT16:
-      tensor_size = 2;
-      break;
-    case ML_TENSOR_TYPE_INT32:
-    case ML_TENSOR_TYPE_UINT32:
-    case ML_TENSOR_TYPE_FLOAT32:
-      tensor_size = 4;
-      break;
-    case ML_TENSOR_TYPE_FLOAT64:
-    case ML_TENSOR_TYPE_INT64:
-    case ML_TENSOR_TYPE_UINT64:
-      tensor_size = 8;
-      break;
-    default:
-      _ml_loge ("In the given param, tensor type is invalid.");
-      return 0;
-  }
-
-  if (!is_extended)
-    valid_rank = ML_TENSOR_RANK_LIMIT_PREV;
-
-  for (i = 0; i < valid_rank; i++) {
-    if (info->dimension[i] == 0)
-      break;
-    tensor_size *= info->dimension[i];
-  }
-
-  return tensor_size;
-}
-
-/**
  * @brief Gets the byte size of the given handle of tensors information.
  */
 int
@@ -841,7 +570,6 @@ ml_tensors_info_get_tensor_size (ml_tensors_info_h info,
     int index, size_t *data_size)
 {
   ml_tensors_info_s *tensors_info;
-  ml_tensor_info_s *_tensor_info;
 
   check_feature_state (ML_FEATURE);
 
@@ -858,38 +586,31 @@ ml_tensors_info_get_tensor_size (ml_tensors_info_h info,
   /* init 0 */
   *data_size = 0;
 
-  if (index >= 0 && tensors_info->num_tensors <= index) {
+  if (index >= 0 && tensors_info->info.num_tensors <= index) {
     G_UNLOCK_UNLESS_NOLOCK (*tensors_info);
     _ml_error_report_return (ML_ERROR_INVALID_PARAMETER,
         "The number of tensors in 'info' parameter is %u, which is not larger than the given 'index' %u. Thus, we cannot get %u'th tensor from 'info'. Please set the number of tensors of 'info' correctly or check the value of the given 'index'.",
-        tensors_info->num_tensors, index, index);
+        tensors_info->info.num_tensors, index, index);
   }
 
-  if (index < 0) {
-    guint i;
+  *data_size = gst_tensors_info_get_size (&tensors_info->info, index);
 
-    /* get total byte size */
-    for (i = 0; i < tensors_info->num_tensors; i++) {
-      _tensor_info = ml_tensors_info_get_nth_info (tensors_info, i);
-      if (!_tensor_info) {
-        G_UNLOCK_UNLESS_NOLOCK (*tensors_info);
-        return ML_ERROR_INVALID_PARAMETER;
-      }
-      *data_size +=
-          _ml_tensor_info_get_size (_tensor_info, tensors_info->is_extended);
-    }
-  } else {
-    _tensor_info = ml_tensors_info_get_nth_info (tensors_info, index);
-    if (!_tensor_info) {
-      G_UNLOCK_UNLESS_NOLOCK (*tensors_info);
-      return ML_ERROR_INVALID_PARAMETER;
-    }
+  G_UNLOCK_UNLESS_NOLOCK (*tensors_info);
+  return ML_ERROR_NONE;
+}
 
-    *data_size =
-        _ml_tensor_info_get_size (_tensor_info, tensors_info->is_extended);
-  }
+/**
+ * @brief Initializes the tensors information with default value.
+ */
+int
+_ml_tensors_info_initialize (ml_tensors_info_s * info)
+{
+  if (!info)
+    _ml_error_report_return (ML_ERROR_INVALID_PARAMETER,
+        "The parameter, info, is NULL. Provide a valid pointer.");
+
+  gst_tensors_info_init (&info->info);
 
-  G_UNLOCK_UNLESS_NOLOCK (*tensors_info);
   return ML_ERROR_NONE;
 }
 
@@ -900,28 +621,10 @@ ml_tensors_info_get_tensor_size (ml_tensors_info_h info,
 void
 _ml_tensors_info_free (ml_tensors_info_s * info)
 {
-  gint i;
-
   if (!info)
     return;
 
-  for (i = 0; i < ML_TENSOR_SIZE_LIMIT_STATIC; i++) {
-    if (info->info[i].name) {
-      g_free (info->info[i].name);
-    }
-  }
-
-  if (info->extra) {
-    for (i = 0; i < ML_TENSOR_SIZE_EXTRA_LIMIT; i++) {
-      if (info->extra[i].name) {
-        g_free (info->extra[i].name);
-      }
-    }
-
-    g_free (info->extra);
-  }
-
-  _ml_tensors_info_initialize (info);
+  gst_tensors_info_free (&info->info);
 }
 
 /**
@@ -1023,11 +726,9 @@ _ml_tensors_data_create_no_alloc (const ml_tensors_info_h info,
     ml_tensors_info_clone (_data->info, info);
 
     G_LOCK_UNLESS_NOLOCK (*_info);
-    _data->num_tensors = _info->num_tensors;
+    _data->num_tensors = _info->info.num_tensors;
     for (i = 0; i < _data->num_tensors; i++) {
-      ml_tensor_info_s *_tensor_info = ml_tensors_info_get_nth_info (_info, i);
-      _data->tensors[i].size =
-          _ml_tensor_info_get_size (_tensor_info, _info->is_extended);
+      _data->tensors[i].size = gst_tensors_info_get_size (&_info->info, i);
       _data->tensors[i].data = NULL;
     }
     G_UNLOCK_UNLESS_NOLOCK (*_info);
@@ -1264,8 +965,6 @@ int
 ml_tensors_info_clone (ml_tensors_info_h dest, const ml_tensors_info_h src)
 {
   ml_tensors_info_s *dest_info, *src_info;
-  guint i, j;
-  bool valid;
   int status = ML_ERROR_NONE;
 
   check_feature_state (ML_FEATURE);
@@ -1283,49 +982,16 @@ ml_tensors_info_clone (ml_tensors_info_h dest, const ml_tensors_info_h src)
   G_LOCK_UNLESS_NOLOCK (*dest_info);
   G_LOCK_UNLESS_NOLOCK (*src_info);
 
-  status = _ml_tensors_info_validate_nolock (src_info, &valid);
-  if (status != ML_ERROR_NONE) {
-    _ml_error_report_continue
-        ("Cannot check the validity of src. Maybe src is not valid or its internal data is not consistent.");
-    goto done;
-  }
-  if (!valid) {
+  if (gst_tensors_info_validate (&src_info->info)) {
+    dest_info->is_extended = src_info->is_extended;
+    gst_tensors_info_copy (&dest_info->info, &src_info->info);
+  } else {
     _ml_error_report
         ("The parameter, src, is a ml_tensors_info_h handle without valid data. Every tensor-info of tensors-info should have a valid type and dimension information and the number of tensors should be between 1 and %d.",
         ML_TENSOR_SIZE_LIMIT);
     status = ML_ERROR_INVALID_PARAMETER;
-    goto done;
-  }
-
-  _ml_tensors_info_initialize (dest_info);
-
-  dest_info->num_tensors = src_info->num_tensors;
-  dest_info->is_extended = src_info->is_extended;
-
-  for (i = 0; i < dest_info->num_tensors; i++) {
-    ml_tensor_info_s *dest_tensor_info =
-        ml_tensors_info_get_nth_info (dest_info, i);
-    ml_tensor_info_s *src_tensor_info =
-        ml_tensors_info_get_nth_info (src_info, i);
-
-    if (!dest_tensor_info || !src_tensor_info) {
-      _ml_error_report
-          ("Cannot get the %u'th tensor info from src or dest. Maybe src or dest is not valid or its internal data is not consistent.",
-          i);
-      status = ML_ERROR_INVALID_PARAMETER;
-      goto done;
-    }
-
-    dest_tensor_info->name =
-        (src_tensor_info->name) ? g_strdup (src_tensor_info->name) : NULL;
-    dest_tensor_info->type = src_tensor_info->type;
-
-    for (j = 0; j < ML_TENSOR_RANK_LIMIT; j++) {
-      dest_tensor_info->dimension[j] = src_tensor_info->dimension[j];
-    }
   }
 
-done:
   G_UNLOCK_UNLESS_NOLOCK (*src_info);
   G_UNLOCK_UNLESS_NOLOCK (*dest_info);
 
index fdcb8ed..efd78d3 100644 (file)
 #include "ml-api-internal.h"
 
 /**
- * @brief Convert the type from ml_tensor_type_e to tensor_type.
- * @note This code is based on the same order between NNS type and ML type.
- * The index should be the same in case of adding a new type.
- */
-static tensor_type
-convert_tensor_type_from (ml_tensor_type_e type)
-{
-  if (type < ML_TENSOR_TYPE_INT32 || type >= ML_TENSOR_TYPE_UNKNOWN) {
-    _ml_error_report
-        ("Failed to convert the type. Input ml_tensor_type_e %d is invalid.",
-        type);
-    return _NNS_END;
-  }
-
-  return (tensor_type) type;
-}
-
-/**
- * @brief Convert the type from tensor_type to ml_tensor_type_e.
- * @note This code is based on the same order between NNS type and ML type.
- * The index should be the same in case of adding a new type.
- */
-static ml_tensor_type_e
-convert_ml_tensor_type_from (tensor_type type)
-{
-  if (type < _NNS_INT32 || type >= _NNS_END) {
-    _ml_error_report
-        ("Failed to convert the type. Input tensor_type %d is invalid.", type);
-    return ML_TENSOR_TYPE_UNKNOWN;
-  }
-
-  return (ml_tensor_type_e) type;
-}
-
-/**
  * @brief Check tensor-info has extended rank value.
  */
 static gboolean
@@ -107,11 +72,10 @@ _ml_tensors_info_create_from_gst (ml_tensors_info_h * ml_info,
  * @bug Thread safety required. Check its internal users first!
  */
 int
-_ml_tensors_info_copy_from_gst (ml_tensors_info_s * ml_info,
+_ml_tensors_info_copy_from_gst (ml_tensors_info_h ml_info,
     const GstTensorsInfo * gst_info)
 {
-  guint i, j;
-  guint max_dim;
+  ml_tensors_info_s *_info;
 
   if (!ml_info)
     _ml_error_report_return (ML_ERROR_INVALID_PARAMETER,
@@ -120,54 +84,13 @@ _ml_tensors_info_copy_from_gst (ml_tensors_info_s * ml_info,
     _ml_error_report_return (ML_ERROR_INVALID_PARAMETER,
         "The parmater, gst_info, is NULL. It should be a valid GstTensorsInfo instance. This is probably an internal bug of ML API.");
 
-  _ml_tensors_info_initialize (ml_info);
-
-  max_dim = MIN (ML_TENSOR_RANK_LIMIT, NNS_TENSOR_RANK_LIMIT);
+  _info = (ml_tensors_info_s *) ml_info;
 
-  ml_info->num_tensors = gst_info->num_tensors;
-  ml_info->is_extended = gst_info_is_extended (gst_info);
-  if (gst_info->extra) {
-    /* create ml_info_extra in ml_tensors_info_s */
-    _ml_tensors_info_create_extra (ml_info);
-  }
+  G_LOCK_UNLESS_NOLOCK (*_info);
+  _info->is_extended = gst_info_is_extended (gst_info);
+  gst_tensors_info_copy (&_info->info, gst_info);
+  G_UNLOCK_UNLESS_NOLOCK (*_info);
 
-  for (i = 0; i < gst_info->num_tensors; i++) {
-    GstTensorInfo *_gst_tensor_info =
-        gst_tensors_info_get_nth_info ((GstTensorsInfo *) gst_info, i);
-    ml_tensor_info_s *_ml_tensor_info =
-        ml_tensors_info_get_nth_info (ml_info, i);
-    if (!_gst_tensor_info) {
-      _ml_error_report_return (ML_ERROR_INVALID_PARAMETER,
-          "The parameter, gst_info, is invalid. It should be a valid GstTensorsInfo instance. This is probably an internal bug of ML API.");
-    }
-
-    if (!_ml_tensor_info) {
-      _ml_error_report_return (ML_ERROR_INVALID_PARAMETER,
-          "The parameter, ml_info, is invalid. It should be a valid ml_tensors_info_s instance, usually created by ml_tensors_info_create(). This is probably an internal bug of ML API.");
-    }
-
-    if (_gst_tensor_info->name) {
-      _ml_tensor_info->name = g_strdup (_gst_tensor_info->name);
-    }
-
-    _ml_tensor_info->type =
-        convert_ml_tensor_type_from (_gst_tensor_info->type);
-
-    /* Set dimension */
-    for (j = 0; j < max_dim; j++) {
-      _ml_tensor_info->dimension[j] = _gst_tensor_info->dimension[j];
-    }
-
-    for (; j < ML_TENSOR_RANK_LIMIT; j++) {
-      _ml_tensor_info->dimension[j] = 0U;
-    }
-
-    if (!ml_info->is_extended) {
-      for (j = ML_TENSOR_RANK_LIMIT_PREV; j < ML_TENSOR_RANK_LIMIT; j++) {
-        _ml_tensor_info->dimension[j] = 0U;
-      }
-    }
-  }
   return ML_ERROR_NONE;
 }
 
@@ -177,10 +100,9 @@ _ml_tensors_info_copy_from_gst (ml_tensors_info_s * ml_info,
  */
 int
 _ml_tensors_info_copy_from_ml (GstTensorsInfo * gst_info,
-    const ml_tensors_info_s * ml_info)
+    const ml_tensors_info_h ml_info)
 {
-  guint i, j;
-  guint max_dim;
+  ml_tensors_info_s *_info;
 
   if (!ml_info)
     _ml_error_report_return (ML_ERROR_INVALID_PARAMETER,
@@ -189,55 +111,11 @@ _ml_tensors_info_copy_from_ml (GstTensorsInfo * gst_info,
     _ml_error_report_return (ML_ERROR_INVALID_PARAMETER,
         "The parmater, gst_info, is NULL. It should be a valid GstTensorsInfo instance. This is probably an internal bug of ML API.");
 
-  G_LOCK_UNLESS_NOLOCK (*ml_info);
-
-  gst_tensors_info_init (gst_info);
-  max_dim = MIN (ML_TENSOR_RANK_LIMIT, NNS_TENSOR_RANK_LIMIT);
-
-  gst_info->num_tensors = ml_info->num_tensors;
-
-  for (i = 0; i < ml_info->num_tensors; i++) {
-    ml_tensor_info_s *_ml_tensor_info =
-        ml_tensors_info_get_nth_info ((ml_tensors_info_s *) ml_info, i);
-    GstTensorInfo *_gst_tensor_info =
-        gst_tensors_info_get_nth_info (gst_info, i);
-
-    if (!_gst_tensor_info) {
-      G_UNLOCK_UNLESS_NOLOCK (*ml_info);
-      _ml_error_report_return (ML_ERROR_INVALID_PARAMETER,
-          "The parameter, gst_info, is invalid. It should be a valid GstTensorsInfo instance. This is probably an internal bug of ML API.");
-    }
-
-    if (!_ml_tensor_info) {
-      G_UNLOCK_UNLESS_NOLOCK (*ml_info);
-      _ml_error_report_return (ML_ERROR_INVALID_PARAMETER,
-          "The parameter, ml_info, is invalid. It should be a valid ml_tensors_info_s instance, usually created by ml_tensors_info_create(). This is probably an internal bug of ML API.");
-    }
-
-    /* Copy name string */
-    if (_ml_tensor_info->name) {
-      _gst_tensor_info->name = g_strdup (_ml_tensor_info->name);
-    }
-
-    /* Copy type */
-    _gst_tensor_info->type = convert_tensor_type_from (_ml_tensor_info->type);
-
-    /* Set dimension */
-    for (j = 0; j < max_dim; j++) {
-      _gst_tensor_info->dimension[j] = _ml_tensor_info->dimension[j];
-    }
-
-    for (; j < NNS_TENSOR_RANK_LIMIT; j++) {
-      _gst_tensor_info->dimension[j] = 0;
-    }
-
-    if (!ml_info->is_extended) {
-      for (j = ML_TENSOR_RANK_LIMIT_PREV; j < NNS_TENSOR_RANK_LIMIT; j++) {
-        _gst_tensor_info->dimension[j] = 0;
-      }
-    }
-  }
-  G_UNLOCK_UNLESS_NOLOCK (*ml_info);
+  _info = (ml_tensors_info_s *) ml_info;
+
+  G_LOCK_UNLESS_NOLOCK (*_info);
+  gst_tensors_info_copy (gst_info, &_info->info);
+  G_UNLOCK_UNLESS_NOLOCK (*_info);
 
   return ML_ERROR_NONE;
 }
index a601fb5..06ffc2a 100644 (file)
@@ -36,12 +36,12 @@ int _ml_tensors_info_create_from_gst (ml_tensors_info_h *ml_info, GstTensorsInfo
 /**
  * @brief Copies tensor metadata from gst tensors info.
  */
-int _ml_tensors_info_copy_from_gst (ml_tensors_info_s *ml_info, const GstTensorsInfo *gst_info);
+int _ml_tensors_info_copy_from_gst (ml_tensors_info_ml_info, const GstTensorsInfo *gst_info);
 
 /**
  * @brief Copies tensor metadata from ml tensors info.
  */
-int _ml_tensors_info_copy_from_ml (GstTensorsInfo *gst_info, const ml_tensors_info_s *ml_info);
+int _ml_tensors_info_copy_from_ml (GstTensorsInfo *gst_info, const ml_tensors_info_ml_info);
 
 #ifdef __cplusplus
 }
index 91605b4..6083cef 100644 (file)
@@ -136,36 +136,14 @@ typedef enum {
 #define ML_TENSOR_RANK_LIMIT_PREV  (4)
 
 /**
- * @brief The tensor size limit with static gst buffer.
- */
-#define ML_TENSOR_SIZE_LIMIT_STATIC  (16)
-
-/**
- * @brief The size limit of "extra" tensors.
- */
-#define ML_TENSOR_SIZE_EXTRA_LIMIT (ML_TENSOR_SIZE_LIMIT - ML_TENSOR_SIZE_LIMIT_STATIC)
-
-/**
- * @brief Data structure for tensor information.
- * @since_tizen 5.5
- */
-typedef struct {
-  char *name;              /**< Name of each element in the tensor. */
-  ml_tensor_type_e type;   /**< Type of each element in the tensor. */
-  ml_tensor_dimension dimension;     /**< Dimension information. */
-} ml_tensor_info_s;
-
-/**
  * @brief Data structure for tensors information, which contains multiple tensors.
  * @since_tizen 5.5
  */
 typedef struct {
-  unsigned int num_tensors; /**< The number of tensors. */
-  ml_tensor_info_s info[ML_TENSOR_SIZE_LIMIT_STATIC];  /**< The list of tensor info. */
-  ml_tensor_info_s *extra; /**< The list of extra tensor info. */
   GMutex lock; /**< Lock for thread safety */
   int nolock; /**< Set non-zero to avoid using m (giving up thread safety) */
   bool is_extended; /**< True if tensors are extended */
+  GstTensorsInfo info;
 } ml_tensors_info_s;
 
 /**
@@ -243,22 +221,6 @@ typedef struct {
 } ml_tensors_data_s;
 
 /**
- * @brief Gets the byte size of the given tensor info.
- * @note This is not thread safe.
- */
-size_t _ml_tensor_info_get_size (const ml_tensor_info_s *info, bool is_extended);
-
-/**
- * @brief Allocates memory in given tensors_info for extra tensor infos.
- */
-gboolean _ml_tensors_info_create_extra (ml_tensors_info_s * ml_info);
-
-/**
- * @brief Initializes given tensor_info with default value.
- */
-int _ml_tensor_info_initialize (ml_tensor_info_s * info);
-
-/**
  * @brief Initializes the tensors information with default value.
  * @since_tizen 5.5
  * @param[in] info The tensors info pointer to be initialized.
@@ -276,11 +238,6 @@ int _ml_tensors_info_initialize (ml_tensors_info_s *info);
 void _ml_tensors_info_free (ml_tensors_info_s *info);
 
 /**
- * @brief Get the pointer of nth tensor info.
- */
-ml_tensor_info_s * ml_tensors_info_get_nth_info (ml_tensors_info_s *info, guint nth);
-
-/**
  * @brief Creates a tensor data frame without allocating new buffer cloning the given tensors data.
  * @details If @a data_src is null, this returns error.
  * @param[in] data_src The handle of tensors data to be cloned.
index a46aefe..64e7770 100644 (file)
@@ -581,6 +581,7 @@ nns_convert_tensors_info (pipeline_info_s * pipe_info, JNIEnv * env,
   guint i;
   info_class_info_s *icls_info;
   ml_tensors_info_s *info;
+  GstTensorInfo *_info;
   jobject obj_info = NULL;
 
   g_return_val_if_fail (pipe_info, FALSE);
@@ -597,19 +598,21 @@ nns_convert_tensors_info (pipeline_info_s * pipe_info, JNIEnv * env,
     goto done;
   }
 
-  for (i = 0; i < info->num_tensors; i++) {
+  for (i = 0; i < info->info.num_tensors; i++) {
     jstring name = NULL;
     jint type;
     jintArray dimension;
 
-    if (info->info[i].name)
-      name = (*env)->NewStringUTF (env, info->info[i].name);
+    _info = gst_tensors_info_get_nth_info (&info->info, i);
 
-    type = (jint) info->info[i].type;
+    if (_info->name)
+      name = (*env)->NewStringUTF (env, _info->name);
+
+    type = (jint) _info->type;
 
     dimension = (*env)->NewIntArray (env, ML_TENSOR_RANK_LIMIT);
     (*env)->SetIntArrayRegion (env, dimension, 0, ML_TENSOR_RANK_LIMIT,
-        (jint *) info->info[i].dimension);
+        (jint *) _info->dimension);
 
     (*env)->CallVoidMethod (env, obj_info, icls_info->mid_add_info,
         name, type, dimension);
@@ -634,6 +637,7 @@ nns_parse_tensors_info (pipeline_info_s * pipe_info, JNIEnv * env,
   guint i;
   info_class_info_s *icls_info;
   ml_tensors_info_s *info;
+  GstTensorInfo *_info;
   jobjectArray info_arr;
 
   g_return_val_if_fail (pipe_info, FALSE);
@@ -652,15 +656,16 @@ nns_parse_tensors_info (pipeline_info_s * pipe_info, JNIEnv * env,
   info_arr = (*env)->CallObjectMethod (env, obj_info, icls_info->mid_get_array);
 
   /* number of tensors info */
-  info->num_tensors = (unsigned int) (*env)->GetArrayLength (env, info_arr);
+  info->info.num_tensors = (unsigned int) (*env)->GetArrayLength (env, info_arr);
 
   /* read tensor info */
-  for (i = 0; i < info->num_tensors; i++) {
+  for (i = 0; i < info->info.num_tensors; i++) {
     jobject item;
     jstring name_str;
     jintArray dimension;
 
     item = (*env)->GetObjectArrayElement (env, info_arr, i);
+    _info = gst_tensors_info_get_nth_info (&info->info, i);
 
     /* tensor name */
     name_str = (jstring) (*env)->GetObjectField (env, item,
@@ -668,20 +673,20 @@ nns_parse_tensors_info (pipeline_info_s * pipe_info, JNIEnv * env,
     if (name_str) {
       const gchar *name = (*env)->GetStringUTFChars (env, name_str, NULL);
 
-      info->info[i].name = g_strdup (name);
+      _info->name = g_strdup (name);
       (*env)->ReleaseStringUTFChars (env, name_str, name);
       (*env)->DeleteLocalRef (env, name_str);
     }
 
     /* tensor type */
-    info->info[i].type = (ml_tensor_type_e) (*env)->GetIntField (env, item,
+    _info->type = (tensor_type) (*env)->GetIntField (env, item,
         icls_info->fid_info_type);
 
     /* tensor dimension */
     dimension = (jintArray) (*env)->GetObjectField (env, item,
         icls_info->fid_info_dim);
     (*env)->GetIntArrayRegion (env, dimension, 0, ML_TENSOR_RANK_LIMIT,
-        (jint *) info->info[i].dimension);
+        (jint *) _info->dimension);
     (*env)->DeleteLocalRef (env, dimension);
 
     (*env)->DeleteLocalRef (env, item);
index 470b7c3..67bd1cd 100644 (file)
@@ -2948,16 +2948,15 @@ TEST (nnstreamer_capi_util, info_comp_0)
 {
   bool equal;
   ml_tensors_info_h info1, info2;
-  ml_tensors_info_s *is;
   int status = ml_tensors_info_create (&info1);
   ASSERT_EQ (status, ML_ERROR_NONE);
   status = ml_tensors_info_create (&info2);
   ASSERT_EQ (status, ML_ERROR_NONE);
 
-  is = (ml_tensors_info_s *) info1;
-  is->num_tensors = 1;
-  is = (ml_tensors_info_s *) info2;
-  is->num_tensors = 2;
+  status = ml_tensors_info_set_count (info1, 1U);
+  ASSERT_EQ (status, ML_ERROR_NONE);
+  status = ml_tensors_info_set_count (info2, 2U);
+  ASSERT_EQ (status, ML_ERROR_NONE);
 
   status = _ml_tensors_info_compare (info1, info2, &equal);
   ASSERT_EQ (status, ML_ERROR_NONE);
@@ -3592,66 +3591,6 @@ TEST (nnstreamer_capi_util, info_clone_02_n)
 }
 
 /**
- * @brief Test utility function `ml_tensors_info_get_nth_info`
- */
-TEST (nnstreamer_capi_util, get_nth_info_00)
-{
-  int status;
-  ml_tensors_info_h info;
-
-  status = ml_tensors_info_create (&info);
-  ASSERT_EQ (status, ML_ERROR_NONE);
-
-  status = ml_tensors_info_set_count (info, 1U);
-  ASSERT_EQ (status, ML_ERROR_NONE);
-
-  status = ml_tensors_info_set_tensor_type (info, 0U, ML_TENSOR_TYPE_UINT8);
-  ASSERT_EQ (status, ML_ERROR_NONE);
-
-  ml_tensor_dimension in_dim = { 5, 1, 1, 1 };
-  status = ml_tensors_info_set_tensor_dimension (info, 0U, in_dim);
-  ASSERT_EQ (status, ML_ERROR_NONE);
-
-  status = ml_tensors_info_set_tensor_name (info, 0U, "test");
-  ASSERT_EQ (status, ML_ERROR_NONE);
-
-  ml_tensors_info_s *info_s = (ml_tensors_info_s *) info;
-  ml_tensor_info_s *tinfo_s = ml_tensors_info_get_nth_info (info_s, 0U);
-  EXPECT_NE (tinfo_s, nullptr);
-
-  EXPECT_EQ (tinfo_s->type, ML_TENSOR_TYPE_UINT8);
-  EXPECT_EQ (tinfo_s->dimension[0], 5U);
-  EXPECT_STREQ (tinfo_s->name, "test");
-
-  status = ml_tensors_info_destroy (info);
-  ASSERT_EQ (status, ML_ERROR_NONE);
-}
-
-/**
- * @brief Test utility function `ml_tensors_info_get_nth_info`
- */
-TEST (nnstreamer_capi_util, get_nth_info_01_n)
-{
-  EXPECT_EQ (ml_tensors_info_get_nth_info (NULL, 0U), nullptr);
-
-  ml_tensors_info_s info;
-  EXPECT_EQ (ml_tensors_info_get_nth_info (&info, ML_TENSOR_SIZE_LIMIT), nullptr);
-}
-
-/**
- * @brief Test internal util functions for extra info.
- */
-TEST (nnstreamer_capi_util, info_extra_n)
-{
-  int status;
-
-  status = _ml_tensor_info_initialize (NULL);
-  EXPECT_EQ (status, ML_ERROR_INVALID_PARAMETER);
-
-  EXPECT_FALSE (_ml_tensors_info_create_extra (NULL));
-}
-
-/**
  * @brief Test utility functions (public)
  */
 TEST (nnstreamer_capi_util, data_create_01_n)
@@ -6923,7 +6862,7 @@ TEST (nnstreamer_capi_internal, copy_from_gst)
   status = ml_tensors_info_create (&ml_info);
   EXPECT_EQ (status, ML_ERROR_NONE);
 
-  _ml_tensors_info_copy_from_gst ((ml_tensors_info_s *) ml_info, &gst_info);
+  _ml_tensors_info_copy_from_gst (ml_info, &gst_info);
   status = ml_tensors_info_get_count (ml_info, &count);
   EXPECT_EQ (status, ML_ERROR_NONE);
   EXPECT_EQ (count, 2U);
@@ -6936,7 +6875,7 @@ TEST (nnstreamer_capi_internal, copy_from_gst)
 
   gst_info.info[0].type = _NNS_INT32;
   gst_info.info[1].type = _NNS_UINT32;
-  _ml_tensors_info_copy_from_gst ((ml_tensors_info_s *) ml_info, &gst_info);
+  _ml_tensors_info_copy_from_gst (ml_info, &gst_info);
   status = ml_tensors_info_get_tensor_type (ml_info, 0, &type);
   EXPECT_EQ (status, ML_ERROR_NONE);
   EXPECT_EQ (type, ML_TENSOR_TYPE_INT32);
@@ -6946,7 +6885,7 @@ TEST (nnstreamer_capi_internal, copy_from_gst)
 
   gst_info.info[0].type = _NNS_INT16;
   gst_info.info[1].type = _NNS_UINT16;
-  _ml_tensors_info_copy_from_gst ((ml_tensors_info_s *) ml_info, &gst_info);
+  _ml_tensors_info_copy_from_gst (ml_info, &gst_info);
   status = ml_tensors_info_get_tensor_type (ml_info, 0, &type);
   EXPECT_EQ (status, ML_ERROR_NONE);
   EXPECT_EQ (type, ML_TENSOR_TYPE_INT16);
@@ -6956,7 +6895,7 @@ TEST (nnstreamer_capi_internal, copy_from_gst)
 
   gst_info.info[0].type = _NNS_INT8;
   gst_info.info[1].type = _NNS_UINT8;
-  _ml_tensors_info_copy_from_gst ((ml_tensors_info_s *) ml_info, &gst_info);
+  _ml_tensors_info_copy_from_gst (ml_info, &gst_info);
   status = ml_tensors_info_get_tensor_type (ml_info, 0, &type);
   EXPECT_EQ (status, ML_ERROR_NONE);
   EXPECT_EQ (type, ML_TENSOR_TYPE_INT8);
@@ -6966,7 +6905,7 @@ TEST (nnstreamer_capi_internal, copy_from_gst)
 
   gst_info.info[0].type = _NNS_INT64;
   gst_info.info[1].type = _NNS_UINT64;
-  _ml_tensors_info_copy_from_gst ((ml_tensors_info_s *) ml_info, &gst_info);
+  _ml_tensors_info_copy_from_gst (ml_info, &gst_info);
   status = ml_tensors_info_get_tensor_type (ml_info, 0, &type);
   EXPECT_EQ (status, ML_ERROR_NONE);
   EXPECT_EQ (type, ML_TENSOR_TYPE_INT64);
@@ -6976,7 +6915,7 @@ TEST (nnstreamer_capi_internal, copy_from_gst)
 
   gst_info.info[0].type = _NNS_FLOAT64;
   gst_info.info[1].type = _NNS_FLOAT32;
-  _ml_tensors_info_copy_from_gst ((ml_tensors_info_s *) ml_info, &gst_info);
+  _ml_tensors_info_copy_from_gst (ml_info, &gst_info);
   status = ml_tensors_info_get_tensor_type (ml_info, 0, &type);
   EXPECT_EQ (status, ML_ERROR_NONE);
   EXPECT_EQ (type, ML_TENSOR_TYPE_FLOAT64);
@@ -6986,7 +6925,7 @@ TEST (nnstreamer_capi_internal, copy_from_gst)
 
   gst_info.info[0].name = g_strdup ("tn1");
   gst_info.info[1].name = g_strdup ("tn2");
-  _ml_tensors_info_copy_from_gst ((ml_tensors_info_s *) ml_info, &gst_info);
+  _ml_tensors_info_copy_from_gst (ml_info, &gst_info);
   status = ml_tensors_info_get_tensor_name (ml_info, 0, &name);
   EXPECT_EQ (status, ML_ERROR_NONE);
   EXPECT_STREQ (name, "tn1");
@@ -7027,7 +6966,7 @@ TEST (nnstreamer_capi_internal, copy_from_gst_extended)
   status = ml_tensors_info_create_extended (&ml_info);
   EXPECT_EQ (status, ML_ERROR_NONE);
 
-  _ml_tensors_info_copy_from_gst ((ml_tensors_info_s *) ml_info, &gst_info);
+  _ml_tensors_info_copy_from_gst (ml_info, &gst_info);
   status = ml_tensors_info_get_count (ml_info, &count);
   EXPECT_EQ (status, ML_ERROR_NONE);
   EXPECT_EQ (count, 2U);
@@ -7067,7 +7006,7 @@ TEST (nnstreamer_capi_internal, copy_from_gst_02_n)
   status = ml_tensors_info_create (&ml_info);
   EXPECT_EQ (status, ML_ERROR_NONE);
 
-  status = _ml_tensors_info_copy_from_gst ((ml_tensors_info_s *) ml_info, NULL);
+  status = _ml_tensors_info_copy_from_gst (ml_info, NULL);
   EXPECT_NE (status, ML_ERROR_NONE);
 
   status = ml_tensors_info_destroy (ml_info);
@@ -7095,7 +7034,7 @@ TEST (nnstreamer_capi_internal, copy_from_ml)
   status = ml_tensors_info_set_tensor_dimension (ml_info, 1, dim);
   EXPECT_EQ (status, ML_ERROR_NONE);
 
-  _ml_tensors_info_copy_from_ml (&gst_info, (ml_tensors_info_s *) ml_info);
+  _ml_tensors_info_copy_from_ml (&gst_info, ml_info);
   EXPECT_EQ (gst_info.num_tensors, 2U);
   EXPECT_EQ (gst_info.info[0].dimension[0], 1U);
   EXPECT_EQ (gst_info.info[0].dimension[1], 2U);
@@ -7106,7 +7045,7 @@ TEST (nnstreamer_capi_internal, copy_from_ml)
   EXPECT_EQ (status, ML_ERROR_NONE);
   status = ml_tensors_info_set_tensor_type (ml_info, 1, ML_TENSOR_TYPE_UINT32);
   EXPECT_EQ (status, ML_ERROR_NONE);
-  _ml_tensors_info_copy_from_ml (&gst_info, (ml_tensors_info_s *) ml_info);
+  _ml_tensors_info_copy_from_ml (&gst_info, ml_info);
   EXPECT_EQ (gst_info.info[0].type, _NNS_INT32);
   EXPECT_EQ (gst_info.info[1].type, _NNS_UINT32);
 
@@ -7114,7 +7053,7 @@ TEST (nnstreamer_capi_internal, copy_from_ml)
   EXPECT_EQ (status, ML_ERROR_NONE);
   status = ml_tensors_info_set_tensor_type (ml_info, 1, ML_TENSOR_TYPE_UINT16);
   EXPECT_EQ (status, ML_ERROR_NONE);
-  _ml_tensors_info_copy_from_ml (&gst_info, (ml_tensors_info_s *) ml_info);
+  _ml_tensors_info_copy_from_ml (&gst_info, ml_info);
   EXPECT_EQ (gst_info.info[0].type, _NNS_INT16);
   EXPECT_EQ (gst_info.info[1].type, _NNS_UINT16);
 
@@ -7122,7 +7061,7 @@ TEST (nnstreamer_capi_internal, copy_from_ml)
   EXPECT_EQ (status, ML_ERROR_NONE);
   status = ml_tensors_info_set_tensor_type (ml_info, 1, ML_TENSOR_TYPE_UINT8);
   EXPECT_EQ (status, ML_ERROR_NONE);
-  _ml_tensors_info_copy_from_ml (&gst_info, (ml_tensors_info_s *) ml_info);
+  _ml_tensors_info_copy_from_ml (&gst_info, ml_info);
   EXPECT_EQ (gst_info.info[0].type, _NNS_INT8);
   EXPECT_EQ (gst_info.info[1].type, _NNS_UINT8);
 
@@ -7130,7 +7069,7 @@ TEST (nnstreamer_capi_internal, copy_from_ml)
   EXPECT_EQ (status, ML_ERROR_NONE);
   status = ml_tensors_info_set_tensor_type (ml_info, 1, ML_TENSOR_TYPE_UINT64);
   EXPECT_EQ (status, ML_ERROR_NONE);
-  _ml_tensors_info_copy_from_ml (&gst_info, (ml_tensors_info_s *) ml_info);
+  _ml_tensors_info_copy_from_ml (&gst_info, ml_info);
   EXPECT_EQ (gst_info.info[0].type, _NNS_INT64);
   EXPECT_EQ (gst_info.info[1].type, _NNS_UINT64);
 
@@ -7138,7 +7077,7 @@ TEST (nnstreamer_capi_internal, copy_from_ml)
   EXPECT_EQ (status, ML_ERROR_NONE);
   status = ml_tensors_info_set_tensor_type (ml_info, 1, ML_TENSOR_TYPE_FLOAT32);
   EXPECT_EQ (status, ML_ERROR_NONE);
-  _ml_tensors_info_copy_from_ml (&gst_info, (ml_tensors_info_s *) ml_info);
+  _ml_tensors_info_copy_from_ml (&gst_info, ml_info);
   EXPECT_EQ (gst_info.info[0].type, _NNS_FLOAT64);
   EXPECT_EQ (gst_info.info[1].type, _NNS_FLOAT32);
 
@@ -7146,7 +7085,7 @@ TEST (nnstreamer_capi_internal, copy_from_ml)
   EXPECT_EQ (status, ML_ERROR_NONE);
   status = ml_tensors_info_set_tensor_name (ml_info, 1, "tn2");
   EXPECT_EQ (status, ML_ERROR_NONE);
-  _ml_tensors_info_copy_from_ml (&gst_info, (ml_tensors_info_s *) ml_info);
+  _ml_tensors_info_copy_from_ml (&gst_info, ml_info);
   EXPECT_STREQ (gst_info.info[0].name, "tn1");
   EXPECT_STREQ (gst_info.info[1].name, "tn2");
 
@@ -7167,7 +7106,7 @@ TEST (nnstreamer_capi_internal, copy_from_ml_01_n)
   status = ml_tensors_info_create (&ml_info);
   EXPECT_EQ (status, ML_ERROR_NONE);
 
-  status = _ml_tensors_info_copy_from_ml (NULL, (ml_tensors_info_s *) ml_info);
+  status = _ml_tensors_info_copy_from_ml (NULL, ml_info);
   EXPECT_NE (status, ML_ERROR_NONE);
 
   status = ml_tensors_info_destroy (ml_info);