From f9ac18f4cd0a78777e163b9de64406f1c18eb5fc Mon Sep 17 00:00:00 2001 From: Jaeyun Jung Date: Tue, 9 Apr 2024 19:02:56 +0900 Subject: [PATCH] [Service] fix svace issues Code clean, update function name for offloading and fix svace issues. Signed-off-by: Jaeyun Jung --- c/src/ml-api-service-offloading.c | 170 ++++++--------- c/src/ml-api-service-offloading.h | 55 +++-- c/src/ml-api-service-private.h | 8 +- c/src/ml-api-service-training-offloading.c | 330 +++++++++++++++-------------- c/src/ml-api-service-training-offloading.h | 33 ++- c/src/ml-api-service.c | 2 +- packaging/machine-learning-api.spec | 10 +- 7 files changed, 302 insertions(+), 306 deletions(-) diff --git a/c/src/ml-api-service-offloading.c b/c/src/ml-api-service-offloading.c index b151ac5..2ef9adf 100644 --- a/c/src/ml-api-service-offloading.c +++ b/c/src/ml-api-service-offloading.c @@ -30,32 +30,6 @@ #define MAX_PORT_NUM_LEN 6U /** - * @brief Enumeration for ml-service offloading mode type. - */ -typedef enum -{ - ML_SERVICE_OFFLOADING_MODE_TYPE_DEFAULT = 0, - ML_SERVICE_OFFLOADING_MODE_TYPE_TRAINING = 1, - - ML_SERVICE_OFFLOADING_MODE_TYPE_MAX -} ml_service_offloading_mode_type_e; - -/** - * @brief Enumeration for ml-offloading service type. - */ -typedef enum -{ - ML_SERVICE_OFFLOADING_TYPE_UNKNOWN = 0, - ML_SERVICE_OFFLOADING_TYPE_MODEL_RAW, - ML_SERVICE_OFFLOADING_TYPE_MODEL_URI, - ML_SERVICE_OFFLOADING_TYPE_PIPELINE_RAW = 3, /* The same value is defined and used in ml-api-service-training-offloading.c. */ - ML_SERVICE_OFFLOADING_TYPE_PIPELINE_URI, - ML_SERVICE_OFFLOADING_TYPE_REPLY = 5, /* The same value is defined and used in ml-api-service-training-offloading.c. */ - - ML_SERVICE_OFFLOADING_TYPE_MAX -} ml_service_offloading_type_e; - -/** * @brief Data struct for options. */ typedef struct @@ -71,7 +45,7 @@ typedef struct } edge_info_s; /** - * @brief Structure for ml_service_offloading + * @brief Structure for ml_service_offloading. */ typedef struct { @@ -81,7 +55,7 @@ typedef struct gchar *path; /**< A path to save the received model file */ GHashTable *table; - ml_service_offloading_mode_type_e offloading_mode; + ml_service_offloading_mode_e offloading_mode; void *priv; } _ml_service_offloading_s; @@ -398,6 +372,7 @@ _mlrs_process_service_offloading (nns_edge_data_h data_h, void *user_data) "Failed to get service type while processing the ml-offloading service."); } service_type = _mlrs_get_service_type (service_str); + ret = nns_edge_data_get_info (data_h, "service-key", &service_key); if (NNS_EDGE_ERROR_NONE != ret) { _ml_error_report_return (ret, @@ -406,7 +381,7 @@ _mlrs_process_service_offloading (nns_edge_data_h data_h, void *user_data) dir_path = _mlrs_get_model_dir_path (offloading_s, service_key); - if (offloading_s->offloading_mode == ML_SERVICE_OFFLOADING_MODE_TYPE_TRAINING) { + if (offloading_s->offloading_mode == ML_SERVICE_OFFLOADING_MODE_TRAINING) { ml_service_training_offloading_process_received_data (mls, data_h, dir_path, data, service_type); if (service_type == ML_SERVICE_OFFLOADING_TYPE_REPLY) { @@ -427,13 +402,15 @@ _mlrs_process_service_offloading (nns_edge_data_h data_h, void *user_data) switch (service_type) { case ML_SERVICE_OFFLOADING_TYPE_MODEL_URI: { - GByteArray *array = g_byte_array_new (); + GByteArray *array; if (!dir_path) { _ml_error_report_return (NNS_EDGE_ERROR_UNKNOWN, "Failed to get model directory path."); } + array = g_byte_array_new (); + if (!_mlrs_get_data_from_uri ((gchar *) data, array)) { g_byte_array_free (array, TRUE); _ml_error_report_return (NNS_EDGE_ERROR_IO, @@ -613,56 +590,54 @@ _mlrs_create_edge_handle (ml_service_s * mls, edge_info_s * edge_info) } /** - * @brief Set training offloading handle or Set null when destroying. - * @param[in] handle The handle of ml-service - * @param[in] training_handle training offloading handle or NULL. + * @brief Set offloading mode and private data. */ int -ml_service_offloading_set_training_handle (ml_service_h handle, - void *training_handle) +ml_service_offloading_set_mode (ml_service_h handle, + ml_service_offloading_mode_e mode, void *priv) { - int ret = ML_ERROR_NONE; - ml_service_s *mls = NULL; - _ml_service_offloading_s *offloading_s = NULL; + ml_service_s *mls = (ml_service_s *) handle; + _ml_service_offloading_s *offloading_s; - if (!handle) { + if (!_ml_service_handle_is_valid (mls)) { _ml_error_report_return (ML_ERROR_INVALID_PARAMETER, - "The parameter, 'handle' (ml_service_h), is NULL. It should be a valid ml_service_h."); + "The parameter, 'handle' (ml_service_h), is invalid. It should be a valid ml_service_h instance."); } - mls = (ml_service_s *) handle; offloading_s = (_ml_service_offloading_s *) mls->priv; - if (!offloading_s) { - _ml_error_report_return (ML_ERROR_INVALID_PARAMETER, - "An offloading instance must be created first."); - } - offloading_s->priv = training_handle; - offloading_s->offloading_mode = ML_SERVICE_OFFLOADING_MODE_TYPE_TRAINING; + offloading_s->offloading_mode = mode; + offloading_s->priv = priv; - return ret; + return ML_ERROR_NONE; } /** - * @brief Get training offloading handle. + * @brief Get offloading mode and private data. */ -void * -ml_service_offloading_get_training_handle (ml_service_h handle) +int +ml_service_offloading_get_mode (ml_service_h handle, + ml_service_offloading_mode_e * mode, void **priv) { - ml_service_s *mls = NULL; - _ml_service_offloading_s *offloading_s = NULL; + ml_service_s *mls = (ml_service_s *) handle; + _ml_service_offloading_s *offloading_s; - if (!handle) { - _ml_error_report - ("The parameter, 'handle' (ml_service_h), is NULL. It should be a valid ml_service_h."); - return NULL; + if (!_ml_service_handle_is_valid (mls)) { + _ml_error_report_return (ML_ERROR_INVALID_PARAMETER, + "The parameter, 'handle' (ml_service_h), is invalid. It should be a valid ml_service_h instance."); } - mls = (ml_service_s *) handle; + if (!mode || !priv) { + _ml_error_report_return (ML_ERROR_INVALID_PARAMETER, + "The parameter, mode or priv, is null. It should be a valid pointer."); + } offloading_s = (_ml_service_offloading_s *) mls->priv; - return offloading_s->priv; + *mode = offloading_s->offloading_mode; + *priv = offloading_s->priv; + + return ML_ERROR_NONE; } /** @@ -671,24 +646,28 @@ ml_service_offloading_get_training_handle (ml_service_h handle) int ml_service_offloading_release_internal (ml_service_s * mls) { - _ml_service_offloading_s *offloading_s = - (_ml_service_offloading_s *) mls->priv; + _ml_service_offloading_s *offloading_s; /* Supposed internal function call to release handle. */ - if (!offloading_s) + if (!mls || !mls->priv) return ML_ERROR_NONE; - if (offloading_s->offloading_mode == ML_SERVICE_OFFLOADING_MODE_TYPE_TRAINING) { + offloading_s = (_ml_service_offloading_s *) mls->priv; - /** 'ml_service_training_offloading_destroy' transfers internally trained models. - So keep offloading handle */ - if (ML_ERROR_NONE != ml_service_training_offloading_destroy (mls)) + if (offloading_s->offloading_mode == ML_SERVICE_OFFLOADING_MODE_TRAINING) { + /** + * 'ml_service_training_offloading_destroy' transfers internally trained models. + * So keep offloading handle. + */ + if (ML_ERROR_NONE != ml_service_training_offloading_destroy (mls)) { _ml_error_report ("Failed to release ml-service training offloading handle"); + } } if (offloading_s->edge_h) { nns_edge_release_handle (offloading_s->edge_h); + offloading_s->edge_h = NULL; } if (offloading_s->table) { @@ -711,8 +690,14 @@ ml_service_offloading_set_information (ml_service_h handle, const gchar * name, const gchar * value) { ml_service_s *mls = (ml_service_s *) handle; - _ml_service_offloading_s *offloading_s = - (_ml_service_offloading_s *) mls->priv; + _ml_service_offloading_s *offloading_s; + + if (!_ml_service_handle_is_valid (mls)) { + _ml_error_report_return (ML_ERROR_INVALID_PARAMETER, + "The parameter, 'handle' (ml_service_h), is invalid. It should be a valid ml_service_h instance."); + } + + offloading_s = (_ml_service_offloading_s *) mls->priv; if (g_ascii_strcasecmp (name, "path") == 0) { if (!g_file_test (value, G_FILE_TEST_IS_DIR)) { @@ -720,6 +705,7 @@ ml_service_offloading_set_information (ml_service_h handle, const gchar * name, "The given param, dir path '%s' is invalid or the dir is not found or accessible.", value); } + if (g_access (value, W_OK) != 0) { _ml_error_report_return (ML_ERROR_PERMISSION_DENIED, "Write permission to dir '%s' is denied.", value); @@ -792,37 +778,25 @@ ml_service_offloading_create (ml_service_h handle, ml_option_h option) int ml_service_offloading_start (ml_service_h handle) { - ml_service_s *mls = NULL; - _ml_service_offloading_s *offloading_s = NULL; + ml_service_s *mls = (ml_service_s *) handle; + _ml_service_offloading_s *offloading_s; int ret = ML_ERROR_NONE; - if (!handle) { - _ml_error_report - ("The parameter, 'handle' (ml_service_h), is NULL. It should be a valid ml_service_h."); - goto error; + if (!_ml_service_handle_is_valid (mls)) { + _ml_error_report_return (ML_ERROR_INVALID_PARAMETER, + "The parameter, 'handle' (ml_service_h), is invalid. It should be a valid ml_service_h instance."); } - mls = (ml_service_s *) handle; offloading_s = (_ml_service_offloading_s *) mls->priv; - if (!offloading_s) { - _ml_error_report - ("The parameter, 'handle' (ml_service_h), does not have offloading service handle."); - goto error; - } - if (offloading_s->offloading_mode == ML_SERVICE_OFFLOADING_MODE_TYPE_TRAINING) { + if (offloading_s->offloading_mode == ML_SERVICE_OFFLOADING_MODE_TRAINING) { ret = ml_service_training_offloading_start (mls); if (ret != ML_ERROR_NONE) { _ml_error_report ("Failed to start training offloading."); - goto error; } } return ret; - -error: - ml_service_offloading_release_internal (mls); - return ret; } @@ -832,37 +806,25 @@ error: int ml_service_offloading_stop (ml_service_h handle) { - ml_service_s *mls = NULL; - _ml_service_offloading_s *offloading_s = NULL; + ml_service_s *mls = (ml_service_s *) handle; + _ml_service_offloading_s *offloading_s; int ret = ML_ERROR_NONE; - if (!handle) { - _ml_error_report - ("The parameter, 'handle' (ml_service_h), is NULL. It should be a valid ml_service_h."); - goto error; + if (!_ml_service_handle_is_valid (mls)) { + _ml_error_report_return (ML_ERROR_INVALID_PARAMETER, + "The parameter, 'handle' (ml_service_h), is invalid. It should be a valid ml_service_h instance."); } - mls = (ml_service_s *) handle; offloading_s = (_ml_service_offloading_s *) mls->priv; - if (!offloading_s) { - _ml_error_report - ("The parameter, 'handle' (ml_service_h), does not have offloading service handle."); - goto error; - } - if (offloading_s->offloading_mode == ML_SERVICE_OFFLOADING_MODE_TYPE_TRAINING) { + if (offloading_s->offloading_mode == ML_SERVICE_OFFLOADING_MODE_TRAINING) { ret = ml_service_training_offloading_stop (mls); if (ret != ML_ERROR_NONE) { _ml_error_report ("Failed to stop training offloading."); - goto error; } } return ret; - -error: - ml_service_offloading_release_internal (mls); - return ret; } /** diff --git a/c/src/ml-api-service-offloading.h b/c/src/ml-api-service-offloading.h index 3fdec90..35b85b3 100644 --- a/c/src/ml-api-service-offloading.h +++ b/c/src/ml-api-service-offloading.h @@ -19,6 +19,32 @@ extern "C" { #endif /* __cplusplus */ +/** + * @brief Enumeration for ml-offloading service type. + */ +typedef enum +{ + ML_SERVICE_OFFLOADING_TYPE_UNKNOWN = 0, + ML_SERVICE_OFFLOADING_TYPE_MODEL_RAW = 1, + ML_SERVICE_OFFLOADING_TYPE_MODEL_URI = 2, + ML_SERVICE_OFFLOADING_TYPE_PIPELINE_RAW = 3, + ML_SERVICE_OFFLOADING_TYPE_PIPELINE_URI = 4, + ML_SERVICE_OFFLOADING_TYPE_REPLY = 5, + + ML_SERVICE_OFFLOADING_TYPE_MAX +} ml_service_offloading_type_e; + +/** + * @brief Enumeration for ml-service offloading mode. + */ +typedef enum +{ + ML_SERVICE_OFFLOADING_MODE_NONE = 0, + ML_SERVICE_OFFLOADING_MODE_TRAINING = 1, + + ML_SERVICE_OFFLOADING_MODE_MAX +} ml_service_offloading_mode_e; + #if defined(ENABLE_SERVICE_OFFLOADING) /** * @brief Parse configuration file and create offloading service. @@ -34,9 +60,8 @@ int ml_service_offloading_create (ml_service_h handle, ml_option_h option); /** * @brief Start ml offloading service. - * @remarks The @a handle should be destroyed using ml_service_destroy(). * @param[in] handle ml-service handle created by ml_service_new(). - * @return @c 0 on Success. Otherwise a negative error value. + * @return @c 0 on success. Otherwise a negative error value. * @retval #ML_ERROR_NONE Successful. * @retval #ML_ERROR_NOT_SUPPORTED Not supported. * @retval #ML_ERROR_INVALID_PARAMETER Fail. The parameter is invalid. @@ -49,9 +74,8 @@ int ml_service_offloading_start (ml_service_h handle); /** * @brief Stop ml offloading service. - * @remarks The @a handle should be destroyed using ml_service_destroy(). * @param[in] handle ml-service handle created by ml_service_new(). - * @return @c 0 on Success. Otherwise a negative error value. + * @return @c 0 on success. Otherwise a negative error value. * @retval #ML_ERROR_NONE Successful. * @retval #ML_ERROR_NOT_SUPPORTED Not supported. * @retval #ML_ERROR_INVALID_PARAMETER Fail. The parameter is invalid. @@ -99,21 +123,28 @@ int ml_service_offloading_set_service (ml_service_h handle, const char *name, co int ml_service_offloading_set_information (ml_service_h handle, const char *name, const char *value); /** - * @brief Set training offloading handle or Set null when destroying. - * @param[in] handle The handle of ml-service - * @param[in] training_handle training offloading handle or NULL. + * @brief Set offloading mode and private data. + * @param[in] handle The handle of ml-service. + * @param[in] mode The offloading mode. + * @param[in] priv The private data for each offloading mode. * @return @c 0 on success. Otherwise a negative error value. * @retval #ML_ERROR_NONE Successful. * @retval #ML_ERROR_NOT_SUPPORTED Not supported. * @retval #ML_ERROR_INVALID_PARAMETER Given parameter is invalid. */ -int ml_service_offloading_set_training_handle (ml_service_h handle, void *training_handle); +int ml_service_offloading_set_mode (ml_service_h handle, ml_service_offloading_mode_e mode, void *priv); /** - * @brief Get training offloading handle. + * @brief Get offloading mode and private data. * @param[in] handle The handle of ml-service. + * @param[out] mode The offloading mode. + * @param[out] priv The private data for each offloading mode. + * @return @c 0 on success. Otherwise a negative error value. + * @retval #ML_ERROR_NONE Successful. + * @retval #ML_ERROR_NOT_SUPPORTED Not supported. + * @retval #ML_ERROR_INVALID_PARAMETER Given parameter is invalid. */ -void *ml_service_offloading_get_training_handle (ml_service_h handle); +int ml_service_offloading_get_mode (ml_service_h handle, ml_service_offloading_mode_e *mode, void **priv); /** * @brief Internal function to release ml-service offloading data. @@ -127,8 +158,8 @@ int ml_service_offloading_release_internal (ml_service_s *mls); #define ml_service_offloading_set_service(...) ML_ERROR_NOT_SUPPORTED #define ml_service_offloading_set_information(...) ML_ERROR_NOT_SUPPORTED #define ml_service_offloading_release_internal(...) ML_ERROR_NOT_SUPPORTED -#define ml_service_offloading_set_training_handle(...) ML_ERROR_NOT_SUPPORTED -#define ml_service_offloading_get_training_handle(...) ML_ERROR_NOT_SUPPORTED +#define ml_service_offloading_set_mode(...) ML_ERROR_NOT_SUPPORTED +#define ml_service_offloading_get_mode(...) ML_ERROR_NOT_SUPPORTED #endif /* ENABLE_SERVICE_OFFLOADING */ #ifdef __cplusplus diff --git a/c/src/ml-api-service-private.h b/c/src/ml-api-service-private.h index 240efd9..436700a 100644 --- a/c/src/ml-api-service-private.h +++ b/c/src/ml-api-service-private.h @@ -82,7 +82,7 @@ typedef struct /** * @brief Internal function to validate ml-service handle. */ -gboolean _ml_service_handle_is_valid (ml_service_s * mls); +gboolean _ml_service_handle_is_valid (ml_service_s *mls); /** * @brief Internal function to create new ml-service handle. @@ -92,7 +92,7 @@ ml_service_s * _ml_service_create_internal (ml_service_type_e ml_service_type); /** * @brief Internal function to release ml-service handle. */ -int _ml_service_destroy_internal (ml_service_s * mls); +int _ml_service_destroy_internal (ml_service_s *mls); /** * @brief Internal function to get ml-service event callback. @@ -112,12 +112,12 @@ int _ml_service_conf_parse_tensors_info (JsonNode *info_node, ml_tensors_info_h /** * @brief Internal function to release ml-service pipeline data. */ -int ml_service_pipeline_release_internal (ml_service_s * mls); +int ml_service_pipeline_release_internal (ml_service_s *mls); /** * @brief Internal function to release ml-service query data. */ -int ml_service_query_release_internal (ml_service_s * mls); +int ml_service_query_release_internal (ml_service_s *mls); #ifdef __cplusplus } diff --git a/c/src/ml-api-service-training-offloading.c b/c/src/ml-api-service-training-offloading.c index 12829db..c1a48a9 100644 --- a/c/src/ml-api-service-training-offloading.c +++ b/c/src/ml-api-service-training-offloading.c @@ -5,7 +5,7 @@ * @file ml-api-service-training-offloading.c * @date 5 Apr 2024 * @brief ML training offloading service of NNStreamer/Service C-API - * @see https://github.com/nnstreamer/nnstreamer + * @see https://github.com/nnstreamer/api * @author Hyunil Park * @bug No known bugs except for NYI items */ @@ -21,14 +21,12 @@ #include "ml-api-service.h" #include "ml-api-service-training-offloading.h" -#define ML_SERVICE_OFFLOADING_TYPE_PIPELINE_RAW 3 -#define ML_SERVICE_OFFLOADING_TYPE_REPLY 5 - /** It(@~~@) will be replaced with the path set by the app.*/ #define APP_RW_PATH "@APP_RW_PATH@" #define REMOTE_APP_RW_PATH "@REMOTE_APP_RW_PATH@" /** combined with trained model file name set in conf */ #define TRAINED_MODEL_FILE "@TRAINED_MODEL_FILE@" + /** * @brief Internal enumeration for ml-service training offloading types. */ @@ -60,7 +58,6 @@ typedef struct { gchar *name; ml_training_offloading_node_type_e type; - ml_tensors_info_h info; void *handle; void *mls; } ml_training_offloading_node_info_s; @@ -96,18 +93,20 @@ _ml_service_training_offloadin_conf_parse_json (ml_service_s * mls, JsonObject * object) { ml_training_services_s *training_s = NULL; + ml_service_offloading_mode_e mode = ML_SERVICE_OFFLOADING_MODE_NONE; JsonObject *training_obj, *data_obj; JsonNode *training_node, *data_node, *pipline_node; const gchar *key; const gchar *val; - GList *list = NULL, *iter; + GList *list, *iter; - g_return_val_if_fail (mls != NULL, ML_ERROR_INVALID_PARAMETER); g_return_val_if_fail (object != NULL, ML_ERROR_INVALID_PARAMETER); - training_s = (ml_training_services_s *) - ml_service_offloading_get_training_handle (mls); - g_return_val_if_fail (training_s != NULL, ML_ERROR_INVALID_PARAMETER); + ml_service_offloading_get_mode (mls, &mode, (void **) &training_s); + if (mode != ML_SERVICE_OFFLOADING_MODE_TRAINING || training_s == NULL) { + _ml_error_report_return (ML_ERROR_INVALID_PARAMETER, + "The ml service is not training mode."); + } val = json_object_get_string_member (object, "node-type"); @@ -126,9 +125,10 @@ _ml_service_training_offloadin_conf_parse_json (ml_service_s * mls, val = json_object_get_string_member (training_obj, "sender-pipeline"); training_s->sender_pipe = g_strdup (val); - if (!json_object_has_member (training_obj, "transfer-data")) + if (!json_object_has_member (training_obj, "transfer-data")) { _ml_error_report_return (ML_ERROR_INVALID_PARAMETER, "The given param, \"transfer-data\" is invalid."); + } data_node = json_object_get_member (training_obj, "transfer-data"); data_obj = json_node_get_object (data_node); @@ -140,20 +140,23 @@ _ml_service_training_offloadin_conf_parse_json (ml_service_s * mls, for (iter = list; iter != NULL; iter = g_list_next (iter)) { key = iter->data; + if (!STR_IS_VALID (key)) { _ml_error_report_return (ML_ERROR_INVALID_PARAMETER, - "The parameter, 'key' is NULL. It should be a valid string."); + "The parameter, 'key' is invalid. It should be a valid string."); } - val = json_object_get_string_member (data_obj, iter->data); + val = json_object_get_string_member (data_obj, key); + if (!STR_IS_VALID (val)) { /* pipeline is a JSON string */ - pipline_node = json_object_get_member (data_obj, iter->data); + pipline_node = json_object_get_member (data_obj, key); val = json_to_string (pipline_node, TRUE); - if (!g_strstr_len (val, -1, "pipeline")) + if (!g_strstr_len (val, -1, "pipeline")) { _ml_error_report_return (ML_ERROR_INVALID_PARAMETER, "The parameter, 'val' is invalid. It should be a valid string."); + } } g_hash_table_insert (training_s->transfer_data_table, g_strdup (key), @@ -189,7 +192,6 @@ _ml_training_offloading_node_info_free (gpointer data) static int _ml_service_create_training_offloading (ml_service_s * mls) { - int ret = ML_ERROR_NONE; ml_training_services_s *training_s = NULL; g_return_val_if_fail (mls != NULL, ML_ERROR_INVALID_PARAMETER); @@ -200,27 +202,32 @@ _ml_service_create_training_offloading (ml_service_s * mls) "Failed to allocate memory for the service handle's private data. Out of memory?"); } + g_cond_init (&training_s->received_cond); + g_mutex_init (&training_s->received_lock); + + training_s->type = ML_TRAINING_OFFLOADING_TYPE_UNKNOWN; + + ml_service_offloading_set_mode (mls, + ML_SERVICE_OFFLOADING_MODE_TRAINING, training_s); + training_s->transfer_data_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); if (!training_s->transfer_data_table) { - _ml_error_report ("Failed to allocate memory for the hash table."); + ml_service_training_offloading_destroy (mls); + _ml_error_report_return (ML_ERROR_OUT_OF_MEMORY, + "Failed to allocate memory for the data table. Out of memory?"); } training_s->node_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, _ml_training_offloading_node_info_free); if (!training_s->node_table) { - _ml_error_report ("Failed to allocate memory for the hash table."); + ml_service_training_offloading_destroy (mls); + _ml_error_report_return (ML_ERROR_OUT_OF_MEMORY, + "Failed to allocate memory for the node table. Out of memory?"); } - g_cond_init (&training_s->received_cond); - g_mutex_init (&training_s->received_lock); - - training_s->type = ML_TRAINING_OFFLOADING_TYPE_UNKNOWN; - - ret = ml_service_offloading_set_training_handle (mls, training_s); - - return ret; + return ML_ERROR_NONE; } /** @@ -242,7 +249,8 @@ ml_service_training_offloading_create (ml_service_s * mls, JsonObject * object) if (!node) { _ml_logw ("The parameter, 'object' has not `training`. It's not training offloading"); - return ret; + /* Internal condition when given configuration is not training. */ + return ML_ERROR_NONE; } ret = _ml_service_create_training_offloading (mls); @@ -275,20 +283,21 @@ _ml_service_training_offloading_request (ml_service_s * mls, g_return_val_if_fail (data != NULL, ML_ERROR_INVALID_PARAMETER); g_return_val_if_fail (len > 0, ML_ERROR_INVALID_PARAMETER); - ret = ml_tensors_info_create (&in_info); + ml_tensors_info_create (&in_info); ml_tensors_info_set_count (in_info, 1); ml_tensors_info_set_tensor_type (in_info, 0, ML_TENSOR_TYPE_UINT8); in_dim[0] = len; ml_tensors_info_set_tensor_dimension (in_info, 0, in_dim); - ret = ml_tensors_data_create (in_info, &input); - ret = ml_tensors_data_set_tensor_data (input, 0, data, len); + ml_tensors_data_create (in_info, &input); + ml_tensors_data_set_tensor_data (input, 0, data, len); ret = ml_service_offloading_request (mls, service_name, input); - if (ret != ML_ERROR_NONE) - _ml_error_report_return (ret, "Failed to request service(name:%s)", - service_name); - ret = ml_tensors_info_destroy (in_info); - ret = ml_tensors_data_destroy (input); + if (ret != ML_ERROR_NONE) { + _ml_error_report ("Failed to request service '%s'.)", service_name); + } + + ml_tensors_info_destroy (in_info); + ml_tensors_data_destroy (input); return ret; } @@ -300,18 +309,19 @@ static int _ml_service_training_offloading_services_request (ml_service_s * mls) { ml_training_services_s *training_s = NULL; + ml_service_offloading_mode_e mode = ML_SERVICE_OFFLOADING_MODE_NONE; int ret = ML_ERROR_NONE; - GList *list = NULL, *iter; - gchar *transfer_data = NULL, *service_name = NULL, *contents = - NULL, *pipeline = NULL; + GList *list, *iter; + gchar *transfer_data = NULL, *service_name = NULL; + gchar *contents = NULL, *pipeline = NULL; guint changed; gsize len; - g_return_val_if_fail (mls != NULL, ML_ERROR_INVALID_PARAMETER); - - training_s = (ml_training_services_s *) - ml_service_offloading_get_training_handle (mls); - g_return_val_if_fail (training_s != NULL, ML_ERROR_INVALID_PARAMETER); + ml_service_offloading_get_mode (mls, &mode, (void **) &training_s); + if (mode != ML_SERVICE_OFFLOADING_MODE_TRAINING || training_s == NULL) { + _ml_error_report_return (ML_ERROR_INVALID_PARAMETER, + "The ml service is not training mode."); + } _ml_logd ("path set by app:%s ", training_s->path); @@ -322,13 +332,13 @@ _ml_service_training_offloading_services_request (ml_service_s * mls) } for (iter = list; iter != NULL; iter = g_list_next (iter)) { + const gchar *name = iter->data; + transfer_data = - g_strdup (g_hash_table_lookup (training_s->transfer_data_table, - (gchar *) iter->data)); + g_strdup (g_hash_table_lookup (training_s->transfer_data_table, name)); if (g_strstr_len (transfer_data, -1, APP_RW_PATH)) { - transfer_data = - _ml_replace_string (transfer_data, APP_RW_PATH, + transfer_data = _ml_replace_string (transfer_data, APP_RW_PATH, training_s->path, NULL, &changed); _ml_logd ("transfer_data:%s", transfer_data); @@ -337,19 +347,15 @@ _ml_service_training_offloading_services_request (ml_service_s * mls) _ml_error_report ("Failed to read file:%s", transfer_data); goto error; } - ret = - _ml_service_training_offloading_request (mls, (gchar *) iter->data, - contents, len); + ret = _ml_service_training_offloading_request (mls, name, contents, len); if (ret != ML_ERROR_NONE) { - _ml_error_report ("Failed to request service(%s)", - (gchar *) iter->data); + _ml_error_report ("Failed to request service '%s'.", name); goto error; } g_free (transfer_data); g_free (contents); transfer_data = NULL; contents = NULL; - } else if (g_strstr_len (transfer_data, -1, "pipeline")) { service_name = g_strdup (iter->data); pipeline = g_strdup (transfer_data); @@ -358,17 +364,19 @@ _ml_service_training_offloading_services_request (ml_service_s * mls) } if (pipeline) { - /** The remote sender sends the last in the pipeline. - When the pipeline arrives, the remote receiver determines that the sender has sent all the necessary files specified in the pipeline. - pipeline description must be sent last. */ + /** + * The remote sender sends the last in the pipeline. + * When the pipeline arrives, the remote receiver determines that the sender has sent all the necessary files specified in the pipeline. + * pipeline description must be sent last. + */ _ml_logd ("In case of pipeline, @REMOTE_APP_RW_PATH@ will be replaced at the remote receiver.\n transfer_data:pipeline(%s),", pipeline); - ret = - _ml_service_training_offloading_request (mls, service_name, pipeline, + ret = _ml_service_training_offloading_request (mls, service_name, pipeline, strlen (pipeline) + 1); - if (ret != ML_ERROR_NONE) + if (ret != ML_ERROR_NONE) { _ml_error_report ("Failed to request service(%s)", service_name); + } } error: @@ -386,7 +394,8 @@ error: static void check_received_data (ml_training_services_s * training_s) { - int loop = 100; /*FIXME: let's value by conf */ + /** @todo FIXME: let's value by conf */ + int loop = 100; g_return_if_fail (training_s != NULL); @@ -409,8 +418,8 @@ check_received_data (ml_training_services_s * training_s) _ml_loge ("Required data is null, receive_pipe:%s", training_s->receiver_pipe_json_str); - training_s->is_received = FALSE; g_mutex_lock (&training_s->received_lock); + training_s->is_received = FALSE; g_cond_signal (&training_s->received_cond); g_mutex_unlock (&training_s->received_lock); } @@ -418,11 +427,13 @@ check_received_data (ml_training_services_s * training_s) /** * @brief Check if all necessary data is received */ -static int +static gboolean _ml_service_training_offloading_check_received_data (ml_training_services_s * training_s) { - g_return_val_if_fail (training_s != NULL, ML_ERROR_INVALID_PARAMETER); + gboolean is_received = FALSE; + + g_return_val_if_fail (training_s != NULL, FALSE); training_s->received_thread = g_thread_new ("check_received_file", (GThreadFunc) check_received_data, @@ -437,10 +448,11 @@ _ml_service_training_offloading_check_received_data (ml_training_services_s * break; } + is_received = training_s->is_received; g_mutex_unlock (&training_s->received_lock); _ml_logd ("unlock, receive all data"); - return training_s->is_received; + return is_received; } /** @@ -451,12 +463,13 @@ _ml_service_training_offloading_replce_pipeline_data_path (ml_service_s * mls) { guint changed = 0; ml_training_services_s *training_s = NULL; + ml_service_offloading_mode_e mode = ML_SERVICE_OFFLOADING_MODE_NONE; - g_return_if_fail (mls != NULL); - - training_s = (ml_training_services_s *) - ml_service_offloading_get_training_handle (mls); - g_return_if_fail (training_s != NULL); + ml_service_offloading_get_mode (mls, &mode, (void **) &training_s); + if (mode != ML_SERVICE_OFFLOADING_MODE_TRAINING || training_s == NULL) { + _ml_error_report ("The ml service is not training mode."); + return; + } if (training_s->type == ML_TRAINING_OFFLOADING_TYPE_SENDER) { if (training_s->sender_pipe) { @@ -512,13 +525,16 @@ _invoke_event_new_data (ml_service_s * mls, const char *name, goto done; status = _ml_information_set (info, "data", (void *) data, NULL); - if (status == ML_ERROR_NONE) - cb_info.cb (ML_SERVICE_EVENT_NEW_DATA, info, cb_info.pdata); + if (status != ML_ERROR_NONE) + goto done; + + cb_info.cb (ML_SERVICE_EVENT_NEW_DATA, info, cb_info.pdata); } done: - if (info) + if (info) { ml_information_destroy (info); + } if (status != ML_ERROR_NONE) { _ml_error_report ("Failed to invoke 'new data' event."); @@ -557,13 +573,14 @@ _ml_service_training_offloading_node_info_new (ml_service_s * mls, { ml_training_offloading_node_info_s *node_info; ml_training_services_s *training_s = NULL; + ml_service_offloading_mode_e mode = ML_SERVICE_OFFLOADING_MODE_NONE; - g_return_val_if_fail (mls != NULL, NULL); g_return_val_if_fail (name != NULL, NULL); - training_s = (ml_training_services_s *) - ml_service_offloading_get_training_handle (mls); - g_return_val_if_fail (training_s != NULL, NULL); + ml_service_offloading_get_mode (mls, &mode, (void **) &training_s); + if (mode != ML_SERVICE_OFFLOADING_MODE_TRAINING || training_s == NULL) { + _ml_error_report_return (NULL, "The ml service is not training mode."); + } if (g_hash_table_lookup (training_s->node_table, name)) { _ml_error_report_return (NULL, @@ -585,7 +602,6 @@ _ml_service_training_offloading_node_info_new (ml_service_s * mls, return node_info; } - /** * @brief Internal function to parse the node info in pipeline. */ @@ -600,13 +616,15 @@ _ml_service_training_offloading_conf_parse_pipeline_node (ml_service_s * mls, JsonObject *node_object; ml_training_offloading_node_info_s *node_info = NULL; ml_training_services_s *training_s = NULL; + ml_service_offloading_mode_e mode = ML_SERVICE_OFFLOADING_MODE_NONE; - g_return_val_if_fail (mls != NULL, ML_ERROR_INVALID_PARAMETER); g_return_val_if_fail (node != NULL, ML_ERROR_INVALID_PARAMETER); - training_s = (ml_training_services_s *) - ml_service_offloading_get_training_handle (mls); - g_return_val_if_fail (training_s != NULL, ML_ERROR_INVALID_PARAMETER); + ml_service_offloading_get_mode (mls, &mode, (void **) &training_s); + if (mode != ML_SERVICE_OFFLOADING_MODE_TRAINING || training_s == NULL) { + _ml_error_report_return (ML_ERROR_INVALID_PARAMETER, + "The ml service is not training mode."); + } n = 1; if (JSON_NODE_HOLDS_ARRAY (node)) { @@ -620,9 +638,10 @@ _ml_service_training_offloading_conf_parse_pipeline_node (ml_service_s * mls, else node_object = json_node_get_object (node); - if (!json_object_has_member (node_object, "name")) + if (!json_object_has_member (node_object, "name")) { _ml_error_report_return (ret, "Failed to parse configuration file, cannot get the name for pipeline node."); + } name = json_object_get_string_member (node_object, "name"); @@ -634,13 +653,11 @@ _ml_service_training_offloading_conf_parse_pipeline_node (ml_service_s * mls, switch (type) { case ML_TRAINING_OFFLOADING_NODE_TYPE_TRAINING: - ret = - ml_pipeline_element_get_handle (training_s->pipeline_h, name, + ret = ml_pipeline_element_get_handle (training_s->pipeline_h, name, &node_info->handle); break; case ML_TRAINING_OFFLOADING_NODE_TYPE_OUTPUT: - ret = - ml_pipeline_sink_register (training_s->pipeline_h, name, + ret = ml_pipeline_sink_register (training_s->pipeline_h, name, _pipeline_sink_cb, node_info, &node_info->handle); break; default: @@ -657,7 +674,6 @@ _ml_service_training_offloading_conf_parse_pipeline_node (ml_service_s * mls, return ret; } - /** * @brief register sink callback */ @@ -673,8 +689,7 @@ _ml_service_training_offloading_conf_parse_pipeline (ml_service_s * mls, if (json_object_has_member (pipe, "output_node")) { node = json_object_get_member (pipe, "output_node"); - ret = - _ml_service_training_offloading_conf_parse_pipeline_node (mls, node, + ret = _ml_service_training_offloading_conf_parse_pipeline_node (mls, node, ML_TRAINING_OFFLOADING_NODE_TYPE_OUTPUT); if (ret != ML_ERROR_NONE) { _ml_error_report_return (ret, @@ -684,8 +699,7 @@ _ml_service_training_offloading_conf_parse_pipeline (ml_service_s * mls, if (json_object_has_member (pipe, "training_node")) { node = json_object_get_member (pipe, "training_node"); - ret = - _ml_service_training_offloading_conf_parse_pipeline_node (mls, node, + ret = _ml_service_training_offloading_conf_parse_pipeline_node (mls, node, ML_TRAINING_OFFLOADING_NODE_TYPE_TRAINING); if (ret != ML_ERROR_NONE) { _ml_error_report_return (ret, @@ -704,13 +718,15 @@ ml_service_training_offloading_set_path (ml_service_s * mls, const gchar * path) { int ret = ML_ERROR_NONE; ml_training_services_s *training_s = NULL; + ml_service_offloading_mode_e mode = ML_SERVICE_OFFLOADING_MODE_NONE; - g_return_val_if_fail (mls != NULL, ML_ERROR_INVALID_PARAMETER); g_return_val_if_fail (path != NULL, ML_ERROR_INVALID_PARAMETER); - training_s = (ml_training_services_s *) - ml_service_offloading_get_training_handle (mls); - g_return_val_if_fail (training_s != NULL, ML_ERROR_INVALID_PARAMETER); + ml_service_offloading_get_mode (mls, &mode, (void **) &training_s); + if (mode != ML_SERVICE_OFFLOADING_MODE_TRAINING || training_s == NULL) { + _ml_error_report_return (ML_ERROR_INVALID_PARAMETER, + "The ml service is not training mode."); + } g_free (training_s->path); training_s->path = g_strdup (path); @@ -729,24 +745,23 @@ ml_service_training_offloading_start (ml_service_s * mls) JsonObject *pipeline_obj; JsonObject *pipe; ml_training_services_s *training_s = NULL; + ml_service_offloading_mode_e mode = ML_SERVICE_OFFLOADING_MODE_NONE; - if (!mls) { + ml_service_offloading_get_mode (mls, &mode, (void **) &training_s); + if (mode != ML_SERVICE_OFFLOADING_MODE_TRAINING || training_s == NULL) { _ml_error_report_return (ML_ERROR_INVALID_PARAMETER, - "The parameter, 'mls' (ml_service_s), is NULL."); + "The ml service is not training mode."); } - training_s = (ml_training_services_s *) - ml_service_offloading_get_training_handle (mls); - g_return_val_if_fail (training_s != NULL, ML_ERROR_INVALID_PARAMETER); - if (training_s->type == ML_TRAINING_OFFLOADING_TYPE_SENDER) { ret = _ml_service_training_offloading_services_request (mls); - if (ret != ML_ERROR_NONE) + if (ret != ML_ERROR_NONE) { _ml_error_report_return (ret, "Failed to request service"); + } + _ml_service_training_offloading_replce_pipeline_data_path (mls); - ret = - ml_pipeline_construct (training_s->sender_pipe, NULL, NULL, + ret = ml_pipeline_construct (training_s->sender_pipe, NULL, NULL, &training_s->pipeline_h); if (ML_ERROR_NONE != ret) { _ml_error_report_return (ret, "Failed to construct pipeline"); @@ -754,15 +769,14 @@ ml_service_training_offloading_start (ml_service_s * mls) ret = ml_pipeline_start (training_s->pipeline_h); if (ret != ML_ERROR_NONE) { - _ml_error_report_return (ret, "Failed to start ml pipeline ret", ret); + _ml_error_report_return (ret, "Failed to start ml pipeline."); } - } else if (training_s->type == ML_TRAINING_OFFLOADING_TYPE_RECEIVER) { /* checking if all required files are received */ - if (FALSE == - _ml_service_training_offloading_check_received_data (training_s)) + if (!_ml_service_training_offloading_check_received_data (training_s)) { _ml_error_report_return (ML_ERROR_INVALID_PARAMETER, "Failed to receive the required data"); + } _ml_service_training_offloading_replce_pipeline_data_path (mls); @@ -779,9 +793,10 @@ ml_service_training_offloading_start (ml_service_s * mls) "Failed to get the json object from the json node."); } - if (!json_object_has_member (pipeline_obj, "pipeline")) + if (!json_object_has_member (pipeline_obj, "pipeline")) { _ml_error_report_return (ML_ERROR_INVALID_PARAMETER, "Failed to parse configuration file, cannot get the pipeline JSON object."); + } pipe = json_object_get_object_member (pipeline_obj, "pipeline"); @@ -793,16 +808,16 @@ ml_service_training_offloading_start (ml_service_s * mls) "Failed to parse configuration file, cannot get the pipeline description."); } - ret = - ml_pipeline_construct (training_s->receiver_pipe, NULL, NULL, + ret = ml_pipeline_construct (training_s->receiver_pipe, NULL, NULL, &training_s->pipeline_h); if (ML_ERROR_NONE != ret) { _ml_error_report_return (ret, "Failed to construct pipeline"); } ret = _ml_service_training_offloading_conf_parse_pipeline (mls, pipe); - if (ret != ML_ERROR_NONE) + if (ret != ML_ERROR_NONE) { return ret; + } ret = ml_pipeline_start (training_s->pipeline_h); if (ret != ML_ERROR_NONE) { @@ -824,16 +839,16 @@ _ml_service_training_offloading_ready_to_complete (ml_service_s * mls) { int ret = ML_ERROR_NONE; int loop = 120; - GList *list = NULL, *iter; + GList *list, *iter; ml_training_services_s *training_s = NULL; ml_training_offloading_node_info_s *node_info = NULL; + ml_service_offloading_mode_e mode = ML_SERVICE_OFFLOADING_MODE_NONE; - g_return_val_if_fail (mls != NULL, ML_ERROR_INVALID_PARAMETER); - - training_s = (ml_training_services_s *) - ml_service_offloading_get_training_handle (mls); - g_return_val_if_fail (training_s != NULL, ML_ERROR_INVALID_PARAMETER); - + ml_service_offloading_get_mode (mls, &mode, (void **) &training_s); + if (mode != ML_SERVICE_OFFLOADING_MODE_TRAINING || training_s == NULL) { + _ml_error_report_return (ML_ERROR_INVALID_PARAMETER, + "The ml service is not training mode."); + } list = g_hash_table_get_keys (training_s->node_table); if (!list) { @@ -843,17 +858,19 @@ _ml_service_training_offloading_ready_to_complete (ml_service_s * mls) /* For now, let's set values for all tensor_trainers */ for (iter = list; iter != NULL; iter = g_list_next (iter)) { - node_info = - g_hash_table_lookup (training_s->node_table, (gchar *) iter->data); - if (node_info->type == ML_TRAINING_OFFLOADING_NODE_TYPE_TRAINING) { - _ml_logd ("Set `ready to complete` to tensor_trainer node name:%s", - (gchar *) iter->data); + const gchar *name = iter->data; + + node_info = g_hash_table_lookup (training_s->node_table, name); + if (node_info && + node_info->type == ML_TRAINING_OFFLOADING_NODE_TYPE_TRAINING) { + _ml_logd ("Set `ready to complete` to tensor_trainer node name:%s", name); + ml_pipeline_element_set_property_bool (node_info->handle, "ready-to-complete", TRUE); } } - /* FIXME : Let's make up for it later. */ + /** @todo FIXME : Let's make up for it later. */ while (loop--) { if (g_file_test (training_s->trained_model_path, G_FILE_TEST_EXISTS)) break; @@ -871,25 +888,24 @@ ml_service_training_offloading_stop (ml_service_s * mls) { int ret = ML_ERROR_NONE; ml_training_services_s *training_s = NULL; + ml_service_offloading_mode_e mode = ML_SERVICE_OFFLOADING_MODE_NONE; - if (!mls) { + ml_service_offloading_get_mode (mls, &mode, (void **) &training_s); + if (mode != ML_SERVICE_OFFLOADING_MODE_TRAINING || training_s == NULL) { _ml_error_report_return (ML_ERROR_INVALID_PARAMETER, - "The parameter, 'mls' (ml_service_s), is NULL."); + "The ml service is not training mode."); } - training_s = (ml_training_services_s *) - ml_service_offloading_get_training_handle (mls); - g_return_val_if_fail (training_s != NULL, ML_ERROR_INVALID_PARAMETER); - if (training_s->type == ML_TRAINING_OFFLOADING_TYPE_RECEIVER) { if (!g_file_test (training_s->trained_model_path, G_FILE_TEST_EXISTS)) { _ml_service_training_offloading_ready_to_complete (mls); } } - if (!training_s->pipeline_h) + if (!training_s->pipeline_h) { _ml_error_report_return (ML_ERROR_STREAMS_PIPE, "Pipeline is not constructed."); + } ret = ml_pipeline_stop (training_s->pipeline_h); if (ML_ERROR_NONE != ret) { @@ -908,15 +924,17 @@ ml_service_training_offloading_process_received_data (ml_service_s * mls, { g_autofree gchar *name = NULL; ml_training_services_s *training_s = NULL; + ml_service_offloading_mode_e mode = ML_SERVICE_OFFLOADING_MODE_NONE; - g_return_if_fail (mls != NULL); g_return_if_fail (data_h != NULL); g_return_if_fail (dir_path != NULL); g_return_if_fail (data != NULL); - training_s = (ml_training_services_s *) - ml_service_offloading_get_training_handle (mls); - g_return_if_fail (training_s != NULL); + ml_service_offloading_get_mode (mls, &mode, (void **) &training_s); + if (mode != ML_SERVICE_OFFLOADING_MODE_TRAINING || training_s == NULL) { + _ml_error_report ("The ml service is not training mode."); + return; + } _ml_logd ("Received data, service_type:%d", service_type); @@ -945,15 +963,16 @@ static void _ml_service_training_offloading_send_trained_model (ml_service_s * mls) { ml_training_services_s *training_s = NULL; - GList *list = NULL, *iter; - gchar *contents; + ml_service_offloading_mode_e mode = ML_SERVICE_OFFLOADING_MODE_NONE; + GList *list, *iter; + gchar *contents = NULL; gsize len; - g_return_if_fail (mls != NULL); - - training_s = (ml_training_services_s *) - ml_service_offloading_get_training_handle (mls); - g_return_if_fail (training_s != NULL); + ml_service_offloading_get_mode (mls, &mode, (void **) &training_s); + if (mode != ML_SERVICE_OFFLOADING_MODE_TRAINING || training_s == NULL) { + _ml_error_report ("The ml service is not training mode."); + return; + } if (training_s->trained_model_path == NULL) return; @@ -973,8 +992,9 @@ _ml_service_training_offloading_send_trained_model (ml_service_s * mls) _ml_service_training_offloading_request (mls, (gchar *) iter->data, contents, len); } - g_list_free (list); + g_list_free (list); + g_free (contents); return; } @@ -986,18 +1006,12 @@ ml_service_training_offloading_destroy (ml_service_s * mls) { int ret = ML_ERROR_NONE; ml_training_services_s *training_s = NULL; + ml_service_offloading_mode_e mode = ML_SERVICE_OFFLOADING_MODE_NONE; - if (!mls) { + ml_service_offloading_get_mode (mls, &mode, (void **) &training_s); + if (mode != ML_SERVICE_OFFLOADING_MODE_TRAINING || training_s == NULL) { _ml_error_report_return (ML_ERROR_INVALID_PARAMETER, - "The parameter, 'mls' is NULL."); - } - - training_s = (ml_training_services_s *) - ml_service_offloading_get_training_handle (mls); - - if (!training_s) { - _ml_logw ("training_s(%p) is already destroyed", training_s); - return ret; + "The ml service is not training mode."); } if (training_s->type == ML_TRAINING_OFFLOADING_TYPE_RECEIVER) { @@ -1026,9 +1040,9 @@ ml_service_training_offloading_destroy (ml_service_s * mls) if (training_s->pipeline_h) { ret = ml_pipeline_destroy (training_s->pipeline_h); if (ret != ML_ERROR_NONE) { - _ml_error_report_return (ret, "Failed to destroy ml pipeline ret"); - return ret; + _ml_error_report ("Failed to destroy ml pipeline, clear handle anyway."); } + training_s->pipeline_h = NULL; } @@ -1047,10 +1061,8 @@ ml_service_training_offloading_destroy (ml_service_s * mls) g_free (training_s->sender_pipe); training_s->sender_pipe = NULL; - g_free (training_s); - training_s = NULL; - ml_service_offloading_set_training_handle (mls, training_s); + ml_service_offloading_set_mode (mls, ML_SERVICE_OFFLOADING_MODE_NONE, NULL); return ret; } diff --git a/c/src/ml-api-service-training-offloading.h b/c/src/ml-api-service-training-offloading.h index 13c5ad8..fdbdd67 100644 --- a/c/src/ml-api-service-training-offloading.h +++ b/c/src/ml-api-service-training-offloading.h @@ -7,7 +7,7 @@ * @brief ml-service training offloading internal header. * This file should NOT be exported to SDK or devel package. * @brief ML training offloading service of NNStreamer/Service C-API - * @see https://github.com/nnstreamer/nnstreamer + * @see https://github.com/nnstreamer/api * @author Hyunil Park * @bug No known bugs except for NYI items */ @@ -16,13 +16,10 @@ #define __ML_SERVICE_TRAINING_OFFLOADING_H__ #include -#include "nnstreamer-tizen-internal.h" #include "ml-api-service-offloading.h" -#include "ml-api-service-private.h" #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif /* __cplusplus */ /** @@ -38,11 +35,10 @@ extern "C" * @retval #ML_ERROR_STREAMS_PIPE Failed to open the model. * @retval #ML_ERROR_OUT_OF_MEMORY Failed to allocate required memory. */ - int ml_service_training_offloading_create (ml_service_s * mls, JsonObject * object); +int ml_service_training_offloading_create (ml_service_s *mls, JsonObject *object); /** * @brief Set path in ml-service training offloading handle. - * @note This is not official and public API but experimental API. * @param[in] mls ml-service handle created by ml_service_new(). * @param[in] path Readable and writable path set by the app. * @return @c 0 on success. Otherwise a negative error value. @@ -50,13 +46,12 @@ extern "C" * @retval #ML_ERROR_NOT_SUPPORTED Not supported. * @retval #ML_ERROR_INVALID_PARAMETER Given parameter is invalid. */ - int ml_service_training_offloading_set_path (ml_service_s *mls, const gchar * path); +int ml_service_training_offloading_set_path (ml_service_s *mls, const gchar *path); /** * @brief Start ml training offloading service. - * @remarks The @a handle should be destroyed using ml_service_destroy(). * @param[in] mls ml-service handle created by ml_service_new(). - * @return @c 0 on Success. Otherwise a negative error value. + * @return @c 0 on success. Otherwise a negative error value. * @retval #ML_ERROR_NONE Successful. * @retval #ML_ERROR_NOT_SUPPORTED Not supported. * @retval #ML_ERROR_INVALID_PARAMETER Fail. The parameter is invalid. @@ -65,13 +60,12 @@ extern "C" * @retval #ML_ERROR_TRY_AGAIN The pipeline is not ready yet. * @retval #ML_ERROR_PERMISSION_DENIED The application does not have the privilege to access to the storage. */ - int ml_service_training_offloading_start (ml_service_s * mls); +int ml_service_training_offloading_start (ml_service_s *mls); /** * @brief Stop ml training offloading service. - * @remarks The @a handle should be destroyed using ml_service_destroy(). * @param[in] mls ml-service handle created by ml_service_new(). - * @return @c 0 on Success. Otherwise a negative error value. + * @return @c 0 on success. Otherwise a negative error value. * @retval #ML_ERROR_NONE Successful. * @retval #ML_ERROR_NOT_SUPPORTED Not supported. * @retval #ML_ERROR_INVALID_PARAMETER Fail. The parameter is invalid. @@ -80,7 +74,7 @@ extern "C" * @retval #ML_ERROR_TRY_AGAIN The pipeline is not ready yet. * @retval #ML_ERROR_PERMISSION_DENIED The application does not have the privilege to access to the storage. */ - int ml_service_training_offloading_stop (ml_service_s * mls); +int ml_service_training_offloading_stop (ml_service_s *mls); /** * @brief Request all services to ml-service offloading. @@ -90,7 +84,7 @@ extern "C" * @retval #ML_ERROR_NOT_SUPPORTED Not supported. * @retval #ML_ERROR_INVALID_PARAMETER Given parameter is invalid. */ - int ml_service_training_offloading_all_services_request (ml_service_s * mls); +int ml_service_training_offloading_all_services_request (ml_service_s *mls); /** * @brief Process received data @@ -100,7 +94,7 @@ extern "C" * @param[in] dir_path dir path * @param[in] service_type received service type from remote edge */ - void ml_service_training_offloading_process_received_data (ml_service_s * mls, void * data_h, const gchar *dir_path, const gchar * data, int service_type); +void ml_service_training_offloading_process_received_data (ml_service_s *mls, void *data_h, const gchar *dir_path, const gchar *data, int service_type); /** * @brief Internal function to destroy ml-service training offloading data. @@ -109,12 +103,9 @@ extern "C" * @retval #ML_ERROR_NONE Successful. * @retval #ML_ERROR_NOT_SUPPORTED Not supported. * @retval #ML_ERROR_INVALID_PARAMETER Given parameter is invalid. - * @return @c 0 on success. Otherwise a negative error value. - * @retval #ML_ERROR_NONE Successful. - * @retval #ML_ERROR_NOT_SUPPORTED Not supported. - * @retval #ML_ERROR_INVALID_PARAMETER Given parameter is invalid. */ - int ml_service_training_offloading_destroy (ml_service_s * mls); +int ml_service_training_offloading_destroy (ml_service_s *mls); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/c/src/ml-api-service.c b/c/src/ml-api-service.c index a3cdd35..e55dcc1 100644 --- a/c/src/ml-api-service.c +++ b/c/src/ml-api-service.c @@ -284,7 +284,7 @@ static int _ml_service_offloading_conf_to_opt (ml_service_s * mls, JsonObject * object, const gchar * name, ml_option_h option) { - int status; + int status = ML_ERROR_NONE; JsonObject *offloading_object; const gchar *val = NULL; const gchar *key = NULL; diff --git a/packaging/machine-learning-api.spec b/packaging/machine-learning-api.spec index 1c89887..a839968 100644 --- a/packaging/machine-learning-api.spec +++ b/packaging/machine-learning-api.spec @@ -17,7 +17,7 @@ %define armnn_support 0 %define onnxruntime_support 1 %define ncnn_support 0 -%define nntrainer_trainer_support 1 +%define nntrainer_support 1 %define release_test 0 %define test_script $(pwd)/packaging/run_unittests.sh @@ -41,6 +41,7 @@ %define enable_tizen_privilege 0 %define enable_ml_service 0 %define nnstreamer_edge_support 0 +%define nntrainer_support 0 %endif # If it is tizen, we can export Tizen API packages. @@ -163,14 +164,13 @@ BuildRequires: ncnn-devel BuildRequires: nnstreamer-ncnn %endif -%if 0%{?nntrainer_trainer_support} +%if 0%{?enable_ml_service} +BuildRequires: mlops-agent-test +%if 0%{?nntrainer_support} BuildRequires: nnstreamer-datarepo BuildRequires: nnstreamer-nntrainer-trainer BuildRequires: nntrainer %endif - -%if 0%{?enable_ml_service} -BuildRequires: mlops-agent-test %endif %endif # unit_test -- 2.7.4