Skip to content

Commit f150623

Browse files
committed
wasi_nn_openvino.c: remove pre/postprocessing and layout assumptions
as wasi-nn doesn't have these concepts, the best we can do without risking breaking certain applications here is to pass through tensors as they are. this matches wasmtime's behavior. tested with: * wasmtime classification-example (with this change, this example fails on tensor size mismatch instead of implicitly resizing it.) * license-plate-recognition-barrier-0007, a converted version with non-fp32 output. [1] (with this change, this model outputs integers as expected.) [1] https://github.com/openvinotoolkit/open_model_zoo/tree/cd7ebe313b69372763e76b82e5d24935308fece4/models/public/license-plate-recognition-barrier-0007
1 parent 0343aaf commit f150623

File tree

1 file changed

+2
-81
lines changed

1 file changed

+2
-81
lines changed

core/iwasm/libraries/wasi-nn/src/wasi_nn_openvino.c

Lines changed: 2 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ typedef struct {
3232
void *weight_data;
3333
ov_tensor_t *weights_tensor;
3434
ov_model_t *model;
35-
/* add prepostprocess */
36-
ov_model_t *new_model;
3735
ov_compiled_model_t *compiled_model;
3836
ov_infer_request_t *infer_request;
3937
ov_tensor_t *input_tensor;
@@ -290,16 +288,6 @@ set_input(void *ctx, graph_execution_context exec_ctx, uint32_t index,
290288
ov_shape_t input_shape = { 0 };
291289
int64_t *ov_dims = NULL;
292290

293-
ov_preprocess_prepostprocessor_t *ppp = NULL;
294-
ov_preprocess_input_info_t *input_info = NULL;
295-
ov_preprocess_input_tensor_info_t *input_tensor_info = NULL;
296-
ov_layout_t *input_layout = NULL;
297-
ov_preprocess_preprocess_steps_t *input_process = NULL;
298-
ov_preprocess_input_model_info_t *p_input_model = NULL;
299-
ov_layout_t *model_layout = NULL;
300-
ov_preprocess_output_info_t *output_info = NULL;
301-
ov_preprocess_output_tensor_info_t *output_tensor_info = NULL;
302-
303291
/* wasi_nn_tensor -> ov_tensor */
304292
{
305293
ret = uint32_array_to_int64_array(wasi_nn_tensor->dimensions->size,
@@ -328,57 +316,8 @@ set_input(void *ctx, graph_execution_context exec_ctx, uint32_t index,
328316
ret);
329317
}
330318

331-
/* set preprocess based on wasi_nn_tensor */
332-
{
333-
CHECK_OV_STATUS(
334-
ov_preprocess_prepostprocessor_create(ov_ctx->model, &ppp), ret);
335-
336-
/* reuse user' created tensor's info */
337-
CHECK_OV_STATUS(ov_preprocess_prepostprocessor_get_input_info_by_index(
338-
ppp, index, &input_info),
339-
ret);
340-
CHECK_OV_STATUS(ov_preprocess_input_info_get_tensor_info(
341-
input_info, &input_tensor_info),
342-
ret);
343-
CHECK_OV_STATUS(ov_preprocess_input_tensor_info_set_from(
344-
input_tensor_info, ov_ctx->input_tensor),
345-
ret);
346-
347-
/* add RESIZE */
348-
CHECK_OV_STATUS(ov_preprocess_input_info_get_preprocess_steps(
349-
input_info, &input_process),
350-
ret);
351-
CHECK_OV_STATUS(
352-
ov_preprocess_preprocess_steps_resize(input_process, RESIZE_LINEAR),
353-
ret);
354-
355-
/* input model */
356-
CHECK_OV_STATUS(
357-
ov_preprocess_input_info_get_model_info(input_info, &p_input_model),
358-
ret);
359-
// TODO: what if not?
360-
CHECK_OV_STATUS(ov_layout_create("NCHW", &model_layout), ret);
361-
CHECK_OV_STATUS(ov_preprocess_input_model_info_set_layout(p_input_model,
362-
model_layout),
363-
ret);
364-
365-
/* output -> F32(possibility) */
366-
CHECK_OV_STATUS(ov_preprocess_prepostprocessor_get_output_info_by_index(
367-
ppp, index, &output_info),
368-
ret);
369-
CHECK_OV_STATUS(ov_preprocess_output_info_get_tensor_info(
370-
output_info, &output_tensor_info),
371-
ret);
372-
CHECK_OV_STATUS(
373-
ov_preprocess_output_set_element_type(output_tensor_info, F32),
374-
ret);
375-
376-
CHECK_OV_STATUS(
377-
ov_preprocess_prepostprocessor_build(ppp, &ov_ctx->new_model), ret);
378-
}
379-
380-
CHECK_OV_STATUS(ov_core_compile_model(ov_ctx->core, ov_ctx->new_model,
381-
"CPU", 0, &ov_ctx->compiled_model),
319+
CHECK_OV_STATUS(ov_core_compile_model(ov_ctx->core, ov_ctx->model, "CPU", 0,
320+
&ov_ctx->compiled_model),
382321
ret);
383322

384323
CHECK_OV_STATUS(ov_compiled_model_create_infer_request(
@@ -395,24 +334,6 @@ set_input(void *ctx, graph_execution_context exec_ctx, uint32_t index,
395334
if (ov_dims)
396335
os_free(ov_dims);
397336
ov_shape_free(&input_shape);
398-
if (ppp)
399-
ov_preprocess_prepostprocessor_free(ppp);
400-
if (input_info)
401-
ov_preprocess_input_info_free(input_info);
402-
if (input_tensor_info)
403-
ov_preprocess_input_tensor_info_free(input_tensor_info);
404-
if (input_layout)
405-
ov_layout_free(input_layout);
406-
if (input_process)
407-
ov_preprocess_preprocess_steps_free(input_process);
408-
if (p_input_model)
409-
ov_preprocess_input_model_info_free(p_input_model);
410-
if (model_layout)
411-
ov_layout_free(model_layout);
412-
if (output_info)
413-
ov_preprocess_output_info_free(output_info);
414-
if (output_tensor_info)
415-
ov_preprocess_output_tensor_info_free(output_tensor_info);
416337

417338
return ret;
418339
}

0 commit comments

Comments
 (0)