Skip to content

Commit 1bb0fb0

Browse files
authored
Merge pull request #699 from bytecodealliance/main
Merge bytecodealliance:main into wenyongh:main
2 parents da74e54 + 0435acd commit 1bb0fb0

File tree

33 files changed

+1272
-576
lines changed

33 files changed

+1272
-576
lines changed

.github/workflows/compilation_on_nuttx.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,12 @@ jobs:
6565
"boards/risc-v/k210/maix-bit/configs/nsh",
6666
]
6767
wamr_config_option: [
68-
"CONFIG_INTERPRETERS_WAMR=y\\nCONFIG_INTERPRETERS_WAMR_AOT=y\\nCONFIG_INTERPRETERS_WAMR_FAST=y\\nCONFIG_INTERPRETERS_WAMR_LIBC_BUILTIN=y\\n",
6968
"CONFIG_INTERPRETERS_WAMR=y\\nCONFIG_INTERPRETERS_WAMR_AOT=y\\nCONFIG_INTERPRETERS_WAMR_FAST=y\\n",
69+
"CONFIG_INTERPRETERS_WAMR=y\\nCONFIG_INTERPRETERS_WAMR_AOT=y\\nCONFIG_INTERPRETERS_WAMR_FAST=y\\nCONFIG_INTERPRETERS_WAMR_LIBC_WASI=y\\n",
70+
"CONFIG_INTERPRETERS_WAMR=y\\nCONFIG_INTERPRETERS_WAMR_AOT=y\\nCONFIG_INTERPRETERS_WAMR_FAST=y\\nCONFIG_INTERPRETERS_WAMR_LIBC_BUILTIN=y\\n",
7071
"CONFIG_INTERPRETERS_WAMR=y\\nCONFIG_INTERPRETERS_WAMR_AOT=y\\nCONFIG_INTERPRETERS_WAMR_CLASSIC=y\\n",
72+
"CONFIG_INTERPRETERS_WAMR=y\\nCONFIG_INTERPRETERS_WAMR_AOT=y\\nCONFIG_INTERPRETERS_WAMR_CLASSIC=y\\nCONFIG_INTERPRETERS_WAMR_LIBC_WASI=y\\n",
73+
"CONFIG_INTERPRETERS_WAMR=y\\nCONFIG_INTERPRETERS_WAMR_AOT=y\\nCONFIG_INTERPRETERS_WAMR_CLASSIC=y\\nCONFIG_INTERPRETERS_WAMR_LIBC_BUILTIN=y\\n",
7174
"CONFIG_INTERPRETERS_WAMR=y\\nCONFIG_INTERPRETERS_WAMR_AOT=y\\nCONFIG_INTERPRETERS_WAMR_LIBC_BUILTIN=y\\n",
7275
"CONFIG_INTERPRETERS_WAMR=y\\nCONFIG_INTERPRETERS_WAMR_AOT=y\\n",
7376
"CONFIG_INTERPRETERS_WAMR=y\\nCONFIG_INTERPRETERS_WAMR_FAST=y\\n",

build-scripts/runtime_lib.cmake

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,13 @@ if (WAMR_BUILD_LIB_PTHREAD_SEMAPHORE EQUAL 1)
9696
endif ()
9797

9898
if (WAMR_BUILD_WASI_NN EQUAL 1)
99-
execute_process(COMMAND ${WAMR_ROOT_DIR}/core/deps/install_tensorflow.sh
100-
RESULT_VARIABLE TENSORFLOW_RESULT
101-
)
99+
if (NOT EXISTS "${WAMR_ROOT_DIR}/core/deps/tensorflow-src")
100+
execute_process(COMMAND ${WAMR_ROOT_DIR}/core/deps/install_tensorflow.sh
101+
RESULT_VARIABLE TENSORFLOW_RESULT
102+
)
103+
else ()
104+
message("Tensorflow is already downloaded.")
105+
endif()
102106
set(TENSORFLOW_SOURCE_DIR "${WAMR_ROOT_DIR}/core/deps/tensorflow-src")
103107
include_directories (${CMAKE_CURRENT_BINARY_DIR}/flatbuffers/include)
104108
include_directories (${TENSORFLOW_SOURCE_DIR})

core/iwasm/aot/aot_runtime.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,17 @@ aot_instantiate(AOTModule *module, bool is_sub_inst, uint32 stack_size,
10831083
}
10841084
#endif
10851085

1086+
#if WASM_ENABLE_WASI_NN != 0
1087+
if (!is_sub_inst) {
1088+
if (!(((AOTModuleInstanceExtra *)module_inst->e)->wasi_nn_ctx =
1089+
wasi_nn_initialize())) {
1090+
set_error_buf(error_buf, error_buf_size,
1091+
"wasi nn initialization failed");
1092+
goto fail;
1093+
}
1094+
}
1095+
#endif
1096+
10861097
/* Initialize the thread related data */
10871098
if (stack_size == 0)
10881099
stack_size = DEFAULT_WASM_STACK_SIZE;
@@ -1194,6 +1205,15 @@ aot_deinstantiate(AOTModuleInstance *module_inst, bool is_sub_inst)
11941205
wasm_runtime_free(
11951206
((AOTModuleInstanceExtra *)module_inst->e)->c_api_func_imports);
11961207

1208+
#if WASM_ENABLE_WASI_NN != 0
1209+
if (!is_sub_inst) {
1210+
WASINNContext *wasi_nn_ctx =
1211+
((AOTModuleInstanceExtra *)module_inst->e)->wasi_nn_ctx;
1212+
if (wasi_nn_ctx)
1213+
wasi_nn_destroy(wasi_nn_ctx);
1214+
}
1215+
#endif
1216+
11971217
wasm_runtime_free(module_inst);
11981218
}
11991219

core/iwasm/aot/aot_runtime.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
#include "../interpreter/wasm_runtime.h"
1212
#include "../compilation/aot.h"
1313

14+
#if WASM_ENABLE_WASI_NN != 0
15+
#include "../libraries/wasi-nn/src/wasi_nn_private.h"
16+
#endif
17+
1418
#ifdef __cplusplus
1519
extern "C" {
1620
#endif
@@ -75,6 +79,9 @@ typedef struct AOTFunctionInstance {
7579

7680
typedef struct AOTModuleInstanceExtra {
7781
CApiFuncImport *c_api_func_imports;
82+
#if WASM_ENABLE_WASI_NN != 0
83+
WASINNContext *wasi_nn_ctx;
84+
#endif
7885
} AOTModuleInstanceExtra;
7986

8087
#if defined(OS_ENABLE_HW_BOUND_CHECK) && defined(BH_PLATFORM_WINDOWS)

core/iwasm/interpreter/wasm_runtime.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1803,6 +1803,16 @@ wasm_instantiate(WASMModule *module, bool is_sub_inst, uint32 stack_size,
18031803
}
18041804
#endif
18051805

1806+
#if WASM_ENABLE_WASI_NN != 0
1807+
if (!is_sub_inst) {
1808+
if (!(module_inst->e->wasi_nn_ctx = wasi_nn_initialize())) {
1809+
set_error_buf(error_buf, error_buf_size,
1810+
"wasi nn initialization failed");
1811+
goto fail;
1812+
}
1813+
}
1814+
#endif
1815+
18061816
#if WASM_ENABLE_DEBUG_INTERP != 0 \
18071817
|| (WASM_ENABLE_FAST_JIT != 0 && WASM_ENABLE_JIT != 0 \
18081818
&& WASM_ENABLE_LAZY_JIT != 0)
@@ -1984,6 +1994,14 @@ wasm_deinstantiate(WASMModuleInstance *module_inst, bool is_sub_inst)
19841994
if (module_inst->e->c_api_func_imports)
19851995
wasm_runtime_free(module_inst->e->c_api_func_imports);
19861996

1997+
#if WASM_ENABLE_WASI_NN != 0
1998+
if (!is_sub_inst) {
1999+
WASINNContext *wasi_nn_ctx = module_inst->e->wasi_nn_ctx;
2000+
if (wasi_nn_ctx)
2001+
wasi_nn_destroy(wasi_nn_ctx);
2002+
}
2003+
#endif
2004+
19872005
wasm_runtime_free(module_inst);
19882006
}
19892007

core/iwasm/interpreter/wasm_runtime.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
#include "../common/wasm_runtime_common.h"
1212
#include "../common/wasm_exec_env.h"
1313

14+
#if WASM_ENABLE_WASI_NN != 0
15+
#include "../libraries/wasi-nn/src/wasi_nn_private.h"
16+
#endif
17+
1418
#ifdef __cplusplus
1519
extern "C" {
1620
#endif
@@ -242,6 +246,10 @@ typedef struct WASMModuleInstanceExtra {
242246
&& WASM_ENABLE_LAZY_JIT != 0)
243247
WASMModuleInstance *next;
244248
#endif
249+
250+
#if WASM_ENABLE_WASI_NN != 0
251+
WASINNContext *wasi_nn_ctx;
252+
#endif
245253
} WASMModuleInstanceExtra;
246254

247255
struct AOTFuncPerfProfInfo;

core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3226,6 +3226,7 @@ wasi_ssp_sock_get_reuse_port(
32263226
#else
32273227
errno = ENOTSUP;
32283228
ret = BHT_ERROR;
3229+
optval = 0;
32293230
#endif /* defined(SO_REUSEPORT) */
32303231

32313232
fd_object_release(fo);

core/iwasm/libraries/wasi-nn/.dockerignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

core/iwasm/libraries/wasi-nn/README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ Tests: passed!
3737

3838
## What is missing
3939

40-
* Only 1 model at a time is supported.
40+
Supported:
41+
42+
* Only 1 WASM app at a time.
43+
* Only 1 model at a time.
4144
* `graph` and `graph-execution-context` are ignored.
42-
* Only `tensorflow` (lite) is supported.
43-
* Only `cpu` is supported.
45+
* Graph encoding: `tensorflowlite`.
46+
* Execution target: `cpu`.
47+
* Tensor type: `fp32`.

core/iwasm/libraries/wasi-nn/logger.h

Lines changed: 0 additions & 55 deletions
This file was deleted.

0 commit comments

Comments
 (0)