@@ -11,8 +11,8 @@ Then, the user passes <em>tensor</em> inputs to the <em>graph</em>, computes the
11
11
<ul >
12
12
<li >interface <a href =" #wasi:nn_tensor " ><code >wasi:nn/tensor</code ></a ></li >
13
13
<li >interface <a href =" #wasi:nn_errors " ><code >wasi:nn/errors</code ></a ></li >
14
- <li >interface <a href =" #wasi:nn_graph " ><code >wasi:nn/graph</code ></a ></li >
15
14
<li >interface <a href =" #wasi:nn_inference " ><code >wasi:nn/inference</code ></a ></li >
15
+ <li >interface <a href =" #wasi:nn_graph " ><code >wasi:nn/graph</code ></a ></li >
16
16
</ul >
17
17
</li >
18
18
</ul >
@@ -45,12 +45,46 @@ and the array length must match the product of all of the dimensions and the num
45
45
in the type (e.g., a 2x2 tensor with 4-byte f32 elements would have a data array of length
46
46
16). Naturally, this representation requires some knowledge of how to lay out data in
47
47
memory--e.g., using row-major ordering--and could perhaps be improved.</p >
48
- <h4 ><a name =" tensor " ><code >record tensor</code ></a ></h4 >
49
- <h5 >Record Fields</h5 >
48
+ <h4 ><a name =" tensor " ><code >resource tensor</code ></a ></h4 >
49
+ <hr />
50
+ <h3 >Functions</h3 >
51
+ <h4 ><a name =" constructor_tensor " ><code >[constructor]tensor: func</code ></a ></h4 >
52
+ <h5 >Params</h5 >
53
+ <ul >
54
+ <li ><a name =" constructor_tensor.dimensions " ><code >dimensions</code ></a >: <a href =" #tensor_dimensions " ><a href =" #tensor_dimensions " ><code >tensor-dimensions</code ></a ></a ></li >
55
+ <li ><a name =" constructor_tensor.ty " ><code >ty</code ></a >: <a href =" #tensor_type " ><a href =" #tensor_type " ><code >tensor-type</code ></a ></a ></li >
56
+ <li ><a name =" constructor_tensor.data " ><code >data</code ></a >: <a href =" #tensor_data " ><a href =" #tensor_data " ><code >tensor-data</code ></a ></a ></li >
57
+ </ul >
58
+ <h5 >Return values</h5 >
50
59
<ul >
51
- <li ><a name =" tensor.dimensions " ><code >dimensions</code ></a >: <a href =" #tensor_dimensions " ><a href =" #tensor_dimensions " ><code >tensor-dimensions</code ></a ></a ></li >
52
- <li ><a name =" tensor.tensor_type " ><a href =" #tensor_type " ><code >tensor-type</code ></a ></a >: <a href =" #tensor_type " ><a href =" #tensor_type " ><code >tensor-type</code ></a ></a ></li >
53
- <li ><a name =" tensor.data " ><code >data</code ></a >: <a href =" #tensor_data " ><a href =" #tensor_data " ><code >tensor-data</code ></a ></a ></li >
60
+ <li ><a name =" constructor_tensor.0 " ></a > own< ; <a href =" #tensor " ><a href =" #tensor " ><code >tensor</code ></a ></a >> ; </li >
61
+ </ul >
62
+ <h4 ><a name =" method_tensor.dimensions " ><code >[method]tensor.dimensions: func</code ></a ></h4 >
63
+ <h5 >Params</h5 >
64
+ <ul >
65
+ <li ><a name =" method_tensor.dimensions.self " ><code >self</code ></a >: borrow< ; <a href =" #tensor " ><a href =" #tensor " ><code >tensor</code ></a ></a >> ; </li >
66
+ </ul >
67
+ <h5 >Return values</h5 >
68
+ <ul >
69
+ <li ><a name =" method_tensor.dimensions.0 " ></a > <a href =" #tensor_dimensions " ><a href =" #tensor_dimensions " ><code >tensor-dimensions</code ></a ></a ></li >
70
+ </ul >
71
+ <h4 ><a name =" method_tensor.ty " ><code >[method]tensor.ty: func</code ></a ></h4 >
72
+ <h5 >Params</h5 >
73
+ <ul >
74
+ <li ><a name =" method_tensor.ty.self " ><code >self</code ></a >: borrow< ; <a href =" #tensor " ><a href =" #tensor " ><code >tensor</code ></a ></a >> ; </li >
75
+ </ul >
76
+ <h5 >Return values</h5 >
77
+ <ul >
78
+ <li ><a name =" method_tensor.ty.0 " ></a > <a href =" #tensor_type " ><a href =" #tensor_type " ><code >tensor-type</code ></a ></a ></li >
79
+ </ul >
80
+ <h4 ><a name =" method_tensor.data " ><code >[method]tensor.data: func</code ></a ></h4 >
81
+ <h5 >Params</h5 >
82
+ <ul >
83
+ <li ><a name =" method_tensor.data.self " ><code >self</code ></a >: borrow< ; <a href =" #tensor " ><a href =" #tensor " ><code >tensor</code ></a ></a >> ; </li >
84
+ </ul >
85
+ <h5 >Return values</h5 >
86
+ <ul >
87
+ <li ><a name =" method_tensor.data.0 " ></a > <a href =" #tensor_data " ><a href =" #tensor_data " ><code >tensor-data</code ></a ></a ></li >
54
88
</ul >
55
89
<h2 ><a name =" wasi:nn_errors " >Import interface wasi:nn/errors</a ></h2 >
56
90
<p >TODO: create function-specific errors (https://github.com/WebAssembly/wasi-nn/issues/42)</p >
@@ -67,6 +101,59 @@ memory--e.g., using row-major ordering--and could perhaps be improved.</p>
67
101
<li ><a name =" error.too_large " ><code >too-large</code ></a ></li >
68
102
<li ><a name =" error.not_found " ><code >not-found</code ></a ></li >
69
103
</ul >
104
+ <h2 ><a name =" wasi:nn_inference " >Import interface wasi:nn/inference</a ></h2 >
105
+ <p >An inference " ; session" ; is encapsulated by a <a href =" #graph_execution_context " ><code >graph-execution-context</code ></a >. This structure binds a
106
+ <a href =" #graph " ><code >graph</code ></a > to input tensors before <code >compute</code >-ing an inference:</p >
107
+ <hr />
108
+ <h3 >Types</h3 >
109
+ <h4 ><a name =" error " ><code >type error</code ></a ></h4 >
110
+ <p ><a href =" #error " ><a href =" #error " ><code >error</code ></a ></a ></p >
111
+ <p >
112
+ #### <a name =" tensor " >` type tensor ` </a >
113
+ [ ` tensor ` ] ( #tensor )
114
+ <p >
115
+ #### <a name =" tensor_data " >` type tensor-data ` </a >
116
+ [ ` tensor-data ` ] ( #tensor_data )
117
+ <p >
118
+ #### <a name =" graph_execution_context " >` resource graph-execution-context ` </a >
119
+ <hr />
120
+ <h3 >Functions</h3 >
121
+ <h4 ><a name =" method_graph_execution_context.set_input " ><code >[method]graph-execution-context.set-input: func</code ></a ></h4 >
122
+ <p >Define the inputs to use for inference.</p >
123
+ <h5 >Params</h5 >
124
+ <ul >
125
+ <li ><a name =" method_graph_execution_context.set_input.self " ><code >self</code ></a >: borrow< ; <a href =" #graph_execution_context " ><a href =" #graph_execution_context " ><code >graph-execution-context</code ></a ></a >> ; </li >
126
+ <li ><a name =" method_graph_execution_context.set_input.name " ><code >name</code ></a >: <code >string</code ></li >
127
+ <li ><a name =" method_graph_execution_context.set_input.tensor " ><a href =" #tensor " ><code >tensor</code ></a ></a >: own< ; <a href =" #tensor " ><a href =" #tensor " ><code >tensor</code ></a ></a >> ; </li >
128
+ </ul >
129
+ <h5 >Return values</h5 >
130
+ <ul >
131
+ <li ><a name =" method_graph_execution_context.set_input.0 " ></a > result< ; _, <a href =" #error " ><a href =" #error " ><code >error</code ></a ></a >> ; </li >
132
+ </ul >
133
+ <h4 ><a name =" method_graph_execution_context.compute " ><code >[method]graph-execution-context.compute: func</code ></a ></h4 >
134
+ <p >Compute the inference on the given inputs.</p >
135
+ <p >Note the expected sequence of calls: <code >set-input</code >, <code >compute</code >, <code >get-output</code >. TODO: this
136
+ expectation could be removed as a part of
137
+ https://github.com/WebAssembly/wasi-nn/issues/43 .</p >
138
+ <h5 >Params</h5 >
139
+ <ul >
140
+ <li ><a name =" method_graph_execution_context.compute.self " ><code >self</code ></a >: borrow< ; <a href =" #graph_execution_context " ><a href =" #graph_execution_context " ><code >graph-execution-context</code ></a ></a >> ; </li >
141
+ </ul >
142
+ <h5 >Return values</h5 >
143
+ <ul >
144
+ <li ><a name =" method_graph_execution_context.compute.0 " ></a > result< ; _, <a href =" #error " ><a href =" #error " ><code >error</code ></a ></a >> ; </li >
145
+ </ul >
146
+ <h4 ><a name =" method_graph_execution_context.get_output " ><code >[method]graph-execution-context.get-output: func</code ></a ></h4 >
147
+ <p >Extract the outputs after inference.</p >
148
+ <h5 >Params</h5 >
149
+ <ul >
150
+ <li ><a name =" method_graph_execution_context.get_output.self " ><code >self</code ></a >: borrow< ; <a href =" #graph_execution_context " ><a href =" #graph_execution_context " ><code >graph-execution-context</code ></a ></a >> ; </li >
151
+ <li ><a name =" method_graph_execution_context.get_output.name " ><code >name</code ></a >: <code >string</code ></li >
152
+ </ul >
153
+ <h5 >Return values</h5 >
154
+ <ul >
155
+ <li ><a name =" method_graph_execution_context.get_output.0 " ></a > result< ; own< ; <a href =" #tensor " ><a href =" #tensor " ><code >tensor</code ></a ></a >> ; , <a href =" #error " ><a href =" #error " ><code >error</code ></a ></a >> ; </li >
156
+ </ul >
70
157
<h2 ><a name =" wasi:nn_graph " >Import interface wasi:nn/graph</a ></h2 >
71
158
<p >A <a href =" #graph " ><code >graph</code ></a > is a loaded instance of a specific ML model (e.g., MobileNet) for a specific ML
72
159
framework (e.g., TensorFlow):</p >
@@ -78,10 +165,10 @@ framework (e.g., TensorFlow):</p>
78
165
#### <a name =" tensor " >` type tensor ` </a >
79
166
[ ` tensor ` ] ( #tensor )
80
167
<p >
81
- #### <a name =" graph " >` type graph ` </a >
82
- ` u32 `
83
- <p >An execution graph for performing inference (i.e., a model).
84
- < p >TODO: replace with < code > resource</ code > (https://github.com/WebAssembly/wasi-nn/issues/47).</ p >
168
+ #### <a name =" graph_execution_context " >` type graph-execution-context ` </a >
169
+ [ ` graph-execution-context ` ] ( #graph_execution_context )
170
+ <p >
171
+ #### < a name = " graph " > ` resource graph ` </ a >
85
172
<h4 ><a name =" graph_encoding " ><code >enum graph-encoding</code ></a ></h4 >
86
173
<p >Describes the encoding of the graph. This allows the API to be implemented by various
87
174
backends that encode (i.e., serialize) their graph IR with different formats.</p >
@@ -109,6 +196,15 @@ backends that encode (i.e., serialize) their graph IR with different formats.</p
109
196
graph IR in parts (e.g., OpenVINO stores its IR and weights separately).</p >
110
197
<hr />
111
198
<h3 >Functions</h3 >
199
+ <h4 ><a name =" method_graph.init_execution_context " ><code >[method]graph.init-execution-context: func</code ></a ></h4 >
200
+ <h5 >Params</h5 >
201
+ <ul >
202
+ <li ><a name =" method_graph.init_execution_context.self " ><code >self</code ></a >: borrow< ; <a href =" #graph " ><a href =" #graph " ><code >graph</code ></a ></a >> ; </li >
203
+ </ul >
204
+ <h5 >Return values</h5 >
205
+ <ul >
206
+ <li ><a name =" method_graph.init_execution_context.0 " ></a > result< ; own< ; <a href =" #graph_execution_context " ><a href =" #graph_execution_context " ><code >graph-execution-context</code ></a ></a >> ; , <a href =" #error " ><a href =" #error " ><code >error</code ></a ></a >> ; </li >
207
+ </ul >
112
208
<h4 ><a name =" load " ><code >load: func</code ></a ></h4 >
113
209
<p >Load a <a href =" #graph " ><code >graph</code ></a > from an opaque sequence of bytes to use for inference.</p >
114
210
<h5 >Params</h5 >
@@ -119,7 +215,7 @@ graph IR in parts (e.g., OpenVINO stores its IR and weights separately).</p>
119
215
</ul >
120
216
<h5 >Return values</h5 >
121
217
<ul >
122
- <li ><a name =" load.0 " ></a > result< ; <a href =" #graph " ><a href =" #graph " ><code >graph</code ></a ></a >, <a href =" #error " ><a href =" #error " ><code >error</code ></a ></a >> ; </li >
218
+ <li ><a name =" load.0 " ></a > result< ; own & lt ; <a href =" #graph " ><a href =" #graph " ><code >graph</code ></a ></a >& gt ; , <a href =" #error " ><a href =" #error " ><code >error</code ></a ></a >> ; </li >
123
219
</ul >
124
220
<h4 ><a name =" load_by_name " ><code >load-by-name: func</code ></a ></h4 >
125
221
<p >Load a <a href =" #graph " ><code >graph</code ></a > by name.</p >
@@ -132,73 +228,5 @@ range from simple to complex (e.g., URLs?) and caching mechanisms of various kin
132
228
</ul >
133
229
<h5 >Return values</h5 >
134
230
<ul >
135
- <li ><a name =" load_by_name.0 " ></a > result< ; <a href =" #graph " ><a href =" #graph " ><code >graph</code ></a ></a >, <a href =" #error " ><a href =" #error " ><code >error</code ></a ></a >> ; </li >
136
- </ul >
137
- <h2 ><a name =" wasi:nn_inference " >Import interface wasi:nn/inference</a ></h2 >
138
- <p >An inference " ; session" ; is encapsulated by a <a href =" #graph_execution_context " ><code >graph-execution-context</code ></a >. This structure binds a
139
- <a href =" #graph " ><code >graph</code ></a > to input tensors before <a href =" #compute " ><code >compute</code ></a >-ing an inference:</p >
140
- <hr />
141
- <h3 >Types</h3 >
142
- <h4 ><a name =" error " ><code >type error</code ></a ></h4 >
143
- <p ><a href =" #error " ><a href =" #error " ><code >error</code ></a ></a ></p >
144
- <p >
145
- #### <a name =" tensor " >` type tensor ` </a >
146
- [ ` tensor ` ] ( #tensor )
147
- <p >
148
- #### <a name =" tensor_data " >` type tensor-data ` </a >
149
- [ ` tensor-data ` ] ( #tensor_data )
150
- <p >
151
- #### <a name =" graph " >` type graph ` </a >
152
- [ ` graph ` ] ( #graph )
153
- <p >
154
- #### <a name =" graph_execution_context " >` type graph-execution-context ` </a >
155
- ` u32 `
156
- <p >Bind a `graph` to the input and output tensors for an inference.
157
- <p >TODO: this is no longer necessary in WIT (https://github.com/WebAssembly/wasi-nn/issues/43)</p >
158
- <hr />
159
- <h3 >Functions</h3 >
160
- <h4 ><a name =" init_execution_context " ><code >init-execution-context: func</code ></a ></h4 >
161
- <p >Create an execution instance of a loaded graph.</p >
162
- <h5 >Params</h5 >
163
- <ul >
164
- <li ><a name =" init_execution_context.graph " ><a href =" #graph " ><code >graph</code ></a ></a >: <a href =" #graph " ><a href =" #graph " ><code >graph</code ></a ></a ></li >
165
- </ul >
166
- <h5 >Return values</h5 >
167
- <ul >
168
- <li ><a name =" init_execution_context.0 " ></a > result< ; <a href =" #graph_execution_context " ><a href =" #graph_execution_context " ><code >graph-execution-context</code ></a ></a >, <a href =" #error " ><a href =" #error " ><code >error</code ></a ></a >> ; </li >
169
- </ul >
170
- <h4 ><a name =" set_input " ><code >set-input: func</code ></a ></h4 >
171
- <p >Define the inputs to use for inference.</p >
172
- <h5 >Params</h5 >
173
- <ul >
174
- <li ><a name =" set_input.ctx " ><code >ctx</code ></a >: <a href =" #graph_execution_context " ><a href =" #graph_execution_context " ><code >graph-execution-context</code ></a ></a ></li >
175
- <li ><a name =" set_input.name " ><code >name</code ></a >: <code >string</code ></li >
176
- <li ><a name =" set_input.tensor " ><a href =" #tensor " ><code >tensor</code ></a ></a >: <a href =" #tensor " ><a href =" #tensor " ><code >tensor</code ></a ></a ></li >
177
- </ul >
178
- <h5 >Return values</h5 >
179
- <ul >
180
- <li ><a name =" set_input.0 " ></a > result< ; _, <a href =" #error " ><a href =" #error " ><code >error</code ></a ></a >> ; </li >
181
- </ul >
182
- <h4 ><a name =" compute " ><code >compute: func</code ></a ></h4 >
183
- <p >Compute the inference on the given inputs.</p >
184
- <p >Note the expected sequence of calls: <a href =" #set_input " ><code >set-input</code ></a >, <a href =" #compute " ><code >compute</code ></a >, <a href =" #get_output " ><code >get-output</code ></a >. TODO: this
185
- expectation could be removed as a part of https://github.com/WebAssembly/wasi-nn/issues/43 .</p >
186
- <h5 >Params</h5 >
187
- <ul >
188
- <li ><a name =" compute.ctx " ><code >ctx</code ></a >: <a href =" #graph_execution_context " ><a href =" #graph_execution_context " ><code >graph-execution-context</code ></a ></a ></li >
189
- </ul >
190
- <h5 >Return values</h5 >
191
- <ul >
192
- <li ><a name =" compute.0 " ></a > result< ; _, <a href =" #error " ><a href =" #error " ><code >error</code ></a ></a >> ; </li >
193
- </ul >
194
- <h4 ><a name =" get_output " ><code >get-output: func</code ></a ></h4 >
195
- <p >Extract the outputs after inference.</p >
196
- <h5 >Params</h5 >
197
- <ul >
198
- <li ><a name =" get_output.ctx " ><code >ctx</code ></a >: <a href =" #graph_execution_context " ><a href =" #graph_execution_context " ><code >graph-execution-context</code ></a ></a ></li >
199
- <li ><a name =" get_output.name " ><code >name</code ></a >: <code >string</code ></li >
200
- </ul >
201
- <h5 >Return values</h5 >
202
- <ul >
203
- <li ><a name =" get_output.0 " ></a > result< ; <a href =" #tensor_data " ><a href =" #tensor_data " ><code >tensor-data</code ></a ></a >, <a href =" #error " ><a href =" #error " ><code >error</code ></a ></a >> ; </li >
231
+ <li ><a name =" load_by_name.0 " ></a > result< ; own< ; <a href =" #graph " ><a href =" #graph " ><code >graph</code ></a ></a >> ; , <a href =" #error " ><a href =" #error " ><code >error</code ></a ></a >> ; </li >
204
232
</ul >
0 commit comments