doppler-gpu 0.4.15 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -0
- package/package.json +25 -2
- package/src/cli/doppler-cli.js +253 -94
- package/src/cli/runtime-profiles.js +3 -7
- package/src/client/doppler-api.d.ts +28 -0
- package/src/client/doppler-api.js +2 -0
- package/src/client/inspection.d.ts +122 -0
- package/src/client/inspection.js +343 -0
- package/src/client/runtime/index.d.ts +54 -0
- package/src/client/runtime/index.js +190 -18
- package/src/client/runtime/model-manager.d.ts +0 -4
- package/src/client/runtime/model-manager.js +0 -28
- package/src/client/runtime/model-session.d.ts +48 -1
- package/src/client/runtime/model-session.js +149 -30
- package/src/client/runtime/model-source.d.ts +10 -1
- package/src/client/runtime/scoped-session.d.ts +117 -0
- package/src/client/runtime/scoped-session.js +257 -0
- package/src/client/runtime/types.d.ts +0 -1
- package/src/client/runtime/types.js +0 -1
- package/src/config/evidence/boundary-evidence-policy.json +54 -0
- package/src/config/evidence/source-intake-policy.json +122 -0
- package/src/config/inspection/observation-policies.json +80 -0
- package/src/config/param-validator.js +21 -36
- package/src/config/runtime/compute/f16-activations.json +1 -0
- package/src/config/runtime/compute/f16-batched.json +1 -0
- package/src/config/runtime/default.json +1 -0
- package/src/config/runtime/diagnostics/debug-logits.json +1 -0
- package/src/config/runtime/experiments/bench/gemma3-bench-q4k-alt.json +1 -0
- package/src/config/runtime/experiments/bench/gemma3-bench-q4k-batched.json +1 -0
- package/src/config/runtime/experiments/bench/gemma3-bench-q4k.json +1 -0
- package/src/config/runtime/experiments/bench/gemma4-bench-q4k.json +1 -0
- package/src/config/runtime/experiments/bench/qwen3-bench-q4k-alt.json +1 -0
- package/src/config/runtime/experiments/bench/qwen3-bench-q4k-batched.json +1 -0
- package/src/config/runtime/experiments/debug/gemma3-browser-diagnose-q4k.json +1 -1
- package/src/config/runtime/experiments/debug/gemma3-debug-q4k.json +1 -3
- package/src/config/runtime/experiments/debug/gemma4-e2b-browser-diagnose-q4k.json +1 -1
- package/src/config/runtime/experiments/debug/qwen35-browser-diagnose-q4k.json +1 -1
- package/src/config/runtime/experiments/verify/gemma3-verify.json +1 -3
- package/src/config/runtime/experiments/verify/gemma4-e2b-verify.json +1 -3
- package/src/config/runtime/experiments/verify/lfm2-verify.json +1 -3
- package/src/config/runtime/experiments/verify/translategemma-verify.json +1 -3
- package/src/config/runtime/model/gemma2-debug.json +1 -0
- package/src/config/runtime/model/gemma2-pipeline-debug.json +1 -0
- package/src/config/runtime/model/gemma2-pipeline.json +1 -0
- package/src/config/runtime/model/gemma3-layer-probe.json +1 -0
- package/src/config/runtime/model/qwen3-5-layer-probe.json +1 -0
- package/src/config/runtime/model/qwen3-5-layer3-boundary-probe.json +1 -0
- package/src/config/runtime/model/qwen3-5-linear-attn-debug.json +1 -0
- package/src/config/runtime/optimization-candidates/registry.json +5 -0
- package/src/config/runtime/platform/metal-apple-q4k.json +1 -0
- package/src/config/runtime/profiles/default.json +1 -0
- package/src/config/runtime/profiles/diffusiongemma-26b-a4b-throughput.json +1 -0
- package/src/config/runtime/profiles/gemma3-270m-q4k-throughput-overlapped-probe.json +1 -0
- package/src/config/runtime/profiles/gemma3-270m-q4k-throughput-probe.json +1 -0
- package/src/config/runtime/profiles/gemma4-12b-rdrr-safe-b4.json +1 -3
- package/src/config/runtime/profiles/gemma4-12b-rdrr-safe-single.json +1 -3
- package/src/config/runtime/profiles/gemma4-31b-f16-activations-probe.json +1 -5
- package/src/config/runtime/profiles/gemma4-e2b-baseline-probe.json +1 -3
- package/src/config/runtime/profiles/gemma4-e2b-fused-rmsnorm-probe.json +1 -3
- package/src/config/runtime/profiles/gemma4-e2b-fused-rmsnorm-test.json +1 -0
- package/src/config/runtime/profiles/gemma4-e2b-int4ple-baseline-probe.json +1 -5
- package/src/config/runtime/profiles/gemma4-e2b-int4ple-f16a-probe.json +1 -5
- package/src/config/runtime/profiles/gemma4-e2b-int4ple-reference-export.json +1 -3
- package/src/config/runtime/profiles/gemma4-e2b-int4ple-retain-q4k-probe.json +1 -5
- package/src/config/runtime/profiles/gemma4-e2b-low-memory.json +1 -0
- package/src/config/runtime/profiles/gemma4-e2b-prefill-profile.json +1 -3
- package/src/config/runtime/profiles/gemma4-e2b-throughput-probe.json +1 -0
- package/src/config/runtime/profiles/low-memory.json +1 -0
- package/src/config/runtime/profiles/production.json +1 -3
- package/src/config/runtime/profiles/qwen-3-5-0-8b-metal-attn128-candidate.json +1 -0
- package/src/config/runtime/profiles/qwen-3-5-0-8b-metal-maxbatch64-candidate.json +1 -0
- package/src/config/runtime/profiles/qwen-3-5-0-8b-metal-normed-ffn-candidate.json +1 -0
- package/src/config/runtime/profiles/qwen-3-5-0-8b-metal-overlap-ringtokens1-candidate.json +1 -0
- package/src/config/runtime/profiles/qwen-3-5-0-8b-metal-parity.json +1 -0
- package/src/config/runtime/profiles/qwen-3-5-0-8b-metal-sequential-candidate.json +1 -0
- package/src/config/runtime/profiles/qwen-3-5-0-8b-metal-throughput.json +1 -0
- package/src/config/runtime/profiles/qwen-3-5-0-8b-prefill-profile.json +1 -3
- package/src/config/runtime/profiles/qwen-3-5-0-8b-throughput-probe.json +1 -0
- package/src/config/runtime/profiles/qwen-3-5-2b-f16-primary-throughput.json +1 -5
- package/src/config/runtime/profiles/qwen-3-5-2b-metal-parity.json +1 -0
- package/src/config/runtime/profiles/qwen-3-5-2b-metal-throughput.json +1 -0
- package/src/config/runtime/profiles/qwen-3-5-9b-metal-correctness.json +1 -0
- package/src/config/runtime/profiles/qwen-3-embedding-0-6b-metal-stability.json +1 -3
- package/src/config/runtime/profiles/qwen-3-embedding-0-6b-metal-throughput.json +1 -0
- package/src/config/runtime/profiles/qwen-3-reranker-0-6b-metal-stability.json +1 -0
- package/src/config/runtime/profiles/qwen-3-reranker-0-6b-metal-throughput.json +1 -0
- package/src/config/runtime/profiles/qwen3-6-27b-f16-activations-probe.json +1 -5
- package/src/config/runtime/profiles/rerank-stability.json +1 -3
- package/src/config/runtime/profiles/rerank-throughput.json +1 -3
- package/src/config/runtime/profiles/simulation.json +1 -3
- package/src/config/runtime/profiles/throughput.json +1 -3
- package/src/config/runtime/profiles/trace-layers.json +1 -3
- package/src/config/runtime/profiles/translategemma-1b-nativekd2-q4k-rdna3-throughput-probe.json +1 -0
- package/src/config/runtime/profiles/turboquant-contiguous-prod.json +1 -0
- package/src/config/runtime/profiles/turboquant-contiguous.json +1 -0
- package/src/config/runtime/profiles/turboquant.json +1 -0
- package/src/config/runtime/profiles/vector-stability.json +1 -3
- package/src/config/runtime/profiles/vector-throughput.json +1 -0
- package/src/config/runtime/profiles/verbose-trace.json +1 -3
- package/src/config/runtime/tiers/gemma4-128gb.json +1 -0
- package/src/config/runtime/tiers/gemma4-16gb.json +1 -0
- package/src/config/runtime/tiers/gemma4-24gb.json +1 -0
- package/src/config/runtime/tiers/gemma4-32gb.json +1 -0
- package/src/config/schema/benchmark.schema.d.ts +7 -0
- package/src/config/schema/benchmark.schema.js +5 -0
- package/src/config/schema/index.d.ts +8 -16
- package/src/config/schema/index.js +5 -8
- package/src/config/schema/kernel-thresholds.schema.d.ts +0 -12
- package/src/config/schema/kernel-thresholds.schema.js +0 -12
- package/src/config/schema/kernel-warmup.schema.d.ts +1 -3
- package/src/config/schema/kernel-warmup.schema.js +0 -1
- package/src/config/schema/runtime-profile.schema.d.ts +24 -0
- package/src/config/schema/runtime-profile.schema.js +92 -0
- package/src/config/schema/shared-runtime.schema.d.ts +1 -4
- package/src/config/schema/shared-runtime.schema.js +0 -2
- package/src/config/schema/tooling.schema.d.ts +8 -5
- package/src/config/schema/tooling.schema.js +3 -2
- package/src/debug/tensor.d.ts +2 -0
- package/src/debug/tensor.js +21 -2
- package/src/gpu/command-recorder.d.ts +5 -0
- package/src/gpu/command-recorder.js +17 -0
- package/src/gpu/kernel-runtime.js +2 -10
- package/src/gpu/kernels/index.d.ts +0 -2
- package/src/gpu/kernels/index.js +0 -2
- package/src/gpu/kernels/kernel-prewarm.d.ts +3 -0
- package/src/gpu/kernels/kernel-prewarm.js +60 -0
- package/src/gpu/kernels/utils.d.ts +2 -4
- package/src/gpu/kernels/utils.js +2 -4
- package/src/index.d.ts +13 -1
- package/src/index.js +7 -1
- package/src/inference/browser-harness-model-helpers.js +4 -0
- package/src/inference/browser-harness-runtime-helpers.js +25 -10
- package/src/inference/browser-harness-text-helpers.js +4 -1
- package/src/inference/browser-harness.d.ts +4 -0
- package/src/inference/browser-harness.js +91 -4
- package/src/inference/observation-context.d.ts +22 -0
- package/src/inference/observation-context.js +41 -0
- package/src/inference/pipelines/text/attention/attn-config.js +1 -1
- package/src/inference/pipelines/text/attention/executor-immediate.js +42 -0
- package/src/inference/pipelines/text/attention/executor-recorded.js +29 -0
- package/src/inference/pipelines/text/attention/index.js +7 -0
- package/src/inference/pipelines/text/attention/interpreter.js +1334 -0
- package/src/inference/pipelines/text/attention/plan.d.ts +36 -0
- package/src/inference/pipelines/text/attention/plan.js +328 -0
- package/src/inference/pipelines/text/attention/receipt.js +60 -0
- package/src/inference/pipelines/text/attention/record.js +8 -1278
- package/src/inference/pipelines/text/attention/run.js +8 -1386
- package/src/inference/pipelines/text/generator-decode-policy.js +4 -1
- package/src/inference/pipelines/text/generator-helpers.js +2 -0
- package/src/inference/pipelines/text/generator-steps.js +32 -15
- package/src/inference/pipelines/text/generator.js +10 -5
- package/src/inference/pipelines/text/init.d.ts +3 -0
- package/src/inference/pipelines/text/layer-plan-gpu.js +2 -0
- package/src/inference/pipelines/text/layer.js +2 -0
- package/src/inference/pipelines/text/model-load.d.ts +0 -1
- package/src/inference/pipelines/text/model-load.js +2 -11
- package/src/inference/pipelines/text/probes.js +10 -0
- package/src/inference/pipelines/text/resolved-runtime-session.d.ts +56 -0
- package/src/inference/pipelines/text/resolved-runtime-session.js +175 -0
- package/src/inference/pipelines/text/state.d.ts +6 -0
- package/src/inference/pipelines/text/state.js +3 -0
- package/src/inference/pipelines/text/types.d.ts +6 -0
- package/src/inference/pipelines/text.js +16 -1
- package/src/inference/refactor-receipt.d.ts +49 -0
- package/src/inference/refactor-receipt.js +188 -0
- package/src/inference/resource-scope.d.ts +33 -0
- package/src/inference/resource-scope.js +168 -0
- package/src/inference/test-harness.d.ts +3 -0
- package/src/inference/test-harness.js +1 -0
- package/src/storage/model-cache.d.ts +53 -0
- package/src/storage/model-cache.js +550 -0
- package/src/tooling/boundary-evidence.d.ts +51 -0
- package/src/tooling/boundary-evidence.js +408 -0
- package/src/tooling/browser-command-runner.js +4 -4
- package/src/tooling/command-context.d.ts +25 -0
- package/src/tooling/command-context.js +53 -0
- package/src/tooling/command-runner-shared.js +22 -5
- package/src/tooling/demo-receipts.d.ts +56 -0
- package/src/tooling/demo-receipts.js +113 -0
- package/src/tooling/diagnose-runner.js +2 -2
- package/src/tooling/execution-cost-ledger.d.ts +21 -0
- package/src/tooling/execution-cost-ledger.js +199 -0
- package/src/tooling/node-command-runner.js +2 -2
- package/src/tooling/opfs-cache.d.ts +11 -49
- package/src/tooling/opfs-cache.js +4 -510
- package/src/tooling/precision-replay-math.d.ts +42 -0
- package/src/tooling/precision-replay-math.js +174 -0
- package/src/tooling/program-bundle-parity.d.ts +3 -0
- package/src/tooling/program-bundle-parity.js +8 -0
- package/src/tooling/program-bundle.d.ts +1 -52
- package/src/tooling/program-bundle.js +0 -139
- package/src/tooling/registered-variant-calibration.d.ts +24 -0
- package/src/tooling/registered-variant-calibration.js +286 -0
- package/src/tooling/runtime-input-composition.js +105 -53
- package/src/tooling/runtime-intent.js +41 -0
- package/src/tooling/runtime-optimization-index.d.ts +6 -0
- package/src/tooling/runtime-optimization-index.js +72 -0
- package/src/tooling/runtime-optimization.d.ts +47 -6
- package/src/tooling/runtime-optimization.js +559 -40
- package/src/tooling/source-intake.d.ts +49 -0
- package/src/tooling/source-intake.js +414 -0
- package/src/tooling-exports/evidence.d.ts +34 -0
- package/src/tooling-exports/evidence.js +34 -0
- package/src/tooling-exports/runtime.d.ts +7 -0
- package/src/tooling-exports/runtime.js +7 -0
- package/src/tooling-exports.d.ts +11 -0
- package/src/tooling-exports.js +6 -3
- package/src/tooling-exports.shared.d.ts +32 -0
- package/src/tooling-exports.shared.js +31 -0
- package/src/version.js +1 -1
- package/src/config/schema/tuner.schema.d.ts +0 -39
- package/src/config/schema/tuner.schema.js +0 -13
- package/src/gpu/kernel-tuner/benchmarks.js +0 -902
- package/src/gpu/kernel-tuner/cache.js +0 -145
- package/src/gpu/kernel-tuner/index.js +0 -38
- package/src/gpu/kernel-tuner/tuner.js +0 -247
- package/src/gpu/kernel-tuner.js +0 -12
- package/src/gpu/kernels/kernel-tuning.d.ts +0 -42
- package/src/gpu/kernels/kernel-tuning.js +0 -158
- package/src/gpu/profiler.js +0 -382
- package/src/inference/pipelines/text/attention/output-gate-fusion.js +0 -37
package/src/gpu/profiler.js
DELETED
|
@@ -1,382 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { getDevice, hasFeature, FEATURES } from './device.js';
|
|
4
|
-
import { allowReadback } from './perf-guards.js';
|
|
5
|
-
import { log } from '../debug/index.js';
|
|
6
|
-
import { getRuntimeConfig } from '../config/runtime.js';
|
|
7
|
-
import { computeBasicStats } from '../debug/stats.js';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
export class GPUProfiler {
|
|
19
|
-
|
|
20
|
-
#device;
|
|
21
|
-
|
|
22
|
-
#hasTimestampQuery;
|
|
23
|
-
|
|
24
|
-
// Query set for timestamp queries (if supported)
|
|
25
|
-
|
|
26
|
-
#querySet = null;
|
|
27
|
-
|
|
28
|
-
#queryBuffer = null;
|
|
29
|
-
|
|
30
|
-
#readbackBuffer = null;
|
|
31
|
-
|
|
32
|
-
#queryCapacity = 0;
|
|
33
|
-
|
|
34
|
-
#maxSamples = 0;
|
|
35
|
-
|
|
36
|
-
#maxDurationMs = 0;
|
|
37
|
-
|
|
38
|
-
// Maximum number of distinct labels tracked before oldest are evicted
|
|
39
|
-
#maxHistoryLabels = 0;
|
|
40
|
-
|
|
41
|
-
// Tracking state
|
|
42
|
-
|
|
43
|
-
#activeLabels = new Map();
|
|
44
|
-
|
|
45
|
-
#nextQueryIndex = 0;
|
|
46
|
-
|
|
47
|
-
#pendingResolves = [];
|
|
48
|
-
|
|
49
|
-
// Results storage
|
|
50
|
-
|
|
51
|
-
#results = new Map();
|
|
52
|
-
|
|
53
|
-
// CPU fallback timing
|
|
54
|
-
|
|
55
|
-
#cpuTimings = new Map();
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
constructor(device = null) {
|
|
59
|
-
this.#device = device || getDevice();
|
|
60
|
-
this.#hasTimestampQuery = this.#device?.features?.has(FEATURES.TIMESTAMP_QUERY) ?? false;
|
|
61
|
-
const runtimeProfiler = getRuntimeConfig().shared?.debug?.profiler;
|
|
62
|
-
if (!runtimeProfiler) {
|
|
63
|
-
throw new Error('runtime.shared.debug.profiler is required.');
|
|
64
|
-
}
|
|
65
|
-
this.#queryCapacity = runtimeProfiler.queryCapacity;
|
|
66
|
-
this.#maxSamples = runtimeProfiler.maxSamples;
|
|
67
|
-
this.#maxDurationMs = runtimeProfiler.maxDurationMs;
|
|
68
|
-
this.#maxHistoryLabels = requirePositiveInteger(
|
|
69
|
-
runtimeProfiler.maxHistoryLabels,
|
|
70
|
-
'runtime.shared.debug.profiler.maxHistoryLabels'
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
// Initialize query resources if timestamp queries available
|
|
74
|
-
if (this.#hasTimestampQuery && this.#device) {
|
|
75
|
-
this.#initQueryResources();
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
#initQueryResources() {
|
|
81
|
-
if (!this.#device) return;
|
|
82
|
-
|
|
83
|
-
try {
|
|
84
|
-
this.#querySet = this.#device.createQuerySet({
|
|
85
|
-
type: 'timestamp',
|
|
86
|
-
count: this.#queryCapacity * 2, // Start and end for each measurement
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
// Buffer to hold query results (8 bytes per timestamp)
|
|
90
|
-
this.#queryBuffer = this.#device.createBuffer({
|
|
91
|
-
size: this.#queryCapacity * 2 * 8,
|
|
92
|
-
usage: GPUBufferUsage.QUERY_RESOLVE | GPUBufferUsage.COPY_SRC,
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
// Readback buffer
|
|
96
|
-
this.#readbackBuffer = this.#device.createBuffer({
|
|
97
|
-
size: this.#queryCapacity * 2 * 8,
|
|
98
|
-
usage: GPUBufferUsage.MAP_READ | GPUBufferUsage.COPY_DST,
|
|
99
|
-
});
|
|
100
|
-
} catch (e) {
|
|
101
|
-
log.warn('GPUProfiler', `Failed to create timestamp query resources: ${e}`);
|
|
102
|
-
this.#hasTimestampQuery = false;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
begin(label) {
|
|
108
|
-
if (this.#activeLabels.has(label)) {
|
|
109
|
-
log.warn('GPUProfiler', `Label "${label}" already active`);
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const startTime = performance.now();
|
|
114
|
-
|
|
115
|
-
// CPU timing for begin/end; GPU timestamps require writeTimestamp() in a pass.
|
|
116
|
-
this.#activeLabels.set(label, {
|
|
117
|
-
cpuStartTime: startTime,
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
end(label) {
|
|
123
|
-
const active = this.#activeLabels.get(label);
|
|
124
|
-
if (!active) {
|
|
125
|
-
log.warn('GPUProfiler', `No active measurement for label "${label}"`);
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const endTime = performance.now();
|
|
130
|
-
this.#activeLabels.delete(label);
|
|
131
|
-
|
|
132
|
-
if (this.#hasTimestampQuery && 'startQueryIndex' in active) {
|
|
133
|
-
// GPU timing will be resolved later
|
|
134
|
-
this.#pendingResolves.push({
|
|
135
|
-
label,
|
|
136
|
-
startIndex: active.startQueryIndex,
|
|
137
|
-
endIndex: active.startQueryIndex + 1,
|
|
138
|
-
cpuStartTime: active.cpuStartTime,
|
|
139
|
-
cpuEndTime: endTime,
|
|
140
|
-
});
|
|
141
|
-
} else {
|
|
142
|
-
// CPU fallback - record immediately
|
|
143
|
-
this.#recordResult(label, endTime - active.cpuStartTime);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
writeTimestamp(pass, label, isEnd = false) {
|
|
149
|
-
if (!this.#hasTimestampQuery || !this.#querySet) return;
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
let queryIndex;
|
|
153
|
-
if (!isEnd) {
|
|
154
|
-
// Start timestamp
|
|
155
|
-
queryIndex = this.#nextQueryIndex;
|
|
156
|
-
this.#nextQueryIndex += 2;
|
|
157
|
-
this.#activeLabels.set(label, {
|
|
158
|
-
startQueryIndex: queryIndex,
|
|
159
|
-
cpuStartTime: performance.now(),
|
|
160
|
-
});
|
|
161
|
-
} else {
|
|
162
|
-
// End timestamp
|
|
163
|
-
const active = this.#activeLabels.get(label);
|
|
164
|
-
if (!active || !('startQueryIndex' in active)) return;
|
|
165
|
-
queryIndex = active.startQueryIndex + 1;
|
|
166
|
-
this.#activeLabels.delete(label);
|
|
167
|
-
this.#pendingResolves.push({
|
|
168
|
-
label,
|
|
169
|
-
startIndex: active.startQueryIndex,
|
|
170
|
-
endIndex: queryIndex,
|
|
171
|
-
cpuStartTime: active.cpuStartTime,
|
|
172
|
-
cpuEndTime: performance.now(),
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// Note: writeTimestamp is deprecated in modern WebGPU spec but still works in Chrome
|
|
177
|
-
// Future: migrate to timestampWrites in GPUComputePassDescriptor
|
|
178
|
-
(pass).writeTimestamp(this.#querySet, queryIndex);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
async resolve() {
|
|
183
|
-
if (!this.#hasTimestampQuery || this.#pendingResolves.length === 0) {
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
if (!this.#device || !this.#querySet || !this.#queryBuffer || !this.#readbackBuffer) {
|
|
188
|
-
log.warn('GPUProfiler', 'Missing required resources for resolve');
|
|
189
|
-
this.#pendingResolves = [];
|
|
190
|
-
this.#nextQueryIndex = 0;
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
const encoder = this.#device.createCommandEncoder();
|
|
195
|
-
|
|
196
|
-
// Resolve all timestamps to buffer
|
|
197
|
-
const maxIndex = Math.max(...this.#pendingResolves.map(p => p.endIndex)) + 1;
|
|
198
|
-
encoder.resolveQuerySet(this.#querySet, 0, maxIndex, this.#queryBuffer, 0);
|
|
199
|
-
|
|
200
|
-
// Copy to readback buffer
|
|
201
|
-
encoder.copyBufferToBuffer(
|
|
202
|
-
this.#queryBuffer,
|
|
203
|
-
0,
|
|
204
|
-
this.#readbackBuffer,
|
|
205
|
-
0,
|
|
206
|
-
maxIndex * 8
|
|
207
|
-
);
|
|
208
|
-
|
|
209
|
-
this.#device.queue.submit([encoder.finish()]);
|
|
210
|
-
|
|
211
|
-
let mapped = false;
|
|
212
|
-
|
|
213
|
-
try {
|
|
214
|
-
if (!allowReadback('GPUProfiler.resolve')) {
|
|
215
|
-
return;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
await this.#readbackBuffer.mapAsync(GPUMapMode.READ);
|
|
219
|
-
mapped = true;
|
|
220
|
-
const timestamps = new BigUint64Array(this.#readbackBuffer.getMappedRange());
|
|
221
|
-
|
|
222
|
-
for (const pending of this.#pendingResolves) {
|
|
223
|
-
const startNs = timestamps[pending.startIndex];
|
|
224
|
-
const endNs = timestamps[pending.endIndex];
|
|
225
|
-
const durationMs = Number(endNs - startNs) / 1_000_000;
|
|
226
|
-
|
|
227
|
-
if (durationMs < 0 || durationMs > this.#maxDurationMs) {
|
|
228
|
-
this.#recordResult(pending.label, pending.cpuEndTime - pending.cpuStartTime);
|
|
229
|
-
} else {
|
|
230
|
-
this.#recordResult(pending.label, durationMs);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
} finally {
|
|
234
|
-
if (mapped) {
|
|
235
|
-
this.#readbackBuffer.unmap();
|
|
236
|
-
}
|
|
237
|
-
this.#pendingResolves = [];
|
|
238
|
-
this.#nextQueryIndex = 0;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
#recordResult(label, timeMs) {
|
|
244
|
-
if (!this.#results.has(label)) {
|
|
245
|
-
// Evict oldest labels when history exceeds the configured limit.
|
|
246
|
-
// Map iteration order is insertion order, so the first key is the oldest.
|
|
247
|
-
while (this.#results.size >= this.#maxHistoryLabels) {
|
|
248
|
-
const oldest = this.#results.keys().next().value;
|
|
249
|
-
this.#results.delete(oldest);
|
|
250
|
-
}
|
|
251
|
-
this.#results.set(label, {
|
|
252
|
-
times: [],
|
|
253
|
-
min: Infinity,
|
|
254
|
-
max: -Infinity,
|
|
255
|
-
sum: 0,
|
|
256
|
-
count: 0,
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
const result = this.#results.get(label);
|
|
261
|
-
result.times.push(timeMs);
|
|
262
|
-
result.min = Math.min(result.min, timeMs);
|
|
263
|
-
result.max = Math.max(result.max, timeMs);
|
|
264
|
-
result.sum += timeMs;
|
|
265
|
-
result.count++;
|
|
266
|
-
|
|
267
|
-
// Keep only last N samples for running average
|
|
268
|
-
if (result.times.length > this.#maxSamples) {
|
|
269
|
-
const removed = result.times.shift();
|
|
270
|
-
result.sum -= removed;
|
|
271
|
-
result.count--;
|
|
272
|
-
// Recalculate min/max if needed (expensive, so only do occasionally)
|
|
273
|
-
if (result.times.length % 20 === 0) {
|
|
274
|
-
result.min = Math.min(...result.times);
|
|
275
|
-
result.max = Math.max(...result.times);
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
getResults() {
|
|
282
|
-
|
|
283
|
-
const output = {};
|
|
284
|
-
|
|
285
|
-
for (const [label, data] of this.#results) {
|
|
286
|
-
const stats = computeBasicStats(data.times);
|
|
287
|
-
output[label] = {
|
|
288
|
-
avg: stats.mean,
|
|
289
|
-
min: stats.min,
|
|
290
|
-
max: stats.max,
|
|
291
|
-
count: stats.count,
|
|
292
|
-
total: stats.total,
|
|
293
|
-
};
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
return output;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
getResult(label) {
|
|
301
|
-
const data = this.#results.get(label);
|
|
302
|
-
if (!data) return null;
|
|
303
|
-
|
|
304
|
-
const stats = computeBasicStats(data.times);
|
|
305
|
-
return {
|
|
306
|
-
avg: stats.mean,
|
|
307
|
-
min: stats.min,
|
|
308
|
-
max: stats.max,
|
|
309
|
-
count: stats.count,
|
|
310
|
-
total: stats.total,
|
|
311
|
-
};
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
reset() {
|
|
316
|
-
this.#results.clear();
|
|
317
|
-
this.#activeLabels.clear();
|
|
318
|
-
this.#pendingResolves = [];
|
|
319
|
-
this.#nextQueryIndex = 0;
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
getReport() {
|
|
324
|
-
const results = this.getResults();
|
|
325
|
-
const labels = Object.keys(results).sort();
|
|
326
|
-
|
|
327
|
-
if (labels.length === 0) {
|
|
328
|
-
return 'No profiling data collected';
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
let report = 'GPU Profiler Results\n';
|
|
332
|
-
report += '\u2500'.repeat(60) + '\n';
|
|
333
|
-
report += 'Label'.padEnd(30) + 'Avg (ms)'.padStart(10) + 'Min'.padStart(10) + 'Max'.padStart(10) + '\n';
|
|
334
|
-
report += '\u2500'.repeat(60) + '\n';
|
|
335
|
-
|
|
336
|
-
for (const label of labels) {
|
|
337
|
-
const r = results[label];
|
|
338
|
-
report += label.padEnd(30);
|
|
339
|
-
report += r.avg.toFixed(3).padStart(10);
|
|
340
|
-
report += r.min.toFixed(3).padStart(10);
|
|
341
|
-
report += r.max.toFixed(3).padStart(10);
|
|
342
|
-
report += '\n';
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
return report;
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
isGPUTimingAvailable() {
|
|
350
|
-
return this.#hasTimestampQuery;
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
destroy() {
|
|
355
|
-
if (this.#querySet) {
|
|
356
|
-
this.#querySet.destroy();
|
|
357
|
-
this.#querySet = null;
|
|
358
|
-
}
|
|
359
|
-
if (this.#queryBuffer) {
|
|
360
|
-
this.#queryBuffer.destroy();
|
|
361
|
-
this.#queryBuffer = null;
|
|
362
|
-
}
|
|
363
|
-
if (this.#readbackBuffer) {
|
|
364
|
-
this.#readbackBuffer.destroy();
|
|
365
|
-
this.#readbackBuffer = null;
|
|
366
|
-
}
|
|
367
|
-
this.#results.clear();
|
|
368
|
-
this.#activeLabels.clear();
|
|
369
|
-
this.#pendingResolves = [];
|
|
370
|
-
this.#nextQueryIndex = 0;
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
function requirePositiveInteger(value, label) {
|
|
375
|
-
if (!Number.isInteger(value) || value <= 0) {
|
|
376
|
-
throw new Error(`${label} must be a positive integer.`);
|
|
377
|
-
}
|
|
378
|
-
return value;
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
export default GPUProfiler;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
function kernelPathUsesHead256DecodeAttention(kernelPath) {
|
|
2
|
-
const steps = kernelPath?.decode?.steps;
|
|
3
|
-
if (!Array.isArray(steps)) return false;
|
|
4
|
-
return steps.some((step) => (
|
|
5
|
-
step?.op === 'attention'
|
|
6
|
-
&& step?.kernel === 'attention_decode_online_head256_f16kv_output_gate.wgsl'
|
|
7
|
-
&& (step?.entry === undefined || step.entry === 'main')
|
|
8
|
-
));
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
function tensorElementCount(tensor) {
|
|
12
|
-
if (!Array.isArray(tensor?.shape)) return null;
|
|
13
|
-
return tensor.shape.reduce((total, value) => total * value, 1);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function canUseAttentionOutputGateFusion(options = {}) {
|
|
17
|
-
const {
|
|
18
|
-
session,
|
|
19
|
-
qGateTensor,
|
|
20
|
-
numTokens,
|
|
21
|
-
numHeads,
|
|
22
|
-
headDim,
|
|
23
|
-
cachedKDtype,
|
|
24
|
-
cachedVDtype,
|
|
25
|
-
kernelPath,
|
|
26
|
-
diffusionGemmaDecoder,
|
|
27
|
-
} = options;
|
|
28
|
-
if (diffusionGemmaDecoder === true) return false;
|
|
29
|
-
if (session?.attentionDecodeOnline?.useOutputGateFusion !== true) return false;
|
|
30
|
-
if (!qGateTensor?.buffer || qGateTensor.dtype !== 'f32') return false;
|
|
31
|
-
if (numTokens !== 1 || headDim !== 256) return false;
|
|
32
|
-
if (cachedKDtype !== 'f16' || cachedVDtype !== 'f16') return false;
|
|
33
|
-
if (!kernelPathUsesHead256DecodeAttention(kernelPath)) return false;
|
|
34
|
-
const gateElements = tensorElementCount(qGateTensor);
|
|
35
|
-
if (gateElements !== null && gateElements < numTokens * numHeads * headDim) return false;
|
|
36
|
-
return true;
|
|
37
|
-
}
|