Giter VIP home page Giter VIP logo

yomo-flow-ssvm-example's Introduction

ssvm-yomo

yomo-flow-ssvm-example

This examples represents how to write a yomo-flow with ssvm

Prerequisites

Install the SSVM shared library and SSVM-go

Compile wasm file

# Install wasm-pack tool
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh

cd triple
wasm-pack build

will get the wasm file at triple/pkg/ directory

Run this flow

  1. Run this yomo-flow
go run main.go ./triple/pkg/triple_lib_bg.wasm triple

Then start your yomo source and yomo zipper

  1. Run yomo-zipper
yomo wf run workflow.yaml
  1. Run yomo-source-example
gh repo clone yomorun/yomo-source-example
cd yomo-source-example
YOMO_ZIPPER_ENDPOINT=localhost:9999 go run main.go

you'll get:

Ξ _wrk/yomo-sink-ssvm β†’ go run main.go
2021/01/26 00:14:20 Starting sink server...
2021/01/26 00:14:20 βœ… Listening on 0.0.0.0:4141
+6.913980e+015
+9.036794e+015
^Csignal: interrupt

Code

The triple/src/lib.rs source file will be built into pkg/triple_lib_bg.wasm, which is then passed to vm.RunWasmFile function as a command argument.

The definition RunWasmFile(path string, funcname string, params ...interface{}) ([]interface{}, error) shows that the second parameter is the calling function name which is also passed as a command argument. Other params will be passed to the calling function in the wasm. Please attention that the type of params and return values can only be i32, i64, f32, f64 currently. Check source

The other function for calling wasm function is RunWasmFileWithDataAndWASI which can receive bytes array as parameters. There is an example for this.

Additional information

Why WebAssembly in edge computing

In an edge computing framework (e.g., YOMO), we often need to execute user submitted code in the dataflow to handle application-specific logic. Since the user submitted code is potentially unsafe and poorly tested, it is crucial that they are executed in a sandbox for security and cross-platform compatibility. WebAssembly is an application sandbox that is very light and very fastβ€”making it an ideal choice for resource-constrained and real-time edge computing scenarios.

Compared with prevailing application containers like Docker, WebAssembly provides a higher level of abstraction, and hence higher productivity, for developers. WebAssembly can deploy functions instantly, instead of launching an operating system and then a language runtime, making it suitable for real-time and high-performance applications.

Why SSVM

The SSVM (Second State VM) is a popular WebAssembly VM optimized for high-performance applications on the server-side. With advanced AOT (Ahead of Time compiler) support, the SSVM is already one of the fastest WebAssembly VMs.

Reference: A Lightweight Design for High-performance Serverless Computing, published on IEEE Software, Jan 2021.

A key differentiator of the SSVM is its support for WebAssembly extensions. For example, the SSVM supports an extension for Tensorflow and other AI frameworks. Developers can write AI inference functions using a simple Rust API, and then run the function securely at native speed on CPU / GHPU / AI chips from the SSVM. That is an excellent fit for edge computing.

YOMO and SSVM

Through its support for the WebAssembly System Interface (WASI), the SSVM can be easily started and managed by the golang-based YOMO host environment, making it a good choice for YOMO extensions. In the future, the SSVM will also support a golang SDK based on WebAssembly interface types specification and make golang / WebAssembly interoperations seamless. SSVM also supports high-performance AI inference, which is commonly required in edge computing settings. YOMO and SSVM is a perfect match.

yomo-flow-ssvm-example's People

Contributors

alabulei1 avatar dependabot[bot] avatar fanweixiao avatar imgbotapp avatar juntao avatar xiaojian-hong avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.