mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-01 03:45:06 +00:00
[js/webgpu] Check profilingMode in each run (#16897)
### Description <!-- Describe your changes. --> This PR moves checking profilingMode to each run instead of the initialization stage. In this way, users can start/stop profiling at any time. Otherwise, profiling only take effects at the very beginning and can't be stopped.
This commit is contained in:
parent
3c72f43f78
commit
fa8487ea3a
2 changed files with 10 additions and 7 deletions
|
|
@ -90,10 +90,12 @@ export class WebGpuBackend {
|
|||
computePassEncoder: GPUComputePassEncoder|null = null;
|
||||
pendingDispatchNumber = 0;
|
||||
|
||||
profilingEnabled = false;
|
||||
supportTimestampQuery = false;
|
||||
profilingQuerySet: GPUQuerySet;
|
||||
profilingTimeBase?: bigint;
|
||||
|
||||
env: Env;
|
||||
|
||||
async initialize(env: Env): Promise<void> {
|
||||
if (!navigator.gpu) {
|
||||
// WebGPU is not available.
|
||||
|
|
@ -105,6 +107,7 @@ export class WebGpuBackend {
|
|||
throw new Error('WebGpuBackend: Failed to get GPU adapter.');
|
||||
}
|
||||
|
||||
this.env = env;
|
||||
const deviceDescriptor: GPUDeviceDescriptor = {
|
||||
requiredLimits: {
|
||||
maxComputeWorkgroupStorageSize: adapter.limits.maxComputeWorkgroupStorageSize,
|
||||
|
|
@ -114,8 +117,8 @@ export class WebGpuBackend {
|
|||
};
|
||||
// WebGPU Spec: Timestamp Queries Inside Passes
|
||||
// https://github.com/gpuweb/gpuweb/blob/main/proposals/timestamp-query-inside-passes.md
|
||||
if (adapter.features.has('timestamp-query-inside-passes') && env.webgpu.profilingMode === 'default') {
|
||||
this.profilingEnabled = true;
|
||||
if (adapter.features.has('timestamp-query-inside-passes')) {
|
||||
this.supportTimestampQuery = true;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
deviceDescriptor.requiredFeatures = ['timestamp-query-inside-passes' as any];
|
||||
}
|
||||
|
|
@ -139,7 +142,7 @@ export class WebGpuBackend {
|
|||
}
|
||||
};
|
||||
|
||||
if (this.profilingEnabled) {
|
||||
if (this.supportTimestampQuery) {
|
||||
this.profilingQuerySet = this.device.createQuerySet({
|
||||
type: 'timestamp',
|
||||
count: 2,
|
||||
|
|
|
|||
|
|
@ -33,8 +33,8 @@ export class ProgramManager {
|
|||
run(buildArtifact: Artifact, inputs: GpuData[], outputs: GpuData[], dispatchGroup: [number, number, number]): void {
|
||||
const device = this.backend.device;
|
||||
const computePassEncoder = this.backend.getComputePassEncoder();
|
||||
|
||||
if (this.backend.profilingEnabled) {
|
||||
const profilingEnabled = this.backend.supportTimestampQuery && this.backend.env.webgpu.profilingMode === 'default';
|
||||
if (profilingEnabled) {
|
||||
// profiling write start timestamp
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
|
|
@ -56,7 +56,7 @@ export class ProgramManager {
|
|||
|
||||
this.backend.pendingDispatchNumber++;
|
||||
|
||||
if (this.backend.profilingEnabled) {
|
||||
if (profilingEnabled) {
|
||||
// profiling write end timestamp
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
|
|
|
|||
Loading…
Reference in a new issue