Skip to content

Commit 892af84

Browse files
authored
Update sample workload wasm-av1 and add workload XNNPACK (#443)
1 parent a2641e1 commit 892af84

File tree

17 files changed

+1474
-19
lines changed

17 files changed

+1474
-19
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ The WAMR [samples](./samples) integrate the iwasm VM core, application manager a
115115
- **[spawn-thread](./samples/spawn-thread)**: Demonstrating how to execute wasm functions of the same wasm application concurrently, in threads created by host embedder or runtime, but not the wasm application itself.
116116
- **[multi-module](./samples/multi-module)**: Demonstrating the [multiple modules as dependencies](./doc/multi_module.md) feature which implements the [load-time dynamic linking](https://webassembly.org/docs/dynamic-linking/).
117117
- **[wasm-c-api](./samples/wasm-c-api/README.md)**: Demonstrating how to run some samples from [wasm-c-api proposal](https://github.com/WebAssembly/wasm-c-api) and showing the supported API's.
118+
- **[workload](./samples/workload/README.md)**: Demonstrating how to build and run some complex workloads, e.g. tensorflow-lite, XNNPACK, wasm-av1, meshoptimizer and bwa.
118119

119120

120121
License

core/iwasm/aot/aot_reloc.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ typedef struct {
3636
REG_SYM(aot_call_indirect), \
3737
REG_SYM(wasm_runtime_enlarge_memory), \
3838
REG_SYM(wasm_runtime_set_exception), \
39+
REG_SYM(memset), \
40+
REG_SYM(memmove), \
3941
REG_BULK_MEMORY_SYM() \
4042
REG_ATOMIC_WAIT_SYM()
4143
#else /* else of (defined(_WIN32) || defined(_WIN32_)) && defined(NDEBUG) */
@@ -45,6 +47,8 @@ typedef struct {
4547
REG_SYM(aot_call_indirect), \
4648
REG_SYM(wasm_runtime_enlarge_memory), \
4749
REG_SYM(wasm_runtime_set_exception), \
50+
REG_SYM(memset), \
51+
REG_SYM(memmove), \
4852
REG_SYM(fmin), \
4953
REG_SYM(fminf), \
5054
REG_SYM(fmax), \

core/iwasm/libraries/libc-builtin/libc_builtin_wrapper.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,21 @@ __cxa_throw_wrapper(wasm_exec_env_t exec_env,
10071007
wasm_runtime_set_exception(module_inst, buf);
10081008
}
10091009

1010+
static int
1011+
setjmp_wrapper(wasm_exec_env_t exec_env,
1012+
void *jmp_buf)
1013+
{
1014+
os_printf("in setjmp()\n");
1015+
return 0;
1016+
}
1017+
1018+
static void
1019+
longjmp_wrapper(wasm_exec_env_t exec_env,
1020+
void *jmp_buf, int val)
1021+
{
1022+
os_printf("in longjmp()\n");
1023+
}
1024+
10101025
#if WASM_ENABLE_SPEC_TEST != 0
10111026
static void
10121027
print_wrapper(wasm_exec_env_t exec_env)
@@ -1104,7 +1119,9 @@ static NativeSymbol native_symbols_libc_builtin[] = {
11041119
REG_NATIVE_FUNC(nullFunc_X, "(i)"),
11051120
REG_NATIVE_FUNC(__cxa_allocate_exception, "(i)i"),
11061121
REG_NATIVE_FUNC(__cxa_begin_catch, "(*)"),
1107-
REG_NATIVE_FUNC(__cxa_throw, "(**i)")
1122+
REG_NATIVE_FUNC(__cxa_throw, "(**i)"),
1123+
REG_NATIVE_FUNC(setjmp, "(*)i"),
1124+
REG_NATIVE_FUNC(longjmp, "(*i)"),
11081125
};
11091126

11101127
#if WASM_ENABLE_SPEC_TEST != 0

core/iwasm/libraries/libc-emcc/libc_emcc_wrapper.c

Lines changed: 147 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,27 @@
1111
#define get_module_inst(exec_env) \
1212
wasm_runtime_get_module_inst(exec_env)
1313

14+
#define validate_app_addr(offset, size) \
15+
wasm_runtime_validate_app_addr(module_inst, offset, size)
16+
17+
#define validate_app_str_addr(offset) \
18+
wasm_runtime_validate_app_str_addr(module_inst, offset)
19+
1420
#define validate_native_addr(addr, size) \
1521
wasm_runtime_validate_native_addr(module_inst, addr, size)
1622

23+
#define addr_app_to_native(offset) \
24+
wasm_runtime_addr_app_to_native(module_inst, offset)
25+
26+
#define addr_native_to_app(ptr) \
27+
wasm_runtime_addr_native_to_app(module_inst, ptr)
28+
1729
#define module_malloc(size, p_native_addr) \
1830
wasm_runtime_module_malloc(module_inst, size, p_native_addr)
1931

2032
#define module_free(offset) \
2133
wasm_runtime_module_free(module_inst, offset)
2234

23-
#define REG_NATIVE_FUNC(func_name, signature) \
24-
{ #func_name, func_name##_wrapper, signature, NULL }
25-
2635
extern bool
2736
wasm_runtime_call_indirect(wasm_exec_env_t exec_env,
2837
uint32 element_idx,
@@ -282,12 +291,15 @@ fopen_wrapper(wasm_exec_env_t exec_env,
282291
int file_id;
283292

284293
if (pathname == NULL || mode == NULL)
285-
return -1;
294+
return 0;
286295

287296
if ((file_id = get_free_file_slot()) == -1)
288-
return -1;
297+
return 0;
289298

290299
file = fopen(pathname, mode);
300+
if (!file)
301+
return 0;
302+
291303
file_list[file_id] = file;
292304
return file_id + 1;
293305
}
@@ -308,6 +320,22 @@ fread_wrapper(wasm_exec_env_t exec_env,
308320
return (uint32)fread(ptr, size, nmemb, file);
309321
}
310322

323+
static int
324+
fseeko_wrapper(wasm_exec_env_t exec_env,
325+
int file_id, int64 offset, int whence)
326+
{
327+
FILE *file;
328+
329+
file_id = file_id - 1;
330+
if ((unsigned)file_id >= sizeof(file_list) / sizeof(FILE *)) {
331+
return -1;
332+
}
333+
if ((file = file_list[file_id]) == NULL) {
334+
return -1;
335+
}
336+
return (uint32)fseek(file, offset, whence);
337+
}
338+
311339
static uint32
312340
emcc_fwrite_wrapper(wasm_exec_env_t exec_env,
313341
const void *ptr, uint32 size, uint32 nmemb,
@@ -351,6 +379,113 @@ fclose_wrapper(wasm_exec_env_t exec_env, int file_id)
351379
file_list[file_id] = NULL;
352380
return fclose(file);
353381
}
382+
383+
static int
384+
__sys_mkdir_wrapper(wasm_exec_env_t exec_env,
385+
const char *pathname, int mode)
386+
{
387+
if (!pathname)
388+
return -1;
389+
return mkdir(pathname, mode);
390+
}
391+
392+
static int
393+
__sys_rmdir_wrapper(wasm_exec_env_t exec_env, const char *pathname)
394+
{
395+
if (!pathname)
396+
return -1;
397+
return rmdir(pathname);
398+
}
399+
400+
static int
401+
__sys_unlink_wrapper(wasm_exec_env_t exec_env, const char *pathname)
402+
{
403+
if (!pathname)
404+
return -1;
405+
return unlink(pathname);
406+
}
407+
408+
static uint32
409+
__sys_getcwd_wrapper(wasm_exec_env_t exec_env, char *buf, uint32 size)
410+
{
411+
wasm_module_inst_t module_inst = get_module_inst(exec_env);
412+
char *ret;
413+
414+
if (!buf)
415+
return -1;
416+
417+
ret = getcwd(buf, size);
418+
return ret ? addr_native_to_app(ret) : 0;
419+
}
420+
421+
#include <sys/utsname.h>
422+
423+
struct utsname_app {
424+
char sysname[64];
425+
char nodename[64];
426+
char release[64];
427+
char version[64];
428+
char machine[64];
429+
char domainname[64];
430+
};
431+
432+
static int
433+
__sys_uname_wrapper(wasm_exec_env_t exec_env, struct utsname_app *uname_app)
434+
{
435+
wasm_module_inst_t module_inst = get_module_inst(exec_env);
436+
struct utsname uname_native = { 0 };
437+
uint32 length;
438+
439+
if (!validate_native_addr(uname_app, sizeof(struct utsname_app)))
440+
return -1;
441+
442+
if (uname(&uname_native) != 0) {
443+
return -1;
444+
}
445+
446+
memset(uname_app, 0, sizeof(struct utsname_app));
447+
448+
length = strlen(uname_native.sysname);
449+
if (length > sizeof(uname_app->sysname) - 1)
450+
length = sizeof(uname_app->sysname) - 1;
451+
bh_memcpy_s(uname_app->sysname, sizeof(uname_app->sysname),
452+
uname_native.sysname, length);
453+
454+
length = strlen(uname_native.nodename);
455+
if (length > sizeof(uname_app->nodename) - 1)
456+
length = sizeof(uname_app->nodename) - 1;
457+
bh_memcpy_s(uname_app->nodename, sizeof(uname_app->nodename),
458+
uname_native.nodename, length);
459+
460+
length = strlen(uname_native.release);
461+
if (length > sizeof(uname_app->release) - 1)
462+
length = sizeof(uname_app->release) - 1;
463+
bh_memcpy_s(uname_app->release, sizeof(uname_app->release),
464+
uname_native.release, length);
465+
466+
length = strlen(uname_native.version);
467+
if (length > sizeof(uname_app->version) - 1)
468+
length = sizeof(uname_app->version) - 1;
469+
bh_memcpy_s(uname_app->version, sizeof(uname_app->version),
470+
uname_native.version, length);
471+
472+
#ifdef _GNU_SOURCE
473+
length = strlen(uname_native.domainname);
474+
if (length > sizeof(uname_app->domainname) - 1)
475+
length = sizeof(uname_app->domainname) - 1;
476+
bh_memcpy_s(uname_app->domainname, sizeof(uname_app->domainname),
477+
uname_native.domainname, length);
478+
#endif
479+
480+
return 0;
481+
}
482+
483+
static void
484+
emscripten_notify_memory_growth_wrapper(wasm_exec_env_t exec_env, int i)
485+
{
486+
(void)i;
487+
}
488+
354489
#endif /* end of BH_PLATFORM_LINUX_SGX */
355490

356491
#define REG_NATIVE_FUNC(func_name, signature) \
@@ -374,9 +509,16 @@ static NativeSymbol native_symbols_libc_emcc[] = {
374509
#if !defined(BH_PLATFORM_LINUX_SGX)
375510
REG_NATIVE_FUNC(fopen, "($$)i"),
376511
REG_NATIVE_FUNC(fread, "(*iii)i"),
512+
REG_NATIVE_FUNC(fseeko, "(iIi)i"),
377513
REG_NATIVE_FUNC(emcc_fwrite, "(*iii)i"),
378514
REG_NATIVE_FUNC(feof, "(i)i"),
379515
REG_NATIVE_FUNC(fclose, "(i)i"),
516+
REG_NATIVE_FUNC(__sys_mkdir, "($i)i"),
517+
REG_NATIVE_FUNC(__sys_rmdir, "($)i"),
518+
REG_NATIVE_FUNC(__sys_unlink, "($)i"),
519+
REG_NATIVE_FUNC(__sys_getcwd, "(*~)i"),
520+
REG_NATIVE_FUNC(__sys_uname, "(*)i"),
521+
REG_NATIVE_FUNC(emscripten_notify_memory_growth, "(i)"),
380522
#endif /* end of BH_PLATFORM_LINUX_SGX */
381523
};
382524

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# Copyright (C) 2019 Intel Corporation. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
cmake_minimum_required (VERSION 3.0)
5+
6+
project(xnnpack_wasm)
7+
8+
################ EMCC ################
9+
if(NOT DEFINED ENV{EMSDK})
10+
message(SEND_ERROR
11+
"can not find emsdk. "
12+
"please refer to https://emscripten.org/docs/getting_started/downloads.html "
13+
"and install it, "
14+
"or active emsdk by 'source ./emsdk_env.sh'"
15+
)
16+
endif()
17+
18+
include(ExternalProject)
19+
20+
ExternalProject_Add(xnnpack
21+
PREFIX xnnpack
22+
GIT_REPOSITORY https://github.com/google/XNNPACK.git
23+
GIT_TAG 2da0de89960b829c6fae74204a102db524e73047
24+
GIT_PROGRESS ON
25+
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/xnnpack
26+
UPDATE_COMMAND git checkout .bazelrc BUILD.bazel emscripten.bzl
27+
&& git apply ${CMAKE_CURRENT_SOURCE_DIR}/xnnpack.patch
28+
&& cmake -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/toolchain ${CMAKE_CURRENT_SOURCE_DIR}/xnnpack/toolchain
29+
CONFIGURE_COMMAND ""
30+
BUILD_COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR}/xnnpack
31+
&& bazel build -c opt --sandbox_writable_path=$ENV{HOME} --config=emscripten_wasm
32+
//:qs8_gemm_bench.wasm
33+
//:qs8_requantization_bench.wasm
34+
//:qu8_gemm_bench.wasm
35+
//:qu8_requantization_bench.wasm
36+
//:f16_igemm_bench.wasm
37+
//:f16_gemm_bench.wasm
38+
//:f16_spmm_bench.wasm
39+
//:f32_igemm_bench.wasm
40+
//:f16_relu_bench.wasm
41+
//:f32_conv_hwc_bench.wasm
42+
//:f32_conv_hwc2chw_bench.wasm
43+
//:f16_dwconv_bench.wasm
44+
//:f32_dwconv_bench.wasm
45+
//:f32_dwconv2d_chw_bench.wasm
46+
//:f32_gemm_bench.wasm
47+
//:f32_hswish_bench.wasm
48+
//:f32_raddexpminusmax_bench.wasm
49+
//:f32_raddextexp_bench.wasm
50+
//:f32_raddstoreexpminusmax_bench.wasm
51+
//:f32_relu_bench.wasm
52+
//:f32_rmax_bench.wasm
53+
//:f32_sigmoid_bench.wasm
54+
//:f32_spmm_bench.wasm
55+
//:f32_softmax_bench.wasm
56+
//:f32_vscaleexpminusmax_bench.wasm
57+
//:f32_vscaleextexp_bench.wasm
58+
//:f32_vsqrt_bench.wasm
59+
//:f32_im2col_gemm_bench.wasm
60+
//:rounding_bench.wasm
61+
//:average_pooling_bench.wasm
62+
//:bankers_rounding_bench.wasm
63+
//:ceiling_bench.wasm
64+
//:channel_shuffle_bench.wasm
65+
//:convolution_bench.wasm
66+
//:deconvolution_bench.wasm
67+
//:floor_bench.wasm
68+
//:global_average_pooling_bench.wasm
69+
//:hardswish_bench.wasm
70+
//:max_pooling_bench.wasm
71+
//:sigmoid_bench.wasm
72+
//:prelu_bench.wasm
73+
//:softmax_bench.wasm
74+
//:square_root_bench.wasm
75+
//:truncation_bench.wasm
76+
//:fp32_mobilenet_v1.wasm
77+
//:fp16_mobilenet_v1.wasm
78+
//:qs8_mobilenet_v1.wasm
79+
//:qs8_mobilenet_v2.wasm
80+
//:fp32_mobilenet_v2.wasm
81+
//:fp16_mobilenet_v2.wasm
82+
//:fp32_mobilenet_v3_large.wasm
83+
//:fp16_mobilenet_v3_large.wasm
84+
//:fp32_mobilenet_v3_small.wasm
85+
//:fp16_mobilenet_v3_small.wasm
86+
//:f32_dwconv_e2e_bench.wasm
87+
//:f32_gemm_e2e_bench.wasm
88+
//:end2end_bench.wasm
89+
//:f32_exp_eval.wasm
90+
//:f32_expminus_eval.wasm
91+
//:f32_extexp_eval.wasm
92+
//:f32_roundne_eval.wasm
93+
//:f32_roundd_eval.wasm
94+
//:f32_roundu_eval.wasm
95+
//:f32_roundz_eval.wasm
96+
//:f32_sigmoid_eval.wasm
97+
//:f32_sqrt_eval.wasm
98+
#--sandbox_debug
99+
INSTALL_COMMAND ${CMAKE_COMMAND} -E create_symlink
100+
${CMAKE_CURRENT_SOURCE_DIR}/xnnpack/bazel-out/wasm-opt/bin/
101+
${CMAKE_CURRENT_SOURCE_DIR}/build/wasm-opt
102+
)

0 commit comments

Comments
 (0)