Skip to content

Commit f47f35c

Browse files
authored
Fill in "API walk-through" section (#40)
The `README.md` template has a section to explain how the API will be used. This change updates that section with some pseudo-Rust and points readers to the more detailed examples in the `wasi-nn` bindings. Closes #39.
1 parent 0f77c48 commit f47f35c

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

README.md

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,24 +89,37 @@ browser deals with image or video encoding.
8989

9090
### Non-goals
9191

92-
wasi-nn is not designed to provide support for individual ML operations (a "model builder" API). The
93-
ML field is still evolving rapidly, with new operations and network topologies emerging
92+
`wasi-nn` is not designed to provide support for individual ML operations (a "model builder" API).
93+
The ML field is still evolving rapidly, with new operations and network topologies emerging
9494
continuously. It would be a challenge to define an evolving set of operations to support in the API.
9595
Instead, our approach is to start with a "model loader" API, inspired by WebNN’s model loader
9696
proposal.
9797

9898
### API walk-through
9999

100-
The following example describes how a user would use `wasi-nn` to classify an image.
100+
The following example describes how a user would use `wasi-nn`:
101101

102-
```
103-
TODO
102+
```rust
103+
// Load the model.
104+
let encoding = wasi_nn::GRAPH_ENCODING_...;
105+
let target = wasi_nn::EXECUTION_TARGET_CPU;
106+
let graph = wasi_nn::load(&[bytes, more_bytes], encoding, target);
107+
108+
// Configure the execution context.
109+
let context = wasi_nn::init_execution_context(graph);
110+
let tensor = wasi_nn::Tensor { ... };
111+
wasi_nn::set_input(context, 0, tensor);
112+
113+
// Compute the inference.
114+
wasi_nn::compute(context);
115+
wasi_nn::get_output(context, 0, &mut output_buffer, output_buffer.len());
104116
```
105117

106-
<!--
107-
More use cases go here: provide example code snippets and diagrams explaining how the API would be
108-
used to solve the given problem.
109-
-->
118+
Note that the details above will depend on the model and backend used; the pseudo-Rust simply
119+
illustrates the general idea, minus any error-checking. Consult the
120+
[AssemblyScript](https://github.com/bytecodealliance/wasi-nn/tree/main/assemblyscript/examples) and
121+
[Rust](https://github.com/bytecodealliance/wasi-nn/tree/main/rust/examples) bindings for more
122+
detailed examples.
110123

111124
### Detailed design discussion
112125

0 commit comments

Comments
 (0)