@@ -44,7 +44,8 @@ interface tensor {
44
44
type tensor-data = list <u8 >;
45
45
46
46
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 >);
48
49
49
50
// Describe the size of the tensor (e.g., 2x2x2x2 -> [2, 2, 2, 2]). To represent a tensor
50
51
// containing a single value, use `[1]` for the tensor dimensions.
@@ -53,9 +54,20 @@ interface tensor {
53
54
// Describe the type of element in the tensor (e.g., `f32`).
54
55
ty : func () -> tensor-type ;
55
56
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.
57
62
data : func () -> tensor-data ;
58
63
}
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?
59
71
}
60
72
61
73
/// A `graph` is a loaded instance of a specific ML model (e.g., MobileNet) for a specific ML
0 commit comments