Skip to content

Commit aa53d64

Browse files
authored
wasi-nn: fix tensor_data abi for wasi_ephemeral_nn (#4379)
it's "(list u8)" in the witx definition. the new definition matches both of our own host definition (struct tensor_wasm) and wasmtime. cf. #4352
1 parent a29f394 commit aa53d64

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,13 @@ WASI_NN_NAME(compute)
108108
WASI_NN_ERROR_TYPE
109109
WASI_NN_NAME(get_output)
110110
(WASI_NN_NAME(graph_execution_context) ctx, uint32_t index,
111-
WASI_NN_NAME(tensor_data) output_tensor, uint32_t output_tensor_max_size,
111+
uint8_t *output_tensor, uint32_t output_tensor_max_size,
112112
uint32_t *output_tensor_size) WASI_NN_IMPORT("get_output");
113113
#else
114114
WASI_NN_ERROR_TYPE
115115
WASI_NN_NAME(get_output)
116-
(graph_execution_context ctx, uint32_t index,
117-
WASI_NN_NAME(tensor_data) output_tensor, uint32_t *output_tensor_size)
118-
WASI_NN_IMPORT("get_output");
116+
(graph_execution_context ctx, uint32_t index, uint8_t *output_tensor,
117+
uint32_t *output_tensor_size) WASI_NN_IMPORT("get_output");
119118
#endif
120119

121120
#endif

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,14 @@ typedef enum {
9999
// 4-byte f32 elements would have a data array of length 16). Naturally, this
100100
// representation requires some knowledge of how to lay out data in
101101
// memory--e.g., using row-major ordering--and could perhaps be improved.
102+
#if WASM_ENABLE_WASI_EPHEMERAL_NN != 0 && defined(__wasm__)
103+
typedef struct {
104+
uint8_t *buf;
105+
uint32_t size;
106+
} WASI_NN_NAME(tensor_data);
107+
#else
102108
typedef uint8_t *WASI_NN_NAME(tensor_data);
109+
#endif
103110

104111
// A tensor.
105112
typedef struct {

wamr-wasi-extensions/samples/nn-cli/main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,8 @@ set_input(char *options)
266266
wasi_ephemeral_nn_error nnret;
267267
wasi_ephemeral_nn_graph_execution_context c =
268268
map_get(&contexts, context_id);
269-
tensor.data = buf;
269+
tensor.data.buf = buf;
270+
tensor.data.size = sz;
270271
nnret = wasi_ephemeral_nn_set_input(c, idx, &tensor);
271272
unmap_file(buf, sz);
272273
if (nnret != wasi_ephemeral_nn_error_success) {

wamr-wasi-extensions/samples/nn/app.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ main(int argc, char **argv)
147147
wasi_ephemeral_nn_tensor tensor = {
148148
.dimensions = { .buf = (uint32_t[]){1, 3, 224, 224,}, .size = 4, },
149149
.type = wasi_ephemeral_nn_type_fp32,
150-
.data = tensordata,
150+
.data.buf = tensordata,
151+
.data.size = tensordatasz,
151152
};
152153
nnret = wasi_ephemeral_nn_set_input(ctx, 0, &tensor);
153154
unmap_file(tensordata, tensordatasz);

0 commit comments

Comments
 (0)