Skip to content

Commit

Permalink
webgpu: Fix timestamp query (tensorflow#7723)
Browse files Browse the repository at this point in the history
If a pass that needs timestamp query follows a pass without timestamp
query, querySet may not be created as expected. This PR fixes this
issue.
  • Loading branch information
Yang Gu authored May 29, 2023
1 parent 80d4526 commit 428e55b
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions tfjs-backend-webgpu/src/backend_webgpu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -950,28 +950,30 @@ export class WebGPUBackend extends KernelBackend {
const shouldTimeProgram = this.activeTimers != null;
this.ensureCommandEncoderReady();

if (!this.computePassEncoder) {
const computePassDescriptor: GPUComputePassDescriptor = {};
if (shouldTimeProgram && this.supportTimestampQuery) {
if (this.querySet == null) {
this.querySet = this.device.createQuerySet({
type: 'timestamp',
count: this.querySetCount,
});
}
computePassDescriptor.timestampWrites = [
{
querySet: this.querySet,
queryIndex: 0,
location: 'beginning',
},
{
querySet: this.querySet,
queryIndex: 1,
location: 'end',
}
];
const computePassDescriptor: GPUComputePassDescriptor = {};
if (shouldTimeProgram && this.supportTimestampQuery) {
this.endComputePassEncoder();
if (this.querySet == null) {
this.querySet = this.device.createQuerySet({
type: 'timestamp',
count: this.querySetCount,
});
}
computePassDescriptor.timestampWrites = [
{
querySet: this.querySet,
queryIndex: 0,
location: 'beginning',
},
{
querySet: this.querySet,
queryIndex: 1,
location: 'end',
}
];
this.computePassEncoder =
this.commandEncoder.beginComputePass(computePassDescriptor);
} else if (!this.computePassEncoder) {
this.computePassEncoder =
this.commandEncoder.beginComputePass(computePassDescriptor);
}
Expand Down

0 comments on commit 428e55b

Please sign in to comment.