Update sample workload wasm-av1 and add workload XNNPACK (#443)

This commit is contained in:
Wenyong Huang
2020-11-13 17:53:23 +08:00
committed by GitHub
parent a2641e174a
commit 892af84161
17 changed files with 1474 additions and 19 deletions

8
samples/workload/wasm-av1/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
# from CMakeLists
av1
build
include
# from build.sh
wasm-av1
out

View File

@ -0,0 +1,79 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
cmake_minimum_required (VERSION 3.0)
project(testavx)
# a workaround to let aom find our non-public headers
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../include/libc)
################ AOM ################
set(ENABLE_CCACHE ON)
set(ENABLE_DOCS OFF CACHE BOOL "ENABLE_DOCS" FORCE)
set(ENABLE_EXAMPLES OFF CACHE BOOL "ENABLE_EXAMPLES" FORCE)
set(ENABLE_NEON OFF CACHE BOOL "ENABLE_EXAMPLES" FORCE)
set(ENABLE_NEON_ASM OFF CACHE BOOL "ENABLE_EXAMPLES" FORCE)
set(ENABLE_VSX OFF CACHE BOOL "ENABLE_EXAMPLES" FORCE)
set(ENABLE_MMX OFF CACHE BOOL "ENABLE_EXAMPLES" FORCE)
set(AOM_TARGET_CPU generic)
set(CONFIG_ACCOUNTING 1 CACHE NUMBER "" FORCE)
set(CONFIG_INSPECTION 1 CACHE NUMBER "" FORCE)
set(CONFIG_MULTITHREAD 0 CACHE NUMBER "" FORCE)
set(CONFIG_RUNTIME_CPU_DETECT 0 CACHE NUMBER "" FORCE)
set(CONFIG_UNIT_TESTS 0 CACHE NUMBER "" FORCE)
set(CONFIG_WEBM_IO 0 CACHE NUMBER "" FORCE)
add_subdirectory(third_party/aom third_party/aom/bin EXCLUDE_FROM_ALL)
################ AV ################
add_executable(${PROJECT_NAME}
test.c
decode-av1.c
)
target_include_directories(${PROJECT_NAME}
PRIVATE
third_party/aom/
${CMAKE_CURRENT_BINARY_DIR}/third_party/aom/bin
)
set_target_properties(${PROJECT_NAME}
PROPERTIES
OUTPUT_NAME ${PROJECT_NAME}.wasm
)
target_link_options(${PROJECT_NAME}
PRIVATE
LINKER:--allow-undefined
LINKER:--export=__heap_base
LINKER:--export=__data_end
LINKER:--initial-memory=33554432
LINKER:-z,stack-size=25165824
)
target_link_libraries(${PROJECT_NAME}
PRIVATE
aom
)
add_dependencies(${PROJECT_NAME} aom)
find_program(WASM_OPT
NAMES wasm-opt
PATHS /opt/binaryen-version_97/bin /opt/binaryen/bin
)
if (NOT WASM_OPT)
message(WARNING "can not find wasm-opt and will not optimize any wasm module")
endif()
add_custom_target(${PROJECT_NAME}_opt ALL
COMMAND
${WASM_OPT} -Oz --enable-simd -o ${PROJECT_NAME}.opt.wasm ${PROJECT_NAME}.wasm
BYPRODUCTS
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.opt.wasm
WORKING_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}
)
add_dependencies(${PROJECT_NAME}_opt ${PROJECT_NAME})

View File

@ -0,0 +1,61 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
cmake_minimum_required (VERSION 3.0)
project(av1_wasm)
################ BINARYEN ################
find_program(WASM_OPT
NAMES wasm-opt
PATHS /opt/binaryen-version_97/bin /opt/binaryen/bin
)
if (NOT WASM_OPT)
message(FATAL_ERROR
"can not find wasm-opt. "
"please download it from "
"https://github.com/WebAssembly/binaryen/releases/download/version_97/binaryen-version_97-x86_64-linux.tar.gz "
"and install it under /opt"
)
endif()
#######################################
include(ExternalProject)
################ HEADERS ################
ExternalProject_Add(headers_from_emcc
PREFIX headers
SOURCE_DIR "$ENV{EMSDK}/upstream/emscripten/system/"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_SOURCE_DIR}/include/pthread/sys
&& ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_SOURCE_DIR}/include/libc/bits
# copy emscripten pthread related header files
&& ${CMAKE_COMMAND} -E copy $ENV{EMSDK}/upstream/emscripten/system/include/libc/pthread.h ${CMAKE_CURRENT_SOURCE_DIR}/include/pthread/
&& ${CMAKE_COMMAND} -E copy $ENV{EMSDK}/upstream/emscripten/system/include/libc/signal.h ${CMAKE_CURRENT_SOURCE_DIR}/include/pthread/
&& ${CMAKE_COMMAND} -E copy $ENV{EMSDK}/upstream/emscripten/system/include/libc/netdb.h ${CMAKE_CURRENT_SOURCE_DIR}/include/pthread/
&& ${CMAKE_COMMAND} -E copy $ENV{EMSDK}/upstream/emscripten/system/include/libc/sys/wait.h ${CMAKE_CURRENT_SOURCE_DIR}/include/pthread/sys/
&& ${CMAKE_COMMAND} -E copy $ENV{EMSDK}/upstream/emscripten/system/include/libc/sys/socket.h ${CMAKE_CURRENT_SOURCE_DIR}/include/pthread/sys/
# copy emscripten setjmp headers
&& ${CMAKE_COMMAND} -E copy $ENV{EMSDK}/upstream/emscripten/system/include/libc/setjmp.h ${CMAKE_CURRENT_SOURCE_DIR}/include/libc/setjmp.h
&& ${CMAKE_COMMAND} -E copy $ENV{EMSDK}/upstream/emscripten/system/lib/libc/musl/arch/emscripten/bits/setjmp.h ${CMAKE_CURRENT_SOURCE_DIR}/include/libc/bits/setjmp.h
)
################ av1 ################
ExternalProject_Add(av1
PREFIX av1
GIT_REPOSITORY https://github.com/GoogleChromeLabs/wasm-av1.git
GIT_TAG master
GIT_PROGRESS ON
GIT_SHALLOW ON
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/av1
DEPENDS headers_from_emcc
UPDATE_COMMAND git clean -fd && git checkout -- *
&& ${CMAKE_COMMAND} -E echo "Copying pre-installed CMakeLists.txt"
&& ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.avx_wasm.txt CMakeLists.txt
&& git apply ../av1-clang.patch
CONFIGURE_COMMAND ${CMAKE_COMMAND} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_CURRENT_SOURCE_DIR}/../cmake/toolchain.cmake ${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
)

View File

@ -1,22 +1,56 @@
"wasm-av1" sample introduction
==============
This sample demonstrates how to build [wasm-av1](https://github.com/GoogleChromeLabs/wasm-av1) into WebAssembly with emcc toolchain and run it with iwasm. Please first install [emsdk](https://github.com/emscripten-core/emsdk):
```bash
git clone https://github.com/emscripten-core/emsdk.git
cd emsdk
./emsdk install latest
./emsdk activate latest
```
And set up ensdk environment:
```bash
source emsdk_env.sh
```
Then run
This sample demonstrates how to build [wasm-av1](https://github.com/GoogleChromeLabs/wasm-av1) into
WebAssembly with simd support and run it with iwasm.
## Preparation
please refer to [installation instructions](../README.md).
## Build with EMSDK
just run the convenience script:
```bash
./build.sh
```
to build wasm-av1 and run it with iwasm, which basically contains the following steps:
it is going to build wasm-av1 and run it with iwasm, which basically contains the following steps:
- hack emcc to delete some objects in libc.a
- patch wasm-av1 and build it with emcc compiler
- build iwasm with simd and libc-emcc support
- run testav1.aot with iwasm
## Or build with clang-11 and wasi-sdk
``` shell
$ mkdir build && cd build
$ cmake ..
$ make
# to verify
$ ls testavx.wasm
```
### Run workload
Firstly please build iwasm with simd support:
``` shell
$ cd <wamr dir>/product-mini/platforms/linux/
$ mkdir build && cd build
$ cmake .. -DWAMR_BUILD_SIMD=1
$ make
```
Then compile wasm file to aot file and run:
``` shell
$ cd <wamr dir>/wamr-compiler/build
$ ./wamrc --enable-simd -o testavx.aot testavx.wasm
$ cd <wamr dir>/product-mini/platforms/linux/
$ # copy sample data like <wamr dir>/samples/workload/wasm-av1/av1/third_party/samples/elephants_dream_480p24.ivf
$ # copy testavx.aot
$ # make sure you declare the access priority of the directory in which the sample data is
$ ./iwasm --dir=. ./testavx.aot ./elephants_dream_480p24.ivf
```

View File

@ -0,0 +1,19 @@
diff --git a/test.c b/test.c
index df2d44b..520bf13 100644
--- a/test.c
+++ b/test.c
@@ -63,9 +63,14 @@ main(int argc, char *argv[]) {
static int i = 0;
++i;
+ printf("Decoding frame #%d\n", i);
if (30 <= i && i < 40) {
+ printf("Dumping frame #%d\n", i);
dump_raw_frame(af, i);
}
+ if (i >= 1000) {
+ break;
+ }
}
/*
* Run the decoder every time, so that we keep