Doxygen Book
nnstreamer_plugin_api_util_impl.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: LGPL-2.1-only */
13 #include <string.h>
15 #include "nnstreamer_log.h"
16 
20 static const gchar *tensor_element_typename[] = {
21  [_NNS_INT32] = "int32",
22  [_NNS_UINT32] = "uint32",
23  [_NNS_INT16] = "int16",
24  [_NNS_UINT16] = "uint16",
25  [_NNS_INT8] = "int8",
26  [_NNS_UINT8] = "uint8",
27  [_NNS_FLOAT64] = "float64",
28  [_NNS_FLOAT32] = "float32",
29  [_NNS_INT64] = "int64",
30  [_NNS_UINT64] = "uint64",
31  [_NNS_FLOAT16] = "float16",
32  [_NNS_END] = NULL,
33 };
34 
38 static const guint tensor_element_size[] = {
39  [_NNS_INT32] = 4,
40  [_NNS_UINT32] = 4,
41  [_NNS_INT16] = 2,
42  [_NNS_UINT16] = 2,
43  [_NNS_INT8] = 1,
44  [_NNS_UINT8] = 1,
45  [_NNS_FLOAT64] = 8,
46  [_NNS_FLOAT32] = 4,
47  [_NNS_INT64] = 8,
48  [_NNS_UINT64] = 8,
49  [_NNS_FLOAT16] = 2,
50  [_NNS_END] = 0,
51 };
52 
56 static const gchar *tensor_format_name[] = {
57  [_NNS_TENSOR_FORMAT_STATIC] = "static",
58  [_NNS_TENSOR_FORMAT_FLEXIBLE] = "flexible",
59  [_NNS_TENSOR_FORMAT_SPARSE] = "sparse",
60  [_NNS_TENSOR_FORMAT_END] = NULL
61 };
62 
66 static gint
67 _gcd (gint a, gint b)
68 {
69  while (b != 0) {
70  int temp = a;
71 
72  a = b;
73  b = temp % b;
74  }
75 
76  return ABS (a);
77 }
78 
82 static gint
83 _compare_rate (gint a_n, gint a_d, gint b_n, gint b_d)
84 {
85  gint64 new_num_1;
86  gint64 new_num_2;
87  gint gcd;
88 
89  g_return_val_if_fail (a_d != 0 && b_d != 0, 0);
90 
91  /* Simplify */
92  gcd = _gcd (a_n, a_d);
93  a_n /= gcd;
94  a_d /= gcd;
95 
96  gcd = _gcd (b_n, b_d);
97  b_n /= gcd;
98  b_d /= gcd;
99 
100  /* fractions are reduced when set, so we can quickly see if they're equal */
101  if (a_n == b_n && a_d == b_d)
102  return 0;
103 
104  /* extend to 64 bits */
105  new_num_1 = ((gint64) a_n) * b_d;
106  new_num_2 = ((gint64) b_n) * a_d;
107  if (new_num_1 < new_num_2)
108  return -1;
109  if (new_num_1 > new_num_2)
110  return 1;
111 
112  /* Should not happen because a_d and b_d are not 0 */
113  g_return_val_if_reached (0);
114 }
115 
120 void
122 {
123  guint i;
124 
125  g_return_if_fail (info != NULL);
126 
127  info->name = NULL;
128  info->type = _NNS_END;
129 
130  for (i = 0; i < NNS_TENSOR_RANK_LIMIT; i++) {
131  info->dimension[i] = 0;
132  }
133 }
134 
139 void
141 {
142  g_return_if_fail (info != NULL);
143 
144  g_free (info->name);
145 
146  /* Init default */
147  gst_tensor_info_init (info);
148 }
149 
155 gsize
157 {
158  gsize data_size;
159 
160  g_return_val_if_fail (info != NULL, 0);
161 
162  data_size = gst_tensor_get_element_count (info->dimension) *
164 
165  return data_size;
166 }
167 
173 gboolean
175 {
176  g_return_val_if_fail (info != NULL, FALSE);
177 
178  if (info->type == _NNS_END) {
179  nns_logd
180  ("Failed to validate tensor info. type: %s. Please specify tensor type. e.g., type=uint8 ",
183  ("Failed to validate tensor info. type: %s. Please specify tensor type. e.g., type=uint8 ",
185  return FALSE;
186  }
187 
188  /* validate tensor dimension */
190 }
191 
196 gboolean
198 {
200  return FALSE;
201  }
202 
203  if (i1->type != i2->type) {
204  nns_logd ("Tensor info is not equal. Given tensor types %s vs %s",
207  return FALSE;
208  }
209 
211  g_autofree gchar *_dim1 = gst_tensor_get_dimension_string (i1->dimension);
212  g_autofree gchar *_dim2 = gst_tensor_get_dimension_string (i2->dimension);
213  nns_logd ("Tensor info is not equal. Given tensor dimensions %s vs %s",
214  _dim1, _dim2);
215  return FALSE;
216  }
217 
218  /* matched all */
219  return TRUE;
220 }
221 
226 void
228  const guint n)
229 {
230  guint i;
231 
232  g_return_if_fail (dest != NULL);
233  g_return_if_fail (src != NULL);
234 
235  dest->name = g_strdup (src->name);
236  dest->type = src->type;
237 
238  for (i = 0; i < n; i++) {
239  dest->dimension[i] = src->dimension[i];
240  }
241 }
242 
247 void
249 {
251 }
252 
259 gboolean
261 {
262  guint i;
263 
264  g_return_val_if_fail (gst_tensor_info_validate (info), FALSE);
265  g_return_val_if_fail (meta != NULL, FALSE);
266 
268 
269  meta->type = info->type;
270 
271  for (i = 0; i < NNS_TENSOR_RANK_LIMIT; i++) {
273  meta->dimension[i] = info->dimension[i];
274  }
275 
276  return TRUE;
277 }
278 
284 guint
286 {
287  g_return_val_if_fail (info != NULL, 0);
288 
290 }
291 
297 {
298  guint i;
299 
300  g_return_val_if_fail (info != NULL, NULL);
301 
302  if (index < NNS_TENSOR_MEMORY_MAX)
303  return &info->info[index];
304 
305  if (!info->extra) {
307 
308  for (i = 0; i < NNS_TENSOR_SIZE_EXTRA_LIMIT; ++i)
309  gst_tensor_info_init (&info->extra[i]);
310  }
311 
312  if (index < NNS_TENSOR_SIZE_LIMIT)
313  return &info->extra[index - NNS_TENSOR_MEMORY_MAX];
314 
315  nns_loge ("Failed to get the information, invalid index %u (max %d).",
316  index, NNS_TENSOR_SIZE_LIMIT);
317  return NULL;
318 }
319 
324 void
326 {
327  guint i;
328 
329  g_return_if_fail (info != NULL);
330 
331  info->num_tensors = 0;
332  info->extra = NULL;
333 
336 
337  for (i = 0; i < NNS_TENSOR_MEMORY_MAX; i++) {
338  gst_tensor_info_init (&info->info[i]);
339  }
340 }
341 
346 void
348 {
349  guint i;
350 
351  g_return_if_fail (info != NULL);
352 
353  for (i = 0; i < NNS_TENSOR_MEMORY_MAX; i++) {
354  gst_tensor_info_free (&info->info[i]);
355  }
356 
357  if (info->extra) {
358  for (i = 0; i < NNS_TENSOR_SIZE_EXTRA_LIMIT; ++i)
359  gst_tensor_info_free (&info->extra[i]);
360 
361  g_free (info->extra);
362  info->extra = NULL;
363  }
364 
365  /* Init default */
366  gst_tensors_info_init (info);
367 }
368 
375 gsize
376 gst_tensors_info_get_size (const GstTensorsInfo * info, gint index)
377 {
378  GstTensorInfo *_info;
379  gsize data_size = 0;
380  guint i;
381 
382  g_return_val_if_fail (info != NULL, 0);
383  g_return_val_if_fail (index < (gint) info->num_tensors, 0);
384 
385  if (index < 0) {
386  for (i = 0; i < info->num_tensors; ++i) {
387  _info = gst_tensors_info_get_nth_info ((GstTensorsInfo *) info, i);
388  data_size += gst_tensor_info_get_size (_info);
389  }
390  } else {
391  _info = gst_tensors_info_get_nth_info ((GstTensorsInfo *) info, index);
392  data_size = gst_tensor_info_get_size (_info);
393  }
394 
395  return data_size;
396 }
397 
403 gboolean
405 {
406  guint i;
407  GstTensorInfo *_info;
408 
409  g_return_val_if_fail (info != NULL, FALSE);
410 
411  /* tensor stream format */
412  if (info->format >= _NNS_TENSOR_FORMAT_END) {
413  nns_logd
414  ("Failed to validate tensors info, format: %s. format should be one of %s.",
418  ("Failed to validate tensors info, format: %s. format should be one of %s.",
421  return FALSE;
422  }
423 
424  /* cannot check tensor info when tensor is not static */
425  if (info->format != _NNS_TENSOR_FORMAT_STATIC) {
426  return TRUE;
427  }
428 
429  if (info->num_tensors < 1) {
430  nns_logd
431  ("Failed to validate tensors info. the number of tensors: %d. the number of tensors should be greater than 0.",
432  info->num_tensors);
434  ("Failed to validate tensors info. the number of tensors: %d. the number of tensors should be greater than 0.",
435  info->num_tensors);
436  return FALSE;
437  }
438 
439  for (i = 0; i < info->num_tensors; i++) {
440  _info = gst_tensors_info_get_nth_info ((GstTensorsInfo *) info, i);
441 
442  if (!gst_tensor_info_validate (_info))
443  return FALSE;
444  }
445 
446  return TRUE;
447 }
448 
453 gboolean
455 {
456  guint i;
457  GstTensorInfo *_info1, *_info2;
458 
459  g_return_val_if_fail (i1 != NULL, FALSE);
460  g_return_val_if_fail (i2 != NULL, FALSE);
461 
462  if (i1->format != i2->format || i1->format == _NNS_TENSOR_FORMAT_END) {
463  nns_logd ("Tensors info is not equal. format: %s vs %s ",
466  return FALSE;
467  }
468 
469  /* cannot compare tensor info when tensor is not static */
470  if (i1->format != _NNS_TENSOR_FORMAT_STATIC) {
471  return TRUE;
472  }
473 
475  return FALSE;
476  }
477 
478  if (i1->num_tensors != i2->num_tensors) {
479  nns_logd ("Tensors info is not equal. the number of tensors: %d vs %d. ",
480  i1->num_tensors, i2->num_tensors);
481  return FALSE;
482  }
483 
484  for (i = 0; i < i1->num_tensors; i++) {
485  _info1 = gst_tensors_info_get_nth_info ((GstTensorsInfo *) i1, i);
486  _info2 = gst_tensors_info_get_nth_info ((GstTensorsInfo *) i2, i);
487 
488  if (!gst_tensor_info_is_equal (_info1, _info2)) {
489  return FALSE;
490  }
491  }
492 
493  /* matched all */
494  return TRUE;
495 }
496 
501 void
503 {
504  guint i, num;
505  GstTensorInfo *_dest, *_src;
506 
507  g_return_if_fail (dest != NULL);
508  g_return_if_fail (src != NULL);
509 
510  gst_tensors_info_init (dest);
511  num = dest->num_tensors = src->num_tensors;
512  dest->format = src->format;
513 
514  if (src->format != _NNS_TENSOR_FORMAT_STATIC)
515  return;
516 
517  for (i = 0; i < num; i++) {
518  _dest = gst_tensors_info_get_nth_info (dest, i);
519  _src = gst_tensors_info_get_nth_info ((GstTensorsInfo *) src, i);
520 
521  gst_tensor_info_copy (_dest, _src);
522  }
523 }
524 
531 guint
533  const gchar * dim_string)
534 {
535  guint num_dims = 0;
536  GstTensorInfo *_info;
537 
538  g_return_val_if_fail (info != NULL, 0);
539 
540  if (dim_string) {
541  guint i;
542  gchar **str_dims;
543 
544  str_dims = g_strsplit_set (dim_string, ",.", -1);
545  num_dims = g_strv_length (str_dims);
546 
547  if (num_dims > NNS_TENSOR_SIZE_LIMIT) {
548  nns_logw ("Invalid param, dimensions (%d) max (%d)\n",
549  num_dims, NNS_TENSOR_SIZE_LIMIT);
550 
551  num_dims = NNS_TENSOR_SIZE_LIMIT;
552  }
553 
554  for (i = 0; i < num_dims; i++) {
555  _info = gst_tensors_info_get_nth_info (info, i);
556  gst_tensor_parse_dimension (str_dims[i], _info->dimension);
557  }
558 
559  g_strfreev (str_dims);
560  }
561 
562  return num_dims;
563 }
564 
571 guint
573  const gchar * type_string)
574 {
575  guint num_types = 0;
576  GstTensorInfo *_info;
577 
578  g_return_val_if_fail (info != NULL, 0);
579 
580  if (type_string) {
581  guint i;
582  gchar **str_types;
583 
584  str_types = g_strsplit_set (type_string, ",.", -1);
585  num_types = g_strv_length (str_types);
586 
587  if (num_types > NNS_TENSOR_SIZE_LIMIT) {
588  nns_logw ("Invalid param, types (%d) max (%d)\n",
589  num_types, NNS_TENSOR_SIZE_LIMIT);
590 
591  num_types = NNS_TENSOR_SIZE_LIMIT;
592  }
593 
594  for (i = 0; i < num_types; i++) {
595  _info = gst_tensors_info_get_nth_info (info, i);
596  _info->type = gst_tensor_get_type (str_types[i]);
597  }
598 
599  g_strfreev (str_types);
600  }
601 
602  return num_types;
603 }
604 
611 guint
613  const gchar * name_string)
614 {
615  guint num_names = 0;
616  GstTensorInfo *_info;
617 
618  g_return_val_if_fail (info != NULL, 0);
619 
620  if (name_string) {
621  guint i;
622  gchar **str_names;
623 
624  str_names = g_strsplit (name_string, ",", -1);
625  num_names = g_strv_length (str_names);
626 
627  if (num_names > NNS_TENSOR_SIZE_LIMIT) {
628  nns_logw ("Invalid param, names (%d) max (%d)\n",
629  num_names, NNS_TENSOR_SIZE_LIMIT);
630 
631  num_names = NNS_TENSOR_SIZE_LIMIT;
632  }
633 
634  for (i = 0; i < num_names; i++) {
635  gchar *str_name;
636 
637  _info = gst_tensors_info_get_nth_info (info, i);
638  g_free (_info->name);
639  _info->name = NULL;
640 
641  str_name = g_strstrip (g_strdup (str_names[i]));
642  if (str_name && strlen (str_name))
643  _info->name = str_name;
644  else
645  g_free (str_name);
646  }
647 
648  g_strfreev (str_names);
649  }
650 
651  return num_names;
652 }
653 
660 gchar *
662 {
665 }
666 
675 gchar *
677  const unsigned int rank)
678 {
679  gchar *dim_str = NULL;
680  GstTensorInfo *_info;
681 
682  g_return_val_if_fail (info != NULL, NULL);
683 
684  if (info->num_tensors > 0) {
685  guint i;
686  GString *dimensions = g_string_new (NULL);
687 
688  for (i = 0; i < info->num_tensors; i++) {
689  _info = gst_tensors_info_get_nth_info ((GstTensorsInfo *) info, i);
690  dim_str = gst_tensor_get_rank_dimension_string (_info->dimension, rank);
691 
692  g_string_append (dimensions, dim_str);
693 
694  if (i < info->num_tensors - 1) {
695  g_string_append (dimensions, ",");
696  }
697 
698  g_free (dim_str);
699  }
700 
701  dim_str = g_string_free (dimensions, FALSE);
702  }
703 
704  return dim_str;
705 }
706 
713 gchar *
715 {
716  gchar *type_str = NULL;
717  GstTensorInfo *_info;
718 
719  g_return_val_if_fail (info != NULL, NULL);
720 
721  if (info->num_tensors > 0) {
722  guint i;
723  GString *types = g_string_new (NULL);
724 
725  for (i = 0; i < info->num_tensors; i++) {
726  _info = gst_tensors_info_get_nth_info ((GstTensorsInfo *) info, i);
727 
728  if (_info->type != _NNS_END)
729  g_string_append (types, gst_tensor_get_type_string (_info->type));
730 
731  if (i < info->num_tensors - 1) {
732  g_string_append (types, ",");
733  }
734  }
735 
736  type_str = g_string_free (types, FALSE);
737  }
738 
739  return type_str;
740 }
741 
748 gchar *
750 {
751  gchar *name_str = NULL;
752  GstTensorInfo *_info;
753 
754  g_return_val_if_fail (info != NULL, NULL);
755 
756  if (info->num_tensors > 0) {
757  guint i;
758  GString *names = g_string_new (NULL);
759 
760  for (i = 0; i < info->num_tensors; i++) {
761  _info = gst_tensors_info_get_nth_info ((GstTensorsInfo *) info, i);
762 
763  if (_info->name)
764  g_string_append (names, _info->name);
765 
766  if (i < info->num_tensors - 1) {
767  g_string_append (names, ",");
768  }
769  }
770 
771  name_str = g_string_free (names, FALSE);
772  }
773 
774  return name_str;
775 }
776 
782 gchar *
784 {
785  GString *gstr = g_string_new (NULL);
786  unsigned int i;
787  unsigned int limit = info->num_tensors;
788  GstTensorInfo *_info;
789 
790  g_string_append_printf (gstr, "Format = %s",
792  g_string_append_printf (gstr, ", Num_Tensors = %u", info->num_tensors);
793 
794  if (info->format == _NNS_TENSOR_FORMAT_STATIC) {
795  g_string_append_printf (gstr, ", Tensors = [");
796  if (limit > NNS_TENSOR_SIZE_LIMIT) {
797  limit = NNS_TENSOR_SIZE_LIMIT;
798  g_string_append_printf (gstr,
799  "(Num_Tensors out of bound. Showing %d only)", limit);
800  }
801 
802  for (i = 0; i < limit; i++) {
803  const gchar *name;
804  const gchar *type;
805  gchar *dim;
806 
807  _info = gst_tensors_info_get_nth_info ((GstTensorsInfo *) info, i);
808  name = _info->name;
811 
812  g_string_append_printf (gstr, "{\"%s\", %s, %s}%s",
813  name ? name : "", type, dim,
814  (i == info->num_tensors - 1) ? "" : ", ");
815 
816  g_free (dim);
817  }
818 
819  g_string_append_printf (gstr, "]");
820  }
821 
822  return g_string_free (gstr, FALSE);
823 }
824 
829 void
831 {
832  g_return_if_fail (config != NULL);
833 
834  gst_tensors_info_init (&config->info);
835 
836  config->rate_n = -1;
837  config->rate_d = -1;
838 }
839 
844 void
846 {
847  g_return_if_fail (config != NULL);
848 
849  gst_tensors_info_free (&config->info);
850 }
851 
857 gboolean
859 {
860  g_return_val_if_fail (config != NULL, FALSE);
861 
862  /* framerate (numerator >= 0 and denominator > 0) */
863  if (config->rate_n < 0 || config->rate_d <= 0) {
864  nns_logd
865  ("Failed to validate tensors config. framerate: %d/%d. framerate should be numerator >= 0 and denominator > 0.",
866  config->rate_n, config->rate_d);
868  ("Failed to validate tensors config. framerate: %d/%d. framerate should be numerator >= 0 and denominator > 0.",
869  config->rate_n, config->rate_d);
870  return FALSE;
871  }
872 
873  return gst_tensors_info_validate (&config->info);
874 }
875 
880 gboolean
882  const GstTensorsConfig * c2)
883 {
884  g_return_val_if_fail (c1 != NULL, FALSE);
885  g_return_val_if_fail (c2 != NULL, FALSE);
886 
888  return FALSE;
889  }
890 
891  if (_compare_rate (c1->rate_n, c1->rate_d, c2->rate_n, c2->rate_d)) {
892  nns_logd ("Tensors config is not equal. framerate: %d/%d vs %d/%d.",
893  c1->rate_n, c1->rate_d, c2->rate_n, c2->rate_d);
894  return FALSE;
895  }
896 
897  return gst_tensors_info_is_equal (&c1->info, &c2->info);
898 }
899 
903 void
905 {
906  g_return_if_fail (dest != NULL);
907  g_return_if_fail (src != NULL);
908 
909  gst_tensors_info_copy (&dest->info, &src->info);
910  dest->rate_n = src->rate_n;
911  dest->rate_d = src->rate_d;
912 }
913 
919 gchar *
921 {
922  GString *gstr = g_string_new (NULL);
923  const gchar *fmt = gst_tensor_get_format_string (config->info.format);
924  g_string_append_printf (gstr, "Format = %s, Framerate = %d/%d",
925  fmt, config->rate_n, config->rate_d);
926  if (config->info.format == _NNS_TENSOR_FORMAT_STATIC) {
927  gchar *infostr = gst_tensors_info_to_string (&config->info);
928  g_string_append_printf (gstr, ", %s", infostr);
929  g_free (infostr);
930  }
931  return g_string_free (gstr, FALSE);
932 }
933 
939 gboolean
941 {
942  guint i;
943  gboolean is_valid = FALSE;
944 
946  if (i == 0)
947  goto done;
948 
949  for (; i < NNS_TENSOR_RANK_LIMIT; i++) {
950  if (dim[i] > 0)
951  goto done;
952  }
953 
954  is_valid = TRUE;
955 
956 done:
957  if (!is_valid) {
958  nns_logd
959  ("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.");
961  ("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.");
962  }
963 
964  return is_valid;
965 }
966 
971 gboolean
973 {
974  guint i;
975 
976  /* Do not compare invalid dimensions. */
977  if (!gst_tensor_dimension_is_valid (dim1) ||
979  return FALSE;
980 
981  for (i = 0; i < NNS_TENSOR_RANK_LIMIT; i++) {
982  if (dim1[i] != dim2[i]) {
983  /* Supposed dimension is same if remained dimension is 1. */
984  if (dim1[i] > 1 || dim2[i] > 1)
985  return FALSE;
986  }
987  }
988 
989  return TRUE;
990 }
991 
997 guint
999 {
1000  guint i;
1001 
1002  for (i = 0; i < NNS_TENSOR_RANK_LIMIT; i++) {
1003  if (dim[i] == 0)
1004  break;
1005  }
1006 
1007  return i;
1008 }
1009 
1016 guint
1018 {
1019  guint i, rank;
1020 
1021  rank = gst_tensor_dimension_get_rank (dim);
1022  if (rank == 0)
1023  return 0;
1024 
1025  for (i = rank - 1; i > 0; i--) {
1026  if (dim[i] > 1)
1027  break;
1028  }
1029 
1030  return (i + 1);
1031 }
1032 
1039 guint
1040 gst_tensor_parse_dimension (const gchar * dimstr, tensor_dim dim)
1041 {
1042  guint rank = 0;
1043  guint64 val;
1044  gchar **strv;
1045  gchar *dim_string;
1046  guint i, num_dims;
1047 
1048  /* 0-init */
1049  for (i = 0; i < NNS_TENSOR_RANK_LIMIT; i++)
1050  dim[i] = 0;
1051 
1052  if (dimstr == NULL)
1053  return 0;
1054 
1055  /* remove spaces */
1056  dim_string = g_strstrip (g_strdup (dimstr));
1057 
1058  strv = g_strsplit (dim_string, ":", NNS_TENSOR_RANK_LIMIT);
1059  num_dims = g_strv_length (strv);
1060 
1061  for (i = 0; i < num_dims; i++) {
1062  g_strstrip (strv[i]);
1063  if (strv[i] == NULL || strlen (strv[i]) == 0)
1064  break;
1065 
1066  val = g_ascii_strtoull (strv[i], NULL, 10);
1067  dim[i] = (uint32_t) val;
1068  rank = i + 1;
1069  }
1070 
1071  g_strfreev (strv);
1072  g_free (dim_string);
1073  return rank;
1074 }
1075 
1082 gchar *
1084 {
1085  gchar *res =
1087 
1088  if (!res)
1089  return NULL;
1090  if (*res == '\0') {
1091  g_free (res);
1092  return NULL;
1093  }
1094 
1095  return res;
1096 }
1097 
1106 gchar *
1108  const unsigned int rank)
1109 {
1110  guint i;
1111  GString *dim_str;
1112  guint actual_rank;
1113 
1114  dim_str = g_string_new (NULL);
1115 
1116  if (rank == 0 || rank > NNS_TENSOR_RANK_LIMIT)
1117  actual_rank = NNS_TENSOR_RANK_LIMIT;
1118  else
1119  actual_rank = rank;
1120 
1121  for (i = 0; i < actual_rank; i++) {
1122  if (dim[i] == 0)
1123  break;
1124 
1125  g_string_append_printf (dim_str, "%u", dim[i]);
1126 
1127  if (i < actual_rank - 1 && dim[i + 1] > 0) {
1128  g_string_append (dim_str, ":");
1129  }
1130  }
1131 
1132  return g_string_free (dim_str, FALSE);
1133 }
1134 
1139 gboolean
1141  const gchar * dimstr2)
1142 {
1143  tensor_dim dim1, dim2;
1144  guint rank1, rank2, i, j, num_tensors1, num_tensors2;
1145  gchar **strv1;
1146  gchar **strv2;
1147  gboolean is_equal = FALSE;
1148 
1149  strv1 = g_strsplit_set (dimstr1, ",.", -1);
1150  strv2 = g_strsplit_set (dimstr2, ",.", -1);
1151 
1152  num_tensors1 = g_strv_length (strv1);
1153  num_tensors2 = g_strv_length (strv2);
1154 
1155  if (num_tensors1 != num_tensors2)
1156  goto done;
1157 
1158  for (i = 0; i < num_tensors1; i++) {
1159  for (j = 0; j < NNS_TENSOR_RANK_LIMIT; j++)
1160  dim1[j] = dim2[j] = 0;
1161 
1162  rank1 = gst_tensor_parse_dimension (strv1[i], dim1);
1163  rank2 = gst_tensor_parse_dimension (strv2[i], dim2);
1164 
1165  /* 'rank 0' means invalid dimension */
1166  if (!rank1 || !rank2 || !gst_tensor_dimension_is_equal (dim1, dim2))
1167  goto done;
1168  }
1169 
1170  /* Compared all tensor dimensions from input string. */
1171  is_equal = TRUE;
1172 
1173 done:
1174  g_strfreev (strv1);
1175  g_strfreev (strv2);
1176 
1177  return is_equal;
1178 }
1179 
1185 gulong
1187 {
1188  gulong count = 1;
1189  guint i;
1190 
1191  for (i = 0; i < NNS_TENSOR_RANK_LIMIT; i++) {
1192  if (dim[i] == 0)
1193  break;
1194 
1195  count *= dim[i];
1196  }
1197 
1198  return (i > 0) ? count : 0;
1199 }
1200 
1204 gsize
1206 {
1207  g_return_val_if_fail (type >= 0 && type <= _NNS_END, 0);
1208 
1209  return tensor_element_size[type];
1210 }
1211 
1218 gst_tensor_get_type (const gchar * typestr)
1219 {
1220  gsize size, len;
1221  gchar *type_string;
1223 
1224  if (typestr == NULL)
1225  return _NNS_END;
1226 
1227  /* remove spaces */
1228  type_string = g_strdup (typestr);
1229  g_strstrip (type_string);
1230 
1231  len = strlen (type_string);
1232 
1233  if (len == 0) {
1234  g_free (type_string);
1235  return _NNS_END;
1236  }
1237 
1238  if (g_regex_match_simple ("^uint(8|16|32|64)$",
1239  type_string, G_REGEX_CASELESS, 0)) {
1240  size = (gsize) g_ascii_strtoull (&type_string[4], NULL, 10);
1241 
1242  switch (size) {
1243  case 8:
1244  type = _NNS_UINT8;
1245  break;
1246  case 16:
1247  type = _NNS_UINT16;
1248  break;
1249  case 32:
1250  type = _NNS_UINT32;
1251  break;
1252  case 64:
1253  type = _NNS_UINT64;
1254  }
1255  } else if (g_regex_match_simple ("^int(8|16|32|64)$",
1256  type_string, G_REGEX_CASELESS, 0)) {
1257  size = (gsize) g_ascii_strtoull (&type_string[3], NULL, 10);
1258 
1259  switch (size) {
1260  case 8:
1261  type = _NNS_INT8;
1262  break;
1263  case 16:
1264  type = _NNS_INT16;
1265  break;
1266  case 32:
1267  type = _NNS_INT32;
1268  break;
1269  case 64:
1270  type = _NNS_INT64;
1271  }
1272  } else if (g_regex_match_simple ("^float(16|32|64)$",
1273  type_string, G_REGEX_CASELESS, 0)) {
1274  size = (gsize) g_ascii_strtoull (&type_string[5], NULL, 10);
1275 
1276  switch (size) {
1277  case 16:
1278  type = _NNS_FLOAT16;
1279  break;
1280  case 32:
1281  type = _NNS_FLOAT32;
1282  break;
1283  case 64:
1284  type = _NNS_FLOAT64;
1285  }
1286  }
1287 
1288  g_free (type_string);
1289  return type;
1290 }
1291 
1295 const gchar *
1297 {
1298  g_return_val_if_fail (type >= 0 && type <= _NNS_END, NULL);
1299 
1300  return tensor_element_typename[type];
1301 }
1302 
1309 gst_tensor_get_format (const gchar * format_str)
1310 {
1311  gint idx;
1313 
1314  idx = find_key_strv (tensor_format_name, format_str);
1315  if (idx >= 0)
1316  format = (tensor_format) idx;
1317 
1318  return format;
1319 }
1320 
1324 const gchar *
1326 {
1327  g_return_val_if_fail (format >= 0 && format <= _NNS_TENSOR_FORMAT_END, NULL);
1328 
1329  return tensor_format_name[format];
1330 }
1331 
1335 #define GST_TENSOR_META_MAGIC (0xfeedcced)
1336 
1340 #define GST_TENSOR_META_MAGIC_VALID(m) ((m) == GST_TENSOR_META_MAGIC)
1341 
1345 #define GST_TENSOR_META_VERSION_VALID(v) (((v) & 0xDE000000) == 0xDE000000)
1346 
1350 #define GST_TENSOR_META_MAKE_VERSION(major,minor) ((major) << 12 | (minor) | 0xDE000000)
1351 
1355 #define GST_TENSOR_META_VERSION GST_TENSOR_META_MAKE_VERSION(1,0)
1356 
1360 #define GST_TENSOR_META_IS_V1(v) (GST_TENSOR_META_VERSION_VALID(v) && (((v) & 0x00FFF000) & GST_TENSOR_META_MAKE_VERSION(1,0)))
1361 
1365 #define GST_TENSOR_META_IS_VALID(m) ((m) && GST_TENSOR_META_MAGIC_VALID ((m)->magic) && GST_TENSOR_META_VERSION_VALID ((m)->version))
1366 
1371 void
1373 {
1374  g_return_if_fail (meta != NULL);
1375 
1376  /* zero-init */
1377  memset (meta, 0, sizeof (GstTensorMetaInfo));
1378 
1379  meta->magic = GST_TENSOR_META_MAGIC;
1381  meta->type = _NNS_END;
1383  meta->media_type = _NNS_TENSOR;
1384 }
1385 
1392 void
1394  guint * major, guint * minor)
1395 {
1396  g_return_if_fail (meta != NULL);
1397 
1398  if (!GST_TENSOR_META_IS_VALID (meta))
1399  return;
1400 
1401  if (major)
1402  *major = (meta->version & 0x00FFF000) >> 12;
1403 
1404  if (minor)
1405  *minor = (meta->version & 0x00000FFF);
1406 }
1407 
1413 gboolean
1415 {
1416  g_return_val_if_fail (meta != NULL, FALSE);
1417 
1418  if (!GST_TENSOR_META_IS_VALID (meta))
1419  return FALSE;
1420 
1421  if (meta->type >= _NNS_END) {
1422  nns_logd ("Failed to validate tensor meta info. type: %s. ",
1424  return FALSE;
1425  }
1426 
1428  gchar *dim_str = gst_tensor_get_dimension_string (meta->dimension);
1429  nns_logd ("Failed to validate tensor meta info. Given dimension: %s",
1430  dim_str);
1431  g_free (dim_str);
1432  return FALSE;
1433  }
1434 
1435  if (meta->format >= _NNS_TENSOR_FORMAT_END) {
1436  nns_logd ("Failed to validate tensors meta info. format: %s. ",
1438  return FALSE;
1439  }
1440 
1441  if (meta->media_type > _NNS_TENSOR) {
1442  nns_logd ("Failed to validate tensor meta info. invalid media type: %d.",
1443  meta->media_type);
1444  return FALSE;
1445  }
1446 
1447  return TRUE;
1448 }
1449 
1455 gsize
1457 {
1458  g_return_val_if_fail (meta != NULL, 0);
1459 
1460  if (!GST_TENSOR_META_IS_VALID (meta))
1461  return 0;
1462 
1463  /* return fixed size for meta version */
1464  if (GST_TENSOR_META_IS_V1 (meta->version)) {
1465  return 128;
1466  }
1467 
1468  return 0;
1469 }
1470 
1476 gsize
1478 {
1479  gsize dsize;
1480 
1481  g_return_val_if_fail (meta != NULL, 0);
1482 
1483  if (!GST_TENSOR_META_IS_VALID (meta))
1484  return 0;
1485 
1486  dsize = gst_tensor_get_element_size (meta->type);
1487 
1488  if (meta->format == _NNS_TENSOR_FORMAT_SPARSE) {
1489  return meta->sparse_info.nnz * (dsize + sizeof (guint));
1490  }
1491 
1492  dsize *= gst_tensor_get_element_count (meta->dimension);
1493 
1494  return dsize;
1495 }
1496 
1504 gboolean
1506 {
1507  gsize hsize;
1508 
1509  g_return_val_if_fail (header != NULL, FALSE);
1510  g_return_val_if_fail (gst_tensor_meta_info_validate (meta), FALSE);
1511 
1512  hsize = gst_tensor_meta_info_get_header_size (meta);
1513 
1514  memset (header, 0, hsize);
1515 
1516  memcpy (header, meta, sizeof (GstTensorMetaInfo));
1517  return TRUE;
1518 }
1519 
1526 gboolean
1528 {
1529  uint32_t *val = (uint32_t *) header;
1530 
1531  g_return_val_if_fail (header != NULL, FALSE);
1532  g_return_val_if_fail (meta != NULL, FALSE);
1533 
1535 
1536  meta->magic = val[0];
1537  meta->version = val[1];
1538  meta->type = val[2];
1539  memcpy (meta->dimension, &val[3], sizeof (uint32_t) * NNS_TENSOR_RANK_LIMIT);
1540  meta->format = val[19];
1541  meta->media_type = val[20];
1542 
1543  switch ((tensor_format) meta->format) {
1545  meta->sparse_info.nnz = val[21];
1546  break;
1547  default:
1548  break;
1549  }
1550 
1552  return gst_tensor_meta_info_validate (meta);
1553 }
1554 
1561 gboolean
1563 {
1564  guint i;
1565 
1566  g_return_val_if_fail (info != NULL, FALSE);
1567  g_return_val_if_fail (gst_tensor_meta_info_validate (meta), FALSE);
1568 
1569  gst_tensor_info_init (info);
1570 
1571  info->type = meta->type;
1572 
1573  for (i = 0; i < NNS_TENSOR_RANK_LIMIT; i++)
1574  info->dimension[i] = meta->dimension[i];
1575 
1576  return TRUE;
1577 }
1578 
1585 gint
1586 find_key_strv (const gchar ** strv, const gchar * key)
1587 {
1588  gint cursor = 0;
1589 
1590  if (strv == NULL) {
1592  ("find_key_strv is called with a null pointer. Possible internal logic errors.\n");
1593  return -1;
1594  }
1595  while (strv[cursor] && key) {
1596  if (g_ascii_strcasecmp (strv[cursor], key) == 0)
1597  return cursor;
1598  cursor++;
1599  }
1600 
1601  return -1; /* Not Found */
1602 }
1603 
1608 gchar *
1610 {
1611  gchar *version;
1612 
1613  version = g_strdup_printf ("NNStreamer %s", VERSION);
1614  return version;
1615 }
1616 
1623 void
1624 nnstreamer_version_fetch (guint * major, guint * minor, guint * micro)
1625 {
1626  if (major)
1627  *major = (NNSTREAMER_VERSION_MAJOR);
1628  if (minor)
1629  *minor = (NNSTREAMER_VERSION_MINOR);
1630  if (micro)
1631  *micro = (NNSTREAMER_VERSION_MICRO);
1632 }
gst_tensors_info_validate
gboolean gst_tensors_info_validate(const GstTensorsInfo *info)
Check the tensors info is valid.
Definition: nnstreamer_plugin_api_util_impl.c:404
gst_tensor_info_init
void gst_tensor_info_init(GstTensorInfo *info)
Initialize the tensor info structure.
Definition: nnstreamer_plugin_api_util_impl.c:121
_NNS_UINT64
@ _NNS_UINT64
Definition: tensor_typedef.h:149
GstTensorInfo::name
char * name
Definition: tensor_typedef.h:263
GstTensorInfo
Internal data structure for tensor info.
Definition: tensor_typedef.h:261
NNS_TENSOR_MEMORY_MAX
#define NNS_TENSOR_MEMORY_MAX
This value, 16, can be checked with gst_buffer_get_max_memory(), which is GST_BUFFER_MEM_MAX in gstre...
Definition: tensor_typedef.h:52
gst_tensors_config_to_string
gchar * gst_tensors_config_to_string(const GstTensorsConfig *config)
Tensor config represented as a string. Caller should free it.
Definition: nnstreamer_plugin_api_util_impl.c:920
NNS_TENSOR_SIZE_LIMIT
#define NNS_TENSOR_SIZE_LIMIT
The number of tensors NNStreamer supports is 256. The max memories of gst-buffer is 16 (See NNS_TENSO...
Definition: tensor_typedef.h:42
_NNS_INT64
@ _NNS_INT64
Definition: tensor_typedef.h:148
tensor_dim
uint32_t tensor_dim[NNS_TENSOR_RANK_LIMIT]
Definition: tensor_typedef.h:247
gst_tensors_info_parse_names_string
guint gst_tensors_info_parse_names_string(GstTensorsInfo *info, const gchar *name_string)
Parse the string of names.
Definition: nnstreamer_plugin_api_util_impl.c:612
FALSE
return FALSE
Definition: gsttensor_transform.c:590
nnstreamer_version_fetch
void nnstreamer_version_fetch(guint *major, guint *minor, guint *micro)
Get the version of NNStreamer (int, divided).
Definition: nnstreamer_plugin_api_util_impl.c:1624
GstTensorsInfo
Internal meta data exchange format for a other/tensors instance.
Definition: tensor_typedef.h:273
tensor_format_name
static const gchar * tensor_format_name[]
String representations for tensor format.
Definition: nnstreamer_plugin_api_util_impl.c:56
_NNS_FLOAT16
@ _NNS_FLOAT16
Definition: tensor_typedef.h:150
nns_logd
#define nns_logd
Definition: nnstreamer_log.h:143
gst_tensors_info_parse_types_string
guint gst_tensors_info_parse_types_string(GstTensorsInfo *info, const gchar *type_string)
Parse the string of types.
Definition: nnstreamer_plugin_api_util_impl.c:572
GstTensorMetaInfo::sparse_info
GstSparseTensorInfo sparse_info
Definition: tensor_typedef.h:323
gst_tensors_info_get_size
gsize gst_tensors_info_get_size(const GstTensorsInfo *info, gint index)
Get data size of single tensor.
Definition: nnstreamer_plugin_api_util_impl.c:376
gst_tensor_info_copy
void gst_tensor_info_copy(GstTensorInfo *dest, const GstTensorInfo *src)
Copy tensor info.
Definition: nnstreamer_plugin_api_util_impl.c:248
gst_tensor_info_get_size
gsize gst_tensor_info_get_size(const GstTensorInfo *info)
Get data size of single tensor.
Definition: nnstreamer_plugin_api_util_impl.c:156
_NNS_UINT16
@ _NNS_UINT16
Definition: tensor_typedef.h:143
GstTensorsInfo::extra
GstTensorInfo * extra
Definition: tensor_typedef.h:277
nnstreamer_log.h
Internal log util for NNStreamer plugins and native APIs.
gst_tensor_get_format
tensor_format gst_tensor_get_format(const gchar *format_str)
Get tensor format from string input.
Definition: nnstreamer_plugin_api_util_impl.c:1309
gst_tensor_get_type
tensor_type gst_tensor_get_type(const gchar *typestr)
Get tensor type from string input.
Definition: nnstreamer_plugin_api_util_impl.c:1218
GstTensorMetaInfo::version
uint32_t version
Definition: tensor_typedef.h:313
GstTensorMetaInfo
Data structure to describe a tensor data. This represents the basic information of a memory block for...
Definition: tensor_typedef.h:310
GstTensorMetaInfo::type
uint32_t type
Definition: tensor_typedef.h:314
GstTensorsConfig::rate_d
int rate_d
Definition: tensor_typedef.h:288
gst_tensor_meta_info_init
void gst_tensor_meta_info_init(GstTensorMetaInfo *meta)
Initialize the tensor meta info structure.
Definition: nnstreamer_plugin_api_util_impl.c:1372
nnstreamer_plugin_api_util.h
Optional/Additional NNStreamer APIs for sub-plugin writers. (No GStreamer dependency)
gst_tensors_config_free
void gst_tensors_config_free(GstTensorsConfig *config)
Free allocated data in tensors config structure.
Definition: nnstreamer_plugin_api_util_impl.c:845
nnstreamer_version_string
gchar * nnstreamer_version_string(void)
Get the version of NNStreamer (string).
Definition: nnstreamer_plugin_api_util_impl.c:1609
gst_tensor_dimension_is_valid
gboolean gst_tensor_dimension_is_valid(const tensor_dim dim)
Check the tensor dimension is valid.
Definition: nnstreamer_plugin_api_util_impl.c:940
_NNS_TENSOR
@ _NNS_TENSOR
Definition: tensor_typedef.h:186
gst_tensor_info_get_rank
guint gst_tensor_info_get_rank(const GstTensorInfo *info)
Get tensor rank.
Definition: nnstreamer_plugin_api_util_impl.c:285
gst_tensors_info_get_nth_info
GstTensorInfo * gst_tensors_info_get_nth_info(GstTensorsInfo *info, guint index)
Get the pointer of nth tensor information.
Definition: nnstreamer_plugin_api_util_impl.c:296
GstTensorMetaInfo::media_type
uint32_t media_type
Definition: tensor_typedef.h:317
gst_tensors_info_copy
void gst_tensors_info_copy(GstTensorsInfo *dest, const GstTensorsInfo *src)
Copy tensor info.
Definition: nnstreamer_plugin_api_util_impl.c:502
gst_tensors_config_init
void gst_tensors_config_init(GstTensorsConfig *config)
Initialize the tensors config info structure (for other/tensors)
Definition: nnstreamer_plugin_api_util_impl.c:830
GstSparseTensorInfo::nnz
uint32_t nnz
Definition: tensor_typedef.h:296
GST_TENSOR_FORMAT_ALL
#define GST_TENSOR_FORMAT_ALL
Possible tensor formats.
Definition: tensor_typedef.h:73
g_free
g_free(self->option[(opnum) - 1])
opnum: \
tensor_type
enum _nns_tensor_type tensor_type
Possible data element types of other/tensor.
gst_tensors_info_to_string
gchar * gst_tensors_info_to_string(const GstTensorsInfo *info)
GstTensorsInfo represented as a string. Caller should free it.
Definition: nnstreamer_plugin_api_util_impl.c:783
ml_logf_stacktrace
#define ml_logf_stacktrace(...)
Definition: nnstreamer_log.h:102
gst_tensor_meta_info_update_header
gboolean gst_tensor_meta_info_update_header(GstTensorMetaInfo *meta, gpointer header)
Update header from tensor meta.
Definition: nnstreamer_plugin_api_util_impl.c:1505
gst_tensor_info_copy_n
void gst_tensor_info_copy_n(GstTensorInfo *dest, const GstTensorInfo *src, const guint n)
Copy tensor info up to n elements.
Definition: nnstreamer_plugin_api_util_impl.c:227
GST_TENSOR_META_IS_V1
#define GST_TENSOR_META_IS_V1(v)
Macro to check the version of tensor meta.
Definition: nnstreamer_plugin_api_util_impl.c:1360
_gcd
static gint _gcd(gint a, gint b)
Internal function, copied from gst_util_greatest_common_divisor() to remove dependency of gstreamer.
Definition: nnstreamer_plugin_api_util_impl.c:67
gst_tensors_info_free
void gst_tensors_info_free(GstTensorsInfo *info)
Free allocated data in tensors info structure.
Definition: nnstreamer_plugin_api_util_impl.c:347
gst_tensors_info_parse_dimensions_string
guint gst_tensors_info_parse_dimensions_string(GstTensorsInfo *info, const gchar *dim_string)
Parse the string of dimensions.
Definition: nnstreamer_plugin_api_util_impl.c:532
GstTensorsConfig::rate_n
int rate_n
Definition: tensor_typedef.h:287
_NNS_END
@ _NNS_END
Definition: tensor_typedef.h:152
gst_tensors_info_is_equal
gboolean gst_tensors_info_is_equal(const GstTensorsInfo *i1, const GstTensorsInfo *i2)
Compare tensors info.
Definition: nnstreamer_plugin_api_util_impl.c:454
_NNS_TENSOR_FORMAT_FLEXIBLE
@ _NNS_TENSOR_FORMAT_FLEXIBLE
Definition: tensor_typedef.h:196
gst_tensor_get_element_size
gsize gst_tensor_get_element_size(tensor_type type)
Get element size of tensor type (byte per element)
Definition: nnstreamer_plugin_api_util_impl.c:1205
GstTensorsInfo::info
GstTensorInfo info[NNS_TENSOR_MEMORY_MAX]
Definition: tensor_typedef.h:276
gst_tensors_info_get_names_string
gchar * gst_tensors_info_get_names_string(const GstTensorsInfo *info)
Get the string of tensor names in tensors info.
Definition: nnstreamer_plugin_api_util_impl.c:749
tensor_format
enum _tensor_format tensor_format
Data format of tensor stream in the pipeline.
GST_TENSOR_META_VERSION
#define GST_TENSOR_META_VERSION
The version of tensor meta.
Definition: nnstreamer_plugin_api_util_impl.c:1355
_NNS_FLOAT32
@ _NNS_FLOAT32
Definition: tensor_typedef.h:147
GST_TENSOR_META_IS_VALID
#define GST_TENSOR_META_IS_VALID(m)
Macro to check the meta is valid.
Definition: nnstreamer_plugin_api_util_impl.c:1365
_NNS_TENSOR_FORMAT_STATIC
@ _NNS_TENSOR_FORMAT_STATIC
Definition: tensor_typedef.h:195
GST_TENSOR_META_MAGIC
#define GST_TENSOR_META_MAGIC
Magic number of tensor meta.
Definition: nnstreamer_plugin_api_util_impl.c:1335
tensor_element_size
static const guint tensor_element_size[]
Byte-per-element of each tensor element type.
Definition: nnstreamer_plugin_api_util_impl.c:38
GstTensorMetaInfo::magic
uint32_t magic
Definition: tensor_typedef.h:312
_NNS_TENSOR_FORMAT_SPARSE
@ _NNS_TENSOR_FORMAT_SPARSE
Definition: tensor_typedef.h:197
GstTensorsConfig
Internal data structure for configured tensors info (for other/tensors).
Definition: tensor_typedef.h:284
GstTensorMetaInfo::dimension
tensor_dim dimension
Definition: tensor_typedef.h:315
_NNS_INT32
@ _NNS_INT32
Definition: tensor_typedef.h:140
TRUE
return TRUE
Definition: gsttensor_if.c:897
_compare_rate
static gint _compare_rate(gint a_n, gint a_d, gint b_n, gint b_d)
Internal function, copied from gst_util_fraction_compare() to remove dependency of gstreamer.
Definition: nnstreamer_plugin_api_util_impl.c:83
gst_tensor_parse_dimension
guint gst_tensor_parse_dimension(const gchar *dimstr, tensor_dim dim)
Parse tensor dimension parameter string.
Definition: nnstreamer_plugin_api_util_impl.c:1040
nns_loge
#define nns_loge
Definition: nnstreamer_log.h:142
tensor_element_typename
static const gchar * tensor_element_typename[]
String representations for each tensor element type.
Definition: nnstreamer_plugin_api_util_impl.c:20
gst_tensor_dimension_is_equal
gboolean gst_tensor_dimension_is_equal(const tensor_dim dim1, const tensor_dim dim2)
Compare the tensor dimension.
Definition: nnstreamer_plugin_api_util_impl.c:972
gst_tensors_config_is_equal
gboolean gst_tensors_config_is_equal(const GstTensorsConfig *c1, const GstTensorsConfig *c2)
Compare tensor config info.
Definition: nnstreamer_plugin_api_util_impl.c:881
gst_tensor_meta_info_validate
gboolean gst_tensor_meta_info_validate(GstTensorMetaInfo *meta)
Check the meta info is valid.
Definition: nnstreamer_plugin_api_util_impl.c:1414
find_key_strv
gint find_key_strv(const gchar **strv, const gchar *key)
Find the index value of the given key string array.
Definition: nnstreamer_plugin_api_util_impl.c:1586
gst_tensor_meta_info_get_data_size
gsize gst_tensor_meta_info_get_data_size(GstTensorMetaInfo *meta)
Get the data size calculated from tensor meta.
Definition: nnstreamer_plugin_api_util_impl.c:1477
gst_tensors_config_copy
void gst_tensors_config_copy(GstTensorsConfig *dest, const GstTensorsConfig *src)
Copy tensors config.
Definition: nnstreamer_plugin_api_util_impl.c:904
gst_tensor_get_element_count
gulong gst_tensor_get_element_count(const tensor_dim dim)
Count the number of elements of a tensor.
Definition: nnstreamer_plugin_api_util_impl.c:1186
gst_tensor_meta_info_get_header_size
gsize gst_tensor_meta_info_get_header_size(GstTensorMetaInfo *meta)
Get the header size to handle a tensor meta.
Definition: nnstreamer_plugin_api_util_impl.c:1456
_NNS_INT16
@ _NNS_INT16
Definition: tensor_typedef.h:142
gst_tensor_info_is_equal
gboolean gst_tensor_info_is_equal(const GstTensorInfo *i1, const GstTensorInfo *i2)
Compare tensor info.
Definition: nnstreamer_plugin_api_util_impl.c:197
gst_tensor_info_validate
gboolean gst_tensor_info_validate(const GstTensorInfo *info)
Check the tensor info is valid.
Definition: nnstreamer_plugin_api_util_impl.c:174
gst_tensors_info_init
void gst_tensors_info_init(GstTensorsInfo *info)
Initialize the tensors info structure.
Definition: nnstreamer_plugin_api_util_impl.c:325
_nnstreamer_error_write
void _nnstreamer_error_write(const char *fmt,...)
overwrites the error message buffer with the new message.
gst_tensor_get_rank_dimension_string
gchar * gst_tensor_get_rank_dimension_string(const tensor_dim dim, const unsigned int rank)
Get dimension string from given tensor dimension and rank count.
Definition: nnstreamer_plugin_api_util_impl.c:1107
gst_tensor_get_format_string
const gchar * gst_tensor_get_format_string(tensor_format format)
Get tensor format string.
Definition: nnstreamer_plugin_api_util_impl.c:1325
gst_tensor_get_dimension_string
gchar * gst_tensor_get_dimension_string(const tensor_dim dim)
Get dimension string from given tensor dimension.
Definition: nnstreamer_plugin_api_util_impl.c:1083
nns_logw
#define nns_logw
Definition: nnstreamer_log.h:141
GstTensorMetaInfo::format
uint32_t format
Definition: tensor_typedef.h:316
GstTensorsInfo::num_tensors
unsigned int num_tensors
Definition: tensor_typedef.h:275
gst_tensors_info_get_dimensions_string
gchar * gst_tensors_info_get_dimensions_string(const GstTensorsInfo *info)
Get the string of dimensions in tensors info.
Definition: nnstreamer_plugin_api_util_impl.c:661
_NNS_FLOAT64
@ _NNS_FLOAT64
Definition: tensor_typedef.h:146
gst_tensor_dimension_string_is_equal
gboolean gst_tensor_dimension_string_is_equal(const gchar *dimstr1, const gchar *dimstr2)
Compare dimension strings.
Definition: nnstreamer_plugin_api_util_impl.c:1140
gst_tensor_get_type_string
const gchar * gst_tensor_get_type_string(tensor_type type)
Get type string of tensor type.
Definition: nnstreamer_plugin_api_util_impl.c:1296
gst_tensor_meta_info_convert
gboolean gst_tensor_meta_info_convert(GstTensorMetaInfo *meta, GstTensorInfo *info)
Convert GstTensorMetaInfo structure to GstTensorInfo.
Definition: nnstreamer_plugin_api_util_impl.c:1562
gst_tensor_meta_info_parse_header
gboolean gst_tensor_meta_info_parse_header(GstTensorMetaInfo *meta, gpointer header)
Parse header and fill the tensor meta.
Definition: nnstreamer_plugin_api_util_impl.c:1527
gst_tensor_dimension_get_rank
guint gst_tensor_dimension_get_rank(const tensor_dim dim)
Get the rank of tensor dimension.
Definition: nnstreamer_plugin_api_util_impl.c:998
gst_tensors_info_get_rank_dimensions_string
gchar * gst_tensors_info_get_rank_dimensions_string(const GstTensorsInfo *info, const unsigned int rank)
Get the string of dimensions in tensors info and rank count.
Definition: nnstreamer_plugin_api_util_impl.c:676
gst_tensor_info_free
void gst_tensor_info_free(GstTensorInfo *info)
Free allocated data in tensor info structure.
Definition: nnstreamer_plugin_api_util_impl.c:140
GstTensorInfo::type
tensor_type type
Definition: tensor_typedef.h:266
GstTensorsConfig::info
GstTensorsInfo info
Definition: tensor_typedef.h:286
gst_tensor_info_convert_to_meta
gboolean gst_tensor_info_convert_to_meta(GstTensorInfo *info, GstTensorMetaInfo *meta)
Convert GstTensorInfo structure to GstTensorMetaInfo.
Definition: nnstreamer_plugin_api_util_impl.c:260
_NNS_TENSOR_FORMAT_END
@ _NNS_TENSOR_FORMAT_END
Definition: tensor_typedef.h:199
_NNS_UINT32
@ _NNS_UINT32
Definition: tensor_typedef.h:141
_STR_NULL
#define _STR_NULL(str)
If the given string is NULL, print "(NULL)". Copied from GST_STR_NULL
Definition: nnstreamer_plugin_api_util.h:26
gst_tensor_meta_info_get_version
void gst_tensor_meta_info_get_version(GstTensorMetaInfo *meta, guint *major, guint *minor)
Get the version of tensor meta.
Definition: nnstreamer_plugin_api_util_impl.c:1393
_NNS_INT8
@ _NNS_INT8
Definition: tensor_typedef.h:144
GstTensorInfo::dimension
tensor_dim dimension
Definition: tensor_typedef.h:267
gst_tensors_info_get_types_string
gchar * gst_tensors_info_get_types_string(const GstTensorsInfo *info)
Get the string of types in tensors info.
Definition: nnstreamer_plugin_api_util_impl.c:714
_NNS_UINT8
@ _NNS_UINT8
Definition: tensor_typedef.h:145
NNS_TENSOR_RANK_LIMIT
#define NNS_TENSOR_RANK_LIMIT
Definition: tensor_typedef.h:34
type
svtc_1 type
Definition: gsttensor_if.c:843
gst_tensors_config_validate
gboolean gst_tensors_config_validate(const GstTensorsConfig *config)
Check the tensors are all configured.
Definition: nnstreamer_plugin_api_util_impl.c:858
gst_tensor_dimension_get_min_rank
guint gst_tensor_dimension_get_min_rank(const tensor_dim dim)
Get the minimum rank of tensor dimension.
Definition: nnstreamer_plugin_api_util_impl.c:1017
GstTensorsInfo::format
tensor_format format
Definition: tensor_typedef.h:278
NNS_TENSOR_SIZE_EXTRA_LIMIT
#define NNS_TENSOR_SIZE_EXTRA_LIMIT
Max number of extra tensors.
Definition: tensor_typedef.h:57