#webassembly #wasm #neural-network

wasi-nn

High-level Rust bindings for wasi-nn

4 releases (2 breaking)

0.3.0 Mar 13, 2023
0.2.1 Sep 19, 2022
0.2.0 Sep 19, 2022
0.1.0 Apr 12, 2021

#134 in WebAssembly

Download history 143/week @ 2022-11-29 119/week @ 2022-12-06 140/week @ 2022-12-13 99/week @ 2022-12-20 62/week @ 2022-12-27 137/week @ 2023-01-03 96/week @ 2023-01-10 164/week @ 2023-01-17 107/week @ 2023-01-24 193/week @ 2023-01-31 193/week @ 2023-02-07 151/week @ 2023-02-14 114/week @ 2023-02-21 75/week @ 2023-02-28 93/week @ 2023-03-07 106/week @ 2023-03-14

401 downloads per month
Used in 2 crates

Apache-2.0

14KB
293 lines

wasi-nn bindings for Rust

This package contains high-level Rust bindings for wasi-nn system calls. It is similar in purpose to the WASI bindings but this package provides optional access to a system's machine learning functionality from WebAssembly.

NOTE: These bindings are experimental (use at your own risk) and subject to upstream changes in the wasi-nn specification.

Use

  1. Depend on this crate in your Cargo.toml:

    [dependencies]
    wasi-nn = "0.3.0"
    
  2. Use the wasi-nn APIs in your application, for example:

    use wasi_nn;
    
    unsafe {
        wasi_nn::load(
            &[&xml.into_bytes(), &weights],
            wasi_nn::GRAPH_ENCODING_OPENVINO,
            wasi_nn::EXECUTION_TARGET_CPU,
        )
        .unwrap()
    }
    
  3. Compile the application to WebAssembly:

    cargo build --target=wasm32-wasi
    
  4. Run the generated WebAssembly in a runtime supporting wasi-nn, e.g. Wasmtime.

Build

To build this crate from source, use: cargo build.

Generation

This crate contains code (src/generated.rs) generated by witx-bindgen. To regenerate this code, run the following script:

$ scripts/regenerate-bindings-from-witx.sh

Examples

The examples demonstrate how to use wasi-nn from a Rust program.

License

This project is licensed under the Apache 2.0 license. See LICENSE for more details.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Apache-2.0 license, shall be licensed as above, without any additional terms or conditions.

No runtime deps