Import SIMD feature and add some workload samples (#438)

This commit is contained in:
Wenyong Huang
2020-11-05 18:15:15 +08:00
committed by GitHub
parent 667282eea9
commit a3074df21b
84 changed files with 7780 additions and 318 deletions

View File

@ -0,0 +1,2 @@
build
meshoptimizer

View File

@ -0,0 +1,39 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
cmake_minimum_required (VERSION 3.0)
project(bench-meshoptimizer)
################ 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()
################ MESHOPTIMIZER ################
include(ExternalProject)
ExternalProject_Add(codecbench
PREFIX codecbench
GIT_REPOSITORY https://github.com/zeux/meshoptimizer.git
GIT_TAG master
GIT_SHALLOW ON
GIT_PROGRESS ON
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/meshoptimizer
UPDATE_COMMAND git clean -fd && git checkout -- *
&& ${CMAKE_COMMAND} -E echo "Applying patch"
&& git apply ${CMAKE_CURRENT_SOURCE_DIR}/codecbench.patch
CONFIGURE_COMMAND ${CMAKE_COMMAND} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_CURRENT_SOURCE_DIR}/../cmake/toolchain.cmake ${CMAKE_CURRENT_SOURCE_DIR}/meshoptimizer
BUILD_COMMAND make codecbench.opt
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy ./codecbench.opt.wasm ${CMAKE_CURRENT_SOURCE_DIR}/build/codecbench.wasm
)

View File

@ -0,0 +1,59 @@
"codecbench of meshoptimizer" sample introduction
==============
This sample demonstrates how to build [codecbench of messoptimizer](https://github.com/zeux/meshoptimizer) into
WebAssembly with simd support and run it with iwasm.
## Preparation
please refer to [installation instructions](../README.md).
## Build with clang-11 and wasi-sdk
``` shell
$ mkdir build && cd build
$ cmake ..
$ make
# to verify
$ ls codecbench.wasm
```
## Or build with EMCC
EMCC is another toolchain to compile C code to WASM. In this case, will have
a higher performance with EMCC.
``` shell
$ git clone https://github.com/zeux/meshoptimizer.git
$ cd messoptimizer
$ emcc tools/codecbench.cpp src/vertexcodec.cpp src/vertexfilter.cpp \
src/overdrawanalyzer.cpp src/indexgenerator.cpp src/vcacheoptimizer.cpp \
src/clusterizer.cpp src/indexcodec.cpp src/vfetchanalyzer.cpp \
src/spatialorder.cpp src/allocator.cpp src/vcacheanalyzer.cpp \
src/vfetchoptimizer.cpp src/overdrawoptimizer.cpp src/simplifier.cpp \
src/stripifier.cpp -O3 -msimd128 \
-s TOTAL_MEMORY=268435456 -s "EXPORTED_FUNCTIONS=['_main']" \
-o codecbench.wasm
$ ls -l codecbench.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 codecbench.aot codecbench.wasm
$ cd <wamr dir>/product-mini/platforms/linux/
$ ./iwasm codecbench.aot
```

View File

@ -0,0 +1,47 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index eccc49e..dac126c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -127,3 +127,42 @@ install(FILES
${CMAKE_CURRENT_BINARY_DIR}/meshoptimizerConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/meshoptimizerConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/meshoptimizer)
+
+##################################################
+# codecbench
+##################################################
+add_executable(codecbench tools/codecbench.cpp ${SOURCES})
+
+set_target_properties(codecbench PROPERTIES OUTPUT_NAME codecbench.wasm)
+
+target_compile_options(codecbench
+ PUBLIC
+ -std=c++11
+ -Wno-unused-function
+ -Wno-unused-variable
+)
+
+target_link_options(codecbench
+ PUBLIC
+ LINKER:-allow-undefined,--demangle
+)
+
+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(codecbench.opt ALL
+ COMMAND
+ ${WASM_OPT} -Oz --enable-simd -o codecbench.opt.wasm codecbench.wasm
+ BYPRODUCTS
+ ${CMAKE_CURRENT_BINARY_DIR}/codecbench.opt.wasm
+ WORKING_DIRECTORY
+ ${CMAKE_CURRENT_BINARY_DIR}
+)
+
+add_dependencies(codecbench.opt codecbench)