Skip to content

Commit

Permalink
[js/webgpu] Fix issue of timestamp query (#19258)
Browse files Browse the repository at this point in the history
When we enable webgpu profiling mode between session.create and
session.run, current implementation has a problem to create querySet
(and also queryResolveBuffer) if we share the commandEncoder with inputs
upload. This PR fixes this by moving the querySet creation to the place
we set queryType.
  • Loading branch information
gyagp committed Jan 24, 2024
1 parent bc54ad3 commit 591f90c
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions js/web/lib/wasm/jsep/backend-webgpu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,16 +222,6 @@ export class WebGpuBackend {
getCommandEncoder(): GPUCommandEncoder {
if (!this.commandEncoder) {
this.commandEncoder = this.device.createCommandEncoder();

if (this.queryType !== 'none' && typeof this.querySet === 'undefined') {
this.querySet = this.device.createQuerySet({
type: 'timestamp',
count: this.maxDispatchNumber * 2,
});
this.queryResolveBuffer = this.device.createBuffer(
// eslint-disable-next-line no-bitwise
{size: this.maxDispatchNumber * 2 * 8, usage: GPUBufferUsage.COPY_SRC | GPUBufferUsage.QUERY_RESOLVE});
}
}
return this.commandEncoder;
}
Expand Down Expand Up @@ -654,6 +644,16 @@ export class WebGpuBackend {
} else if (this.device.features.has('timestamp-query')) {
this.queryType = 'at-passes';
}

if (this.queryType !== 'none' && typeof this.querySet === 'undefined') {
this.querySet = this.device.createQuerySet({
type: 'timestamp',
count: this.maxDispatchNumber * 2,
});
this.queryResolveBuffer = this.device.createBuffer(
// eslint-disable-next-line no-bitwise
{size: this.maxDispatchNumber * 2 * 8, usage: GPUBufferUsage.COPY_SRC | GPUBufferUsage.QUERY_RESOLVE});
}
}
}
onRunStart(): void {
Expand Down

0 comments on commit 591f90c

Please sign in to comment.