From: Jaeyun Jung Date: Mon, 1 Apr 2024 03:20:26 +0000 (+0900) Subject: [C-Api] unnecessary info handle X-Git-Tag: accepted/tizen/unified/20240405.115731~10 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6105b1fc289f232ff357264e890298952d665778;p=platform%2Fcore%2Fapi%2Fmachine-learning.git [C-Api] unnecessary info handle Code clean, remove unnecessary code to create info handle for internal usage. Signed-off-by: Jaeyun Jung --- diff --git a/c/src/ml-api-common.c b/c/src/ml-api-common.c index b24dbf4..05bf859 100644 --- a/c/src/ml-api-common.c +++ b/c/src/ml-api-common.c @@ -749,6 +749,7 @@ _ml_tensors_data_create_no_alloc (const ml_tensors_info_h info, ml_tensors_data_s *_data; ml_tensors_info_s *_info; guint i; + int status = ML_ERROR_NONE; check_feature_state (ML_FEATURE); @@ -762,14 +763,18 @@ _ml_tensors_data_create_no_alloc (const ml_tensors_info_h info, _data = g_new0 (ml_tensors_data_s, 1); if (!_data) _ml_error_report_return (ML_ERROR_OUT_OF_MEMORY, - "Failed to allocate memory for tensors data with g_new0(). Probably the system is out of memory."); + "Failed to allocate memory for tensors data. Probably the system is out of memory."); g_mutex_init (&_data->lock); _info = (ml_tensors_info_s *) info; if (_info != NULL) { - /* Ignore error case when creating internal info handle (single-shot). */ - _ml_tensors_info_create_from (info, &_data->info); + status = _ml_tensors_info_create_from (info, &_data->info); + if (status != ML_ERROR_NONE) { + _ml_error_report_continue + ("Failed to create internal information handle for tensors data."); + goto error; + } G_LOCK_UNLESS_NOLOCK (*_info); _data->num_tensors = _info->info.num_tensors; @@ -780,8 +785,14 @@ _ml_tensors_data_create_no_alloc (const ml_tensors_info_h info, G_UNLOCK_UNLESS_NOLOCK (*_info); } - *data = _data; - return ML_ERROR_NONE; +error: + if (status == ML_ERROR_NONE) { + *data = _data; + } else { + _ml_tensors_data_destroy_internal (_data, FALSE); + } + + return status; } /** diff --git a/c/src/ml-api-inference-pipeline.c b/c/src/ml-api-inference-pipeline.c index c542bd3..3d56c85 100644 --- a/c/src/ml-api-inference-pipeline.c +++ b/c/src/ml-api-inference-pipeline.c @@ -295,7 +295,6 @@ cb_sink_event (GstElement * e, GstBuffer * b, gpointer user_data) guint i, num_tensors; GList *l; ml_tensors_data_s *_data = NULL; - ml_tensors_info_h out_info = NULL; GstTensorsInfo gst_info; int status; @@ -412,7 +411,6 @@ cb_sink_event (GstElement * e, GstBuffer * b, gpointer user_data) } /* Create new output info, data handle should be updated here. */ - _ml_tensors_info_create_from_gst (&out_info, &gst_info); _ml_tensors_info_create_from_gst (&_data->info, &gst_info); /* Iterate e->handles, pass the data to them */ @@ -424,7 +422,7 @@ cb_sink_event (GstElement * e, GstBuffer * b, gpointer user_data) callback = sink->callback_info->sink_cb; if (callback) - callback (_data, out_info, sink->callback_info->sink_pdata); + callback (_data, _data->info, sink->callback_info->sink_pdata); /** @todo Measure time. Warn if it takes long. Kill if it takes too long. */ } @@ -437,9 +435,6 @@ error: gst_memory_unref (mem[i]); } - if (out_info) - ml_tensors_info_destroy (out_info); - _ml_tensors_data_destroy_internal (_data, FALSE); _data = NULL; diff --git a/c/src/ml-api-inference-single.c b/c/src/ml-api-inference-single.c index f099d66..349470b 100644 --- a/c/src/ml-api-inference-single.c +++ b/c/src/ml-api-inference-single.c @@ -280,13 +280,23 @@ ml_check_nnfw_availability (ml_nnfw_type_e nnfw, ml_nnfw_hw_e hw, static void __setup_in_out_tensors (ml_single * single_h) { - int i; + guint i; ml_tensors_data_s *in_tensors = (ml_tensors_data_s *) single_h->in_tensors; ml_tensors_data_s *out_tensors = (ml_tensors_data_s *) single_h->out_tensors; /* Setup input buffer */ - _ml_tensors_info_free (in_tensors->info); - _ml_tensors_info_copy_from_gst (in_tensors->info, &single_h->in_info); + if (in_tensors) { + _ml_tensors_info_free (in_tensors->info); + _ml_tensors_info_copy_from_gst (in_tensors->info, &single_h->in_info); + } else { + ml_tensors_info_h info; + + _ml_tensors_info_create_from_gst (&info, &single_h->in_info); + _ml_tensors_data_create_no_alloc (info, &single_h->in_tensors); + + ml_tensors_info_destroy (info); + in_tensors = (ml_tensors_data_s *) single_h->in_tensors; + } in_tensors->num_tensors = single_h->in_info.num_tensors; for (i = 0; i < in_tensors->num_tensors; i++) { @@ -297,8 +307,18 @@ __setup_in_out_tensors (ml_single * single_h) } /* Setup output buffer */ - _ml_tensors_info_free (out_tensors->info); - _ml_tensors_info_copy_from_gst (out_tensors->info, &single_h->out_info); + if (out_tensors) { + _ml_tensors_info_free (out_tensors->info); + _ml_tensors_info_copy_from_gst (out_tensors->info, &single_h->out_info); + } else { + ml_tensors_info_h info; + + _ml_tensors_info_create_from_gst (&info, &single_h->out_info); + _ml_tensors_data_create_no_alloc (info, &single_h->out_tensors); + + ml_tensors_info_destroy (info); + out_tensors = (ml_tensors_data_s *) single_h->out_tensors; + } out_tensors->num_tensors = single_h->out_info.num_tensors; for (i = 0; i < out_tensors->num_tensors; i++) { @@ -800,8 +820,6 @@ ml_single_create_handle (ml_nnfw_type_e nnfw) { ml_single *single_h; GError *error; - ml_tensors_info_h info_h; - int status; gboolean created = FALSE; single_h = g_new0 (ml_single, 1); @@ -832,28 +850,6 @@ ml_single_create_handle (ml_nnfw_type_e nnfw) g_mutex_init (&single_h->mutex); g_cond_init (&single_h->cond); - /* Dummy info to allocate tensors-info handle in data. */ - status = ml_tensors_info_create_extended (&info_h); - if (status != ML_ERROR_NONE) { - _ml_error_report - ("Failed to create tensor information in single handle. Internal error or out of memory?"); - goto done; - } - - status = _ml_tensors_data_create_no_alloc (info_h, &single_h->in_tensors); - if (status != ML_ERROR_NONE) { - _ml_error_report - ("Failed to create input data in single handle. Internal error or out of memory?"); - goto done; - } - - status = _ml_tensors_data_create_no_alloc (info_h, &single_h->out_tensors); - if (status != ML_ERROR_NONE) { - _ml_error_report - ("Failed to create output data in single handle. Internal error or out of memory?"); - goto done; - } - single_h->klass = g_type_class_ref (G_TYPE_TENSOR_FILTER_SINGLE); if (single_h->klass == NULL) { _ml_error_report @@ -874,8 +870,6 @@ ml_single_create_handle (ml_nnfw_type_e nnfw) created = TRUE; done: - ml_tensors_info_destroy (info_h); - if (!created) { ml_single_close (single_h); single_h = NULL;