Skip to content

Commit 2d2f180

Browse files
committed
WIP: a residence proposal for tensors
1 parent 06c30c0 commit 2d2f180

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

wit/wasi-nn.wit

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ interface tensor {
4444
type tensor-data = list<u8>;
4545

4646
resource tensor {
47-
constructor(dimensions: tensor-dimensions, ty: tensor-type, data: tensor-data);
47+
constructor(dimensions: tensor-dimensions, ty: tensor-type, data: tensor-data,
48+
location: option<execution-target>);
4849

4950
// Describe the size of the tensor (e.g., 2x2x2x2 -> [2, 2, 2, 2]). To represent a tensor
5051
// containing a single value, use `[1]` for the tensor dimensions.
@@ -53,9 +54,20 @@ interface tensor {
5354
// Describe the type of element in the tensor (e.g., `f32`).
5455
ty: func() -> tensor-type;
5556

56-
// Return the tensor data.
57+
// Describe where the tensor is currently located (e.g., `cpu`, `gpu`, `tpu`).
58+
location: func() -> execution-target;
59+
60+
// Return the tensor data. If the tensor is located on a device other than the CPU, this
61+
// operation may result in an expensive data copy operation.
5762
data: func() -> tensor-data;
5863
}
64+
65+
/// Alternately, construct a tensor that lives exclusively on a specific device.
66+
create_on_device: func(dimensions: tensor-dimensions, ty: tensor-type, data: tensor-data,
67+
location: execution-target, backend: graph-encoding) -> result<tensor, error>;
68+
69+
// TODO: rename exection-target to... device?
70+
// TODO: rename graph-encoding to... backend?
5971
}
6072

6173
/// A `graph` is a loaded instance of a specific ML model (e.g., MobileNet) for a specific ML

0 commit comments

Comments
 (0)