Add an initial wasi-nn implementation for Wasmtime (#2208)

* Add an initial wasi-nn implementation for Wasmtime

This change adds a crate, `wasmtime-wasi-nn`, that uses `wiggle` to expose the current state of the wasi-nn API and `openvino` to implement the exposed functions. It includes an end-to-end test demonstrating how to do classification using wasi-nn:
 - `crates/wasi-nn/tests/classification-example` contains Rust code that is compiled to the `wasm32-wasi` target and run with a Wasmtime embedding that exposes the wasi-nn calls
 - the example uses Rust bindings for wasi-nn contained in `crates/wasi-nn/tests/wasi-nn-rust-bindings`; this crate contains code generated by `witx-bindgen` and eventually should be its own standalone crate

* Test wasi-nn as a CI step

This change adds:
 - a GitHub action for installing OpenVINO
 - a script, `ci/run-wasi-nn-example.sh`, to run the classification example
This commit is contained in:
Andrew Brown
2020-11-16 10:54:00 -08:00
committed by GitHub
parent 61a0bcbdc6
commit a61f068c64
33 changed files with 1554 additions and 1 deletions

View File

@@ -15,6 +15,9 @@ use wasi_common::{preopen_dir, WasiCtxBuilder};
use wasmtime::{Engine, Func, Linker, Module, Store, Trap, Val, ValType};
use wasmtime_wasi::Wasi;
#[cfg(feature = "wasi-nn")]
use wasmtime_wasi_nn::{WasiNn, WasiNnCtx};
fn parse_module(s: &OsStr) -> Result<PathBuf, OsString> {
// Do not accept wasmtime subcommand names as the module name
match s.to_str() {
@@ -353,6 +356,12 @@ fn populate_with_wasi(
let wasi = Wasi::new(linker.store(), cx);
wasi.add_to_linker(linker)?;
#[cfg(feature = "wasi-nn")]
{
let wasi_nn = WasiNn::new(linker.store(), WasiNnCtx::new()?);
wasi_nn.add_to_linker(linker)?;
}
// Repeat the above, but this time for snapshot 0.
let mut cx = wasi_common::old::snapshot_0::WasiCtxBuilder::new();
cx.inherit_stdio().args(argv).envs(vars);