Skip to content

[webgpu] Use different batch command policy to save warmup time #5741

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions tfjs-backend-webgpu/src/backend_webgpu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ export class WebGPUBackend extends KernelBackend {
private querySet: GPUQuerySet;
private fromPixelProgram?: FromPixelsProgram;
private fromPixelImportProgram?: FromPixelsImportProgram;
// For the first execution, we should submit GPU command asap. This can save
// warmup time. For the subsequent execution, the batched GPU command is
// faster.
private warmupDone = false;

constructor(device: GPUDevice, supportTimeQuery = false) {
super();
Expand Down Expand Up @@ -356,6 +360,7 @@ export class WebGPUBackend extends KernelBackend {
// Data is on the CPU.
return info.values;
}
this.warmupDone = true;
const staging = this.acquireBuffer(
info.bufferInfo.byteSize,
GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ);
Expand Down Expand Up @@ -819,8 +824,9 @@ export class WebGPUBackend extends KernelBackend {
this.uniformDisposalQueue.push(uniformInfo);
}

if (env().get('WEBGPU_DEFERRED_SUBMIT_BATCH_SIZE') as
number <= this.dispatchNumberInEncoder) {
if (!this.warmupDone ||
env().get('WEBGPU_DEFERRED_SUBMIT_BATCH_SIZE') as
number <= this.dispatchNumberInEncoder) {
this.submitQueue();
}

Expand Down