Merge branch main into dev/wasi_threads

This commit is contained in:
Wenyong Huang
2023-02-17 08:46:12 +08:00
163 changed files with 7153 additions and 1857 deletions

View File

@ -18,7 +18,7 @@
#define WORLD_OFFSET 7
#define NAME_REPLACMENT "James"
#define NAME_REPLACMENT_LEN (sizeof(NAME_REPLACMENT) - 1)
#define ADDITIONAL_SPACE 10
#define ADDITIONAL_SPACE 1 * 1024 * 1024
int
main(int argc, char **argv)
@ -100,7 +100,7 @@ main(int argc, char **argv)
printf("[Test] Reading at specified offset passed.\n");
// Test: allocate more space to the file (posix_fallocate)
printf("Allocate more space to the file..\n");
printf("Allocate more space to the file (posix_fallocate)..\n");
posix_fallocate(fileno(file), ftell(file), ADDITIONAL_SPACE);
printf("File current offset: %ld\n", ftell(file));
printf("Moving to the end..\n");
@ -110,8 +110,8 @@ main(int argc, char **argv)
printf("[Test] Allocation or more space passed.\n");
// Test: allocate more space to the file (ftruncate)
printf("Extend the file size of 10 bytes using ftruncate..\n");
ftruncate(fileno(file), ftell(file) + 10);
printf("Allocate more space to the file (ftruncate)..\n");
ftruncate(fileno(file), ftell(file) + ADDITIONAL_SPACE);
assert(ftell(file) == strlen(text) + ADDITIONAL_SPACE);
printf("File current offset: %ld\n", ftell(file));
printf("Moving to the end..\n");
@ -120,6 +120,31 @@ main(int argc, char **argv)
assert(ftell(file) == strlen(text) + 2 * ADDITIONAL_SPACE);
printf("[Test] Extension of the file size passed.\n");
// Test: allocate more space to the file (fseek)
printf("Allocate more space to the file (fseek) from the start..\n");
printf("File current offset: %ld\n", ftell(file));
fseek(file, 3 * ADDITIONAL_SPACE, SEEK_SET);
printf("File current offset: %ld\n", ftell(file));
assert(ftell(file) == 3 * ADDITIONAL_SPACE);
printf("[Test] Extension of the file size passed.\n");
// Test: allocate more space to the file (fseek)
printf("Allocate more space to the file (fseek) from the end..\n");
printf("File current offset: %ld\n", ftell(file));
fseek(file, ADDITIONAL_SPACE, SEEK_END);
printf("File current offset: %ld\n", ftell(file));
assert(ftell(file) == 4 * ADDITIONAL_SPACE);
printf("[Test] Extension of the file size passed.\n");
// Test: allocate more space to the file (fseek)
printf("Allocate more space to the file (fseek) from the middle..\n");
fseek(file, 3 * ADDITIONAL_SPACE, SEEK_SET);
printf("File current offset: %ld\n", ftell(file));
fseek(file, 2 * ADDITIONAL_SPACE, SEEK_CUR);
printf("File current offset: %ld\n", ftell(file));
assert(ftell(file) == 5 * ADDITIONAL_SPACE);
printf("[Test] Extension of the file size passed.\n");
// Display some debug information
printf("Getting the size of the file on disk..\n");
struct stat st;

View File

@ -41,3 +41,6 @@ target_link_libraries(test.wasm)
add_executable(main_thread_exception.wasm main_thread_exception.c)
target_link_libraries(main_thread_exception.wasm)
add_executable(main_global_atomic.wasm main_global_atomic.c)
target_link_libraries(main_global_atomic.wasm)

View File

@ -0,0 +1,48 @@
/*
* Copyright (C) 2023 Amazon.com Inc. or its affiliates. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include <stdio.h>
#include <pthread.h>
#define MAX_NUM_THREADS 4
#define NUM_ITER 1000
int g_count = 0;
static void *
thread(void *arg)
{
for (int i = 0; i < NUM_ITER; i++) {
__atomic_fetch_add(&g_count, 1, __ATOMIC_SEQ_CST);
}
return NULL;
}
int
main(int argc, char **argv)
{
pthread_t tids[MAX_NUM_THREADS];
for (int i = 0; i < MAX_NUM_THREADS; i++) {
if (pthread_create(&tids[i], NULL, thread, NULL) != 0) {
printf("Thread creation failed\n");
}
}
for (int i = 0; i < MAX_NUM_THREADS; i++) {
if (pthread_join(tids[i], NULL) != 0) {
printf("Thread join failed\n");
}
}
printf("Value of counter after update: %d (expected=%d)\n", g_count,
MAX_NUM_THREADS * NUM_ITER);
if (g_count != MAX_NUM_THREADS * NUM_ITER) {
__builtin_trap();
}
return -1;
}

2
samples/wasm-c-api-imports/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/wasm/inc/**
!/wasm/inc/.*

View File

@ -0,0 +1,169 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
cmake_minimum_required(VERSION 3.14)
project(how-to-deal-with-import)
include(CMakePrintHelpers)
include(CTest)
include(ExternalProject)
include(FetchContent)
#
# dependencies
#
set(WAMR_ROOT ${CMAKE_CURRENT_LIST_DIR}/../../)
# wasm required headers
execute_process(
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${WARM_ROOT}/${WAMR_ROOT}/wamr-sdk/app/libc-builtin-sysroot/include/pthread.h
${CMAKE_CURRENT_LIST_DIR}/wasm/inc
)
# vmlib
################ runtime settings ################
string (TOLOWER ${CMAKE_HOST_SYSTEM_NAME} WAMR_BUILD_PLATFORM)
if (APPLE)
add_definitions(-DBH_PLATFORM_DARWIN)
endif ()
# Resetdefault linker flags
set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
# WAMR features switch
# Set WAMR_BUILD_TARGET, currently values supported:
# "X86_64", "AMD_64", "X86_32", "AARCH64[sub]", "ARM[sub]", "THUMB[sub]",
# "MIPS", "XTENSA", "RISCV64[sub]", "RISCV32[sub]"
if (NOT DEFINED WAMR_BUILD_TARGET)
if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64|aarch64)")
set (WAMR_BUILD_TARGET "AARCH64")
elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64")
set (WAMR_BUILD_TARGET "RISCV64")
elseif (CMAKE_SIZEOF_VOID_P EQUAL 8)
# Build as X86_64 by default in 64-bit platform
set (WAMR_BUILD_TARGET "X86_64")
elseif (CMAKE_SIZEOF_VOID_P EQUAL 4)
# Build as X86_32 by default in 32-bit platform
set (WAMR_BUILD_TARGET "X86_32")
else ()
message(SEND_ERROR "Unsupported build target platform!")
endif ()
endif ()
if (NOT CMAKE_BUILD_TYPE)
set (CMAKE_BUILD_TYPE Release)
endif ()
set(WAMR_BUILD_AOT 1)
set(WAMR_BUILD_INTERP 0)
set(WAMR_BUILD_JIT 0)
set(WAMR_BUILD_FAST_INTERP 1)
set(WAMR_BUILD_LIB_PTHREAD 1)
set(WAMR_BUILD_LIBC_BUILTIN 1)
set(WAMR_BUILD_LIBC_WASI 1)
set(WAMR_BUILD_SIMD 0)
# compiling and linking flags
if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang"))
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
endif ()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security")
# build out vmlib
set(WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..)
include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
add_library(vmlib ${WAMR_RUNTIME_LIB_SOURCE})
target_link_libraries(vmlib INTERFACE dl m pthread)
if(WAMR_BUILD_AOT EQUAL 1)
target_compile_definitions(vmlib INTERFACE -DWASM_ENABLE_AOT=1)
else()
target_compile_definitions(vmlib INTERFACE -DWASM_ENABLE_AOT=0)
endif()
if(WAMR_BUILD_INTERP EQUAL 1)
target_compile_definitions(vmlib INTERFACE -DWASM_ENABLE_INTERP=1)
else()
target_compile_definitions(vmlib INTERFACE -DWASM_ENABLE_INTERP=0)
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
# ASAN + UBSAN
target_compile_options(vmlib INTERFACE -fsanitize=address,undefined)
target_link_options(vmlib INTERFACE -fsanitize=address,undefined)
endif()
# # MSAN
# target_compile_options(vmlib INTERFACE -fsanitize=memory -fno-optimize-sibling-calls -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer)
# target_link_options(vmlib INTERFACE -fsanitize=memory)
# wamrc
if(WAMR_BUILD_AOT EQUAL 1 AND WAMR_BUILD_INTERP EQUAL 0)
ExternalProject_Add(wamrc
PREFIX wamrc-build
SOURCE_DIR ${WAMR_ROOT}/wamr-compiler
CONFIGURE_COMMAND ${CMAKE_COMMAND} -S ${WAMR_ROOT}/wamr-compiler -B build
BUILD_COMMAND ${CMAKE_COMMAND} --build build --target wamrc
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_if_different build/wamrc ${CMAKE_CURRENT_BINARY_DIR}/wamrc
)
endif()
#
# host
add_subdirectory(host)
add_custom_target(
install_host ALL
COMMAND ${CMAKE_COMMAND} -E copy_if_different ./host/example1 .
DEPENDS example1
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
# TODO: replace it with a find_package()
set(WASI_SDK_DIR /opt/wasi-sdk-19.0/)
set(WASI_TOOLCHAIN_FILE ${WASI_SDK_DIR}/share/cmake/wasi-sdk.cmake)
set(WASI_SYS_ROOT ${WASI_SDK_DIR}/share/wasi-sysroot)
#
# wasm
if(WAMR_BUILD_AOT EQUAL 1 AND WAMR_BUILD_INTERP EQUAL 0)
ExternalProject_Add(wasm
PREFIX wasm-build
DEPENDS wamrc
BUILD_ALWAYS TRUE
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/wasm
CONFIGURE_COMMAND ${CMAKE_COMMAND} -S ${CMAKE_CURRENT_LIST_DIR}/wasm -B build
-DWASI_SDK_PREFIX=${WASI_SDK_DIR}
-DCMAKE_TOOLCHAIN_FILE=${WASI_TOOLCHAIN_FILE}
-DCMAKE_SYSROOT=${WASI_SYS_ROOT}
-DWASM_TO_AOT=ON
-DWAMRC_PATH=${CMAKE_CURRENT_BINARY_DIR}/wamrc
-DSOCKET_WASI_CMAKE=${WAMR_ROOT}/core/iwasm/libraries/lib-socket/lib_socket_wasi.cmake
BUILD_COMMAND ${CMAKE_COMMAND} --build build
INSTALL_COMMAND ${CMAKE_COMMAND} --install build --prefix ${CMAKE_CURRENT_BINARY_DIR}
)
else()
ExternalProject_Add(wasm
PREFIX wasm-build
BUILD_ALWAYS TRUE
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/wasm
CONFIGURE_COMMAND ${CMAKE_COMMAND} -S ${CMAKE_CURRENT_LIST_DIR}/wasm -B build
-DWASI_SDK_PREFIX=${WASI_SDK_DIR}
-DCMAKE_TOOLCHAIN_FILE=${WASI_TOOLCHAIN_FILE}
-DCMAKE_SYSROOT=${WASI_SYS_ROOT}
-DSOCKET_WASI_CMAKE=${WAMR_ROOT}/core/iwasm/libraries/lib-socket/lib_socket_wasi.cmake
BUILD_COMMAND ${CMAKE_COMMAND} --build build
INSTALL_COMMAND ${CMAKE_COMMAND} --install build --prefix ${CMAKE_CURRENT_BINARY_DIR}
)
endif()
#
# Test
#
add_test(
NAME run_example1
COMMAND ./example1
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)

View File

@ -0,0 +1,174 @@
# How to create `imports` for wasm_instance_new() properly
It's always been asked how to create `wasm_extern_vec_t *imports` for
`wasm_instance_new()`?
```c
WASM_API_EXTERN own wasm_instance_t* wasm_instance_new(
wasm_store_t*, const wasm_module_t*, const wasm_extern_vec_t *imports,
own wasm_trap_t** trap
);
```
`wasm_extern_vec_t *imports` is required to match the requirement of _the
import section_ of a .wasm.
```bash
$ /opt/wabt-1.0.31/bin/wasm-objdump -j Import -x <some_example>.wasm
Section Details:
Import[27]:
- func[0] sig=2 <pthread_mutex_lock> <- env.pthread_mutex_lock
- func[1] sig=2 <pthread_mutex_unlock> <- env.pthread_mutex_unlock
- func[2] sig=2 <pthread_cond_signal> <- env.pthread_cond_signal
- func[3] sig=3 <host_log> <- env.log
...
- func[11] sig=4 <__imported_wasi_snapshot_preview1_sock_bind> <- wasi_snapshot_preview1.sock_bind
- func[12] sig=4 <__imported_wasi_snapshot_preview1_sock_connect> <- wasi_snapshot_preview1.sock_connect
- func[13] sig=4 <__imported_wasi_snapshot_preview1_sock_listen> <- wasi_snapshot_preview1.sock_listen
- func[14] sig=5 <__imported_wasi_snapshot_preview1_sock_open> <- wasi_snapshot_preview1.sock_open
- func[15] sig=4 <__imported_wasi_snapshot_preview1_sock_addr_remote> <- wasi_snapshot_preview1.sock_addr_remote
- func[16] sig=4 <__imported_wasi_snapshot_preview1_args_get> <- wasi_snapshot_preview1.args_get
- func[17] sig=4 <__imported_wasi_snapshot_preview1_args_sizes_get> <- wasi_snapshot_preview1.args_sizes_get
...
```
Developers should fill in _imports_ with enough host functions and make sure
there are no linking problems during instantiation.
```bash
TODO: linking warnings
```
## A natural way
One natural answer is "to create a list which matches every item in _the import
section_" of the .wasm. Since developers can see the section details of
a .wasm by tools like _wasm-objdump_, the answer is doable. Most of the time,
if they also prepare Wasm modules, developers have full control over import
requirements, and they only need to take a look at the order of _the import
section_.
Yes, _the order_. A proper `wasm_extern_vec_t *imports` includes two things:
1. how many `wasm_extern_t`
2. and order of those
Because there is no "name information" in a `wasm_extern_t`. The only way is let
`wasm_instance_new()` to tell which item in _the import section_ of a .wasm
should match any item in `wasm_extern_vec_t *imports` is based on **_index_**.
The algorithm is quite straightforward. The first one of _the import section_ matches
`wasm_extern_vec_t *imports->data[0] `. The second one matches `wasm_extern_vec_t *imports->data[1]`.
And so on.
So the order of `wasm_extern_vec_t *imports` becomes quite a burden. It requires
developers always checking _the import section_ visually.
Until here, the natural way is still workable although involving some handy work.
Right?
## A blocker
Sorry, the situation changes a lot when driving wasm32-wasi Wasm modules with
wasm-c-api.
As you know, WASI provides _a set of crossing-platform standard libraries_ for
Wasm modules, and leaves some _interfaces_ for native platform-dependent supports.
Those _interfaces_ are those import items with the module name `wasi_snapshot_preview1`
in a Wasm module.
It seems not economical to let developers provide their version of host
implementations of the `wasi_snapshot_preview1.XXX` functions. All those support
should be packed into a common library and shared in different Wasm modules.
Like a [cargo WASI](https://github.com/bytecodealliance/cargo-wasi).
WAMR chooses to integrate the WASI support library in the runtime to reduce
developers' compilation work. It brings developers a new thing of a proper
`wasm_extern_vec_t *imports` that developers should avoid overwriting those items
of _the import section_ of a Wasm module that will be provided by the runtime. It
also not economical to code for those functions.
Using module names as a filter seems to be a simple way. But some private
additional c/c++ libraries are supported in WAMR. Those supporting will bring
more import items that don't use `wasi_snapshot_preview1` as module names but are still
covered by the WASM runtime. Like `env.pthread_`. Plus, [the native lib registeration](https://github.com/bytecodealliance/wasm-micro-runtime/blob/main/doc/export_native_api.md)
provides another possible way to fill in the requirement of _the import section_.
Let's take summarize. A proper `wasm_extern_vec_t *imports` should include:
1. provides all necessary host implementations for items in _the import section_
2. should not override runtime provided implementation or covered by native
registrations. functinal or econmical.
3. keep them in a right order
## A recommendation
The recommendation is:
- use `wasm_module_imports()` to build the order
- use `wasm_importtype_is_linked()` to avoid overwriting
[wasm-c-api-imports](.) is a simple showcase of how to do that.
First, let's take a look at the Wasm module. [send_recv](./wasm/send_recv.c)
uses both standard WASI and WAMR_BUILD_LIB_PTHREAD supporting. Plus a private
native function `host_log`.
So, `wasm_extern_vec_t *imports` should only include the host implementation of
`host_log` and avoid WASI related(`wasm-c-api-imports.XXX`) and pthread related(`env.pthread_XXX`).
[Here is how to do](./host/example1.c):
- get import types with `wasm_module_imports(0)`. it contains name information
```c
wasm_importtype_vec_t importtypes = { 0 };
wasm_module_imports(module, &importtypes);
```
- traversal import types. The final `wasm_importvec_t *imports` should have the
same order with `wasm_importtype_vec_t`
```c
for (unsigned i = 0; i < importtypes.num_elems; i++)
```
- use `wasm_importtype_is_linked()` to avoid those covered by the runtime and
registered natives. A little tip is use "wasm_extern_new_empty()" to create
a placeholder.
```c
/* use wasm_extern_new_empty() to create a placeholder */
if (wasm_importtype_is_linked(importtype)) {
externs[i] = wasm_extern_new_empty(
store, wasm_externtype_kind(wasm_importtype_type(importtype)));
continue;
}
```
- use `wasm_importtype_module()` to get the module name, use `wasm_importtype_name()`
to get the field name.
```c
const wasm_name_t *module_name =
wasm_importtype_module(importtypes.data[i]);
const wasm_name_t *field_name =
wasm_importtype_name(importtypes.data[i]);
```
- fill in `wasm_externvec_t *imports` dynamically and programmatically.
```c
if (strncmp(module_name->data, "env", strlen("env")) == 0
&& strncmp(field_name->data, "log", strlen("log")) == 0) {
wasm_functype_t *log_type = wasm_functype_new_2_0(
wasm_valtype_new_i64(), wasm_valtype_new_i32());
wasm_func_t *log_func = wasm_func_new(store, log_type, host_logs);
wasm_functype_delete(log_type);
externs[i] = wasm_func_as_extern(log_func);
}
}
```

View File

@ -0,0 +1,12 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
cmake_minimum_required(VERSION 3.14)
project(host)
set(CMAKE_BUILD_TYPE Debug)
#
# host
add_executable(example1 ./example1.c)
target_link_libraries(example1 vmlib)

View File

@ -0,0 +1,204 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include <stdlib.h>
#include <stdio.h>
#include "wasm_c_api.h"
#include "wasm_export.h"
static wasm_trap_t *
host_logs(const wasm_val_vec_t *args, wasm_val_vec_t *results)
{
return NULL;
}
static bool
build_imports(wasm_store_t *store, const wasm_module_t *module,
wasm_extern_vec_t *out)
{
wasm_importtype_vec_t importtypes = { 0 };
wasm_module_imports(module, &importtypes);
wasm_extern_t *externs[32] = { 0 };
for (unsigned i = 0; i < importtypes.num_elems; i++) {
wasm_importtype_t *importtype = importtypes.data[i];
/* use wasm_extern_new_empty() to create a placeholder */
if (wasm_importtype_is_linked(importtype)) {
externs[i] = wasm_extern_new_empty(
store, wasm_externtype_kind(wasm_importtype_type(importtype)));
continue;
}
const wasm_name_t *module_name =
wasm_importtype_module(importtypes.data[i]);
const wasm_name_t *field_name =
wasm_importtype_name(importtypes.data[i]);
if (strncmp(module_name->data, "env", strlen("env")) == 0
&& strncmp(field_name->data, "log", strlen("log")) == 0) {
wasm_functype_t *log_type = wasm_functype_new_2_0(
wasm_valtype_new_i64(), wasm_valtype_new_i32());
wasm_func_t *log_func = wasm_func_new(store, log_type, host_logs);
wasm_functype_delete(log_type);
externs[i] = wasm_func_as_extern(log_func);
}
}
wasm_extern_vec_new(out, importtypes.num_elems, externs);
wasm_importtype_vec_delete(&importtypes);
return true;
}
int
main()
{
int main_ret = EXIT_FAILURE;
// Initialize.
printf("Initializing...\n");
wasm_engine_t *engine = wasm_engine_new();
if (!engine)
goto quit;
wasm_store_t *store = wasm_store_new(engine);
if (!store)
goto delete_engine;
// Load binary.
printf("Loading binary...\n");
#if WASM_ENABLE_AOT != 0 && WASM_ENABLE_INTERP == 0
FILE *file = fopen("send_recv.aot", "rb");
printf("> Load .aot\n");
#else
FILE *file = fopen("send_recv.wasm", "rb");
printf("> Load .wasm\n");
#endif
if (!file) {
printf("> Error loading module!\n");
goto delete_store;
}
int ret = fseek(file, 0L, SEEK_END);
if (ret == -1) {
printf("> Error loading module!\n");
goto close_file;
}
long file_size = ftell(file);
if (file_size == -1) {
printf("> Error loading module!\n");
goto close_file;
}
ret = fseek(file, 0L, SEEK_SET);
if (ret == -1) {
printf("> Error loading module!\n");
goto close_file;
}
wasm_byte_vec_t binary;
wasm_byte_vec_new_uninitialized(&binary, file_size);
if (fread(binary.data, file_size, 1, file) != 1) {
printf("> Error loading module!\n");
goto delete_binary;
}
// Compile.
printf("Compiling module...\n");
wasm_module_t *module = wasm_module_new(store, &binary);
if (!module) {
printf("> Error compiling module!\n");
goto delete_binary;
}
// Set Wasi Context
const char *addr_pool[1] = { "127.0.0.1" };
wasm_runtime_set_wasi_addr_pool(*module, addr_pool, 1);
// Instantiate.
printf("Instantiating module...\n");
wasm_extern_vec_t imports = { 0 };
ret = build_imports(store, module, &imports);
if (!ret) {
printf("> Error building imports!\n");
goto delete_module;
}
wasm_instance_t *instance =
wasm_instance_new(store, module, &imports, NULL);
if (!instance) {
printf("> Error instantiating module!\n");
goto delete_imports;
}
// Extract export.
printf("Extracting export...\n");
wasm_extern_vec_t exports;
wasm_instance_exports(instance, &exports);
if (exports.size == 0) {
printf("> Error accessing exports!\n");
goto delete_instance;
}
/**
* should use information from wasm_module_exports to avoid hard coding "1"
*/
const wasm_func_t *start_func = wasm_extern_as_func(exports.data[1]);
if (start_func == NULL) {
printf("> Error accessing export!\n");
goto delete_exports;
}
// Call. "_start(nil) -> i32"
printf("Calling _start ...\n");
wasm_val_t rs[1] = { WASM_I32_VAL(0) };
wasm_val_vec_t args = WASM_EMPTY_VEC;
wasm_val_vec_t results = WASM_ARRAY_VEC(rs);
wasm_trap_t *trap = wasm_func_call(start_func, &args, &results);
if (trap) {
wasm_name_t message = { 0 };
wasm_trap_message(trap, &message);
printf("> Error calling function! %s\n", message.data);
wasm_name_delete(&message);
wasm_trap_delete(trap);
goto delete_exports;
}
// Print result.
printf("Printing result...\n");
printf("> %u\n", rs[0].of.i32);
// Shut down.
printf("Shutting down...\n");
// All done.
printf("Done.\n");
main_ret = EXIT_SUCCESS;
delete_exports:
wasm_extern_vec_delete(&exports);
delete_instance:
wasm_instance_delete(instance);
delete_imports:
wasm_extern_vec_delete(&imports);
delete_module:
wasm_module_delete(module);
delete_binary:
wasm_byte_vec_delete(&binary);
close_file:
fclose(file);
delete_store:
wasm_store_delete(store);
delete_engine:
wasm_engine_delete(engine);
quit:
return main_ret;
}

View File

@ -0,0 +1,47 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
cmake_minimum_required (VERSION 3.14)
project(wasm_modules)
if(NOT SOCKET_WASI_CMAKE)
message(FATAL_ERROR "Require SOCKET_WASI_CMAKE")
endif()
option(WASM_TO_AOT "transfer wasm to aot" OFF)
if(WASM_TO_AOT AND NOT WAMRC_PATH)
message(FATAL_ERROR "Require WAMRC_PATH when WASM_TO_AOT is ON")
endif()
#
# c -> wasm
include(${SOCKET_WASI_CMAKE})
add_executable(send_recv ${CMAKE_CURRENT_LIST_DIR}/send_recv.c)
set_target_properties(send_recv PROPERTIES SUFFIX .wasm)
target_include_directories(send_recv PUBLIC ${CMAKE_CURRENT_LIST_DIR}/inc)
target_link_libraries(send_recv socket_wasi_ext)
target_link_options(send_recv PRIVATE
LINKER:--export=__heap_base
LINKER:--export=__data_end
LINKER:--shared-memory,--max-memory=196608
LINKER:--no-check-features
LINKER:--allow-undefined
)
if(WASM_TO_AOT)
# wasm -> aot
add_custom_target(send_recv_aot ALL
COMMAND pwd && ${WAMRC_PATH} --enable-multi-thread -o ./send_recv.aot ./send_recv.wasm
DEPENDS send_recv
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
endif()
#
# install
if(WASM_TO_AOT)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/send_recv.aot DESTINATION . )
else()
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/send_recv.wasm DESTINATION . )
endif()

View File

@ -0,0 +1,231 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include <arpa/inet.h>
#include <assert.h>
#include <netinet/in.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <sys/socket.h>
#include <unistd.h>
#ifdef __wasi__
#include <wasi_socket_ext.h>
#include "pthread.h"
#else
#include <pthread.h>
#endif
static pthread_mutex_t lock = { 0 };
static pthread_cond_t cond = { 0 };
static bool server_is_ready = false;
#ifdef __wasi__
__attribute__((import_name("log"))) extern void
host_log(uint64_t message, uint32_t length);
#endif
static void
local_printf(const char *formatter, ...)
{
char buffer[128] = { 0 };
va_list args;
va_start(args, formatter);
vsnprintf(buffer, 128, formatter, args);
va_end(args);
#ifdef __wasi__
host_log((uint64_t)(void *)buffer, strlen(buffer));
#endif
printf("--> %s", buffer);
}
void *
run_as_server(void *arg)
{
int sock = -1, on = 1;
struct sockaddr_in addr = { 0 };
int addrlen = 0;
int new_sock = -1;
char *buf[] = {
"The stars shine down", "It brings us light", "Light comes down",
"To make us paths", "It watches us", "And mourns for us",
};
struct iovec iov[] = {
{ .iov_base = buf[0], .iov_len = strlen(buf[0]) + 1 },
{ .iov_base = buf[1], .iov_len = strlen(buf[1]) + 1 },
{ .iov_base = buf[2], .iov_len = strlen(buf[2]) + 1 },
{ .iov_base = buf[3], .iov_len = strlen(buf[3]) + 1 },
{ .iov_base = buf[4], .iov_len = strlen(buf[4]) + 1 },
{ .iov_base = buf[5], .iov_len = strlen(buf[5]) + 1 },
};
struct msghdr msg = { .msg_iov = iov, .msg_iovlen = 6 };
ssize_t send_len = 0;
pthread_mutex_lock(&lock);
sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock < 0) {
pthread_mutex_unlock(&lock);
perror("Create a socket failed");
return NULL;
}
#ifndef __wasi__
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on))) {
pthread_mutex_unlock(&lock);
perror("Setsockopt failed");
goto fail1;
}
#endif
/* 0.0.0.0:1234 */
addr.sin_family = AF_INET;
addr.sin_port = htons(1234);
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
addrlen = sizeof(addr);
if (bind(sock, (struct sockaddr *)&addr, addrlen) < 0) {
pthread_mutex_unlock(&lock);
perror("Bind failed");
goto fail1;
}
if (listen(sock, 0) < 0) {
pthread_mutex_unlock(&lock);
perror("Listen failed");
goto fail1;
}
server_is_ready = true;
pthread_cond_signal(&cond);
pthread_mutex_unlock(&lock);
local_printf("Server is online ... \n");
new_sock = accept(sock, (struct sockaddr *)&addr, (socklen_t *)&addrlen);
if (new_sock < 0) {
perror("Accept failed");
goto fail1;
}
local_printf("Start sending. \n");
send_len = sendmsg(new_sock, &msg, 0);
if (send_len < 0) {
perror("Sendmsg failed");
goto fail2;
}
local_printf("Send %ld bytes successfully!\n", send_len);
fail2:
close(new_sock);
fail1:
shutdown(sock, SHUT_RD);
close(sock);
return NULL;
}
void *
run_as_client(void *arg)
{
int sock = -1;
struct sockaddr_in addr = { 0 };
/* buf of server is 106 bytes */
char buf[110] = { 0 };
struct iovec iov = { .iov_base = buf, .iov_len = sizeof(buf) };
struct msghdr msg = { .msg_iov = &iov, .msg_iovlen = 1 };
ssize_t recv_len = 0;
pthread_mutex_lock(&lock);
while (false == server_is_ready) {
pthread_cond_wait(&cond, &lock);
}
pthread_mutex_unlock(&lock);
local_printf("Client is running...\n");
sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock < 0) {
perror("Create a socket failed");
return NULL;
}
/* 127.0.0.1:1234 */
addr.sin_family = AF_INET;
addr.sin_port = htons(1234);
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
perror("Connect failed");
goto fail;
}
local_printf("Start receiving. \n");
recv_len = recvmsg(sock, &msg, 0);
if (recv_len < 0) {
perror("Recvmsg failed");
goto fail;
}
local_printf("Receive %ld bytes successlly!\n", recv_len);
assert(recv_len == 106);
local_printf("Data:\n");
char *s = msg.msg_iov->iov_base;
while (strlen(s) > 0) {
local_printf(" %s\n", s);
s += strlen(s) + 1;
}
fail:
shutdown(sock, SHUT_RD);
close(sock);
return NULL;
}
int
main(int argc, char *argv[])
{
pthread_t cs[2] = { 0 };
uint8_t i = 0;
int ret = EXIT_SUCCESS;
if (pthread_mutex_init(&lock, NULL)) {
perror("Initialize mutex failed");
ret = EXIT_FAILURE;
goto RETURN;
}
if (pthread_cond_init(&cond, NULL)) {
perror("Initialize condition failed");
ret = EXIT_FAILURE;
goto DESTROY_MUTEX;
}
if (pthread_create(&cs[0], NULL, run_as_server, NULL)) {
perror("Create a server thread failed");
ret = EXIT_FAILURE;
goto DESTROY_COND;
}
if (pthread_create(&cs[1], NULL, run_as_client, NULL)) {
perror("Create a client thread failed");
ret = EXIT_FAILURE;
goto DESTROY_COND;
}
for (i = 0; i < 2; i++) {
pthread_join(cs[i], NULL);
}
DESTROY_COND:
pthread_cond_destroy(&cond);
DESTROY_MUTEX:
pthread_mutex_destroy(&lock);
RETURN:
return ret;
}

View File

@ -136,26 +136,13 @@ include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake)
set(MM_UTIL src/utils/multi_module_utils.c)
# build executable for each .c
set(EXAMPLES
callback
callback_chain
clone
empty_imports
global
hello
hostref
memory
reflect
table
threads
trap
)
if(WAMR_BUILD_JIT AND WAMR_BUILD_LAZY_JIT)
if((${WAMR_BUILD_JIT} EQUAL 1) AND (${WAMR_BUILD_LAZY_JIT} EQUAL 1))
list(APPEND EXAMPLES serialize)
endif()
endif()
list(APPEND EXAMPLES callback callback_chain empty_imports global hello hostref memory reflect table trap)
# FIXME enable both in the future
#list(APPEND EXAMPLES clone threads)
# FIXME
# if(WAMR_BUILD_JIT EQUAL 1 AND WAMR_BUILD_LAZY_JIT EQUAL 0)
# list(APPEND EXAMPLES serialize)
# endif()
check_pie_supported()

View File

@ -4,9 +4,9 @@ Before staring, we need to download and intall [WABT](https://github.com/WebAsse
``` shell
$ cd /opt
$ wget https://github.com/WebAssembly/wabt/releases/download/1.0.19/wabt-1.0.19-ubuntu.tar.gz
$ tar -xzf wabt-1.0.19-ubuntu.tar.gz
$ mv wabt-1.0.19 wabt
$ wget https://github.com/WebAssembly/wabt/releases/download/1.0.31/wabt-1.0.31-ubuntu.tar.gz
$ tar -xzf wabt-1.0.31-ubuntu.tar.gz
$ mv wabt-1.0.31 wabt
```
By default, all samples are compiled and run in "interpreter" mode.
@ -47,4 +47,4 @@ $ ./global
$ ...
$ ./callback
$ ...
```
```

View File

@ -0,0 +1,116 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
cmake_minimum_required (VERSION 3.14)
project(wasm_workloads)
#######################################
add_subdirectory(bwa)
add_subdirectory(meshoptimizer)
add_subdirectory(wasm-av1)
#######################################
include(ExternalProject)
################ iwasm ################
ExternalProject_Add(iwasm
PREFIX
iwasm-build
BUILD_ALWAYS
YES
SOURCE_DIR
${CMAKE_CURRENT_SOURCE_DIR}/../../product-mini/platforms/linux
CONFIGURE_COMMAND
${CMAKE_COMMAND} -S ${CMAKE_CURRENT_SOURCE_DIR}/../../product-mini/platforms/linux -B build -DWAMR_BUILD_LIBC_EMCC=1
BUILD_COMMAND
${CMAKE_COMMAND} --build build
INSTALL_COMMAND
# FIXME: replace with --install
${CMAKE_COMMAND} -E copy_if_different
${CMAKE_CURRENT_BINARY_DIR}/iwasm-build/src/iwasm-build/build/iwasm
${CMAKE_CURRENT_BINARY_DIR}/iwasm
)
################ wamrc ################
ExternalProject_Add(wamrc
PREFIX
wamrc-build
BUILD_ALWAYS
YES
SOURCE_DIR
${CMAKE_CURRENT_SOURCE_DIR}/../../wamr-compiler
CONFIGURE_COMMAND
${CMAKE_COMMAND} -S ${CMAKE_CURRENT_SOURCE_DIR}/../../wamr-compiler -B build
BUILD_COMMAND
${CMAKE_COMMAND} --build build
INSTALL_COMMAND
# FIXME: replace with --install
${CMAKE_COMMAND} -E copy_if_different
${CMAKE_CURRENT_BINARY_DIR}/wamrc-build/src/wamrc-build/build/wamrc
${CMAKE_CURRENT_BINARY_DIR}/wamrc
)
################ .aot ################
add_custom_target(
bwa_to_aot
ALL
DEPENDS
bwa wamrc
COMMAND
./wamrc -o bwa.aot ./bwa/bwa.wasm
WORKING_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}
)
add_custom_target(
codecbench_to_aot
ALL
DEPENDS
codecbench wamrc
COMMAND
./wamrc -o codecbench.aot ./meshoptimizer/codecbench.wasm
WORKING_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}
)
add_custom_target(
av1_to_aot
ALL
DEPENDS
av1 wamrc
COMMAND
./wamrc -o testavx.aot ./wasm-av1/testavx.opt.wasm
WORKING_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}
)
################ smoking test ################
include(CTest)
add_test(
NAME
run_bwa
COMMAND
./iwasm --dir=. ./bwa.aot index ./bwa/hs38DH-extra.fa
WORKING_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}
)
add_test(
NAME
run_codecbench
COMMAND
./iwasm codecbench.aot
WORKING_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}
)
add_test(
NAME
run_av1
COMMAND
./iwasm --dir=. testavx.aot ./wasm-av1/elephants_dream_480p24.ivf
WORKING_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}
)

View File

@ -1,41 +1,30 @@
All workloads have similar requirment of software dependencies, including
**emsdk**, **wabt** and **binaryen**
All workloads have similar requirment of software dependencies, including **emsdk** and **binaryen**
> There might be slight differences when using MacOS and other Linux distro than Ubuntu. This document only target
Ubuntu 18.04 as example.
> There might be slight differences when using MacOS and other Linux distro than Ubuntu. This document targets
Ubuntu 20.04 as an example.
## Installation instructions
use [preparation.sh](./preparation.sh) to install all dependencies before compiling any workload.
use [preparation.sh](./preparation.sh) to install all dependencies before compiling any workload. Or use [*vscode DevContainer*](../../.devcontainer/)
for details, the script includes below steps:
- **wabt**. Install
[latest release](https://github.com/WebAssembly/wabt/releases/download/1.0.23/wabt-1.0.23-ubuntu.tar.gz)
to */opt/wabt*
``` bash
$ wget https://github.com/WebAssembly/wabt/releases/download/${WABT_VER}/${WABT_FILE}
$ tar zxf ${WABT_FILE} -C /opt
$ ln -sf /opt/wabt-${WABT_VER} /opt/wabt
```
The script installs below software:
- **emsdk**. Refer to [the guide](https://emscripten.org/docs/getting_started/downloads.html). Don't forget to activate
emsdk and set up environment variables. Verify it with `echo ${EMSDK}`. Please be sure to install and activate the building
of 2.0.26
of 3.0.0
``` bash
$ cd /opt
$ git clone https://github.com/emscripten-core/emsdk.git
$ cd emsdk
$ git pull
$ ./emsdk install 2.0.26
$ ./emsdk activate 2.0.26
$ ./emsdk install 3.0.0
$ ./emsdk activate 3.0.0
$ echo "source /opt/emsdk/emsdk_env.sh" >> "${HOME}"/.bashrc
```
- **binaryen**. Install
[latest release](https://github.com/WebAssembly/binaryen/releases/download/version_101/binaryen-version_101-x86_64-linux.tar.gz)
[latest release](https://github.com/WebAssembly/binaryen/releases/download/version_111/binaryen-version_111-x86_64-linux.tar.gz)
to */opt/binaryen*
``` bash

View File

@ -15,8 +15,9 @@ ExternalProject_Add(xnnpack
GIT_PROGRESS ON
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/xnnpack
UPDATE_COMMAND git checkout .
&& git reset --hard 4d738aef36872669e4bba05a4b259149ba8e62e1
&& cmake -E copy ${CMAKE_CURRENT_SOURCE_DIR}/benchmark.patch ${CMAKE_CURRENT_SOURCE_DIR}/xnnpack/third_party
&& git reset --hard 4570a7151aa4f3e57eca14a575eeff6bb13e26be
&& cmake -E copy ${CMAKE_CURRENT_SOURCE_DIR}/xnnpack/google3/third_party/XNNPACK/microkernels.bzl
${CMAKE_CURRENT_SOURCE_DIR}/xnnpack/
&& git apply ${CMAKE_CURRENT_SOURCE_DIR}/xnnpack.patch
CONFIGURE_COMMAND ""
# grep xnnpack_benchmark -A 1 BUILD.bazel \
@ -24,70 +25,123 @@ ExternalProject_Add(xnnpack
# | awk '{print $3}' \
# | sed -e 's/\"//g' -e 's/,//g' -e 's/^/\/\/:/g'
BUILD_COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR}/xnnpack
&& bazel --output_user_root=build_user_output build -c opt --config=wasm
&& bazel --output_user_root=build-user-output build -c opt --config=wasm
//:qs8_dwconv_bench.wasm
//:qs8_f32_vcvt_bench.wasm
//:qs8_gemm_bench.wasm
//:qs8_requantization_bench.wasm
//:qs8_vadd_bench.wasm
//:qs8_vaddc_bench.wasm
//:qs8_vcvt_bench.wasm
//:qs8_vlrelu_bench.wasm
//:qs8_vmul_bench.wasm
//:qs8_vmulc_bench.wasm
//:qu8_f32_vcvt_bench.wasm
//:qu8_gemm_bench.wasm
//:qu8_requantization_bench.wasm
//:qu8_vadd_bench.wasm
//:qu8_vaddc_bench.wasm
//:qu8_vcvt_bench.wasm
//:qu8_vlrelu_bench.wasm
//:qu8_vmul_bench.wasm
//:qu8_vmulc_bench.wasm
//:bf16_gemm_bench.wasm
//:f16_igemm_bench.wasm
//:f16_gemm_bench.wasm
//:f16_raddstoreexpminusmax_bench.wasm
//:f16_spmm_bench.wasm
//:f16_vrelu_bench.wasm
//:f16_vsigmoid_bench.wasm
//:f16_f32_vcvt_bench.wasm
//:f32_igemm_bench.wasm
//:f32_conv_hwc_bench.wasm
//:f16_conv_hwc2chw_bench.wasm
//:f16_gavgpool_cw_bench.wasm
//:f32_gavgpool_cw_bench.wasm
//:f32_conv_hwc2chw_bench.wasm
//:f16_dwconv_bench.wasm
//:f32_dwconv_bench.wasm
//:f32_dwconv2d_chw_bench.wasm
//:f16_dwconv2d_chw_bench.wasm
//:f32_f16_vcvt_bench.wasm
//:xx_transpose_bench.wasm
//:x8_transpose_bench.wasm
//:x16_transpose_bench.wasm
//:x24_transpose_bench.wasm
//:x32_transpose_bench.wasm
//:x64_transpose_bench.wasm
//:f32_gemm_bench.wasm
//:f32_qs8_vcvt_bench.wasm
//:f32_qu8_vcvt_bench.wasm
//:f32_raddexpminusmax_bench.wasm
//:f32_raddextexp_bench.wasm
//:f32_raddstoreexpminusmax_bench.wasm
//:f32_rmax_bench.wasm
//:f32_spmm_bench.wasm
//:f32_softmax_bench.wasm
//:f16_velu_bench.wasm
//:f32_velu_bench.wasm
//:f32_vhswish_bench.wasm
//:f32_vlrelu_bench.wasm
//:f32_vrelu_bench.wasm
//:f32_vscaleexpminusmax_bench.wasm
//:f32_vscaleextexp_bench.wasm
//:f32_vsigmoid_bench.wasm
//:f16_vsqrt_bench.wasm
//:f32_vsqrt_bench.wasm
//:f32_im2col_gemm_bench.wasm
//:rounding_bench.wasm
//:s16_rmaxabs_bench.wasm
//:s16_window_bench.wasm
//:u32_filterbank_accumulate_bench.wasm
//:u32_filterbank_subtract_bench.wasm
//:u32_vlog_bench.wasm
//:u64_u32_vsqrtshift_bench.wasm
//:i16_vlshift_bench.wasm
//:cs16_vsquareabs_bench.wasm
//:cs16_bfly4_bench.wasm
//:cs16_fftr_bench.wasm
//:x8_lut_bench.wasm
//:abs_bench.wasm
//:average_pooling_bench.wasm
//:bankers_rounding_bench.wasm
//:ceiling_bench.wasm
//:channel_shuffle_bench.wasm
//:convert_bench.wasm
//:convolution_bench.wasm
//:deconvolution_bench.wasm
//:elu_bench.wasm
//:floor_bench.wasm
//:global_average_pooling_bench.wasm
//:hardswish_bench.wasm
//:leaky_relu_bench.wasm
//:max_pooling_bench.wasm
//:negate_bench.wasm
//:sigmoid_bench.wasm
//:prelu_bench.wasm
//:softmax_bench.wasm
//:square_bench.wasm
//:square_root_bench.wasm
//:truncation_bench.wasm
//:f16_gemm_e2e_bench.wasm
//:f32_dwconv_e2e_bench.wasm
//:f32_gemm_e2e_bench.wasm
//:qs8_dwconv_e2e_bench.wasm
//:qs8_gemm_e2e_bench.wasm
//:qu8_gemm_e2e_bench.wasm
//:qu8_dwconv_e2e_bench.wasm
//:end2end_bench.wasm
//:f16_exp_ulp_eval.wasm
//:f16_expminus_ulp_eval.wasm
//:f16_expm1minus_ulp_eval.wasm
//:f16_sigmoid_ulp_eval.wasm
//:f16_sqrt_ulp_eval.wasm
//:f32_exp_ulp_eval.wasm
//:f32_expminus_ulp_eval.wasm
//:f32_expm1minus_ulp_eval.wasm
//:f32_extexp_ulp_eval.wasm
//:f32_sigmoid_ulp_eval.wasm
//:f32_sqrt_ulp_eval.wasm
//:f32_tanh_ulp_eval.wasm
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/xnnpack/bazel-out/wasm-opt/bin/
${CMAKE_BINARY_DIR}/wasm-opt

View File

@ -24,7 +24,7 @@ Firstly please build iwasm with simd, libc-emcc and lib-pthread support:
``` bash
$ cd <wamr-dir>/product-mini/platforms/linux/
$ mkdir build && cd build
$ cmake .. -DWAMR_BUILD_SIMD=1 -DWAMR_BUILD_LIBC_EMCC=1 -DWAMR_BUILD_LIB_PTHREAD=1
$ cmake .. -DWAMR_BUILD_LIBC_EMCC=1 -DWAMR_BUILD_LIB_PTHREAD=1
$ make
```
@ -42,7 +42,7 @@ Then compile wasm file to aot file and run:
``` shell
$ cd <wamr-dir>/samples/workload/XNNPACK/xnnpack/bazel-bin
$ wamrc --enable-simd -o average_pooling_bench.aot average_pooling_bench.wasm (or other wasm files)
$ wamrc -o average_pooling_bench.aot average_pooling_bench.wasm (or other wasm files)
$ iwasm average_pooling_bench.aot
```

View File

@ -1 +0,0 @@
../docker/build_workload.sh

View File

@ -1,8 +1,8 @@
diff --git a/.bazelrc b/.bazelrc
index ec740f38..29f9d56e 100644
index 688279da1..376996885 100644
--- a/.bazelrc
+++ b/.bazelrc
@@ -49,4 +49,9 @@ build:ios_fat --watchos_cpus=armv7k
@@ -53,4 +53,9 @@ build:ios_fat --watchos_cpus=armv7k
build:macos --apple_platform_type=macos
build:macos_arm64 --config=macos
@ -11,42 +11,26 @@ index ec740f38..29f9d56e 100644
+build:macos_arm64 --cpu=darwin_arm64
+
+build:wasm --cpu=wasm
+build:wasm --copt=-msimd128
+build:wasm --features=wasm_simd
+build:wasm --crosstool_top=@emsdk//emscripten_toolchain:everything
+build:wasm --host_crosstool_top=@bazel_tools//tools/cpp:toolchain
diff --git a/BUILD.bazel b/BUILD.bazel
index 3fc8139f..c893356d 100644
--- a/BUILD.bazel
+++ b/BUILD.bazel
@@ -11988,7 +11988,6 @@ config_setting(
values = {
"crosstool_top": "@emsdk//emscripten_toolchain:everything",
"cpu": "wasm",
- "copt": "-msimd128",
"copt": "-mrelaxed-simd",
},
)
diff --git a/WORKSPACE b/WORKSPACE
index c58e76b6..30934678 100644
index cd8960ffa..5d3e685f4 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -21,6 +21,7 @@ http_archive(
name = "com_google_benchmark",
strip_prefix = "benchmark-master",
urls = ["https://github.com/google/benchmark/archive/master.zip"],
+ patches = ["@//third_party:benchmark.patch"],
)
# FP16 library, used for half-precision conversions
@@ -84,6 +85,19 @@ http_archive(
],
@@ -92,8 +92,25 @@ http_archive(
],
)
+load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
+http_archive(
+ name = "emsdk",
+ strip_prefix = "emsdk-2.0.26/bazel",
+ url = "https://github.com/emscripten-core/emsdk/archive/refs/tags/2.0.26.tar.gz",
+ sha256 = "79e7166aa8eaae6e52cef1363b2d8db795d03684846066bc51f9dcf905dd58ad",
+ name = "emsdk",
+ # Use emsdk-3.0.0 since the larger version may:
+ # - compress the wasm file into a tar file but not directly generate wasm file
+ # - generate incomplete implementation of libc API, e.g. throw exception in getentropy
+ strip_prefix = "emsdk-3.0.0/bazel",
+ url = "https://github.com/emscripten-core/emsdk/archive/refs/tags/3.0.0.tar.gz",
+ sha256 = "a41dccfd15be9e85f923efaa0ac21943cbab77ec8d39e52f25eca1ec61a9ac9e"
+)
+
+load("@emsdk//:deps.bzl", emsdk_deps = "deps")
@ -56,13 +40,17 @@ index c58e76b6..30934678 100644
+emsdk_emscripten_deps()
+
# Android NDK location and version is auto-detected from $ANDROID_NDK_HOME environment variable
android_ndk_repository(name = "androidndk")
-android_ndk_repository(name = "androidndk")
+#android_ndk_repository(name = "androidndk")
# Android SDK location and API is auto-detected from $ANDROID_HOME environment variable
-android_sdk_repository(name = "androidsdk")
+#android_sdk_repository(name = "androidsdk")
diff --git a/build_defs.bzl b/build_defs.bzl
index fbadb400..e496b78d 100644
index b8217a18d..da232966e 100644
--- a/build_defs.bzl
+++ b/build_defs.bzl
@@ -430,7 +430,7 @@ def xnnpack_benchmark(name, srcs, copts = [], deps = [], tags = []):
@@ -380,7 +380,7 @@ def xnnpack_benchmark(name, srcs, copts = [], deps = [], tags = []):
explicitly specified.
"""
native.cc_binary(
@ -72,7 +60,7 @@ index fbadb400..e496b78d 100644
copts = xnnpack_std_cxxopts() + [
"-Iinclude",
diff --git a/emscripten.bzl b/emscripten.bzl
index 130d5f16..2696ad54 100644
index f1557a7b1..7f964a094 100644
--- a/emscripten.bzl
+++ b/emscripten.bzl
@@ -25,12 +25,19 @@ def xnnpack_emscripten_benchmark_linkopts():
@ -84,7 +72,7 @@ index 130d5f16..2696ad54 100644
- "-s EXIT_RUNTIME=1",
+ "-s ERROR_ON_UNDEFINED_SYMBOLS=0",
"-s ALLOW_MEMORY_GROWTH=1",
"-s TOTAL_MEMORY=445644800", # 425M
"-s TOTAL_MEMORY=536870912", # 512M
- "--pre-js $(location :preamble.js.lds)",
+ "-s USE_PTHREADS=0",
+ "-s STANDALONE_WASM=1",
@ -99,11 +87,33 @@ index 130d5f16..2696ad54 100644
]
def xnnpack_emscripten_deps():
diff --git a/src/log.c b/src/log.c
index 5715f2f85..4b3e4261b 100644
--- a/src/log.c
+++ b/src/log.c
@@ -55,7 +55,7 @@
#endif
#if XNN_LOG_TO_STDIO
-static void xnn_vlog(int output_handle, const char* prefix, size_t prefix_length, const char* format, va_list args) {
+void xnn_vlog(int output_handle, const char* prefix, size_t prefix_length, const char* format, va_list args) {
char stack_buffer[XNN_LOG_STACK_BUFFER_SIZE];
char* heap_buffer = NULL;
char* out_buffer = &stack_buffer[0];
diff --git a/third_party/cpuinfo.BUILD b/third_party/cpuinfo.BUILD
index 128d683e..f6c287c4 100644
index 1997f4e3a..5e03c43af 100644
--- a/third_party/cpuinfo.BUILD
+++ b/third_party/cpuinfo.BUILD
@@ -343,5 +343,5 @@ config_setting(
@@ -150,7 +150,7 @@ cc_library(
"src/arm/midr.h",
],
deps = [
- "@clog",
+ "//deps/clog"
],
)
@@ -352,5 +352,5 @@ config_setting(
config_setting(
name = "emscripten",

View File

@ -1,11 +1,14 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
cmake_minimum_required (VERSION 3.0)
cmake_minimum_required (VERSION 3.14)
project(bwa_wasm C)
include(${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/preparation.cmake)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../cmake)
################ dependencies ################
find_package(Binaryen 111 REQUIRED)
################ LIBZ ################
set(LIBZ_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../libz)
@ -86,12 +89,6 @@ add_executable(${PROJECT_NAME} ${BWA_SOURCE})
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME bwa.wasm)
target_include_directories(${PROJECT_NAME}
PRIVATE
${WASI_SDK_HOME}/share/wasi-sysroot/include/libc/musl
${WASI_SDK_HOME}/share/wasi-sysroot/include/sse
)
target_compile_definitions(${PROJECT_NAME}
PRIVATE
USE_MALLOC_WRAPPERS
@ -117,7 +114,7 @@ target_link_libraries(${PROJECT_NAME} z_wasm wasi-emulated-process-clocks)
add_custom_target(bwa_wasm_opt ALL
COMMAND
${WASM_OPT} -Oz --enable-simd -o bwa.opt.wasm bwa.wasm
${Binaryen_WASM_OPT} -Oz --enable-simd -o bwa.opt.wasm bwa.wasm
BYPRODUCTS
${CMAKE_CURRENT_BINARY_DIR}/bwa.opt.wasm
WORKING_DIRECTORY

View File

@ -1,11 +1,19 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
cmake_minimum_required (VERSION 2.8...3.16)
cmake_minimum_required (VERSION 3.14)
project(bwa_wasm)
include(${CMAKE_CURRENT_SOURCE_DIR}/../cmake/preparation.cmake)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../cmake)
################ dependencies ################
find_package(Python3 REQUIRED)
find_package(WASISDK 16.0 REQUIRED)
execute_process(
COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_LIST_DIR}/../../../test-tools/pick-up-emscripten-headers/collect_files.py --install ../include --loglevel=ERROR
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
)
#######################################
include(ExternalProject)
@ -13,7 +21,7 @@ include(ExternalProject)
################ libz ################
ExternalProject_Add(libz_src
GIT_REPOSITORY https://github.com/madler/zlib.git
GIT_TAG master
GIT_TAG 04f42ceca40f73e2978b50e93806c2a18c1281fc
GIT_PROGRESS ON
GIT_SHALLOW ON
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libz
@ -27,7 +35,7 @@ ExternalProject_Add(libz_src
################ bwa ################
ExternalProject_Add(bwa
GIT_REPOSITORY https://github.com/lh3/bwa.git
GIT_TAG master
GIT_TAG 139f68fc4c3747813783a488aef2adc86626b01b
GIT_PROGRESS ON
GIT_SHALLOW ON
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/bwa
@ -37,10 +45,29 @@ ExternalProject_Add(bwa
&& ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.bwa_wasm.txt CMakeLists.txt
&& git apply ../bwa.patch
CONFIGURE_COMMAND ${CMAKE_COMMAND}
-DWASI_SDK_PREFIX=${WASI_SDK_HOME}
-DCMAKE_TOOLCHAIN_FILE=${WASI_SDK_HOME}/share/cmake/wasi-sdk.cmake
-DCMAKE_SYSROOT=${WASI_SDK_HOME}/share/wasi-sysroot
-DWASI_SDK_PREFIX=${WASISDK_HOME}
-DCMAKE_TOOLCHAIN_FILE=${WASISDK_TOOLCHAIN}
-DCMAKE_SYSROOT=${WASISDK_SYSROOT}
-DCMAKE_C_FLAGS=-isystem\ ${CMAKE_CURRENT_SOURCE_DIR}/../include/sse\ -isystem\ ${CMAKE_CURRENT_SOURCE_DIR}/../include/libc/musl
${CMAKE_CURRENT_SOURCE_DIR}/bwa
BUILD_COMMAND make bwa_wasm_opt
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy ./bwa.opt.wasm ${CMAKE_BINARY_DIR}/bwa.wasm
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_if_different ./bwa.opt.wasm ${CMAKE_CURRENT_BINARY_DIR}/bwa.wasm
)
################ bwa data ################
ExternalProject_Add(bwa-kit
PREFIX bwa-kit
URL https://sourceforge.net/projects/bio-bwa/files/bwakit/bwakit-0.7.15_x64-linux.tar.bz2/download
URL_HASH SHA256=0a7b11971bc7916b68e9df35a364afe77cb3000df02ffb3a6fbd1aff9be5878c
DOWNLOAD_NAME bwakit-0.7.15_x64-linux.tar.bz2
DOWNLOAD_EXTRACT_TIMESTAMP ON
DOWNLOAD_NO_EXTRACT OFF
DOWNLOAD_NO_PROGRESS ON
UPDATE_COMMAND ""
PATCH_COMMAND ""
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_CURRENT_BINARY_DIR}/bwa-kit/src/bwa-kit/resource-GRCh38/hs38DH-extra.fa
${CMAKE_CURRENT_BINARY_DIR}/hs38DH-extra.fa
)

View File

@ -33,7 +33,7 @@ Firstly please build iwasm with simd support:
``` shell
$ cd <wamr dir>/product-mini/platforms/linux/
$ mkdir build && cd build
$ cmake .. -DWAMR_BUILD_SIMD=1
$ cmake ..
$ make
```
@ -41,6 +41,6 @@ Then compile wasm file to aot file and run:
``` shell
$ cd <wamr dir>/samples/workload/bwa/build
$ <wamr dir>/wamr-compiler/build/wamrc --enable-simd -o bwa.aot bwa.wasm
$ <wamr dir>/wamr-compiler/build/wamrc -o bwa.aot bwa.wasm
$ <wamr dir>/product-mini/platforms/linux/iwasm --dir=. bwa.aot index hs38DH.fa
```

View File

@ -1 +0,0 @@
../docker/build_workload.sh

View File

@ -0,0 +1,43 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
# Output below variables:
# - Binaryen_HOME. the installation location
#
include(CMakePrintHelpers)
include(FindPackageHandleStandardArgs)
file(GLOB Binaryen_SEARCH_PATH "/opt/binaryen*")
find_path(Binaryen_HOME
NAMES bin/wasm-opt
PATHS ${Binaryen_SEARCH_PATH}
NO_CMAKE_FIND_ROOT_PATH
NO_SYSTEM_ENVIRONMENT_PATH
REQUIRED
)
execute_process(
COMMAND ${Binaryen_HOME}/bin/wasm-opt --version
OUTPUT_VARIABLE WASM_OPT_OUTPUT
OUTPUT_STRIP_TRAILING_WHITESPACE
)
string(REGEX MATCH version_[0-9]+ Binaryen_VERSION_tmp ${WASM_OPT_OUTPUT})
string(REGEX MATCH [0-9]+ Binaryen_VERSION ${Binaryen_VERSION_tmp})
#cmake_print_variables(Binaryen_VERSION_tmp Binaryen_VERSION)
find_package_handle_standard_args(Binaryen REQUIRED_VARS Binaryen_HOME VERSION_VAR Binaryen_VERSION)
if(Binaryen_FOUND)
mark_as_advanced(Binaryen_SEARCH_PATH)
mark_as_advanced(Binaryen_VERSION_tmp)
mark_as_advanced(Binaryen_VERSION)
mark_as_advanced(WASM_OPT_OUTPUT)
set(Binaryen_WASM_OPT ${Binaryen_HOME}/bin/wasm-opt)
else()
# TODO: install WASISDK
endif()

View File

@ -0,0 +1,38 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
# Output below variables:
# - WASISDK_HOME. the installation location
# - WASISDK_SYSROOT. where wasi-sysroot is
# - WASISDK_TOOLCHAIN. where wasi-sdk.cmake is
#
include(CMakePrintHelpers)
include(FindPackageHandleStandardArgs)
file(GLOB WASISDK_SEARCH_PATH "/opt/wasi-sdk-*")
find_path(WASISDK_HOME
NAMES share/wasi-sysroot
PATHS ${WASISDK_SEARCH_PATH}
NO_CMAKE_FIND_ROOT_PATH
NO_SYSTEM_ENVIRONMENT_PATH
REQUIRED
)
string(REGEX MATCH [0-9]+\.[0-9]+\.*[0-9]* WASISDK_VERSION ${WASISDK_HOME})
#cmake_print_variables(WASISDK_HOME WASISDK_VERSION)
find_package_handle_standard_args(WASISDK REQUIRED_VARS WASISDK_HOME VERSION_VAR WASISDK_VERSION)
if(WASISDK_FOUND)
mark_as_advanced(WASISDK_SEARCH_PATH)
mark_as_advanced(WASISDK_VERSION)
set(WASISDK_CC_COMMAND ${WASISDK_HOME}/bin/clang)
set(WASISDK_CXX_COMMAND ${WASISDK_HOME}/bin/clang++)
set(WASISDK_SYSROOT ${WASISDK_HOME}/share/wasi-sysroot)
set(WASISDK_TOOLCHAIN ${WASISDK_HOME}/share/cmake/wasi-sdk.cmake)
else()
# TODO: install WASISDK
endif()

View File

@ -1,49 +0,0 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#######################################
include(ExternalProject)
file(REAL_PATH ../../.. WAMR_ROOT
BASE_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
)
find_path(WASI_SDK_PARENT
name wasi-sdk
PATHS ${WAMR_ROOT}/test-tools/
NO_DEFAULT_PATH
NO_CMAKE_FIND_ROOT_PATH
)
if(NOT WASI_SDK_PARENT)
message(FATAL_ERROR
"can not find 'wasi-sdk' under ${WAMR_ROOT}/test-tools, "
"please run ${WAMR_ROOT}/test-tools/build-wasi-sdk/build_wasi_sdk.py "
"to build wasi-sdk and try again"
)
endif()
set(WASI_SDK_HOME ${WASI_SDK_PARENT}/wasi-sdk)
message(CHECK_START "Detecting WASI-SDK at ${WASI_SDK_HOME}")
if(EXISTS "${WASI_SDK_HOME}/share/cmake/wasi-sdk.cmake")
message(CHECK_PASS "found")
else()
message(CHECK_FAIL "not found")
endif()
################ BINARYEN ################
find_program(WASM_OPT
NAMES wasm-opt
PATHS /opt/binaryen-version_101/bin /opt/binaryen/bin
NO_DEFAULT_PATH
NO_CMAKE_FIND_ROOT_PATH
)
if(NOT WASM_OPT)
message(FATAL_ERROR
"can not find wasm-opt. "
"please download it from "
"https://github.com/WebAssembly/binaryen/releases/download/version_101/binaryen-version_101-x86_64-linux.tar.gz "
"and install it under /opt"
)
endif()

View File

@ -1,33 +0,0 @@
#!/usr/bin/env bash
#
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
readonly SCRIPT_PATH=$(dirname "$(realpath "$0")")
readonly ROOT=$(realpath "${SCRIPT_PATH}"/../../../)
readonly CURRENT_PATH=$(pwd)
readonly CURRENT_RELATIVE_ROOT=$(realpath --relative-base ${ROOT} ${CURRENT_PATH})
readonly VARIANT=$(lsb_release -c | awk '{print $2}')
docker build \
--build-arg VARIANT=${VARIANT} \
--memory 4G --cpu-quota 50000 \
-t wamr_dev_${VARIANT}:0.1 -f "${ROOT}"/.devcontainer/Dockerfile "${ROOT}"/.devcontainer &&
docker run --rm -it \
--memory 4G \
--cpus ".5" \
--name workload_build_env \
--mount type=bind,source="${ROOT}",target=/workspace \
wamr_dev_${VARIANT}:0.1 \
/bin/bash -c "\
pwd \
&& pushd ${CURRENT_RELATIVE_ROOT} \
&& rm -rf build \
&& mkdir build \
&& pushd build \
&& cmake .. \
&& cmake --build . --config Release \
&& popd \
&& popd \
&& echo 'Go and find out results under ${CURRENT_RELATIVE_ROOT}/build' "

View File

View File

@ -1,11 +1,19 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
cmake_minimum_required (VERSION 3.0)
cmake_minimum_required (VERSION 3.14)
project(bench-meshoptimizer)
include(${CMAKE_CURRENT_SOURCE_DIR}/../cmake/preparation.cmake)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../cmake)
################ dependencies ################
find_package(Python3 REQUIRED)
find_package(WASISDK 16.0 REQUIRED)
execute_process(
COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_LIST_DIR}/../../../test-tools/pick-up-emscripten-headers/collect_files.py --install ../include --loglevel=ERROR
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
)
################ MESHOPTIMIZER ################
include(ExternalProject)
@ -13,7 +21,7 @@ include(ExternalProject)
ExternalProject_Add(codecbench
PREFIX codecbench
GIT_REPOSITORY https://github.com/zeux/meshoptimizer.git
GIT_TAG master
GIT_TAG f926b288264522e1b331a41b07ba40167f396913
GIT_SHALLOW ON
GIT_PROGRESS ON
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/meshoptimizer
@ -21,10 +29,10 @@ ExternalProject_Add(codecbench
&& ${CMAKE_COMMAND} -E echo "Applying patch"
&& git apply ${CMAKE_CURRENT_SOURCE_DIR}/codecbench.patch
CONFIGURE_COMMAND ${CMAKE_COMMAND}
-DWASI_SDK_PREFIX=${WASI_SDK_HOME}
-DCMAKE_TOOLCHAIN_FILE=${WASI_SDK_HOME}/share/cmake/wasi-sdk.cmake
-DCMAKE_SYSROOT=${WASI_SDK_HOME}/share/wasi-sysroot
-DWASI_SDK_PREFIX=${WASISDK_HOME}
-DCMAKE_TOOLCHAIN_FILE=${WASISDK_TOOLCHAIN}
-DCMAKE_SYSROOT=${WASISDK_SYSROOT}
${CMAKE_CURRENT_SOURCE_DIR}/meshoptimizer
BUILD_COMMAND make codecbench
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy ./codecbench.wasm ${CMAKE_BINARY_DIR}/codecbench.wasm
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_if_different ./codecbench.wasm ${CMAKE_CURRENT_BINARY_DIR}/codecbench.wasm
)

View File

@ -44,14 +44,14 @@ Firstly please build iwasm with simd support:
``` shell
$ cd <wamr dir>/product-mini/platforms/linux/
$ mkdir build && cd build
$ cmake .. -DWAMR_BUILD_SIMD=1
$ cmake ..
$ make
```
Then compile wasm file to aot file and run:
``` shell
$ <wamr dir>/wamr-compiler/build/wamrc --enable-simd -o codecbench.aot codecbench.wasm
$ <wamr dir>/wamr-compiler/build/wamrc -o codecbench.aot codecbench.wasm
$ <wamr dir>/product-mini/platforms/linux/build/iwasm codecbench.aot
```

View File

@ -1 +0,0 @@
../docker/build_workload.sh

View File

@ -5,13 +5,13 @@
#
readonly BUILD_CONTENT="/tmp/build_content"
readonly WABT_VER=1.0.23
readonly WABT_VER=1.0.31
readonly WABT_FILE="wabt-${WABT_VER}-ubuntu.tar.gz"
readonly CMAKE_VER=3.16.2
readonly CMAKE_VER=3.25.1
readonly CMAKE_FILE="cmake-${CMAKE_VER}-Linux-x86_64.sh"
readonly BINARYEN_VER=version_101
readonly BINARYEN_VER=version_111
readonly BINARYEN_FILE="binaryen-${BINARYEN_VER}-x86_64-linux.tar.gz"
readonly BAZEL_VER=3.7.0
readonly BAZEL_VER=6.0.0
readonly BAZEL_FILE=bazel-${BAZEL_VER}-installer-linux-x86_64.sh
function DEBUG() {
@ -57,8 +57,8 @@ function install_emsdk() {
git clone https://github.com/emscripten-core/emsdk.git
cd emsdk
git pull
./emsdk install 2.0.26
./emsdk activate 2.0.26
./emsdk install 3.1.28
./emsdk activate 3.1.28
echo "source /opt/emsdk/emsdk_env.sh" >> "${HOME}"/.bashrc
}

View File

@ -98,11 +98,11 @@ make
WAMRC_CMD="$(pwd)/wamrc"
cd ${OUT_DIR}
if [[ $1 == '--sgx' ]]; then
${WAMRC_CMD} --enable-simd -sgx -o benchmark_model.aot benchmark_model.wasm
${WAMRC_CMD} -sgx -o benchmark_model.aot benchmark_model.wasm
elif [[ $1 == '--threads' ]]; then
${WAMRC_CMD} --enable-simd --enable-multi-thread -o benchmark_model.aot benchmark_model.wasm
${WAMRC_CMD} --enable-multi-thread -o benchmark_model.aot benchmark_model.wasm
else
${WAMRC_CMD} --enable-simd -o benchmark_model.aot benchmark_model.wasm
${WAMRC_CMD} -o benchmark_model.aot benchmark_model.wasm
fi
# 4. build iwasm with pthread and libc_emcc enable
@ -112,14 +112,14 @@ fi
if [[ $1 == '--sgx' ]]; then
cd ${WAMR_PLATFORM_DIR}/linux-sgx
rm -fr build && mkdir build
cd build && cmake .. -DWAMR_BUILD_SIMD=1 -DWAMR_BUILD_LIB_PTHREAD=1 -DWAMR_BUILD_LIBC_EMCC=1
cd build && cmake .. -DWAMR_BUILD_LIB_PTHREAD=1 -DWAMR_BUILD_LIBC_EMCC=1
make
cd ../enclave-sample
make
else
cd ${WAMR_PLATFORM_DIR}/linux
rm -fr build && mkdir build
cd build && cmake .. -DWAMR_BUILD_SIMD=1 -DWAMR_BUILD_LIB_PTHREAD=1 -DWAMR_BUILD_LIBC_EMCC=1
cd build && cmake .. -DWAMR_BUILD_LIB_PTHREAD=1 -DWAMR_BUILD_LIBC_EMCC=1
make
fi

View File

@ -1,14 +1,14 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
cmake_minimum_required (VERSION 2.8...3.16)
cmake_minimum_required (VERSION 3.14)
project(testavx)
include(${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/preparation.cmake)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../cmake)
# a workaround to let aom find our non-public headers
include_directories(${WASI_SDK_HOME}/share/wasi-sysroot/include/libc/musl)
################ dependencies ################
find_package(Binaryen 111 REQUIRED)
################ AOM ################
set(ENABLE_CCACHE ON)
@ -62,7 +62,7 @@ add_dependencies(${PROJECT_NAME} aom)
add_custom_target(${PROJECT_NAME}_opt ALL
COMMAND
${WASM_OPT} -Oz --enable-simd -o ${PROJECT_NAME}.opt.wasm ${PROJECT_NAME}.wasm
${Binaryen_WASM_OPT} -Oz --enable-simd -o ${PROJECT_NAME}.opt.wasm ${PROJECT_NAME}.wasm
BYPRODUCTS
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.opt.wasm
WORKING_DIRECTORY

View File

@ -1,11 +1,19 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
cmake_minimum_required (VERSION 2.8...3.16)
cmake_minimum_required (VERSION 3.14)
project(av1_wasm)
include(${CMAKE_CURRENT_SOURCE_DIR}/../cmake/preparation.cmake)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../cmake)
################ dependencies ################
find_package(Python3 REQUIRED)
find_package(WASISDK 16.0 REQUIRED)
execute_process(
COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_LIST_DIR}/../../../test-tools/pick-up-emscripten-headers/collect_files.py --install ../include --loglevel=ERROR
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
)
#######################################
include(ExternalProject)
@ -23,10 +31,14 @@ ExternalProject_Add(av1
&& ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.avx_wasm.txt CMakeLists.txt
&& git apply ../av1-clang.patch
CONFIGURE_COMMAND ${CMAKE_COMMAND}
-DWASI_SDK_PREFIX=${WASI_SDK_HOME}
-DCMAKE_TOOLCHAIN_FILE=${WASI_SDK_HOME}/share/cmake/wasi-sdk.cmake
-DCMAKE_SYSROOT=${WASI_SDK_HOME}/share/wasi-sysroot
-DWASI_SDK_PREFIX=${WASISDK_HOME}
-DCMAKE_TOOLCHAIN_FILE=${WASISDK_TOOLCHAIN}
-DCMAKE_SYSROOT=${WASISDK_SYSROOT}
-DCMAKE_C_FLAGS=-isystem\ ${CMAKE_CURRENT_SOURCE_DIR}/../include/sse\ -isystem\ ${CMAKE_CURRENT_SOURCE_DIR}/../include/libc/musl
${CMAKE_CURRENT_SOURCE_DIR}/av1
BUILD_COMMAND make testavx_opt
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy testavx.opt.wasm ${CMAKE_CURRENT_BINARY_DIR}/testavx.wasm
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_if_different
testavx.opt.wasm
${CMAKE_CURRENT_SOURCE_DIR}/av1/third_party/samples/elephants_dream_480p24.ivf
${CMAKE_CURRENT_BINARY_DIR}
)

View File

@ -39,7 +39,7 @@ Firstly please build iwasm with simd support:
``` shell
$ cd <wamr dir>/product-mini/platforms/linux/
$ mkdir build && cd build
$ cmake .. -DWAMR_BUILD_SIMD=1 -DWAMR_BUILD_LIBC_EMCC=1
$ cmake .. -DWAMR_BUILD_LIBC_EMCC=1
$ make
```
@ -47,7 +47,7 @@ Then compile wasm file to aot file and run:
``` shell
$ cd <dir of testavx.wasm>
$ <wamr dir>/wamr-compiler/build/wamrc --enable-simd -o testavx.aot testavx.wasm
$ <wamr dir>/wamr-compiler/build/wamrc -o testavx.aot testavx.wasm
# copy sample data like <wamr dir>/samples/workload/wasm-av1/av1/third_party/samples/elephants_dream_480p24.ivf
# make sure you declare the access priority of the directory in which the sample data is
$ <wamr dir>/product-mini/platforms/linux/build/iwasm --dir=. testavx.aot elephants_dream_480p24.ivf

View File

@ -85,12 +85,12 @@ cd build && cmake ..
make
# 3.2 compile wasm-av1.wasm to wasm-av1.aot
cd ${OUT_DIR}
${WAMRC_CMD} --enable-simd -o testavx.aot testavx.wasm
${WAMRC_CMD} -o testavx.aot testavx.wasm
# 4. build iwasm with pthread and libc_emcc enable
cd ${WAMR_PLATFORM_DIR}/linux
rm -fr build && mkdir build
cd build && cmake .. -DWAMR_BUILD_SIMD=1 -DWAMR_BUILD_LIB_PTHREAD=1 -DWAMR_BUILD_LIBC_EMCC=1
cd build && cmake .. -DWAMR_BUILD_LIB_PTHREAD=1 -DWAMR_BUILD_LIBC_EMCC=1
make
# 5. run wasm-av1 with iwasm

View File

@ -1 +0,0 @@
../docker/build_workload.sh