SSVM is a high performance and enterprise-ready WebAssembly (WASM) Virtual Machine for cloud, AI and Blockchain applications. Its use cases include the following.
- A high performance and secure runtime for Rust functions in Node.js applications. Getting started | VSCode Codespaces | Tensorflow | Privacy computing @ Mozilla Open Labs
- A hardware-optimized runtime for ONNX AI models. ONNC compiler for AI
- Smart contract runtime engine for leading blockchain platforms. Polkadot/Substrate | CyberMiles
$ git clone [email protected]:second-state/SSVM.git
$ cd SSVM
$ git checkout 0.5.1
Our docker image use ubuntu 18.04
as base.
$ docker pull secondstate/ssvm
$ sudo apt install -y \
cmake \
gcc-8 \
g++-8
libboost-all-dev
# And you will need to install llvm-9 for ssvm-aot tools
$ wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
$ sudo apt update && apt install -y \
libllvm9 \
llvm-9 \
llvm-9-dev \
llvm-9-runtime \
libclang-common-9-dev # for yaml-bench
SSVM provides various tools to enabling different runtime environment for optimal performance. After the build is finished, you can find there are several ssvm related tools:
ssvm
is for general wasm runtime. Interpreter mode.ssvm-qitc
is for AI application, supporting ONNC runtime for AI model in ONNX format.- If you want to try
ssvm-qitc
, please refer to ONNC-Wasm project to setup the working environment and run several examples. - And here is our tutorial for ONNC-Wasm project(YouTube Video).
- If you want to try
ssvm-aot
is for general wasm runtime. AOT compilation mode.ssvmc
compiles a general wasm runtime to so file.ssvmr
execute a general wasm runtime or so file in WASI environment.- To disable building the ahead of time compilation runtime, you can set the cmake option
SSVM_DISABLE_AOT_RUNTIME
toOFF
.
# After pulling our ssvm docker image
$ docker run -it --rm \
-v <path/to/your/ssvm/source/folder>:/root/ssvm \
secondstate/ssvm:latest
(docker)$ cd /root/ssvm
(docker)$ mkdir -p build && cd build
(docker)$ cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTS=ON .. && make
The following built-in tests are only avaliable when the build flag BUILD_TESTS
sets to ON
.
Users can use these tests to verify the correctness of SSVM binaries.
$ cd <path/to/ssvm/build_folder>
$ ctest
To run SSVM with general wasm runtime, users will need to provide the following parameters:
- Wasm file(
/path/to/wasm/file
) - (Optional) Entry function name, default value is
main
- (Optional) Argument List, can be one or more arguments.
# cd <path/to/ssvm/build_folder>
$ cd tools/ssvm
# ./ssvm wasm_file.wasm [exported_func_name] [args...]
$ ./ssvm examples/fibonacci.wasm fib 10
2020-04-01 12:31:56,042 INFO [default] Start running...
2020-04-01 12:31:56,042 INFO [default] Execution succeeded.
2020-04-01 12:31:56,042 INFO [default] Done.
2020-04-01 12:31:56,042 INFO [default]
================= Statistics =================
Total execution time: 52 us
Wasm instructions execution time: 52 us
Host functions execution time: 0 us
Executed wasm instructions count: 1766
Gas costs: 1855
Instructions per second: 33961538
Return value: 89
# ./ssvm wasm_file.wasm [exported_func_name] [args...]
$ ./ssvm examples/factorial.wasm fac 5
2020-04-01 12:32:33,153 INFO [default] Start running...
2020-04-01 12:32:33,153 INFO [default] Execution succeeded.
2020-04-01 12:32:33,153 INFO [default] Done.
2020-04-01 12:32:33,153 INFO [default]
================= Statistics =================
Total execution time: 49 us
Wasm instructions execution time: 49 us
Host functions execution time: 0 us
Executed wasm instructions count: 55
Gas costs: 61
Instructions per second: 1122448
Return value: 120
SSVM-EVMC provides support for Ewasm runtime which is compatible with EVMC.
This project provides a shared library that can initialize and execute by the EVMC interface.
SSVM-napi provides support for accessing SSVM as a Node.js addon.
It allows Node.js applications to call WebAssembly functions written in Rust or other high performance languages.
Why do you want to run WebAssembly on the server-side?
The SSVM addon could interact with the wasm files generated by the ssvmup compiler tool.
The Second State DevChain features a powerful and easy-to-use virtual machine that can quickly get you started with smart contract and DApp development.
SSVM-evmc is integrated into our DevChain. Click here to learn how to run an ewasm smart contrat on a real blockchain.