From 6ba9bd8e79660a2cad431d700ebf06e4681e48b6 Mon Sep 17 00:00:00 2001 From: Jaeyun Jung Date: Mon, 28 Aug 2023 18:44:34 +0900 Subject: [PATCH] [Common] util to get nth gst-info Use util function to get nth info from tensors-info struct. Signed-off-by: Jaeyun Jung --- ext/nnstreamer/tensor_filter/tensor_filter_nnfw.c | 9 +++++++-- .../tensor_filter/tensor_filter_trix_engine.cc | 19 +++++++++++-------- tests/nnstreamer_filter_openvino/unittest_openvino.cc | 11 +++++------ .../unittest_tizen_nnfw_runtime_raw.cc | 11 +++++------ 4 files changed, 28 insertions(+), 22 deletions(-) diff --git a/ext/nnstreamer/tensor_filter/tensor_filter_nnfw.c b/ext/nnstreamer/tensor_filter/tensor_filter_nnfw.c index 84bd646..d34fc74 100644 --- a/ext/nnstreamer/tensor_filter/tensor_filter_nnfw.c +++ b/ext/nnstreamer/tensor_filter/tensor_filter_nnfw.c @@ -393,7 +393,7 @@ nnfw_convert_to_gst_info (const nnfw_tinfo_s * nnfw_info, for (i = 0; i < nnfw_info->num_tensors; i++) { const nnfw_tensorinfo *ninfo = &nnfw_info->info[i]; - GstTensorInfo *ginfo = &gst_info->info[i]; + GstTensorInfo *ginfo = gst_tensors_info_get_nth_info (gst_info, i); gint idx; if (ninfo->rank > NNS_TENSOR_RANK_LIMIT) @@ -443,7 +443,12 @@ nnfw_tensor_info_set (const nnfw_pdata * pdata, struct nnfw_tensorinfo nnfw_info; gint err; gint idx; - const GstTensorInfo *info = &tensors_info->info[tensor_idx]; + GstTensorInfo *info; + + info = gst_tensors_info_get_nth_info ((GstTensorsInfo *) tensors_info, + tensor_idx); + if (!info) + return -EINVAL; err = nnfw_tensor_type_from_gst (info->type, &nnfw_info.dtype); if (err) diff --git a/ext/nnstreamer/tensor_filter/tensor_filter_trix_engine.cc b/ext/nnstreamer/tensor_filter/tensor_filter_trix_engine.cc index 985dfd4..c9288cf 100644 --- a/ext/nnstreamer/tensor_filter/tensor_filter_trix_engine.cc +++ b/ext/nnstreamer/tensor_filter/tensor_filter_trix_engine.cc @@ -70,6 +70,7 @@ TensorFilterTRIxEngine::getEmptyInstance () void TensorFilterTRIxEngine::configure_instance (const GstTensorFilterProperties *prop) { + GstTensorInfo *_info; uint32_t i, j, rank_limit; if (!prop->model_files[0] || prop->model_files[0][0] == '\0') { @@ -115,13 +116,14 @@ TensorFilterTRIxEngine::configure_instance (const GstTensorFilterProperties *pro if (prop->input_meta.num_tensors == 0) { nns_in_info_.num_tensors = model_meta_->input_seg_num; for (i = 0; i < nns_in_info_.num_tensors; i++) { - nns_in_info_.info[i].type = _NNS_UINT8; + _info = gst_tensors_info_get_nth_info (&nns_in_info_, i); + + _info->type = _NNS_UINT8; for (j = 0; j < rank_limit; j++) - nns_in_info_.info[i].dimension[j] - = model_meta_->input_seg_dims[i][rank_limit - j - 1]; + _info->dimension[j] = model_meta_->input_seg_dims[i][rank_limit - j - 1]; for (; j < NNS_TENSOR_RANK_LIMIT; j++) - nns_in_info_.info[i].dimension[j] = 1; + _info->dimension[j] = 1; } } else { gst_tensors_info_copy (&nns_in_info_, &prop->input_meta); @@ -131,13 +133,14 @@ TensorFilterTRIxEngine::configure_instance (const GstTensorFilterProperties *pro if (prop->output_meta.num_tensors == 0) { nns_out_info_.num_tensors = model_meta_->output_seg_num; for (i = 0; i < nns_out_info_.num_tensors; i++) { - nns_out_info_.info[i].type = _NNS_UINT8; + _info = gst_tensors_info_get_nth_info (&nns_out_info_, i); + + _info->type = _NNS_UINT8; for (j = 0; j < rank_limit; j++) - nns_out_info_.info[i].dimension[j] - = model_meta_->output_seg_dims[i][rank_limit - j - 1]; + _info->dimension[j] = model_meta_->output_seg_dims[i][rank_limit - j - 1]; for (; j < NNS_TENSOR_RANK_LIMIT; j++) - nns_out_info_.info[i].dimension[j] = 1; + _info->dimension[j] = 1; } } else { gst_tensors_info_copy (&nns_out_info_, &prop->output_meta); diff --git a/tests/nnstreamer_filter_openvino/unittest_openvino.cc b/tests/nnstreamer_filter_openvino/unittest_openvino.cc index 87c171b..a88e401 100644 --- a/tests/nnstreamer_filter_openvino/unittest_openvino.cc +++ b/tests/nnstreamer_filter_openvino/unittest_openvino.cc @@ -619,6 +619,7 @@ TEST (tensorFilterOpenvino, getTensorDim0) const GstTensorFilterFramework *fw = nnstreamer_filter_find (fw_name); GstTensorFilterProperties *prop = NULL; GstTensorsInfo nns_tensors_info; + GstTensorInfo *_info; gpointer private_data = NULL; std::string str_test_model; gchar *test_model; @@ -662,9 +663,8 @@ TEST (tensorFilterOpenvino, getTensorDim0) EXPECT_EQ (ret, 0); EXPECT_EQ (nns_tensors_info.num_tensors, MOBINET_V2_IN_NUM_TENSOR); for (uint32_t i = 0; i < MOBINET_V2_IN_NUM_TENSOR; ++i) { - for (uint32_t j = 0; j < NNS_TENSOR_RANK_LIMIT; ++j) { - EXPECT_EQ (nns_tensors_info.info[i].dimension[j], MOBINET_V2_IN_DIMS[j]); - } + _info = gst_tensors_info_get_nth_info (&nns_tensors_info, i); + EXPECT_TRUE (gst_tensor_dimension_is_equal (_info->dimension, MOBINET_V2_IN_DIMS)); } /* Test getOutputDimension () */ @@ -673,9 +673,8 @@ TEST (tensorFilterOpenvino, getTensorDim0) EXPECT_EQ (ret, 0); EXPECT_EQ (nns_tensors_info.num_tensors, MOBINET_V2_OUT_NUM_TENSOR); for (uint32_t i = 0; i < MOBINET_V2_OUT_NUM_TENSOR; ++i) { - for (uint32_t j = 0; j < NNS_TENSOR_RANK_LIMIT; ++j) { - EXPECT_EQ (nns_tensors_info.info[i].dimension[j], MOBINET_V2_OUT_DIMS[j]); - } + _info = gst_tensors_info_get_nth_info (&nns_tensors_info, i); + EXPECT_TRUE (gst_tensor_dimension_is_equal (_info->dimension, MOBINET_V2_OUT_DIMS)); } fw->close (prop, &private_data); diff --git a/tests/tizen_nnfw_runtime/unittest_tizen_nnfw_runtime_raw.cc b/tests/tizen_nnfw_runtime/unittest_tizen_nnfw_runtime_raw.cc index 9b7ca9a..ad7cc75 100644 --- a/tests/tizen_nnfw_runtime/unittest_tizen_nnfw_runtime_raw.cc +++ b/tests/tizen_nnfw_runtime/unittest_tizen_nnfw_runtime_raw.cc @@ -122,7 +122,7 @@ TEST (nnstreamerNnfwRuntimeRawFunctions, getDimension) */ TEST (nnstreamerNnfwRuntimeRawFunctions, setDimension) { - int ret, i; + int ret; void *data = NULL; GstTensorsInfo in_info, out_info, res; GstTensorMemory input, output; @@ -175,17 +175,16 @@ TEST (nnstreamerNnfwRuntimeRawFunctions, setDimension) EXPECT_EQ (res.num_tensors, in_info.num_tensors); EXPECT_EQ (res.info[0].type, in_info.info[0].type); - - for (i = 0; i < NNS_TENSOR_RANK_LIMIT; i++) - EXPECT_EQ (res.info[0].dimension[i], in_info.info[0].dimension[i]); + EXPECT_TRUE (gst_tensor_dimension_is_equal ( + res.info[0].dimension, in_info.info[0].dimension)); ret = sp->getOutputDimension (&prop, &data, &out_info); EXPECT_EQ (ret, 0); EXPECT_EQ (res.num_tensors, out_info.num_tensors); EXPECT_EQ (res.info[0].type, out_info.info[0].type); - for (i = 0; i < NNS_TENSOR_RANK_LIMIT; i++) - EXPECT_EQ (res.info[0].dimension[i], out_info.info[0].dimension[i]); + EXPECT_TRUE (gst_tensor_dimension_is_equal ( + res.info[0].dimension, out_info.info[0].dimension)); input.size = gst_tensor_info_get_size (&in_info.info[0]); output.size = gst_tensor_info_get_size (&out_info.info[0]); -- 2.7.4