Skip to content

Commit 1674c69

Browse files
committed
[api] Let single handle flexible filter
- Let single API handle flexible filter. Signed-off-by: Yongjoo Ahn <yongjoo1.ahn@samsung.com>
1 parent f774947 commit 1674c69

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

c/src/ml-api-inference-single.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ typedef struct
137137
gboolean invoking; /**< invoke running flag */
138138
ml_tensors_data_h in_tensors; /**< input tensor wrapper for processing */
139139
ml_tensors_data_h out_tensors; /**< output tensor wrapper for processing */
140+
gboolean is_flexible; /**< true if tensor filter handles flexible input/output */
140141

141142
GList *destroy_data_list; /**< data to be freed by filter */
142143
} ml_single;
@@ -778,6 +779,11 @@ ml_single_set_info_in_handle (ml_single_h single, gboolean is_input,
778779
ml_tensors_info_h info = NULL;
779780

780781
ml_single_get_gst_info (single_h, is_input, &gst_info);
782+
if (single_h->is_flexible) {
783+
gst_info.format = _NNS_TENSOR_FORMAT_FLEXIBLE;
784+
gst_info.num_tensors = 1U; /* TODO: Consider multiple input tensors filter */
785+
}
786+
781787
_ml_tensors_info_create_from_gst (&info, &gst_info);
782788

783789
gst_tensors_info_free (&gst_info);
@@ -846,6 +852,7 @@ ml_single_create_handle (ml_nnfw_type_e nnfw)
846852
single_h->output = NULL;
847853
single_h->destroy_data_list = NULL;
848854
single_h->invoking = FALSE;
855+
single_h->is_flexible = FALSE;
849856

850857
gst_tensors_info_init (&single_h->in_info);
851858
gst_tensors_info_init (&single_h->out_info);
@@ -945,6 +952,7 @@ ml_single_open_custom (ml_single_h * single, ml_single_preset * info)
945952
gchar **list_models;
946953
guint i, num_models;
947954
char *hw_name;
955+
gboolean invoke_dynamic = FALSE;
948956

949957
check_feature_state (ML_FEATURE_INFERENCE);
950958

@@ -1083,6 +1091,21 @@ ml_single_open_custom (ml_single_h * single, ml_single_preset * info)
10831091
goto error;
10841092
}
10851093

1094+
/* handle flexible single */
1095+
/**
1096+
* Set invoke_dynamic as TRUE if the given nnfw do invoke_dynamic
1097+
*
1098+
* if (info->nnfw == ML_NNFW_TYPE_EXECUTORCH_LLAMA || info->nnfw == ML_NNFW_TYPE_LLAMACPP) {
1099+
* invoke_dynamic = TRUE;
1100+
* }
1101+
*
1102+
*/
1103+
1104+
if (invoke_dynamic) {
1105+
single_h->is_flexible = TRUE;
1106+
g_object_set (filter_obj, "invoke-dynamic", TRUE, NULL);
1107+
}
1108+
10861109
if (nnfw == ML_NNFW_TYPE_NNTR_INF) {
10871110
if (!in_tensors_info || !out_tensors_info) {
10881111
if (!in_tensors_info) {
@@ -1318,6 +1341,11 @@ _ml_single_invoke_validate_data (ml_single_h single,
13181341
"The %d-th input tensor is not valid. There is no valid dimension metadata for this tensor.",
13191342
i);
13201343

1344+
if (single_h->is_flexible) {
1345+
/* Skip data size check for flexible */
1346+
continue;
1347+
}
1348+
13211349
raw_size = _model->tensors[i].size;
13221350
if (G_UNLIKELY (_data->tensors[i].size != raw_size))
13231351
_ml_error_report_return (ML_ERROR_INVALID_PARAMETER,

0 commit comments

Comments
 (0)