# WebAssembly Standalone for Deep Learning Framework with TVM Runtime
#### Experimental notice: This project is still *experimental* and only serves as a proof of concept for running deep learning frameworks on [WebAssembly runtime](https://github.com/bytecodealliance/wasmtime) with [TVM stack](https://tvm.apache.org/).
- [WebAssembly Standalone for Deep Learning Framework with TVM Runtime](#webassembly-standalone-for-deep-learning-framework-with-tvm-runtime)
- [Motivation](#motivation)
- [Framework Landscape](#framework-landscape)
- [Project Status](#project-status)
- [PoC Guidelines](#poc-guidelines)
- [Pre-installation](#pre-installation)
- [Build ResNet50 model](#build-resnet50-model)
- [Build wasm-graph package](#build-wasm-graph-package)
- [Test](#test)
- [Future Work](#future-work)
- [More networks support](#more-networks-support)
- [Performance benchmark](#performance-benchmark)
- [Native TVM Rust runtime support](#native-tvm-rust-runtime-support)
- [Appendix](#appendix)
- [System packages install](#system-packages-install)
## Motivation
As demonstrated in TVM runtime [tutorials](https://tvm.apache.org/docs/tutorials/get_started/relay_quick_start.html), TVM already supports WASM as the optional hardware backend, so we can leverage the features of WebAssembly (portability, security) and TVM runtime (domain-specific, optimization) to build a flexible and auto-optimized graph compiler for all deep learning frameworks.
## Framework Landscape
The figures below demonstrate the whole landscape of running deep learning frameworks on WASM runtime with TVM compiler stack.
* WASM graph generation
```
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
| | | | | |
| Framework Model | ---> | ONNX Model | ---> | TVM Relay Python API |
|_ _ _ _ _ _ _ _ _ _| |_ _ _ _ _ _ _| |_ _ _ _ _ _ _ _ _ _ _ _|
||
\/
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
| | | |
| WASM Graph Builder | | TVM Compiler Stack |
| (TVM runtime) | |_ _ _ _ _ _ _ _ _ _ _|
|_ _ _ _ _ _ _ _ _ _ _| ||
|| \/
_ _ _ _ _ _ _ _ _ || _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
| | \/ | | llvm-ar | |
| wasm_graph.wasm | <--- | libgraph_wasm32.a | <------- | graph.o |
|_ _ _ _ _ _ _ _ _| |_ _ _ _ _ _ _ _ _ _| |_ _ _ _ _|
```
* WASM graph loading
```
_ _ _ _ _ _ _ _ _ _ _
| |
| WASM Graph Loader |
| (WASM runtime) |
|_ _ _ _ _ _ _ _ _ _ _|
||
\/
_ _ _ _ _ _ _ _ _ _
| |
| wasm_graph.wasm |
|_ _ _ _ _ _ _ _ _ _|
```
## Project Status
This project should be considered **experimental** at the very early stage, all rich features are under active development. Here is the current operator support matrix:
| Model Name | Status |
| ---------- | ------ |
| ResNet50 | ✔️ |
| LeNet |