legendtang / SSVM

SSVM is a high performance, extensible, and hardware optimized WebAssembly Virtual Machine for cloud, AI, and blockchain applications.

Home Page:https://www.secondstate.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Introduction

SSVM is a high performance and enterprise-ready WebAssembly (WASM) Virtual Machine for cloud, AI, and Blockchain applications. Its use cases include the following.

build

Getting Started

Get Source Code

$ git clone git@github.com:second-state/SSVM.git
$ cd SSVM
$ git checkout 0.6.3

Prepare the environment

Use our docker image

Our docker image use ubuntu 20.04 as the base.

$ docker pull secondstate/ssvm

Or setup the environment manually

# Tools and libraries
$ sudo apt install -y \
	software-properties-common \
	cmake \
	libboost-all-dev

# And you will need to install llvm for ssvm-aot tools
$ sudo apt install -y \
	llvm-dev \
	liblld-10-dev

# SSVM supports both clang++ and g++ compilers
# You can choose one of them for building this project
$ sudo apt install -y gcc g++
$ sudo apt install -y clang

Build SSVM

SSVM provides various tools for enabling different runtime environments for optimal performance. After the build is finished, you can find there are several ssvm related tools:

  1. ssvm is for general wasm runtime. Interpreter mode.
  2. ssvm-qitc is for AI application, supporting ONNC runtime for AI model in ONNX format.
  3. 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 to OFF.
# 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 -j

Run built-in tests

The following built-in tests are only available 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

Run ssvm (SSVM with general wasm runtime)

To run SSVM with general wasm runtime, users will need to provide the following parameters:

  1. Wasm file(/path/to/wasm/file)
  2. (Optional) Entry function name, the default value is main
  3. (Optional) Argument List, can be one or more arguments.

Example: Fibonacci

# cd <path/to/ssvm/build_folder>
$ cd tools/ssvm
# ./ssvm wasm_file.wasm [exported_func_name] [args...]
$ ./ssvm examples/fibonacci.wasm fib 10
2020-07-22 10:36:27,721 DEBUG [default] [hydai@unknown-host] [SSVM::Expect<void> SSVM::Interpreter::Interpreter::runFunction(SSVM::Runtime::StoreManager&, const SSVM::Runtime::Instance::FunctionInstance&, SSVM::Span<const SSVM::Support::Variant<unsigned int, long unsigned int, float, double> >)] [/home/hydai/workspace/SSVM/lib/interpreter/engine/engine.cpp:104]  Execution succeeded.
2020-07-22 10:36:27,721 DEBUG [default] [hydai@unknown-host] [SSVM::Expect<void> SSVM::Interpreter::Interpreter::runFunction(SSVM::Runtime::StoreManager&, const SSVM::Runtime::Instance::FunctionInstance&, SSVM::Span<const SSVM::Support::Variant<unsigned int, long unsigned int, float, double> >)] [/home/hydai/workspace/SSVM/lib/interpreter/engine/engine.cpp:120]
 ====================  Statistics  ====================
 Total execution time: 101 us
 Wasm instructions execution time: 101 us
 Host functions execution time: 0 us
 Executed wasm instructions count: 1766
 Gas costs: 1766
 Instructions per second: 17485148

 Return value: 89

Example: Factorial

# ./ssvm wasm_file.wasm [exported_func_name] [args...]
$ ./ssvm examples/factorial.wasm fac 5
2020-07-22 10:37:36,624 DEBUG [default] [hydai@unknown-host] [SSVM::Expect<void> SSVM::Interpreter::Interpreter::runFunction(SSVM::Runtime::StoreManager&, const SSVM::Runtime::Instance::FunctionInstance&, SSVM::Span<const SSVM::Support::Variant<unsigned int, long unsigned int, float, double> >)] [/home/hydai/workspace/SSVM/lib/interpreter/engine/engine.cpp:104]  Execution succeeded.
2020-07-22 10:37:36,624 DEBUG [default] [hydai@unknown-host] [SSVM::Expect<void> SSVM::Interpreter::Interpreter::runFunction(SSVM::Runtime::StoreManager&, const SSVM::Runtime::Instance::FunctionInstance&, SSVM::Span<const SSVM::Support::Variant<unsigned int, long unsigned int, float, double> >)] [/home/hydai/workspace/SSVM/lib/interpreter/engine/engine.cpp:120]
 ====================  Statistics  ====================
 Total execution time: 107 us
 Wasm instructions execution time: 107 us
 Host functions execution time: 0 us
 Executed wasm instructions count: 55
 Gas costs: 55
 Instructions per second: 514018

 Return value: 120

Related tools

SSVM-EVMC

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 nodejs addon

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.

DevChain

The Second State DevChain features a powerful and easy-to-use virtual machine that can quickly get you started with the smart contract and DApp development.

SSVM-evmc is integrated into our DevChain. Click here to learn how to run an ewasm smart contract on a real blockchain.

Customized Host Functions

Design document shows how to register customized host functions into SSVM and execute with wasm files.

About

SSVM is a high performance, extensible, and hardware optimized WebAssembly Virtual Machine for cloud, AI, and blockchain applications.

https://www.secondstate.io/


Languages

Language:C++ 64.5%Language:WebAssembly 34.7%Language:CMake 0.8%Language:Shell 0.0%