Skip to content

Commit 6501e4b

Browse files
committed
Use a specific error type wasi_nn_error_t instead of macro "WASI_NN_ERROR_TYPE"
1 parent c43fbeb commit 6501e4b

2 files changed

Lines changed: 37 additions & 27 deletions

File tree

core/iwasm/libraries/wasi-nn/test/utils.c

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@
88
#include <stdio.h>
99
#include <stdlib.h>
1010

11-
WASI_NN_ERROR_TYPE
11+
#if WASM_ENABLE_WASI_EPHEMERAL_NN != 0
12+
typedef wasi_ephemeral_nn_error wasi_nn_error_t;
13+
#else
14+
typedef wasi_nn_error wasi_nn_error_t;
15+
#endif
16+
17+
wasi_nn_error_t
1218
wasm_load(char *model_name, WASI_NN_NAME(graph) * g,
1319
WASI_NN_NAME(execution_target) target)
1420
{
@@ -39,7 +45,7 @@ wasm_load(char *model_name, WASI_NN_NAME(graph) * g,
3945
arr.buf = buffer;
4046
arr.size = result;
4147

42-
WASI_NN_ERROR_TYPE res = WASI_NN_NAME(load)(
48+
wasi_nn_error_t res = WASI_NN_NAME(load)(
4349
&arr, result, WASI_NN_ENCODING_NAME(tensorflowlite), target, g);
4450
#else
4551
WASI_NN_NAME(graph_builder_array) arr;
@@ -56,7 +62,7 @@ wasm_load(char *model_name, WASI_NN_NAME(graph) * g,
5662
arr.buf[0].size = result;
5763
arr.buf[0].buf = buffer;
5864

59-
WASI_NN_ERROR_TYPE res = WASI_NN_NAME(load)(
65+
wasi_nn_error_t res = WASI_NN_NAME(load)(
6066
&arr, WASI_NN_ENCODING_NAME(tensorflowlite), target, g);
6167
#endif
6268

@@ -66,22 +72,22 @@ wasm_load(char *model_name, WASI_NN_NAME(graph) * g,
6672
return res;
6773
}
6874

69-
WASI_NN_ERROR_TYPE
75+
wasi_nn_error_t
7076
wasm_load_by_name(const char *model_name, WASI_NN_NAME(graph) * g)
7177
{
72-
WASI_NN_ERROR_TYPE res =
78+
wasi_nn_error_t res =
7379
WASI_NN_NAME(load_by_name)(model_name, strlen(model_name), g);
7480
return res;
7581
}
7682

77-
WASI_NN_ERROR_TYPE
83+
wasi_nn_error_t
7884
wasm_init_execution_context(WASI_NN_NAME(graph) g,
7985
WASI_NN_NAME(graph_execution_context) * ctx)
8086
{
8187
return WASI_NN_NAME(init_execution_context)(g, ctx);
8288
}
8389

84-
WASI_NN_ERROR_TYPE
90+
wasi_nn_error_t
8591
wasm_set_input(WASI_NN_NAME(graph_execution_context) ctx, float *input_tensor,
8692
uint32_t *dim)
8793
{
@@ -113,19 +119,19 @@ wasm_set_input(WASI_NN_NAME(graph_execution_context) ctx, float *input_tensor,
113119
tensor.data = (uint8_t *)input_tensor;
114120
#endif
115121

116-
WASI_NN_ERROR_TYPE err = WASI_NN_NAME(set_input)(ctx, 0, &tensor);
122+
wasi_nn_error_t err = WASI_NN_NAME(set_input)(ctx, 0, &tensor);
117123

118124
free(dims.buf);
119125
return err;
120126
}
121127

122-
WASI_NN_ERROR_TYPE
128+
wasi_nn_error_t
123129
wasm_compute(WASI_NN_NAME(graph_execution_context) ctx)
124130
{
125131
return WASI_NN_NAME(compute)(ctx);
126132
}
127133

128-
WASI_NN_ERROR_TYPE
134+
wasi_nn_error_t
129135
wasm_get_output(WASI_NN_NAME(graph_execution_context) ctx, uint32_t index,
130136
float *out_tensor, uint32_t *out_size)
131137
{
@@ -144,8 +150,8 @@ run_inference(float *input, uint32_t *input_size, uint32_t *output_size,
144150
{
145151
WASI_NN_NAME(graph) graph;
146152

147-
WASI_NN_ERROR_TYPE res = wasm_load_by_name(model_name, &graph);
148-
153+
wasi_nn_error_t res = wasm_load_by_name(model_name, &graph);
154+
149155
if (res == WASI_NN_ERROR_NAME(not_found)) {
150156
NN_INFO_PRINTF("Model %s is not loaded, you should pass its path "
151157
"through --wasi-nn-graph",

core/iwasm/libraries/wasi-nn/test/utils.h

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,32 +26,36 @@ typedef struct {
2626
uint32_t elements;
2727
} input_info;
2828

29+
#if WASM_ENABLE_WASI_EPHEMERAL_NN != 0
30+
typedef wasi_ephemeral_nn_error wasi_nn_error_t;
31+
#else
32+
typedef wasi_nn_error wasi_nn_error_t;
33+
#endif
34+
2935
/* wasi-nn wrappers */
3036

31-
WASI_NN_ERROR_TYPE
32-
wasm_load(char *model_name, WASI_NN_NAME(graph) * g,
33-
WASI_NN_NAME(execution_target) target);
37+
wasi_nn_error_t
38+
wasm_load(char *model_name, WASI_NN_NAME(graph) *g, WASI_NN_NAME(execution_target) target);
3439

35-
WASI_NN_ERROR_TYPE
36-
wasm_init_execution_context(WASI_NN_NAME(graph) g,
37-
WASI_NN_NAME(graph_execution_context) * ctx);
40+
wasi_nn_error_t
41+
wasm_init_execution_context(WASI_NN_NAME(graph) g, WASI_NN_NAME(graph_execution_context) *ctx);
3842

39-
WASI_NN_ERROR_TYPE
40-
wasm_set_input(WASI_NN_NAME(graph_execution_context) ctx, float *input_tensor,
41-
uint32_t *dim);
43+
wasi_nn_error_t
44+
wasm_set_input(WASI_NN_NAME(graph_execution_context) ctx, float *input_tensor, uint32_t *dim);
4245

43-
WASI_NN_ERROR_TYPE
46+
wasi_nn_error_t
4447
wasm_compute(WASI_NN_NAME(graph_execution_context) ctx);
4548

46-
WASI_NN_ERROR_TYPE
47-
wasm_get_output(WASI_NN_NAME(graph_execution_context) ctx, uint32_t index,
48-
float *out_tensor, uint32_t *out_size);
49+
wasi_nn_error_t
50+
wasm_get_output(WASI_NN_NAME(graph_execution_context) ctx, uint32_t index, float *out_tensor,
51+
uint32_t *out_size);
4952

5053
/* Utils */
5154

5255
float *
53-
run_inference(float *input, uint32_t *input_size, uint32_t *output_size,
54-
char *model_name, uint32_t num_output_tensors);
56+
run_inference(float *input, uint32_t *input_size,
57+
uint32_t *output_size, char *model_name,
58+
uint32_t num_output_tensors);
5559

5660
input_info
5761
create_input(int *dims);

0 commit comments

Comments
 (0)