Skip to content

Commit 028f43b

Browse files
authored
Fix compilation warnings of wasi-nn (bytecodealliance#3497)
1 parent bd44117 commit 028f43b

File tree

11 files changed

+85
-83
lines changed

11 files changed

+85
-83
lines changed

core/iwasm/aot/aot_runtime.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1945,7 +1945,7 @@ aot_deinstantiate(AOTModuleInstance *module_inst, bool is_sub_inst)
19451945

19461946
if (!is_sub_inst) {
19471947
#if WASM_ENABLE_WASI_NN != 0
1948-
wasi_nn_destroy(module_inst);
1948+
wasi_nn_destroy((WASMModuleInstanceCommon *)module_inst);
19491949
#endif
19501950
wasm_native_call_context_dtors((WASMModuleInstanceCommon *)module_inst);
19511951
}

core/iwasm/interpreter/wasm_runtime.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3182,7 +3182,7 @@ wasm_deinstantiate(WASMModuleInstance *module_inst, bool is_sub_inst)
31823182

31833183
if (!is_sub_inst) {
31843184
#if WASM_ENABLE_WASI_NN != 0
3185-
wasi_nn_destroy(module_inst);
3185+
wasi_nn_destroy((WASMModuleInstanceCommon *)module_inst);
31863186
#endif
31873187
wasm_native_call_context_dtors((WASMModuleInstanceCommon *)module_inst);
31883188
}

core/iwasm/libraries/wasi-nn/include/wasi_nn.h

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
* @param encoding Model encoding.
2323
* @param target Execution target.
2424
* @param g Graph.
25-
* @return error Execution status.
25+
* @return wasi_nn_error Execution status.
2626
*/
27-
error
27+
wasi_nn_error
2828
load(graph_builder_array *builder, graph_encoding encoding,
2929
execution_target target, graph *g)
3030
__attribute__((import_module("wasi_nn")));
@@ -34,17 +34,14 @@ load(graph_builder_array *builder, graph_encoding encoding,
3434
*
3535
*/
3636

37-
// Bind a `graph` to the input and output tensors for an inference.
38-
typedef uint32_t graph_execution_context;
39-
4037
/**
4138
* @brief Create an execution instance of a loaded graph.
4239
*
4340
* @param g Graph.
4441
* @param ctx Execution context.
45-
* @return error Execution status.
42+
* @return wasi_nn_error Execution status.
4643
*/
47-
error
44+
wasi_nn_error
4845
init_execution_context(graph g, graph_execution_context *ctx)
4946
__attribute__((import_module("wasi_nn")));
5047

@@ -54,19 +51,19 @@ init_execution_context(graph g, graph_execution_context *ctx)
5451
* @param ctx Execution context.
5552
* @param index Input tensor index.
5653
* @param tensor Input tensor.
57-
* @return error Execution status.
54+
* @return wasi_nn_error Execution status.
5855
*/
59-
error
56+
wasi_nn_error
6057
set_input(graph_execution_context ctx, uint32_t index, tensor *tensor)
6158
__attribute__((import_module("wasi_nn")));
6259

6360
/**
6461
* @brief Compute the inference on the given inputs.
6562
*
6663
* @param ctx Execution context.
67-
* @return error Execution status.
64+
* @return wasi_nn_error Execution status.
6865
*/
69-
error
66+
wasi_nn_error
7067
compute(graph_execution_context ctx) __attribute__((import_module("wasi_nn")));
7168

7269
/**
@@ -79,9 +76,9 @@ compute(graph_execution_context ctx) __attribute__((import_module("wasi_nn")));
7976
* @param output_tensor_size Pointer to `output_tensor` maximum size.
8077
* After the function call it is updated with the
8178
* copied number of bytes.
82-
* @return error Execution status.
79+
* @return wasi_nn_error Execution status.
8380
*/
84-
error
81+
wasi_nn_error
8582
get_output(graph_execution_context ctx, uint32_t index,
8683
tensor_data output_tensor, uint32_t *output_tensor_size)
8784
__attribute__((import_module("wasi_nn")));

core/iwasm/libraries/wasi-nn/include/wasi_nn_types.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ typedef enum {
2828
busy,
2929
// Runtime Error.
3030
runtime_error,
31-
} error;
31+
} wasi_nn_error;
3232

3333
/**
3434
* TENSOR
@@ -106,4 +106,7 @@ typedef enum {
106106
// Define where the graph should be executed.
107107
typedef enum execution_target { cpu = 0, gpu, tpu } execution_target;
108108

109+
// Bind a `graph` to the input and output tensors for an inference.
110+
typedef uint32_t graph_execution_context;
111+
109112
#endif

core/iwasm/libraries/wasi-nn/src/utils/wasi_nn_app_native.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
#include "wasi_nn_app_native.h"
77

8-
static error
8+
static wasi_nn_error
99
graph_builder_app_native(wasm_module_inst_t instance,
1010
graph_builder_wasm *builder_wasm,
1111
graph_builder *builder)
@@ -27,12 +27,12 @@ graph_builder_app_native(wasm_module_inst_t instance,
2727
* builder_array_wasm is consisted of {builder_wasm, size}
2828
*/
2929
#if WASM_ENABLE_WASI_EPHEMERAL_NN != 0
30-
error
30+
wasi_nn_error
3131
graph_builder_array_app_native(wasm_module_inst_t instance,
3232
graph_builder_wasm *builder_wasm, uint32_t size,
3333
graph_builder_array *builder_array)
3434
#else /* WASM_ENABLE_WASI_EPHEMERAL_NN == 0 */
35-
error
35+
wasi_nn_error
3636
graph_builder_array_app_native(wasm_module_inst_t instance,
3737
graph_builder_array_wasm *builder_array_wasm,
3838
graph_builder_array *builder_array)
@@ -79,7 +79,7 @@ graph_builder_array_app_native(wasm_module_inst_t instance,
7979
return missing_memory;
8080

8181
for (uint32_t i = 0; i < array_size; ++i) {
82-
error res;
82+
wasi_nn_error res;
8383
if (success
8484
!= (res = graph_builder_app_native(instance, &builder_wasm[i],
8585
&builder[i]))) {
@@ -97,7 +97,7 @@ graph_builder_array_app_native(wasm_module_inst_t instance,
9797
#undef array_size
9898
}
9999

100-
static error
100+
static wasi_nn_error
101101
tensor_data_app_native(wasm_module_inst_t instance, uint32_t total_elements,
102102
tensor_wasm *input_tensor_wasm, tensor_data *data)
103103
{
@@ -119,7 +119,7 @@ tensor_data_app_native(wasm_module_inst_t instance, uint32_t total_elements,
119119
#undef data_size
120120
}
121121

122-
static error
122+
static wasi_nn_error
123123
tensor_dimensions_app_native(wasm_module_inst_t instance,
124124
tensor_wasm *input_tensor_wasm,
125125
tensor_dimensions **dimensions)
@@ -159,7 +159,7 @@ tensor_dimensions_app_native(wasm_module_inst_t instance,
159159
return success;
160160
}
161161

162-
error
162+
wasi_nn_error
163163
tensor_app_native(wasm_module_inst_t instance, tensor_wasm *input_tensor_wasm,
164164
tensor *input_tensor)
165165
{
@@ -170,7 +170,7 @@ tensor_app_native(wasm_module_inst_t instance, tensor_wasm *input_tensor_wasm,
170170
return invalid_argument;
171171
}
172172

173-
error res;
173+
wasi_nn_error res;
174174

175175
tensor_dimensions *dimensions = NULL;
176176
if (success

core/iwasm/libraries/wasi-nn/src/utils/wasi_nn_app_native.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include <errno.h>
1313
#include <string.h>
1414

15-
#include "wasi_nn.h"
15+
#include "wasi_nn_types.h"
1616
#include "logger.h"
1717

1818
#include "bh_platform.h"
@@ -47,18 +47,18 @@ typedef struct {
4747
} tensor_wasm;
4848

4949
#if WASM_ENABLE_WASI_EPHEMERAL_NN != 0
50-
error
50+
wasi_nn_error
5151
graph_builder_array_app_native(wasm_module_inst_t instance,
5252
graph_builder_wasm *builder_wasm, uint32_t size,
5353
graph_builder_array *builder_array);
5454
#else /* WASM_ENABLE_WASI_EPHEMERAL_NN == 0 */
55-
error
55+
wasi_nn_error
5656
graph_builder_array_app_native(wasm_module_inst_t instance,
5757
graph_builder_array_wasm *builder,
5858
graph_builder_array *builder_native);
5959
#endif /* WASM_ENABLE_WASI_EPHEMERAL_NN != 0 */
6060

61-
error
61+
wasi_nn_error
6262
tensor_app_native(wasm_module_inst_t instance, tensor_wasm *input_tensor,
6363
tensor *input_tensor_native);
6464

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

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include <string.h>
1212
#include <stdint.h>
1313

14-
#include "wasi_nn.h"
1514
#include "wasi_nn_private.h"
1615
#include "wasi_nn_app_native.h"
1716
#include "wasi_nn_tensorflowlite.hpp"
@@ -24,14 +23,15 @@
2423

2524
/* Definition of 'wasi_nn.h' structs in WASM app format (using offset) */
2625

27-
typedef error (*LOAD)(void *, graph_builder_array *, graph_encoding,
28-
execution_target, graph *);
29-
typedef error (*INIT_EXECUTION_CONTEXT)(void *, graph,
30-
graph_execution_context *);
31-
typedef error (*SET_INPUT)(void *, graph_execution_context, uint32_t, tensor *);
32-
typedef error (*COMPUTE)(void *, graph_execution_context);
33-
typedef error (*GET_OUTPUT)(void *, graph_execution_context, uint32_t,
34-
tensor_data, uint32_t *);
26+
typedef wasi_nn_error (*LOAD)(void *, graph_builder_array *, graph_encoding,
27+
execution_target, graph *);
28+
typedef wasi_nn_error (*INIT_EXECUTION_CONTEXT)(void *, graph,
29+
graph_execution_context *);
30+
typedef wasi_nn_error (*SET_INPUT)(void *, graph_execution_context, uint32_t,
31+
tensor *);
32+
typedef wasi_nn_error (*COMPUTE)(void *, graph_execution_context);
33+
typedef wasi_nn_error (*GET_OUTPUT)(void *, graph_execution_context, uint32_t,
34+
tensor_data, uint32_t *);
3535

3636
typedef struct {
3737
LOAD load;
@@ -177,7 +177,7 @@ is_encoding_implemented(graph_encoding encoding)
177177
&& lookup[encoding].get_output;
178178
}
179179

180-
static error
180+
static wasi_nn_error
181181
is_model_initialized(WASINNContext *wasi_nn_ctx)
182182
{
183183
if (!wasi_nn_ctx->is_model_loaded) {
@@ -190,12 +190,12 @@ is_model_initialized(WASINNContext *wasi_nn_ctx)
190190
/* WASI-NN implementation */
191191

192192
#if WASM_ENABLE_WASI_EPHEMERAL_NN != 0
193-
error
193+
wasi_nn_error
194194
wasi_nn_load(wasm_exec_env_t exec_env, graph_builder_wasm *builder,
195195
uint32_t builder_wasm_size, graph_encoding encoding,
196196
execution_target target, graph *g)
197197
#else /* WASM_ENABLE_WASI_EPHEMERAL_NN == 0 */
198-
error
198+
wasi_nn_error
199199
wasi_nn_load(wasm_exec_env_t exec_env, graph_builder_array_wasm *builder,
200200
graph_encoding encoding, execution_target target, graph *g)
201201
#endif /* WASM_ENABLE_WASI_EPHEMERAL_NN != 0 */
@@ -211,7 +211,7 @@ wasi_nn_load(wasm_exec_env_t exec_env, graph_builder_array_wasm *builder,
211211
wasm_module_inst_t instance = wasm_runtime_get_module_inst(exec_env);
212212
bh_assert(instance);
213213

214-
error res;
214+
wasi_nn_error res;
215215
graph_builder_array builder_native = { 0 };
216216
#if WASM_ENABLE_WASI_EPHEMERAL_NN != 0
217217
if (success
@@ -249,7 +249,7 @@ wasi_nn_load(wasm_exec_env_t exec_env, graph_builder_array_wasm *builder,
249249
return res;
250250
}
251251

252-
error
252+
wasi_nn_error
253253
wasi_nn_init_execution_context(wasm_exec_env_t exec_env, graph g,
254254
graph_execution_context *ctx)
255255
{
@@ -259,7 +259,7 @@ wasi_nn_init_execution_context(wasm_exec_env_t exec_env, graph g,
259259
bh_assert(instance);
260260
WASINNContext *wasi_nn_ctx = wasm_runtime_get_wasi_nn_ctx(instance);
261261

262-
error res;
262+
wasi_nn_error res;
263263
if (success != (res = is_model_initialized(wasi_nn_ctx)))
264264
return res;
265265

@@ -278,7 +278,7 @@ wasi_nn_init_execution_context(wasm_exec_env_t exec_env, graph g,
278278
return res;
279279
}
280280

281-
error
281+
wasi_nn_error
282282
wasi_nn_set_input(wasm_exec_env_t exec_env, graph_execution_context ctx,
283283
uint32_t index, tensor_wasm *input_tensor)
284284
{
@@ -289,7 +289,7 @@ wasi_nn_set_input(wasm_exec_env_t exec_env, graph_execution_context ctx,
289289
bh_assert(instance);
290290
WASINNContext *wasi_nn_ctx = wasm_runtime_get_wasi_nn_ctx(instance);
291291

292-
error res;
292+
wasi_nn_error res;
293293
if (success != (res = is_model_initialized(wasi_nn_ctx)))
294294
return res;
295295

@@ -310,7 +310,7 @@ wasi_nn_set_input(wasm_exec_env_t exec_env, graph_execution_context ctx,
310310
return res;
311311
}
312312

313-
error
313+
wasi_nn_error
314314
wasi_nn_compute(wasm_exec_env_t exec_env, graph_execution_context ctx)
315315
{
316316
NN_DBG_PRINTF("Running wasi_nn_compute [ctx=%d]...", ctx);
@@ -319,7 +319,7 @@ wasi_nn_compute(wasm_exec_env_t exec_env, graph_execution_context ctx)
319319
bh_assert(instance);
320320
WASINNContext *wasi_nn_ctx = wasm_runtime_get_wasi_nn_ctx(instance);
321321

322-
error res;
322+
wasi_nn_error res;
323323
if (success != (res = is_model_initialized(wasi_nn_ctx)))
324324
return res;
325325

@@ -330,12 +330,12 @@ wasi_nn_compute(wasm_exec_env_t exec_env, graph_execution_context ctx)
330330
}
331331

332332
#if WASM_ENABLE_WASI_EPHEMERAL_NN != 0
333-
error
333+
wasi_nn_error
334334
wasi_nn_get_output(wasm_exec_env_t exec_env, graph_execution_context ctx,
335335
uint32_t index, tensor_data output_tensor,
336336
uint32_t output_tensor_len, uint32_t *output_tensor_size)
337337
#else /* WASM_ENABLE_WASI_EPHEMERAL_NN == 0 */
338-
error
338+
wasi_nn_error
339339
wasi_nn_get_output(wasm_exec_env_t exec_env, graph_execution_context ctx,
340340
uint32_t index, tensor_data output_tensor,
341341
uint32_t *output_tensor_size)
@@ -348,7 +348,7 @@ wasi_nn_get_output(wasm_exec_env_t exec_env, graph_execution_context ctx,
348348
bh_assert(instance);
349349
WASINNContext *wasi_nn_ctx = wasm_runtime_get_wasi_nn_ctx(instance);
350350

351-
error res;
351+
wasi_nn_error res;
352352
if (success != (res = is_model_initialized(wasi_nn_ctx)))
353353
return res;
354354

0 commit comments

Comments
 (0)