You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/OPTIMIZATION_PURE_GPU_PIPELINE.md
+46-1Lines changed: 46 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -6,8 +6,9 @@ API that allows data to stay in GPU. Our users are pretty faimilar with
6
6
`tensor.dataSync()` and `tensor.data()`, however both will download data from GPU to CPU. In the latest release, we have added `tensor.dataToGPU()`,
7
7
which returns a `GPUData` type.
8
8
9
+
# For webgl backend
9
10
The example below shows how to get the tensor texture by calling
10
-
`datatoGPU`. Also see this [example code](https://github.com/tensorflow/tfjs-examples/tree/master/gpu-pipeline) for details.
11
+
`dataToGPU`. Also see this [example code](https://github.com/tensorflow/tfjs-examples/tree/master/gpu-pipeline/webgl) for details.
11
12
12
13
```javascript
13
14
// Getting the texture that holds the data on GPU.
@@ -51,3 +52,47 @@ So if a tensor's shape is `[1, height, width, 4]` or `[height, width, 4]`, the w
51
52
downstream processing assumes the texture is an image, it doesn't need to
52
53
do any additional coordination conversion. Each texel is mapped to a [CSS pixel](https://developer.mozilla.org/en-US/docs/Glossary/CSS_pixel) in an image. However, if the tensor has other shapes, downstream
53
54
processing steps may need to reformat the data onto another texture. The `texShape` field has the `[height, width]` information of the texture, which can be used for transformation.
55
+
56
+
# For webgpu backend
57
+
The example below shows how to get the tensor buffer by calling
58
+
`dataToGPU`. Also see this [example code](https://github.com/tensorflow/tfjs-examples/tree/master/gpu-pipeline/webgpu) for details.
59
+
60
+
```javascript
61
+
// Getting the buffer that holds the data on GPU.
62
+
// data has below fields:
63
+
// {buffer, bufSize, tensorRef}
64
+
// buffer: A GPUBuffer.
65
+
// bufSize: the size of the buffer.
66
+
// tensorRef: the tensor associated with the buffer.
67
+
//
68
+
// Unlike webgl backend, There is no parameter for dataToGPU API on the webgpu
69
+
// backend, and the size of returned buffer is the same as the tensor size.
70
+
constdata=tensor.dataToGPU();
71
+
72
+
// Once we have the buffer, we can bind it and pass it to the downstream
73
+
// webgpu processing steps to use the buffer.
74
+
constuniformBindGroup=device.createBindGroup({
75
+
layout:pipeline.getBindGroupLayout(0),
76
+
entries: [
77
+
{
78
+
binding:1,
79
+
resource: {
80
+
buffer:data.buffer,
81
+
size:data.bufSize,
82
+
},
83
+
},
84
+
...
85
+
],
86
+
});
87
+
88
+
// Some webgpu processing steps.
89
+
90
+
// Defines the mapping between resources of all GPUBindGroup objects
91
+
passEncoder.setBindGroup(0, uniformBindGroup);
92
+
93
+
// Some webgpu processing steps.
94
+
95
+
// Remember to dispose the buffer after use, otherwise, there will be
0 commit comments