}
/**
+ * @brief Get data size of single tensor
+ * @param info tensor info structure
+ * @return data size
+ */
+gsize
+gst_tensor_info_get_size (const GstTensorInfo * info)
+{
+ gsize data_size;
+
+ g_return_val_if_fail (info != NULL, 0);
+
+ data_size = get_tensor_element_count (info->dimension) *
+ tensor_element_size[info->type];
+
+ return data_size;
+}
+
+/**
* @brief Initialize the tensors info structure
* @param info tensors info structure to be initialized
*/
* @param dim The tensor dimension
*/
size_t
-get_tensor_element_count (const uint32_t dim[NNS_TENSOR_RANK_LIMIT])
+get_tensor_element_count (const tensor_dim dim)
{
size_t count = 1;
int i;
if (index < 0) {
/** calculate all output tensors */
for (i = 0; i < info->num_tensors; i++) {
- out_size +=
- get_tensor_element_count (info->info[i].dimension) *
- tensor_element_size[info->info[i].type];
+ out_size += gst_tensor_info_get_size (&info->info[i]);
}
} else {
g_assert (index < info->num_tensors);
- out_size =
- get_tensor_element_count (info->info[index].dimension) *
- tensor_element_size[info->info[index].type];
+ out_size = gst_tensor_info_get_size (&info->info[index]);
}
return out_size;
gst_tensor_info_is_equal (const GstTensorInfo * i1, const GstTensorInfo * i2);
/**
+ * @brief Get data size of single tensor
+ * @param info tensor info structure
+ * @return data size
+ */
+extern gsize
+gst_tensor_info_get_size (const GstTensorInfo * info);
+
+/**
* @brief Initialize the tensors info structure
* @param info tensors info structure to be initialized
*/
typedef struct _pt_data
{
uint32_t id; /***< Just for testing */
- tensor_dim dim;
- tensor_type type;
+ GstTensorInfo info; /**< tensor info */
} pt_data;
/**
int i;
data->id = 0;
- data->dim[0] = D1;
- data->dim[1] = D2;
- data->dim[2] = D3;
+ data->info.dimension[0] = D1;
+ data->info.dimension[1] = D2;
+ data->info.dimension[2] = D3;
for (i = 3; i < NNS_TENSOR_RANK_LIMIT; i++)
- data->dim[i] = 1;
- data->type = _NNS_UINT8;
+ data->info.dimension[i] = 1;
+ data->info.type = _NNS_UINT8;
return data;
}
GstTensorsInfo * info)
{
pt_data *data = private_data;
- int i;
g_assert (data);
g_assert (NNS_TENSOR_RANK_LIMIT >= 3);
- info->info[0].dimension[0] = D1;
- info->info[0].dimension[1] = D2;
- info->info[0].dimension[2] = D3;
- for (i = 3; i < NNS_TENSOR_RANK_LIMIT; i++)
- info->info[0].dimension[i] = 1;
- info->info[0].type = _NNS_UINT8;
info->num_tensors = 1;
+ info->info[0] = data->info;
return 0;
}
GstTensorsInfo * info)
{
pt_data *data = private_data;
- int i;
g_assert (data);
g_assert (NNS_TENSOR_RANK_LIMIT >= 3);
- info->info[0].dimension[0] = D1;
- info->info[0].dimension[1] = D2;
- info->info[0].dimension[2] = D3;
- for (i = 3; i < NNS_TENSOR_RANK_LIMIT; i++)
- info->info[0].dimension[i] = 1;
- info->info[0].type = _NNS_UINT8;
info->num_tensors = 1;
+ info->info[0] = data->info;
return 0;
}
g_assert (input);
g_assert (output);
- size = get_tensor_element_count (data->dim) * tensor_element_size[data->type];
+ size = gst_tensor_info_get_size (&data->info);
g_assert (input[0].data != output[0].data);
memcpy (output[0].data, input[0].data, size);
g_assert (output);
for (t = 0; t < prop->output_meta.num_tensors; t++) {
- size = get_tensor_element_count (prop->output_meta.info[t].dimension) *
- tensor_element_size[prop->output_meta.info[t].type];
+ size = gst_tensor_info_get_size (&prop->output_meta.info[t]);
g_assert (input[t].data != output[t].data);
memcpy (output[t].data, input[t].data, size);
/* allocate output data */
elementsize = tensor_element_size[prop->output_meta.info[0].type];
+ size = gst_tensor_info_get_size (&prop->output_meta.info[0]);
- size =
- elementsize *
- get_tensor_element_count (prop->output_meta.info[0].dimension);
output[0].data = malloc (size);
/* This assumes the limit is 4 */
gst_buffer_map (inbuf, &src_info, GST_MAP_READ);
/** Making output buffer (one big buffer for check tensors) */
- out_size = get_tensor_element_count (filter->out_config.info.dimension) *
- tensor_element_size[filter->out_config.info.type];
+ out_size = gst_tensor_info_get_size (&filter->out_config.info);
outbuf = gst_buffer_new_allocate (NULL, out_size, NULL);
gst_buffer_map (outbuf, &dest_info, GST_MAP_WRITE);