Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions core/iwasm/libraries/wasi-nn/include/wasi_nn.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,33 @@
#include <stdint.h>
#include "wasi_nn_types.h"

#if WASM_ENABLE_WASI_EPHEMERAL_NN != 0
#define WASI_NN_IMPORT(name) \
__attribute__((import_module("wasi_ephemeral_nn"), import_name(name)))
#else
#define WASI_NN_IMPORT(name) \
__attribute__((import_module("wasi_nn"), import_name(name)))
#endif

/**
* @brief Load an opaque sequence of bytes to use for inference.
*
* @param builder Model builder.
* @param builder_len The size of model builder.
* @param encoding Model encoding.
* @param target Execution target.
* @param g Graph.
* @return wasi_nn_error Execution status.
*/
#if WASM_ENABLE_WASI_EPHEMERAL_NN != 0
wasi_nn_error
load(graph_builder *builder, uint32_t builder_len, graph_encoding encoding,
execution_target target, graph *g) WASI_NN_IMPORT("load");
#else
wasi_nn_error
load(graph_builder_array *builder, graph_encoding encoding,
execution_target target, graph *g) WASI_NN_IMPORT("load");
#endif

wasi_nn_error
load_by_name(const char *name, uint32_t name_len, graph *g)
Expand Down Expand Up @@ -84,9 +96,16 @@ compute(graph_execution_context ctx) WASI_NN_IMPORT("compute");
* copied number of bytes.
* @return wasi_nn_error Execution status.
*/
#if WASM_ENABLE_WASI_EPHEMERAL_NN != 0
wasi_nn_error
get_output(graph_execution_context ctx, uint32_t index,
tensor_data output_tensor, uint32_t output_tensor_max_size,
uint32_t *output_tensor_size) WASI_NN_IMPORT("get_output");
#else
wasi_nn_error
get_output(graph_execution_context ctx, uint32_t index,
tensor_data output_tensor, uint32_t *output_tensor_size)
WASI_NN_IMPORT("get_output");
#endif

#endif
4 changes: 4 additions & 0 deletions core/iwasm/libraries/wasi-nn/include/wasi_nn_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ typedef struct {
// Describe the size of the tensor (e.g., 2x2x2x2 -> [2, 2, 2, 2]). To
// represent a tensor containing a single value, use `[1]` for the tensor
// dimensions.
#if WASM_ENABLE_WASI_EPHEMERAL_NN != 0 && defined(__wasm__)
tensor_dimensions dimensions;
#else
tensor_dimensions *dimensions;
#endif
// Describe the type of element in the tensor (e.g., f32).
tensor_type type;
// Contains the tensor data.
Expand Down
Loading