This repository has been archived on 2023-11-05. You can view files and clone it, but cannot push or open issues or pull requests.
wasm-micro-runtime/samples/workload/meshoptimizer
Wenyong Huang a5188f5574
Add checks to avoid wasm_runtime_malloc memory with size 0 (#507)
In some platforms, allocating memory with size 0 may return NULL but not an empty memory block, which causes runtime load, instantiate or execute wasm/aot file failed. We add checks to try to avoid allocating memory in runtime if the size is 0. And in wasm_runtime_malloc/free, output warning if allocate memory with size 0 and free memory with NULL ptr.
Also fix some coding style issues, fix handle riscv32 ilp32d issue, and fix several wasm-c-api issues.

Signed-off-by: Wenyong Huang <wenyong.huang@intel.com>
2021-01-28 16:16:02 +08:00
..
.gitignore Import SIMD feature and add some workload samples (#438) 2020-11-05 18:15:15 +08:00
CMakeLists.txt Update build scripts and documents of workload samples for wasi-sdk-12.0 (#484) 2020-12-29 14:41:09 +08:00
codecbench.patch Add checks to avoid wasm_runtime_malloc memory with size 0 (#507) 2021-01-28 16:16:02 +08:00
docker_build.sh Fix app manager install atomics app issue and optimize workload scripts (#458) 2020-12-04 15:35:45 +08:00
README.md Update build scripts and documents of workload samples for wasi-sdk-12.0 (#484) 2020-12-29 14:41:09 +08:00

"codecbench of meshoptimizer" sample introduction

This sample demonstrates how to build codecbench of messoptimizer into WebAssembly with simd support and run it with iwasm.

Preparation

please refer to installation instructions.

Build with wasi-sdk

$ mkdir build && cd build
$ cmake ..
$ make
# to verify
$ ls codecbench.wasm

Or build with EMSDK

EMSDK is another toolchain to compile C/C++ code to WASM. In this case, the output wasm file might have a higher performance than the file generated by wasi-sdk.

$ git clone https://github.com/zeux/meshoptimizer.git
$ cd messoptimizer
$ em++ 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:

$ 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:

$ <wamr dir>/wamr-compiler/build/wamrc --enable-simd -o codecbench.aot codecbench.wasm
$ <wamr dir>/product-mini/platforms/linux/build/iwasm codecbench.aot