Skip to content

Commit

Permalink
[api] Let single handle flexible filter
Browse files Browse the repository at this point in the history
- Let single API handle flexible filter (executorch-llama)

Signed-off-by: Yongjoo Ahn <[email protected]>
  • Loading branch information
anyj0527 committed Oct 29, 2024
1 parent 120c938 commit 7485a33
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions c/src/ml-api-inference-single.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ typedef struct
gboolean invoking; /**< invoke running flag */
ml_tensors_data_h in_tensors; /**< input tensor wrapper for processing */
ml_tensors_data_h out_tensors; /**< output tensor wrapper for processing */
gboolean is_flexible; /**< true if tensor filter handles flexible input/output */

GList *destroy_data_list; /**< data to be freed by filter */
} ml_single;
Expand Down Expand Up @@ -779,6 +780,11 @@ ml_single_set_info_in_handle (ml_single_h single, gboolean is_input,
ml_tensors_info_h info = NULL;

ml_single_get_gst_info (single_h, is_input, &gst_info);
if (single_h->is_flexible) {
gst_info.format = _NNS_TENSOR_FORMAT_FLEXIBLE;
gst_info.num_tensors = 1U; /* TODO: Consider multiple input tensors filter */
}

_ml_tensors_info_create_from_gst (&info, &gst_info);

gst_tensors_info_free (&gst_info);
Expand Down Expand Up @@ -847,6 +853,7 @@ ml_single_create_handle (ml_nnfw_type_e nnfw)
single_h->output = NULL;
single_h->destroy_data_list = NULL;
single_h->invoking = FALSE;
single_h->is_flexible = FALSE;

gst_tensors_info_init (&single_h->in_info);
gst_tensors_info_init (&single_h->out_info);
Expand Down Expand Up @@ -1083,6 +1090,11 @@ ml_single_open_custom (ml_single_h * single, ml_single_preset * info)
status = ML_ERROR_STREAMS_PIPE;
goto error;
}
/* handle flexible single */
if (info->nnfw == ML_NNFW_TYPE_EXECUTORCH_LLAMA) {
single_h->is_flexible = TRUE;
g_object_set (filter_obj, "invoke-dynamic", TRUE, NULL);
}

if (nnfw == ML_NNFW_TYPE_NNTR_INF) {
if (!in_tensors_info || !out_tensors_info) {
Expand Down Expand Up @@ -1319,6 +1331,11 @@ _ml_single_invoke_validate_data (ml_single_h single,
"The %d-th input tensor is not valid. There is no valid dimension metadata for this tensor.",
i);

if (single_h->is_flexible) {
/* Skip data size check for flexible */
continue;
}

raw_size = _model->tensors[i].size;
if (G_UNLIKELY (_data->tensors[i].size != raw_size))
_ml_error_report_return (ML_ERROR_INVALID_PARAMETER,
Expand Down

0 comments on commit 7485a33

Please sign in to comment.