Skip to content

Commit 6c98a20

Browse files
authored
Fix a TODO for gpu-pipeline (#896)
This patch mainly supports tfjs npm packages for gpu-pipeline webgpu backend, and explicitly uses the size of buffer, which is returned by dataToGPU.
1 parent ca7a661 commit 6c98a20

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

Diff for: gpu-pipeline/webgpu/index.html

+3-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ <h1>A demo of pure webgpu pipeline</h1>
1212
segmentation model</a> from tfjs-models. The output of the model is then fed to
1313
a mask processing step to mask the background with purple. And then the result
1414
is painted on the canvas.
15-
Currently, this example only supports local built tfjs libs, and the local tfjs directory is the same level as tfjs-examples directory.
1615
For details on how to keep the tensor data on GPU, see our [optimization doc](https://github.com/tensorflow/tfjs/blob/master/docs/OPTIMIZATION_PURE_GPU_PIPELINE.md).
1716
</p>
1817
<p>
@@ -25,11 +24,10 @@ <h1>A demo of pure webgpu pipeline</h1>
2524
height: auto;
2625
">
2726
</video>
28-
<!-- TODO(xinghua): Support tfjs npm packages -->
2927
<script src="https://cdnjs.cloudflare.com/ajax/libs/stats.js/r16/Stats.min.js"></script>
30-
<script src="../../../tfjs/dist/bin/tfjs-core/tf-core.js"></script>
31-
<script src="../../../tfjs/dist/bin/tfjs-converter/tf-converter.js"></script>
32-
<script src="../../../tfjs/dist/bin/tfjs-backend-webgpu/tf-backend-webgpu.js"></script>
28+
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-core"></script>
29+
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-converter"></script>
30+
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-webgpu"></script>
3331
<script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/body-segmentation"></script>
3432
<script src="./gpu-shaders.js"></script>
3533
<script src="../ui-util.js"></script>

Diff for: gpu-pipeline/webgpu/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ async function init() {
8585
usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST,
8686
});
8787

88-
device.queue.writeBuffer(sizeParamBuffer, 0, new Int32Array([sizeParams.width, sizeParams.height,]));
88+
device.queue.writeBuffer(sizeParamBuffer, 0, new Int32Array([sizeParams.width, sizeParams.height]));
8989

9090
const predict = async () => {
9191
beginEstimateSegmentationStats();
@@ -113,6 +113,7 @@ async function init() {
113113
binding: 3,
114114
resource: {
115115
buffer: data.buffer,
116+
size: data.bufSize,
116117
},
117118
},
118119
{

0 commit comments

Comments
 (0)