-
Notifications
You must be signed in to change notification settings - Fork 2k
Closed
Labels
type:featureNew feature or requestNew feature or request
Description
Hi. I have this scenario of invoking tfjs operations functions for processing GPU resource, for example, invoking tf.add(a, b) with gpuBufferA and gpuBufferB by WebGPU backend.
Current my workaround likes:
// Get TypedArray f32ArrayA
const readbackBufferA = gpuDevice.createBuffer({size: sizeInBytes, usage: GPUBufferUsage.MAP_READ | GPUBufferUsage.COPY_DST});
const readbackEncoder = gpuDevice.createCommandEncoder();
readbackEncoder.copyBufferToBuffer(gpuBufferA, 0, readbackBufferA, 0, sizeInBytes);
device.queue.submit([readbackEncoder.finish()]);
readbackBufferA.mapAsync(GPUMapMode.READ);
const f32ArrayA = new Float32Array(readbackBufferA.getMappedRange());
// Same to get f32ArrayB
...
const f32ArrayB = new Float32Array(readbackBufferB.getMappedRange());
// Invoke tf.add()
const result = tf.add(f32ArrayA, f32ArrayB);I don't think it's good on memory copy / performance.
Is there any efficient solution for this scenario? Any suggestion? Thanks.
Metadata
Metadata
Assignees
Labels
type:featureNew feature or requestNew feature or request