mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-02-06 15:05:19 +00:00
Fix compilation warnings of wasi-nn (#3497)
This commit is contained in:
parent
bd44117676
commit
028f43bc18
|
@ -1945,7 +1945,7 @@ aot_deinstantiate(AOTModuleInstance *module_inst, bool is_sub_inst)
|
||||||
|
|
||||||
if (!is_sub_inst) {
|
if (!is_sub_inst) {
|
||||||
#if WASM_ENABLE_WASI_NN != 0
|
#if WASM_ENABLE_WASI_NN != 0
|
||||||
wasi_nn_destroy(module_inst);
|
wasi_nn_destroy((WASMModuleInstanceCommon *)module_inst);
|
||||||
#endif
|
#endif
|
||||||
wasm_native_call_context_dtors((WASMModuleInstanceCommon *)module_inst);
|
wasm_native_call_context_dtors((WASMModuleInstanceCommon *)module_inst);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3182,7 +3182,7 @@ wasm_deinstantiate(WASMModuleInstance *module_inst, bool is_sub_inst)
|
||||||
|
|
||||||
if (!is_sub_inst) {
|
if (!is_sub_inst) {
|
||||||
#if WASM_ENABLE_WASI_NN != 0
|
#if WASM_ENABLE_WASI_NN != 0
|
||||||
wasi_nn_destroy(module_inst);
|
wasi_nn_destroy((WASMModuleInstanceCommon *)module_inst);
|
||||||
#endif
|
#endif
|
||||||
wasm_native_call_context_dtors((WASMModuleInstanceCommon *)module_inst);
|
wasm_native_call_context_dtors((WASMModuleInstanceCommon *)module_inst);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,9 +22,9 @@
|
||||||
* @param encoding Model encoding.
|
* @param encoding Model encoding.
|
||||||
* @param target Execution target.
|
* @param target Execution target.
|
||||||
* @param g Graph.
|
* @param g Graph.
|
||||||
* @return error Execution status.
|
* @return wasi_nn_error Execution status.
|
||||||
*/
|
*/
|
||||||
error
|
wasi_nn_error
|
||||||
load(graph_builder_array *builder, graph_encoding encoding,
|
load(graph_builder_array *builder, graph_encoding encoding,
|
||||||
execution_target target, graph *g)
|
execution_target target, graph *g)
|
||||||
__attribute__((import_module("wasi_nn")));
|
__attribute__((import_module("wasi_nn")));
|
||||||
|
@ -34,17 +34,14 @@ load(graph_builder_array *builder, graph_encoding encoding,
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Bind a `graph` to the input and output tensors for an inference.
|
|
||||||
typedef uint32_t graph_execution_context;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Create an execution instance of a loaded graph.
|
* @brief Create an execution instance of a loaded graph.
|
||||||
*
|
*
|
||||||
* @param g Graph.
|
* @param g Graph.
|
||||||
* @param ctx Execution context.
|
* @param ctx Execution context.
|
||||||
* @return error Execution status.
|
* @return wasi_nn_error Execution status.
|
||||||
*/
|
*/
|
||||||
error
|
wasi_nn_error
|
||||||
init_execution_context(graph g, graph_execution_context *ctx)
|
init_execution_context(graph g, graph_execution_context *ctx)
|
||||||
__attribute__((import_module("wasi_nn")));
|
__attribute__((import_module("wasi_nn")));
|
||||||
|
|
||||||
|
@ -54,9 +51,9 @@ init_execution_context(graph g, graph_execution_context *ctx)
|
||||||
* @param ctx Execution context.
|
* @param ctx Execution context.
|
||||||
* @param index Input tensor index.
|
* @param index Input tensor index.
|
||||||
* @param tensor Input tensor.
|
* @param tensor Input tensor.
|
||||||
* @return error Execution status.
|
* @return wasi_nn_error Execution status.
|
||||||
*/
|
*/
|
||||||
error
|
wasi_nn_error
|
||||||
set_input(graph_execution_context ctx, uint32_t index, tensor *tensor)
|
set_input(graph_execution_context ctx, uint32_t index, tensor *tensor)
|
||||||
__attribute__((import_module("wasi_nn")));
|
__attribute__((import_module("wasi_nn")));
|
||||||
|
|
||||||
|
@ -64,9 +61,9 @@ set_input(graph_execution_context ctx, uint32_t index, tensor *tensor)
|
||||||
* @brief Compute the inference on the given inputs.
|
* @brief Compute the inference on the given inputs.
|
||||||
*
|
*
|
||||||
* @param ctx Execution context.
|
* @param ctx Execution context.
|
||||||
* @return error Execution status.
|
* @return wasi_nn_error Execution status.
|
||||||
*/
|
*/
|
||||||
error
|
wasi_nn_error
|
||||||
compute(graph_execution_context ctx) __attribute__((import_module("wasi_nn")));
|
compute(graph_execution_context ctx) __attribute__((import_module("wasi_nn")));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -79,9 +76,9 @@ compute(graph_execution_context ctx) __attribute__((import_module("wasi_nn")));
|
||||||
* @param output_tensor_size Pointer to `output_tensor` maximum size.
|
* @param output_tensor_size Pointer to `output_tensor` maximum size.
|
||||||
* After the function call it is updated with the
|
* After the function call it is updated with the
|
||||||
* copied number of bytes.
|
* copied number of bytes.
|
||||||
* @return error Execution status.
|
* @return wasi_nn_error Execution status.
|
||||||
*/
|
*/
|
||||||
error
|
wasi_nn_error
|
||||||
get_output(graph_execution_context ctx, uint32_t index,
|
get_output(graph_execution_context ctx, uint32_t index,
|
||||||
tensor_data output_tensor, uint32_t *output_tensor_size)
|
tensor_data output_tensor, uint32_t *output_tensor_size)
|
||||||
__attribute__((import_module("wasi_nn")));
|
__attribute__((import_module("wasi_nn")));
|
||||||
|
|
|
@ -28,7 +28,7 @@ typedef enum {
|
||||||
busy,
|
busy,
|
||||||
// Runtime Error.
|
// Runtime Error.
|
||||||
runtime_error,
|
runtime_error,
|
||||||
} error;
|
} wasi_nn_error;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TENSOR
|
* TENSOR
|
||||||
|
@ -106,4 +106,7 @@ typedef enum {
|
||||||
// Define where the graph should be executed.
|
// Define where the graph should be executed.
|
||||||
typedef enum execution_target { cpu = 0, gpu, tpu } execution_target;
|
typedef enum execution_target { cpu = 0, gpu, tpu } execution_target;
|
||||||
|
|
||||||
|
// Bind a `graph` to the input and output tensors for an inference.
|
||||||
|
typedef uint32_t graph_execution_context;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
#include "wasi_nn_app_native.h"
|
#include "wasi_nn_app_native.h"
|
||||||
|
|
||||||
static error
|
static wasi_nn_error
|
||||||
graph_builder_app_native(wasm_module_inst_t instance,
|
graph_builder_app_native(wasm_module_inst_t instance,
|
||||||
graph_builder_wasm *builder_wasm,
|
graph_builder_wasm *builder_wasm,
|
||||||
graph_builder *builder)
|
graph_builder *builder)
|
||||||
|
@ -27,12 +27,12 @@ graph_builder_app_native(wasm_module_inst_t instance,
|
||||||
* builder_array_wasm is consisted of {builder_wasm, size}
|
* builder_array_wasm is consisted of {builder_wasm, size}
|
||||||
*/
|
*/
|
||||||
#if WASM_ENABLE_WASI_EPHEMERAL_NN != 0
|
#if WASM_ENABLE_WASI_EPHEMERAL_NN != 0
|
||||||
error
|
wasi_nn_error
|
||||||
graph_builder_array_app_native(wasm_module_inst_t instance,
|
graph_builder_array_app_native(wasm_module_inst_t instance,
|
||||||
graph_builder_wasm *builder_wasm, uint32_t size,
|
graph_builder_wasm *builder_wasm, uint32_t size,
|
||||||
graph_builder_array *builder_array)
|
graph_builder_array *builder_array)
|
||||||
#else /* WASM_ENABLE_WASI_EPHEMERAL_NN == 0 */
|
#else /* WASM_ENABLE_WASI_EPHEMERAL_NN == 0 */
|
||||||
error
|
wasi_nn_error
|
||||||
graph_builder_array_app_native(wasm_module_inst_t instance,
|
graph_builder_array_app_native(wasm_module_inst_t instance,
|
||||||
graph_builder_array_wasm *builder_array_wasm,
|
graph_builder_array_wasm *builder_array_wasm,
|
||||||
graph_builder_array *builder_array)
|
graph_builder_array *builder_array)
|
||||||
|
@ -79,7 +79,7 @@ graph_builder_array_app_native(wasm_module_inst_t instance,
|
||||||
return missing_memory;
|
return missing_memory;
|
||||||
|
|
||||||
for (uint32_t i = 0; i < array_size; ++i) {
|
for (uint32_t i = 0; i < array_size; ++i) {
|
||||||
error res;
|
wasi_nn_error res;
|
||||||
if (success
|
if (success
|
||||||
!= (res = graph_builder_app_native(instance, &builder_wasm[i],
|
!= (res = graph_builder_app_native(instance, &builder_wasm[i],
|
||||||
&builder[i]))) {
|
&builder[i]))) {
|
||||||
|
@ -97,7 +97,7 @@ graph_builder_array_app_native(wasm_module_inst_t instance,
|
||||||
#undef array_size
|
#undef array_size
|
||||||
}
|
}
|
||||||
|
|
||||||
static error
|
static wasi_nn_error
|
||||||
tensor_data_app_native(wasm_module_inst_t instance, uint32_t total_elements,
|
tensor_data_app_native(wasm_module_inst_t instance, uint32_t total_elements,
|
||||||
tensor_wasm *input_tensor_wasm, tensor_data *data)
|
tensor_wasm *input_tensor_wasm, tensor_data *data)
|
||||||
{
|
{
|
||||||
|
@ -119,7 +119,7 @@ tensor_data_app_native(wasm_module_inst_t instance, uint32_t total_elements,
|
||||||
#undef data_size
|
#undef data_size
|
||||||
}
|
}
|
||||||
|
|
||||||
static error
|
static wasi_nn_error
|
||||||
tensor_dimensions_app_native(wasm_module_inst_t instance,
|
tensor_dimensions_app_native(wasm_module_inst_t instance,
|
||||||
tensor_wasm *input_tensor_wasm,
|
tensor_wasm *input_tensor_wasm,
|
||||||
tensor_dimensions **dimensions)
|
tensor_dimensions **dimensions)
|
||||||
|
@ -159,7 +159,7 @@ tensor_dimensions_app_native(wasm_module_inst_t instance,
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
error
|
wasi_nn_error
|
||||||
tensor_app_native(wasm_module_inst_t instance, tensor_wasm *input_tensor_wasm,
|
tensor_app_native(wasm_module_inst_t instance, tensor_wasm *input_tensor_wasm,
|
||||||
tensor *input_tensor)
|
tensor *input_tensor)
|
||||||
{
|
{
|
||||||
|
@ -170,7 +170,7 @@ tensor_app_native(wasm_module_inst_t instance, tensor_wasm *input_tensor_wasm,
|
||||||
return invalid_argument;
|
return invalid_argument;
|
||||||
}
|
}
|
||||||
|
|
||||||
error res;
|
wasi_nn_error res;
|
||||||
|
|
||||||
tensor_dimensions *dimensions = NULL;
|
tensor_dimensions *dimensions = NULL;
|
||||||
if (success
|
if (success
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "wasi_nn.h"
|
#include "wasi_nn_types.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
|
||||||
#include "bh_platform.h"
|
#include "bh_platform.h"
|
||||||
|
@ -47,18 +47,18 @@ typedef struct {
|
||||||
} tensor_wasm;
|
} tensor_wasm;
|
||||||
|
|
||||||
#if WASM_ENABLE_WASI_EPHEMERAL_NN != 0
|
#if WASM_ENABLE_WASI_EPHEMERAL_NN != 0
|
||||||
error
|
wasi_nn_error
|
||||||
graph_builder_array_app_native(wasm_module_inst_t instance,
|
graph_builder_array_app_native(wasm_module_inst_t instance,
|
||||||
graph_builder_wasm *builder_wasm, uint32_t size,
|
graph_builder_wasm *builder_wasm, uint32_t size,
|
||||||
graph_builder_array *builder_array);
|
graph_builder_array *builder_array);
|
||||||
#else /* WASM_ENABLE_WASI_EPHEMERAL_NN == 0 */
|
#else /* WASM_ENABLE_WASI_EPHEMERAL_NN == 0 */
|
||||||
error
|
wasi_nn_error
|
||||||
graph_builder_array_app_native(wasm_module_inst_t instance,
|
graph_builder_array_app_native(wasm_module_inst_t instance,
|
||||||
graph_builder_array_wasm *builder,
|
graph_builder_array_wasm *builder,
|
||||||
graph_builder_array *builder_native);
|
graph_builder_array *builder_native);
|
||||||
#endif /* WASM_ENABLE_WASI_EPHEMERAL_NN != 0 */
|
#endif /* WASM_ENABLE_WASI_EPHEMERAL_NN != 0 */
|
||||||
|
|
||||||
error
|
wasi_nn_error
|
||||||
tensor_app_native(wasm_module_inst_t instance, tensor_wasm *input_tensor,
|
tensor_app_native(wasm_module_inst_t instance, tensor_wasm *input_tensor,
|
||||||
tensor *input_tensor_native);
|
tensor *input_tensor_native);
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "wasi_nn.h"
|
|
||||||
#include "wasi_nn_private.h"
|
#include "wasi_nn_private.h"
|
||||||
#include "wasi_nn_app_native.h"
|
#include "wasi_nn_app_native.h"
|
||||||
#include "wasi_nn_tensorflowlite.hpp"
|
#include "wasi_nn_tensorflowlite.hpp"
|
||||||
|
@ -24,13 +23,14 @@
|
||||||
|
|
||||||
/* Definition of 'wasi_nn.h' structs in WASM app format (using offset) */
|
/* Definition of 'wasi_nn.h' structs in WASM app format (using offset) */
|
||||||
|
|
||||||
typedef error (*LOAD)(void *, graph_builder_array *, graph_encoding,
|
typedef wasi_nn_error (*LOAD)(void *, graph_builder_array *, graph_encoding,
|
||||||
execution_target, graph *);
|
execution_target, graph *);
|
||||||
typedef error (*INIT_EXECUTION_CONTEXT)(void *, graph,
|
typedef wasi_nn_error (*INIT_EXECUTION_CONTEXT)(void *, graph,
|
||||||
graph_execution_context *);
|
graph_execution_context *);
|
||||||
typedef error (*SET_INPUT)(void *, graph_execution_context, uint32_t, tensor *);
|
typedef wasi_nn_error (*SET_INPUT)(void *, graph_execution_context, uint32_t,
|
||||||
typedef error (*COMPUTE)(void *, graph_execution_context);
|
tensor *);
|
||||||
typedef error (*GET_OUTPUT)(void *, graph_execution_context, uint32_t,
|
typedef wasi_nn_error (*COMPUTE)(void *, graph_execution_context);
|
||||||
|
typedef wasi_nn_error (*GET_OUTPUT)(void *, graph_execution_context, uint32_t,
|
||||||
tensor_data, uint32_t *);
|
tensor_data, uint32_t *);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -177,7 +177,7 @@ is_encoding_implemented(graph_encoding encoding)
|
||||||
&& lookup[encoding].get_output;
|
&& lookup[encoding].get_output;
|
||||||
}
|
}
|
||||||
|
|
||||||
static error
|
static wasi_nn_error
|
||||||
is_model_initialized(WASINNContext *wasi_nn_ctx)
|
is_model_initialized(WASINNContext *wasi_nn_ctx)
|
||||||
{
|
{
|
||||||
if (!wasi_nn_ctx->is_model_loaded) {
|
if (!wasi_nn_ctx->is_model_loaded) {
|
||||||
|
@ -190,12 +190,12 @@ is_model_initialized(WASINNContext *wasi_nn_ctx)
|
||||||
/* WASI-NN implementation */
|
/* WASI-NN implementation */
|
||||||
|
|
||||||
#if WASM_ENABLE_WASI_EPHEMERAL_NN != 0
|
#if WASM_ENABLE_WASI_EPHEMERAL_NN != 0
|
||||||
error
|
wasi_nn_error
|
||||||
wasi_nn_load(wasm_exec_env_t exec_env, graph_builder_wasm *builder,
|
wasi_nn_load(wasm_exec_env_t exec_env, graph_builder_wasm *builder,
|
||||||
uint32_t builder_wasm_size, graph_encoding encoding,
|
uint32_t builder_wasm_size, graph_encoding encoding,
|
||||||
execution_target target, graph *g)
|
execution_target target, graph *g)
|
||||||
#else /* WASM_ENABLE_WASI_EPHEMERAL_NN == 0 */
|
#else /* WASM_ENABLE_WASI_EPHEMERAL_NN == 0 */
|
||||||
error
|
wasi_nn_error
|
||||||
wasi_nn_load(wasm_exec_env_t exec_env, graph_builder_array_wasm *builder,
|
wasi_nn_load(wasm_exec_env_t exec_env, graph_builder_array_wasm *builder,
|
||||||
graph_encoding encoding, execution_target target, graph *g)
|
graph_encoding encoding, execution_target target, graph *g)
|
||||||
#endif /* WASM_ENABLE_WASI_EPHEMERAL_NN != 0 */
|
#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,
|
||||||
wasm_module_inst_t instance = wasm_runtime_get_module_inst(exec_env);
|
wasm_module_inst_t instance = wasm_runtime_get_module_inst(exec_env);
|
||||||
bh_assert(instance);
|
bh_assert(instance);
|
||||||
|
|
||||||
error res;
|
wasi_nn_error res;
|
||||||
graph_builder_array builder_native = { 0 };
|
graph_builder_array builder_native = { 0 };
|
||||||
#if WASM_ENABLE_WASI_EPHEMERAL_NN != 0
|
#if WASM_ENABLE_WASI_EPHEMERAL_NN != 0
|
||||||
if (success
|
if (success
|
||||||
|
@ -249,7 +249,7 @@ fail:
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
error
|
wasi_nn_error
|
||||||
wasi_nn_init_execution_context(wasm_exec_env_t exec_env, graph g,
|
wasi_nn_init_execution_context(wasm_exec_env_t exec_env, graph g,
|
||||||
graph_execution_context *ctx)
|
graph_execution_context *ctx)
|
||||||
{
|
{
|
||||||
|
@ -259,7 +259,7 @@ wasi_nn_init_execution_context(wasm_exec_env_t exec_env, graph g,
|
||||||
bh_assert(instance);
|
bh_assert(instance);
|
||||||
WASINNContext *wasi_nn_ctx = wasm_runtime_get_wasi_nn_ctx(instance);
|
WASINNContext *wasi_nn_ctx = wasm_runtime_get_wasi_nn_ctx(instance);
|
||||||
|
|
||||||
error res;
|
wasi_nn_error res;
|
||||||
if (success != (res = is_model_initialized(wasi_nn_ctx)))
|
if (success != (res = is_model_initialized(wasi_nn_ctx)))
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
|
@ -278,7 +278,7 @@ wasi_nn_init_execution_context(wasm_exec_env_t exec_env, graph g,
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
error
|
wasi_nn_error
|
||||||
wasi_nn_set_input(wasm_exec_env_t exec_env, graph_execution_context ctx,
|
wasi_nn_set_input(wasm_exec_env_t exec_env, graph_execution_context ctx,
|
||||||
uint32_t index, tensor_wasm *input_tensor)
|
uint32_t index, tensor_wasm *input_tensor)
|
||||||
{
|
{
|
||||||
|
@ -289,7 +289,7 @@ wasi_nn_set_input(wasm_exec_env_t exec_env, graph_execution_context ctx,
|
||||||
bh_assert(instance);
|
bh_assert(instance);
|
||||||
WASINNContext *wasi_nn_ctx = wasm_runtime_get_wasi_nn_ctx(instance);
|
WASINNContext *wasi_nn_ctx = wasm_runtime_get_wasi_nn_ctx(instance);
|
||||||
|
|
||||||
error res;
|
wasi_nn_error res;
|
||||||
if (success != (res = is_model_initialized(wasi_nn_ctx)))
|
if (success != (res = is_model_initialized(wasi_nn_ctx)))
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
|
@ -310,7 +310,7 @@ wasi_nn_set_input(wasm_exec_env_t exec_env, graph_execution_context ctx,
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
error
|
wasi_nn_error
|
||||||
wasi_nn_compute(wasm_exec_env_t exec_env, graph_execution_context ctx)
|
wasi_nn_compute(wasm_exec_env_t exec_env, graph_execution_context ctx)
|
||||||
{
|
{
|
||||||
NN_DBG_PRINTF("Running wasi_nn_compute [ctx=%d]...", ctx);
|
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)
|
||||||
bh_assert(instance);
|
bh_assert(instance);
|
||||||
WASINNContext *wasi_nn_ctx = wasm_runtime_get_wasi_nn_ctx(instance);
|
WASINNContext *wasi_nn_ctx = wasm_runtime_get_wasi_nn_ctx(instance);
|
||||||
|
|
||||||
error res;
|
wasi_nn_error res;
|
||||||
if (success != (res = is_model_initialized(wasi_nn_ctx)))
|
if (success != (res = is_model_initialized(wasi_nn_ctx)))
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
|
@ -330,12 +330,12 @@ wasi_nn_compute(wasm_exec_env_t exec_env, graph_execution_context ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
#if WASM_ENABLE_WASI_EPHEMERAL_NN != 0
|
#if WASM_ENABLE_WASI_EPHEMERAL_NN != 0
|
||||||
error
|
wasi_nn_error
|
||||||
wasi_nn_get_output(wasm_exec_env_t exec_env, graph_execution_context ctx,
|
wasi_nn_get_output(wasm_exec_env_t exec_env, graph_execution_context ctx,
|
||||||
uint32_t index, tensor_data output_tensor,
|
uint32_t index, tensor_data output_tensor,
|
||||||
uint32_t output_tensor_len, uint32_t *output_tensor_size)
|
uint32_t output_tensor_len, uint32_t *output_tensor_size)
|
||||||
#else /* WASM_ENABLE_WASI_EPHEMERAL_NN == 0 */
|
#else /* WASM_ENABLE_WASI_EPHEMERAL_NN == 0 */
|
||||||
error
|
wasi_nn_error
|
||||||
wasi_nn_get_output(wasm_exec_env_t exec_env, graph_execution_context ctx,
|
wasi_nn_get_output(wasm_exec_env_t exec_env, graph_execution_context ctx,
|
||||||
uint32_t index, tensor_data output_tensor,
|
uint32_t index, tensor_data output_tensor,
|
||||||
uint32_t *output_tensor_size)
|
uint32_t *output_tensor_size)
|
||||||
|
@ -348,7 +348,7 @@ wasi_nn_get_output(wasm_exec_env_t exec_env, graph_execution_context ctx,
|
||||||
bh_assert(instance);
|
bh_assert(instance);
|
||||||
WASINNContext *wasi_nn_ctx = wasm_runtime_get_wasi_nn_ctx(instance);
|
WASINNContext *wasi_nn_ctx = wasm_runtime_get_wasi_nn_ctx(instance);
|
||||||
|
|
||||||
error res;
|
wasi_nn_error res;
|
||||||
if (success != (res = is_model_initialized(wasi_nn_ctx)))
|
if (success != (res = is_model_initialized(wasi_nn_ctx)))
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "wasi_nn.h"
|
#include "wasi_nn_types.h"
|
||||||
#include "wasi_nn_tensorflowlite.hpp"
|
#include "wasi_nn_tensorflowlite.hpp"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ typedef struct {
|
||||||
|
|
||||||
/* Utils */
|
/* Utils */
|
||||||
|
|
||||||
static error
|
static wasi_nn_error
|
||||||
initialize_g(TFLiteContext *tfl_ctx, graph *g)
|
initialize_g(TFLiteContext *tfl_ctx, graph *g)
|
||||||
{
|
{
|
||||||
os_mutex_lock(&tfl_ctx->g_lock);
|
os_mutex_lock(&tfl_ctx->g_lock);
|
||||||
|
@ -63,7 +63,7 @@ initialize_g(TFLiteContext *tfl_ctx, graph *g)
|
||||||
os_mutex_unlock(&tfl_ctx->g_lock);
|
os_mutex_unlock(&tfl_ctx->g_lock);
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
static error
|
static wasi_nn_error
|
||||||
initialize_graph_ctx(TFLiteContext *tfl_ctx, graph g,
|
initialize_graph_ctx(TFLiteContext *tfl_ctx, graph g,
|
||||||
graph_execution_context *ctx)
|
graph_execution_context *ctx)
|
||||||
{
|
{
|
||||||
|
@ -78,7 +78,7 @@ initialize_graph_ctx(TFLiteContext *tfl_ctx, graph g,
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
static error
|
static wasi_nn_error
|
||||||
is_valid_graph(TFLiteContext *tfl_ctx, graph g)
|
is_valid_graph(TFLiteContext *tfl_ctx, graph g)
|
||||||
{
|
{
|
||||||
if (g >= MAX_GRAPHS_PER_INST) {
|
if (g >= MAX_GRAPHS_PER_INST) {
|
||||||
|
@ -96,7 +96,7 @@ is_valid_graph(TFLiteContext *tfl_ctx, graph g)
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
static error
|
static wasi_nn_error
|
||||||
is_valid_graph_execution_context(TFLiteContext *tfl_ctx,
|
is_valid_graph_execution_context(TFLiteContext *tfl_ctx,
|
||||||
graph_execution_context ctx)
|
graph_execution_context ctx)
|
||||||
{
|
{
|
||||||
|
@ -114,7 +114,7 @@ is_valid_graph_execution_context(TFLiteContext *tfl_ctx,
|
||||||
|
|
||||||
/* WASI-NN (tensorflow) implementation */
|
/* WASI-NN (tensorflow) implementation */
|
||||||
|
|
||||||
error
|
wasi_nn_error
|
||||||
tensorflowlite_load(void *tflite_ctx, graph_builder_array *builder,
|
tensorflowlite_load(void *tflite_ctx, graph_builder_array *builder,
|
||||||
graph_encoding encoding, execution_target target, graph *g)
|
graph_encoding encoding, execution_target target, graph *g)
|
||||||
{
|
{
|
||||||
|
@ -135,7 +135,7 @@ tensorflowlite_load(void *tflite_ctx, graph_builder_array *builder,
|
||||||
return invalid_argument;
|
return invalid_argument;
|
||||||
}
|
}
|
||||||
|
|
||||||
error res;
|
wasi_nn_error res;
|
||||||
if (success != (res = initialize_g(tfl_ctx, g)))
|
if (success != (res = initialize_g(tfl_ctx, g)))
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
|
@ -168,13 +168,13 @@ tensorflowlite_load(void *tflite_ctx, graph_builder_array *builder,
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
error
|
wasi_nn_error
|
||||||
tensorflowlite_init_execution_context(void *tflite_ctx, graph g,
|
tensorflowlite_init_execution_context(void *tflite_ctx, graph g,
|
||||||
graph_execution_context *ctx)
|
graph_execution_context *ctx)
|
||||||
{
|
{
|
||||||
TFLiteContext *tfl_ctx = (TFLiteContext *)tflite_ctx;
|
TFLiteContext *tfl_ctx = (TFLiteContext *)tflite_ctx;
|
||||||
|
|
||||||
error res;
|
wasi_nn_error res;
|
||||||
if (success != (res = is_valid_graph(tfl_ctx, g)))
|
if (success != (res = is_valid_graph(tfl_ctx, g)))
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
|
@ -257,13 +257,13 @@ tensorflowlite_init_execution_context(void *tflite_ctx, graph g,
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
error
|
wasi_nn_error
|
||||||
tensorflowlite_set_input(void *tflite_ctx, graph_execution_context ctx,
|
tensorflowlite_set_input(void *tflite_ctx, graph_execution_context ctx,
|
||||||
uint32_t index, tensor *input_tensor)
|
uint32_t index, tensor *input_tensor)
|
||||||
{
|
{
|
||||||
TFLiteContext *tfl_ctx = (TFLiteContext *)tflite_ctx;
|
TFLiteContext *tfl_ctx = (TFLiteContext *)tflite_ctx;
|
||||||
|
|
||||||
error res;
|
wasi_nn_error res;
|
||||||
if (success != (res = is_valid_graph_execution_context(tfl_ctx, ctx)))
|
if (success != (res = is_valid_graph_execution_context(tfl_ctx, ctx)))
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
|
@ -328,12 +328,12 @@ tensorflowlite_set_input(void *tflite_ctx, graph_execution_context ctx,
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
error
|
wasi_nn_error
|
||||||
tensorflowlite_compute(void *tflite_ctx, graph_execution_context ctx)
|
tensorflowlite_compute(void *tflite_ctx, graph_execution_context ctx)
|
||||||
{
|
{
|
||||||
TFLiteContext *tfl_ctx = (TFLiteContext *)tflite_ctx;
|
TFLiteContext *tfl_ctx = (TFLiteContext *)tflite_ctx;
|
||||||
|
|
||||||
error res;
|
wasi_nn_error res;
|
||||||
if (success != (res = is_valid_graph_execution_context(tfl_ctx, ctx)))
|
if (success != (res = is_valid_graph_execution_context(tfl_ctx, ctx)))
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
|
@ -341,14 +341,14 @@ tensorflowlite_compute(void *tflite_ctx, graph_execution_context ctx)
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
error
|
wasi_nn_error
|
||||||
tensorflowlite_get_output(void *tflite_ctx, graph_execution_context ctx,
|
tensorflowlite_get_output(void *tflite_ctx, graph_execution_context ctx,
|
||||||
uint32_t index, tensor_data output_tensor,
|
uint32_t index, tensor_data output_tensor,
|
||||||
uint32_t *output_tensor_size)
|
uint32_t *output_tensor_size)
|
||||||
{
|
{
|
||||||
TFLiteContext *tfl_ctx = (TFLiteContext *)tflite_ctx;
|
TFLiteContext *tfl_ctx = (TFLiteContext *)tflite_ctx;
|
||||||
|
|
||||||
error res;
|
wasi_nn_error res;
|
||||||
if (success != (res = is_valid_graph_execution_context(tfl_ctx, ctx)))
|
if (success != (res = is_valid_graph_execution_context(tfl_ctx, ctx)))
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
|
@ -472,6 +472,8 @@ tensorflowlite_destroy(void *tflite_ctx)
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wasm_runtime_free(tfl_ctx->models[i].model_pointer);
|
wasm_runtime_free(tfl_ctx->models[i].model_pointer);
|
||||||
|
|
|
@ -6,28 +6,28 @@
|
||||||
#ifndef WASI_NN_TENSORFLOWLITE_HPP
|
#ifndef WASI_NN_TENSORFLOWLITE_HPP
|
||||||
#define WASI_NN_TENSORFLOWLITE_HPP
|
#define WASI_NN_TENSORFLOWLITE_HPP
|
||||||
|
|
||||||
#include "wasi_nn.h"
|
#include "wasi_nn_types.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
error
|
wasi_nn_error
|
||||||
tensorflowlite_load(void *tflite_ctx, graph_builder_array *builder,
|
tensorflowlite_load(void *tflite_ctx, graph_builder_array *builder,
|
||||||
graph_encoding encoding, execution_target target, graph *g);
|
graph_encoding encoding, execution_target target, graph *g);
|
||||||
|
|
||||||
error
|
wasi_nn_error
|
||||||
tensorflowlite_init_execution_context(void *tflite_ctx, graph g,
|
tensorflowlite_init_execution_context(void *tflite_ctx, graph g,
|
||||||
graph_execution_context *ctx);
|
graph_execution_context *ctx);
|
||||||
|
|
||||||
error
|
wasi_nn_error
|
||||||
tensorflowlite_set_input(void *tflite_ctx, graph_execution_context ctx,
|
tensorflowlite_set_input(void *tflite_ctx, graph_execution_context ctx,
|
||||||
uint32_t index, tensor *input_tensor);
|
uint32_t index, tensor *input_tensor);
|
||||||
|
|
||||||
error
|
wasi_nn_error
|
||||||
tensorflowlite_compute(void *tflite_ctx, graph_execution_context ctx);
|
tensorflowlite_compute(void *tflite_ctx, graph_execution_context ctx);
|
||||||
|
|
||||||
error
|
wasi_nn_error
|
||||||
tensorflowlite_get_output(void *tflite_ctx, graph_execution_context ctx,
|
tensorflowlite_get_output(void *tflite_ctx, graph_execution_context ctx,
|
||||||
uint32_t index, tensor_data output_tensor,
|
uint32_t index, tensor_data output_tensor,
|
||||||
uint32_t *output_tensor_size);
|
uint32_t *output_tensor_size);
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
error
|
wasi_nn_error
|
||||||
wasm_load(char *model_name, graph *g, execution_target target)
|
wasm_load(char *model_name, graph *g, execution_target target)
|
||||||
{
|
{
|
||||||
FILE *pFile = fopen(model_name, "r");
|
FILE *pFile = fopen(model_name, "r");
|
||||||
|
@ -46,7 +46,7 @@ wasm_load(char *model_name, graph *g, execution_target target)
|
||||||
arr.buf[0].size = result;
|
arr.buf[0].size = result;
|
||||||
arr.buf[0].buf = buffer;
|
arr.buf[0].buf = buffer;
|
||||||
|
|
||||||
error res = load(&arr, tensorflowlite, target, g);
|
wasi_nn_error res = load(&arr, tensorflowlite, target, g);
|
||||||
|
|
||||||
fclose(pFile);
|
fclose(pFile);
|
||||||
free(buffer);
|
free(buffer);
|
||||||
|
@ -54,13 +54,13 @@ wasm_load(char *model_name, graph *g, execution_target target)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
error
|
wasi_nn_error
|
||||||
wasm_init_execution_context(graph g, graph_execution_context *ctx)
|
wasm_init_execution_context(graph g, graph_execution_context *ctx)
|
||||||
{
|
{
|
||||||
return init_execution_context(g, ctx);
|
return init_execution_context(g, ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
error
|
wasi_nn_error
|
||||||
wasm_set_input(graph_execution_context ctx, float *input_tensor, uint32_t *dim)
|
wasm_set_input(graph_execution_context ctx, float *input_tensor, uint32_t *dim)
|
||||||
{
|
{
|
||||||
tensor_dimensions dims;
|
tensor_dimensions dims;
|
||||||
|
@ -75,19 +75,19 @@ wasm_set_input(graph_execution_context ctx, float *input_tensor, uint32_t *dim)
|
||||||
tensor.dimensions->buf[i] = dim[i];
|
tensor.dimensions->buf[i] = dim[i];
|
||||||
tensor.type = fp32;
|
tensor.type = fp32;
|
||||||
tensor.data = (uint8_t *)input_tensor;
|
tensor.data = (uint8_t *)input_tensor;
|
||||||
error err = set_input(ctx, 0, &tensor);
|
wasi_nn_error err = set_input(ctx, 0, &tensor);
|
||||||
|
|
||||||
free(dims.buf);
|
free(dims.buf);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
error
|
wasi_nn_error
|
||||||
wasm_compute(graph_execution_context ctx)
|
wasm_compute(graph_execution_context ctx)
|
||||||
{
|
{
|
||||||
return compute(ctx);
|
return compute(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
error
|
wasi_nn_error
|
||||||
wasm_get_output(graph_execution_context ctx, uint32_t index, float *out_tensor,
|
wasm_get_output(graph_execution_context ctx, uint32_t index, float *out_tensor,
|
||||||
uint32_t *out_size)
|
uint32_t *out_size)
|
||||||
{
|
{
|
||||||
|
|
|
@ -23,19 +23,19 @@ typedef struct {
|
||||||
|
|
||||||
/* wasi-nn wrappers */
|
/* wasi-nn wrappers */
|
||||||
|
|
||||||
error
|
wasi_nn_error
|
||||||
wasm_load(char *model_name, graph *g, execution_target target);
|
wasm_load(char *model_name, graph *g, execution_target target);
|
||||||
|
|
||||||
error
|
wasi_nn_error
|
||||||
wasm_init_execution_context(graph g, graph_execution_context *ctx);
|
wasm_init_execution_context(graph g, graph_execution_context *ctx);
|
||||||
|
|
||||||
error
|
wasi_nn_error
|
||||||
wasm_set_input(graph_execution_context ctx, float *input_tensor, uint32_t *dim);
|
wasm_set_input(graph_execution_context ctx, float *input_tensor, uint32_t *dim);
|
||||||
|
|
||||||
error
|
wasi_nn_error
|
||||||
wasm_compute(graph_execution_context ctx);
|
wasm_compute(graph_execution_context ctx);
|
||||||
|
|
||||||
error
|
wasi_nn_error
|
||||||
wasm_get_output(graph_execution_context ctx, uint32_t index, float *out_tensor,
|
wasm_get_output(graph_execution_context ctx, uint32_t index, float *out_tensor,
|
||||||
uint32_t *out_size);
|
uint32_t *out_size);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user