Go to the documentation of this file.
89 g_return_val_if_fail (a_d != 0 && b_d != 0, 0);
92 gcd =
_gcd (a_n, a_d);
96 gcd =
_gcd (b_n, b_d);
101 if (a_n == b_n && a_d == b_d)
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)
109 if (new_num_1 > new_num_2)
113 g_return_val_if_reached (0);
125 g_return_if_fail (info != NULL);
142 g_return_if_fail (info != NULL);
160 g_return_val_if_fail (info != NULL, 0);
176 g_return_val_if_fail (info != NULL,
FALSE);
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 ",
204 nns_logd (
"Tensor info is not equal. Given tensor types %s vs %s",
213 nns_logd (
"Tensor info is not equal. Given tensor dimensions %s vs %s",
232 g_return_if_fail (dest != NULL);
233 g_return_if_fail (src != NULL);
238 for (i = 0; i < n; i++) {
265 g_return_val_if_fail (meta != NULL,
FALSE);
287 g_return_val_if_fail (info != NULL, 0);
300 g_return_val_if_fail (info != NULL, NULL);
303 return &info->
info[index];
315 nns_loge (
"Failed to get the information, invalid index %u (max %d).",
329 g_return_if_fail (info != NULL);
351 g_return_if_fail (info != NULL);
382 g_return_val_if_fail (info != NULL, 0);
383 g_return_val_if_fail (index < (gint) info->
num_tensors, 0);
409 g_return_val_if_fail (info != NULL,
FALSE);
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.",
431 (
"Failed to validate tensors info. the number of tensors: %d. the number of tensors should be greater than 0.",
434 (
"Failed to validate tensors info. the number of tensors: %d. the number of tensors should be greater than 0.",
459 g_return_val_if_fail (i1 != NULL,
FALSE);
460 g_return_val_if_fail (i2 != NULL,
FALSE);
463 nns_logd (
"Tensors info is not equal. format: %s vs %s ",
479 nns_logd (
"Tensors info is not equal. the number of tensors: %d vs %d. ",
507 g_return_if_fail (dest != NULL);
508 g_return_if_fail (src != NULL);
517 for (i = 0; i < num; i++) {
533 const gchar * dim_string)
538 g_return_val_if_fail (info != NULL, 0);
544 str_dims = g_strsplit_set (dim_string,
",.", -1);
545 num_dims = g_strv_length (str_dims);
548 nns_logw (
"Invalid param, dimensions (%d) max (%d)\n",
554 for (i = 0; i < num_dims; i++) {
559 g_strfreev (str_dims);
573 const gchar * type_string)
578 g_return_val_if_fail (info != NULL, 0);
584 str_types = g_strsplit_set (type_string,
",.", -1);
585 num_types = g_strv_length (str_types);
588 nns_logw (
"Invalid param, types (%d) max (%d)\n",
594 for (i = 0; i < num_types; i++) {
599 g_strfreev (str_types);
613 const gchar * name_string)
618 g_return_val_if_fail (info != NULL, 0);
624 str_names = g_strsplit (name_string,
",", -1);
625 num_names = g_strv_length (str_names);
628 nns_logw (
"Invalid param, names (%d) max (%d)\n",
634 for (i = 0; i < num_names; i++) {
641 str_name = g_strstrip (g_strdup (str_names[i]));
642 if (str_name && strlen (str_name))
643 _info->
name = str_name;
648 g_strfreev (str_names);
677 const unsigned int rank)
679 gchar *dim_str = NULL;
682 g_return_val_if_fail (info != NULL, NULL);
686 GString *dimensions = g_string_new (NULL);
692 g_string_append (dimensions, dim_str);
694 if (i < info->num_tensors - 1) {
695 g_string_append (dimensions,
",");
701 dim_str = g_string_free (dimensions,
FALSE);
716 gchar *type_str = NULL;
719 g_return_val_if_fail (info != NULL, NULL);
723 GString *types = g_string_new (NULL);
731 if (i < info->num_tensors - 1) {
732 g_string_append (types,
",");
736 type_str = g_string_free (types,
FALSE);
751 gchar *name_str = NULL;
754 g_return_val_if_fail (info != NULL, NULL);
758 GString *names = g_string_new (NULL);
764 g_string_append (names, _info->
name);
766 if (i < info->num_tensors - 1) {
767 g_string_append (names,
",");
771 name_str = g_string_free (names,
FALSE);
785 GString *gstr = g_string_new (NULL);
790 g_string_append_printf (gstr,
"Format = %s",
792 g_string_append_printf (gstr,
", Num_Tensors = %u", info->
num_tensors);
795 g_string_append_printf (gstr,
", Tensors = [");
798 g_string_append_printf (gstr,
799 "(Num_Tensors out of bound. Showing %d only)", limit);
802 for (i = 0; i < limit; i++) {
812 g_string_append_printf (gstr,
"{\"%s\", %s, %s}%s",
813 name ? name :
"",
type, dim,
819 g_string_append_printf (gstr,
"]");
822 return g_string_free (gstr,
FALSE);
832 g_return_if_fail (config != NULL);
847 g_return_if_fail (config != NULL);
860 g_return_val_if_fail (config != NULL,
FALSE);
865 (
"Failed to validate tensors config. framerate: %d/%d. framerate should be numerator >= 0 and denominator > 0.",
868 (
"Failed to validate tensors config. framerate: %d/%d. framerate should be numerator >= 0 and denominator > 0.",
884 g_return_val_if_fail (c1 != NULL,
FALSE);
885 g_return_val_if_fail (c2 != NULL,
FALSE);
892 nns_logd (
"Tensors config is not equal. framerate: %d/%d vs %d/%d.",
906 g_return_if_fail (dest != NULL);
907 g_return_if_fail (src != NULL);
922 GString *gstr = g_string_new (NULL);
924 g_string_append_printf (gstr,
"Format = %s, Framerate = %d/%d",
928 g_string_append_printf (gstr,
", %s", infostr);
931 return g_string_free (gstr,
FALSE);
943 gboolean is_valid =
FALSE;
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.");
982 if (dim1[i] != dim2[i]) {
984 if (dim1[i] > 1 || dim2[i] > 1)
1025 for (i = rank - 1; i > 0; i--) {
1056 dim_string = g_strstrip (g_strdup (dimstr));
1059 num_dims = g_strv_length (strv);
1061 for (i = 0; i < num_dims; i++) {
1062 g_strstrip (strv[i]);
1063 if (strv[i] == NULL || strlen (strv[i]) == 0)
1066 val = g_ascii_strtoull (strv[i], NULL, 10);
1067 dim[i] = (uint32_t) val;
1108 const unsigned int rank)
1114 dim_str = g_string_new (NULL);
1121 for (i = 0; i < actual_rank; i++) {
1125 g_string_append_printf (dim_str,
"%u", dim[i]);
1127 if (i < actual_rank - 1 && dim[i + 1] > 0) {
1128 g_string_append (dim_str,
":");
1132 return g_string_free (dim_str,
FALSE);
1141 const gchar * dimstr2)
1144 guint rank1, rank2, i, j, num_tensors1, num_tensors2;
1147 gboolean is_equal =
FALSE;
1149 strv1 = g_strsplit_set (dimstr1,
",.", -1);
1150 strv2 = g_strsplit_set (dimstr2,
",.", -1);
1152 num_tensors1 = g_strv_length (strv1);
1153 num_tensors2 = g_strv_length (strv2);
1155 if (num_tensors1 != num_tensors2)
1158 for (i = 0; i < num_tensors1; i++) {
1160 dim1[j] = dim2[j] = 0;
1198 return (i > 0) ? count : 0;
1224 if (typestr == NULL)
1228 type_string = g_strdup (typestr);
1229 g_strstrip (type_string);
1231 len = strlen (type_string);
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);
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);
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);
1335 #define GST_TENSOR_META_MAGIC (0xfeedcced)
1340 #define GST_TENSOR_META_MAGIC_VALID(m) ((m) == GST_TENSOR_META_MAGIC)
1345 #define GST_TENSOR_META_VERSION_VALID(v) (((v) & 0xDE000000) == 0xDE000000)
1350 #define GST_TENSOR_META_MAKE_VERSION(major,minor) ((major) << 12 | (minor) | 0xDE000000)
1355 #define GST_TENSOR_META_VERSION GST_TENSOR_META_MAKE_VERSION(1,0)
1360 #define GST_TENSOR_META_IS_V1(v) (GST_TENSOR_META_VERSION_VALID(v) && (((v) & 0x00FFF000) & GST_TENSOR_META_MAKE_VERSION(1,0)))
1365 #define GST_TENSOR_META_IS_VALID(m) ((m) && GST_TENSOR_META_MAGIC_VALID ((m)->magic) && GST_TENSOR_META_VERSION_VALID ((m)->version))
1374 g_return_if_fail (meta != NULL);
1394 guint * major, guint * minor)
1396 g_return_if_fail (meta != NULL);
1402 *major = (meta->
version & 0x00FFF000) >> 12;
1405 *minor = (meta->
version & 0x00000FFF);
1416 g_return_val_if_fail (meta != NULL,
FALSE);
1422 nns_logd (
"Failed to validate tensor meta info. type: %s. ",
1429 nns_logd (
"Failed to validate tensor meta info. Given dimension: %s",
1436 nns_logd (
"Failed to validate tensors meta info. format: %s. ",
1442 nns_logd (
"Failed to validate tensor meta info. invalid media type: %d.",
1458 g_return_val_if_fail (meta != NULL, 0);
1481 g_return_val_if_fail (meta != NULL, 0);
1509 g_return_val_if_fail (header != NULL,
FALSE);
1514 memset (header, 0, hsize);
1529 uint32_t *val = (uint32_t *) header;
1531 g_return_val_if_fail (header != NULL,
FALSE);
1532 g_return_val_if_fail (meta != NULL,
FALSE);
1536 meta->
magic = val[0];
1538 meta->
type = val[2];
1566 g_return_val_if_fail (info != NULL,
FALSE);
1592 (
"find_key_strv is called with a null pointer. Possible internal logic errors.\n");
1595 while (strv[cursor] && key) {
1596 if (g_ascii_strcasecmp (strv[cursor], key) == 0)
1613 version = g_strdup_printf (
"NNStreamer %s", VERSION);
1627 *major = (NNSTREAMER_VERSION_MAJOR);
1629 *minor = (NNSTREAMER_VERSION_MINOR);
1631 *micro = (NNSTREAMER_VERSION_MICRO);
gboolean gst_tensors_info_validate(const GstTensorsInfo *info)
Check the tensors info is valid.
void gst_tensor_info_init(GstTensorInfo *info)
Initialize the tensor info structure.
Internal data structure for tensor info.
#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...
gchar * gst_tensors_config_to_string(const GstTensorsConfig *config)
Tensor config represented as a string. Caller should free it.
#define NNS_TENSOR_SIZE_LIMIT
The number of tensors NNStreamer supports is 256. The max memories of gst-buffer is 16 (See NNS_TENSO...
uint32_t tensor_dim[NNS_TENSOR_RANK_LIMIT]
guint gst_tensors_info_parse_names_string(GstTensorsInfo *info, const gchar *name_string)
Parse the string of names.
void nnstreamer_version_fetch(guint *major, guint *minor, guint *micro)
Get the version of NNStreamer (int, divided).
Internal meta data exchange format for a other/tensors instance.
static const gchar * tensor_format_name[]
String representations for tensor format.
guint gst_tensors_info_parse_types_string(GstTensorsInfo *info, const gchar *type_string)
Parse the string of types.
gsize gst_tensors_info_get_size(const GstTensorsInfo *info, gint index)
Get data size of single tensor.
void gst_tensor_info_copy(GstTensorInfo *dest, const GstTensorInfo *src)
Copy tensor info.
gsize gst_tensor_info_get_size(const GstTensorInfo *info)
Get data size of single tensor.
Internal log util for NNStreamer plugins and native APIs.
tensor_format gst_tensor_get_format(const gchar *format_str)
Get tensor format from string input.
tensor_type gst_tensor_get_type(const gchar *typestr)
Get tensor type from string input.
void gst_tensor_meta_info_init(GstTensorMetaInfo *meta)
Initialize the tensor meta info structure.
Optional/Additional NNStreamer APIs for sub-plugin writers. (No GStreamer dependency)
void gst_tensors_config_free(GstTensorsConfig *config)
Free allocated data in tensors config structure.
gchar * nnstreamer_version_string(void)
Get the version of NNStreamer (string).
gboolean gst_tensor_dimension_is_valid(const tensor_dim dim)
Check the tensor dimension is valid.
guint gst_tensor_info_get_rank(const GstTensorInfo *info)
Get tensor rank.
GstTensorInfo * gst_tensors_info_get_nth_info(GstTensorsInfo *info, guint index)
Get the pointer of nth tensor information.
void gst_tensors_info_copy(GstTensorsInfo *dest, const GstTensorsInfo *src)
Copy tensor info.
void gst_tensors_config_init(GstTensorsConfig *config)
Initialize the tensors config info structure (for other/tensors)
#define GST_TENSOR_FORMAT_ALL
Possible tensor formats.
g_free(self->option[(opnum) - 1])
opnum: \
enum _nns_tensor_type tensor_type
Possible data element types of other/tensor.
gchar * gst_tensors_info_to_string(const GstTensorsInfo *info)
GstTensorsInfo represented as a string. Caller should free it.
#define ml_logf_stacktrace(...)
gboolean gst_tensor_meta_info_update_header(GstTensorMetaInfo *meta, gpointer header)
Update header from tensor meta.
void gst_tensor_info_copy_n(GstTensorInfo *dest, const GstTensorInfo *src, const guint n)
Copy tensor info up to n elements.
#define GST_TENSOR_META_IS_V1(v)
Macro to check the version of tensor meta.
static gint _gcd(gint a, gint b)
Internal function, copied from gst_util_greatest_common_divisor() to remove dependency of gstreamer.
void gst_tensors_info_free(GstTensorsInfo *info)
Free allocated data in tensors info structure.
guint gst_tensors_info_parse_dimensions_string(GstTensorsInfo *info, const gchar *dim_string)
Parse the string of dimensions.
gboolean gst_tensors_info_is_equal(const GstTensorsInfo *i1, const GstTensorsInfo *i2)
Compare tensors info.
@ _NNS_TENSOR_FORMAT_FLEXIBLE
gsize gst_tensor_get_element_size(tensor_type type)
Get element size of tensor type (byte per element)
GstTensorInfo info[NNS_TENSOR_MEMORY_MAX]
gchar * gst_tensors_info_get_names_string(const GstTensorsInfo *info)
Get the string of tensor names in tensors info.
enum _tensor_format tensor_format
Data format of tensor stream in the pipeline.
#define GST_TENSOR_META_VERSION
The version of tensor meta.
#define GST_TENSOR_META_IS_VALID(m)
Macro to check the meta is valid.
@ _NNS_TENSOR_FORMAT_STATIC
#define GST_TENSOR_META_MAGIC
Magic number of tensor meta.
static const guint tensor_element_size[]
Byte-per-element of each tensor element type.
@ _NNS_TENSOR_FORMAT_SPARSE
Internal data structure for configured tensors info (for other/tensors).
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.
guint gst_tensor_parse_dimension(const gchar *dimstr, tensor_dim dim)
Parse tensor dimension parameter string.
static const gchar * tensor_element_typename[]
String representations for each tensor element type.
gboolean gst_tensor_dimension_is_equal(const tensor_dim dim1, const tensor_dim dim2)
Compare the tensor dimension.
gboolean gst_tensors_config_is_equal(const GstTensorsConfig *c1, const GstTensorsConfig *c2)
Compare tensor config info.
gboolean gst_tensor_meta_info_validate(GstTensorMetaInfo *meta)
Check the meta info is valid.
gint find_key_strv(const gchar **strv, const gchar *key)
Find the index value of the given key string array.
gsize gst_tensor_meta_info_get_data_size(GstTensorMetaInfo *meta)
Get the data size calculated from tensor meta.
void gst_tensors_config_copy(GstTensorsConfig *dest, const GstTensorsConfig *src)
Copy tensors config.
gulong gst_tensor_get_element_count(const tensor_dim dim)
Count the number of elements of a tensor.
gsize gst_tensor_meta_info_get_header_size(GstTensorMetaInfo *meta)
Get the header size to handle a tensor meta.
gboolean gst_tensor_info_is_equal(const GstTensorInfo *i1, const GstTensorInfo *i2)
Compare tensor info.
gboolean gst_tensor_info_validate(const GstTensorInfo *info)
Check the tensor info is valid.
void gst_tensors_info_init(GstTensorsInfo *info)
Initialize the tensors info structure.
void _nnstreamer_error_write(const char *fmt,...)
overwrites the error message buffer with the new message.
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.
const gchar * gst_tensor_get_format_string(tensor_format format)
Get tensor format string.
gchar * gst_tensor_get_dimension_string(const tensor_dim dim)
Get dimension string from given tensor dimension.
gchar * gst_tensors_info_get_dimensions_string(const GstTensorsInfo *info)
Get the string of dimensions in tensors info.
gboolean gst_tensor_dimension_string_is_equal(const gchar *dimstr1, const gchar *dimstr2)
Compare dimension strings.
const gchar * gst_tensor_get_type_string(tensor_type type)
Get type string of tensor type.
gboolean gst_tensor_meta_info_convert(GstTensorMetaInfo *meta, GstTensorInfo *info)
Convert GstTensorMetaInfo structure to GstTensorInfo.
gboolean gst_tensor_meta_info_parse_header(GstTensorMetaInfo *meta, gpointer header)
Parse header and fill the tensor meta.
guint gst_tensor_dimension_get_rank(const tensor_dim dim)
Get the rank of tensor dimension.
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.
void gst_tensor_info_free(GstTensorInfo *info)
Free allocated data in tensor info structure.
gboolean gst_tensor_info_convert_to_meta(GstTensorInfo *info, GstTensorMetaInfo *meta)
Convert GstTensorInfo structure to GstTensorMetaInfo.
#define _STR_NULL(str)
If the given string is NULL, print "(NULL)". Copied from GST_STR_NULL
void gst_tensor_meta_info_get_version(GstTensorMetaInfo *meta, guint *major, guint *minor)
Get the version of tensor meta.
gchar * gst_tensors_info_get_types_string(const GstTensorsInfo *info)
Get the string of types in tensors info.
#define NNS_TENSOR_RANK_LIMIT
gboolean gst_tensors_config_validate(const GstTensorsConfig *config)
Check the tensors are all configured.
guint gst_tensor_dimension_get_min_rank(const tensor_dim dim)
Get the minimum rank of tensor dimension.
#define NNS_TENSOR_SIZE_EXTRA_LIMIT
Max number of extra tensors.