Skip to content

Commit e5e1a6c

Browse files
authored
Re-add *.witx version of API (#32)
After some discussion with `wit-bindgen` maintainers, it is clear that that tool is not yet ready to use for implementing WASI APIs inside engines (e.g., Wasmtime). Since the existing Wasmtime infrastructure, `wiggle`, uses the WITX syntax, this change re-adds the WITX version of the wasi-nn API. This allows `wiggle` to continue to pull the WITX specification directly from this repository until it is replaced by `wit-bindgen`. All documentation has been removed from `wasi-nn.witx` since we expect the WIT version to be the official version (at some point, it would be nice to check in CI that the WITX and WIT versions expose an identical API but this API does not do that).
1 parent d993faf commit e5e1a6c

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

wasi-nn.witx

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
;; This WITX version of the wasi-nn API is retained for consistency only. See the `wasi-nn.wit.md`
2+
;; version for the official specification and documentation.
3+
4+
(typename $buffer_size u32)
5+
(typename $nn_errno
6+
(enum (@witx tag u16)
7+
$success
8+
$invalid_argument
9+
$invalid_encoding
10+
$missing_memory
11+
$busy
12+
$runtime_error
13+
)
14+
)
15+
(typename $tensor_dimensions (list u32))
16+
(typename $tensor_type
17+
(enum (@witx tag u8)
18+
$f16
19+
$f32
20+
$u8
21+
$i32
22+
)
23+
)
24+
(typename $tensor_data (list u8))
25+
(typename $tensor
26+
(record
27+
(field $dimensions $tensor_dimensions)
28+
(field $type $tensor_type)
29+
(field $data $tensor_data)
30+
)
31+
)
32+
(typename $graph_builder (list u8))
33+
(typename $graph_builder_array (list $graph_builder))
34+
(typename $graph (handle))
35+
(typename $graph_encoding
36+
(enum (@witx tag u8)
37+
$openvino
38+
$onnx
39+
$tensorflow
40+
$pytorch
41+
)
42+
)
43+
(typename $execution_target
44+
(enum (@witx tag u8)
45+
$cpu
46+
$gpu
47+
$tpu
48+
)
49+
)
50+
(typename $graph_execution_context (handle))
51+
52+
(module $wasi_ephemeral_nn
53+
(import "memory" (memory))
54+
(@interface func (export "load")
55+
(param $builder $graph_builder_array)
56+
(param $encoding $graph_encoding)
57+
(param $target $execution_target)
58+
(result $error (expected $graph (error $nn_errno)))
59+
)
60+
(@interface func (export "init_execution_context")
61+
(param $graph $graph)
62+
(result $error (expected $graph_execution_context (error $nn_errno)))
63+
)
64+
(@interface func (export "set_input")
65+
(param $context $graph_execution_context)
66+
(param $index u32)
67+
(param $tensor $tensor)
68+
(result $error (expected (error $nn_errno)))
69+
)
70+
(@interface func (export "get_output")
71+
(param $context $graph_execution_context)
72+
(param $index u32)
73+
(param $out_buffer (@witx pointer u8))
74+
(param $out_buffer_max_size $buffer_size)
75+
(result $error (expected $buffer_size (error $nn_errno)))
76+
)
77+
(@interface func (export "compute")
78+
(param $context $graph_execution_context)
79+
(result $error (expected (error $nn_errno)))
80+
)
81+
)
82+

0 commit comments

Comments
 (0)