@graphty/webgpu-graph-algorithms 0.0.0 → 0.2.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 +378 -23
- package/dist/browser.d.ts +1 -0
- package/dist/browser.js +32 -0
- package/dist/browser.js.map +1 -0
- package/dist/chunks/context-E6iKaeuJ.js +3136 -0
- package/dist/chunks/context-E6iKaeuJ.js.map +1 -0
- package/dist/node.d.ts +1 -0
- package/dist/node.js +131 -0
- package/dist/node.js.map +1 -0
- package/dist/src/accelerator.d.ts +26 -0
- package/dist/src/accelerator.d.ts.map +1 -0
- package/dist/src/accelerator.js +101 -0
- package/dist/src/accelerator.js.map +1 -0
- package/dist/src/algorithms/degree.d.ts +35 -0
- package/dist/src/algorithms/degree.d.ts.map +1 -0
- package/dist/src/algorithms/degree.js +119 -0
- package/dist/src/algorithms/degree.js.map +1 -0
- package/dist/src/browser/index.d.ts +23 -0
- package/dist/src/browser/index.d.ts.map +1 -0
- package/dist/src/browser/index.js +48 -0
- package/dist/src/browser/index.js.map +1 -0
- package/dist/src/constants.d.ts +92 -0
- package/dist/src/constants.d.ts.map +1 -0
- package/dist/src/constants.js +92 -0
- package/dist/src/constants.js.map +1 -0
- package/dist/src/context.d.ts +84 -0
- package/dist/src/context.d.ts.map +1 -0
- package/dist/src/context.js +304 -0
- package/dist/src/context.js.map +1 -0
- package/dist/src/device/acquire.d.ts +57 -0
- package/dist/src/device/acquire.d.ts.map +1 -0
- package/dist/src/device/acquire.js +232 -0
- package/dist/src/device/acquire.js.map +1 -0
- package/dist/src/device/caps.d.ts +43 -0
- package/dist/src/device/caps.d.ts.map +1 -0
- package/dist/src/device/caps.js +104 -0
- package/dist/src/device/caps.js.map +1 -0
- package/dist/src/device/error-scope.d.ts +75 -0
- package/dist/src/device/error-scope.d.ts.map +1 -0
- package/dist/src/device/error-scope.js +152 -0
- package/dist/src/device/error-scope.js.map +1 -0
- package/dist/src/device/lost.d.ts +51 -0
- package/dist/src/device/lost.d.ts.map +1 -0
- package/dist/src/device/lost.js +130 -0
- package/dist/src/device/lost.js.map +1 -0
- package/dist/src/device/webgpu-constants.d.ts +31 -0
- package/dist/src/device/webgpu-constants.d.ts.map +1 -0
- package/dist/src/device/webgpu-constants.js +31 -0
- package/dist/src/device/webgpu-constants.js.map +1 -0
- package/dist/src/errors.d.ts +56 -0
- package/dist/src/errors.d.ts.map +1 -0
- package/dist/src/errors.js +57 -0
- package/dist/src/errors.js.map +1 -0
- package/dist/src/index.d.ts +29 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +27 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/kernel/batch.d.ts +116 -0
- package/dist/src/kernel/batch.d.ts.map +1 -0
- package/dist/src/kernel/batch.js +335 -0
- package/dist/src/kernel/batch.js.map +1 -0
- package/dist/src/kernel/dispatch.d.ts +59 -0
- package/dist/src/kernel/dispatch.d.ts.map +1 -0
- package/dist/src/kernel/dispatch.js +139 -0
- package/dist/src/kernel/dispatch.js.map +1 -0
- package/dist/src/kernel/kernel.d.ts +84 -0
- package/dist/src/kernel/kernel.d.ts.map +1 -0
- package/dist/src/kernel/kernel.js +239 -0
- package/dist/src/kernel/kernel.js.map +1 -0
- package/dist/src/kernel/pipeline-cache.d.ts +90 -0
- package/dist/src/kernel/pipeline-cache.d.ts.map +1 -0
- package/dist/src/kernel/pipeline-cache.js +251 -0
- package/dist/src/kernel/pipeline-cache.js.map +1 -0
- package/dist/src/kernel/prelude.d.ts +35 -0
- package/dist/src/kernel/prelude.d.ts.map +1 -0
- package/dist/src/kernel/prelude.js +211 -0
- package/dist/src/kernel/prelude.js.map +1 -0
- package/dist/src/kernel/profiler.d.ts +64 -0
- package/dist/src/kernel/profiler.d.ts.map +1 -0
- package/dist/src/kernel/profiler.js +120 -0
- package/dist/src/kernel/profiler.js.map +1 -0
- package/dist/src/kernel/struct-block.d.ts +122 -0
- package/dist/src/kernel/struct-block.d.ts.map +1 -0
- package/dist/src/kernel/struct-block.js +353 -0
- package/dist/src/kernel/struct-block.js.map +1 -0
- package/dist/src/kernel/uniform-ring.d.ts +70 -0
- package/dist/src/kernel/uniform-ring.d.ts.map +1 -0
- package/dist/src/kernel/uniform-ring.js +146 -0
- package/dist/src/kernel/uniform-ring.js.map +1 -0
- package/dist/src/kernel/wgsl.d.ts +88 -0
- package/dist/src/kernel/wgsl.d.ts.map +1 -0
- package/dist/src/kernel/wgsl.js +390 -0
- package/dist/src/kernel/wgsl.js.map +1 -0
- package/dist/src/kernels.d.ts +81 -0
- package/dist/src/kernels.d.ts.map +1 -0
- package/dist/src/kernels.js +417 -0
- package/dist/src/kernels.js.map +1 -0
- package/dist/src/layouts/force-simulation.d.ts +498 -0
- package/dist/src/layouts/force-simulation.d.ts.map +1 -0
- package/dist/src/layouts/force-simulation.js +1650 -0
- package/dist/src/layouts/force-simulation.js.map +1 -0
- package/dist/src/layouts/forceatlas2.d.ts +210 -0
- package/dist/src/layouts/forceatlas2.d.ts.map +1 -0
- package/dist/src/layouts/forceatlas2.js +759 -0
- package/dist/src/layouts/forceatlas2.js.map +1 -0
- package/dist/src/layouts/inputs.d.ts +40 -0
- package/dist/src/layouts/inputs.d.ts.map +1 -0
- package/dist/src/layouts/inputs.js +185 -0
- package/dist/src/layouts/inputs.js.map +1 -0
- package/dist/src/layouts/repulsion-exact.d.ts +85 -0
- package/dist/src/layouts/repulsion-exact.d.ts.map +1 -0
- package/dist/src/layouts/repulsion-exact.js +134 -0
- package/dist/src/layouts/repulsion-exact.js.map +1 -0
- package/dist/src/layouts/seed.d.ts +56 -0
- package/dist/src/layouts/seed.d.ts.map +1 -0
- package/dist/src/layouts/seed.js +173 -0
- package/dist/src/layouts/seed.js.map +1 -0
- package/dist/src/memory/buffer-pool.d.ts +73 -0
- package/dist/src/memory/buffer-pool.d.ts.map +1 -0
- package/dist/src/memory/buffer-pool.js +170 -0
- package/dist/src/memory/buffer-pool.js.map +1 -0
- package/dist/src/memory/lease.d.ts +53 -0
- package/dist/src/memory/lease.d.ts.map +1 -0
- package/dist/src/memory/lease.js +85 -0
- package/dist/src/memory/lease.js.map +1 -0
- package/dist/src/memory/readback.d.ts +143 -0
- package/dist/src/memory/readback.d.ts.map +1 -0
- package/dist/src/memory/readback.js +375 -0
- package/dist/src/memory/readback.js.map +1 -0
- package/dist/src/memory/residency.d.ts +83 -0
- package/dist/src/memory/residency.d.ts.map +1 -0
- package/dist/src/memory/residency.js +573 -0
- package/dist/src/memory/residency.js.map +1 -0
- package/dist/src/memory/upload-plan.d.ts +101 -0
- package/dist/src/memory/upload-plan.d.ts.map +1 -0
- package/dist/src/memory/upload-plan.js +265 -0
- package/dist/src/memory/upload-plan.js.map +1 -0
- package/dist/src/node/index.d.ts +64 -0
- package/dist/src/node/index.d.ts.map +1 -0
- package/dist/src/node/index.js +183 -0
- package/dist/src/node/index.js.map +1 -0
- package/dist/src/primitives/reduce.d.ts +57 -0
- package/dist/src/primitives/reduce.d.ts.map +1 -0
- package/dist/src/primitives/reduce.js +161 -0
- package/dist/src/primitives/reduce.js.map +1 -0
- package/dist/src/primitives/segmented-reduce.d.ts +38 -0
- package/dist/src/primitives/segmented-reduce.d.ts.map +1 -0
- package/dist/src/primitives/segmented-reduce.js +211 -0
- package/dist/src/primitives/segmented-reduce.js.map +1 -0
- package/dist/src/types/accelerator.d.ts +209 -0
- package/dist/src/types/accelerator.d.ts.map +1 -0
- package/dist/src/types/accelerator.js +8 -0
- package/dist/src/types/accelerator.js.map +1 -0
- package/dist/src/types/context.d.ts +114 -0
- package/dist/src/types/context.d.ts.map +1 -0
- package/dist/src/types/context.js +7 -0
- package/dist/src/types/context.js.map +1 -0
- package/dist/src/types/layout.d.ts +95 -0
- package/dist/src/types/layout.d.ts.map +1 -0
- package/dist/src/types/layout.js +6 -0
- package/dist/src/types/layout.js.map +1 -0
- package/dist/src/types/memory.d.ts +22 -0
- package/dist/src/types/memory.d.ts.map +1 -0
- package/dist/src/types/memory.js +7 -0
- package/dist/src/types/memory.js.map +1 -0
- package/dist/src/types/options.d.ts +78 -0
- package/dist/src/types/options.d.ts.map +1 -0
- package/dist/src/types/options.js +7 -0
- package/dist/src/types/options.js.map +1 -0
- package/dist/src/types/run.d.ts +13 -0
- package/dist/src/types/run.d.ts.map +1 -0
- package/dist/src/types/run.js +6 -0
- package/dist/src/types/run.js.map +1 -0
- package/dist/src/wgsl/degree.wgsl.d.ts +10 -0
- package/dist/src/wgsl/degree.wgsl.d.ts.map +1 -0
- package/dist/src/wgsl/degree.wgsl.js +25 -0
- package/dist/src/wgsl/degree.wgsl.js.map +1 -0
- package/dist/src/wgsl/fa2-attraction.wgsl.d.ts +12 -0
- package/dist/src/wgsl/fa2-attraction.wgsl.d.ts.map +1 -0
- package/dist/src/wgsl/fa2-attraction.wgsl.js +37 -0
- package/dist/src/wgsl/fa2-attraction.wgsl.js.map +1 -0
- package/dist/src/wgsl/fa2-integrate.wgsl.d.ts +13 -0
- package/dist/src/wgsl/fa2-integrate.wgsl.d.ts.map +1 -0
- package/dist/src/wgsl/fa2-integrate.wgsl.js +69 -0
- package/dist/src/wgsl/fa2-integrate.wgsl.js.map +1 -0
- package/dist/src/wgsl/fa2-repulsion-exact.wgsl.d.ts +12 -0
- package/dist/src/wgsl/fa2-repulsion-exact.wgsl.d.ts.map +1 -0
- package/dist/src/wgsl/fa2-repulsion-exact.wgsl.js +79 -0
- package/dist/src/wgsl/fa2-repulsion-exact.wgsl.js.map +1 -0
- package/dist/src/wgsl/fa2-speed-finalize.wgsl.d.ts +15 -0
- package/dist/src/wgsl/fa2-speed-finalize.wgsl.d.ts.map +1 -0
- package/dist/src/wgsl/fa2-speed-finalize.wgsl.js +54 -0
- package/dist/src/wgsl/fa2-speed-finalize.wgsl.js.map +1 -0
- package/dist/src/wgsl/fa2-stats-finalize.wgsl.d.ts +14 -0
- package/dist/src/wgsl/fa2-stats-finalize.wgsl.d.ts.map +1 -0
- package/dist/src/wgsl/fa2-stats-finalize.wgsl.js +57 -0
- package/dist/src/wgsl/fa2-stats-finalize.wgsl.js.map +1 -0
- package/dist/src/wgsl/fa2-to-scene.wgsl.d.ts +11 -0
- package/dist/src/wgsl/fa2-to-scene.wgsl.d.ts.map +1 -0
- package/dist/src/wgsl/fa2-to-scene.wgsl.js +19 -0
- package/dist/src/wgsl/fa2-to-scene.wgsl.js.map +1 -0
- package/dist/src/wgsl/fill.wgsl.d.ts +7 -0
- package/dist/src/wgsl/fill.wgsl.d.ts.map +1 -0
- package/dist/src/wgsl/fill.wgsl.js +14 -0
- package/dist/src/wgsl/fill.wgsl.js.map +1 -0
- package/dist/src/wgsl/reduce.wgsl.d.ts +10 -0
- package/dist/src/wgsl/reduce.wgsl.d.ts.map +1 -0
- package/dist/src/wgsl/reduce.wgsl.js +63 -0
- package/dist/src/wgsl/reduce.wgsl.js.map +1 -0
- package/dist/src/wgsl/segmented-reduce.wgsl.d.ts +13 -0
- package/dist/src/wgsl/segmented-reduce.wgsl.d.ts.map +1 -0
- package/dist/src/wgsl/segmented-reduce.wgsl.js +35 -0
- package/dist/src/wgsl/segmented-reduce.wgsl.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/webgpu-graph-algorithms.d.ts +1 -0
- package/dist/webgpu-graph-algorithms.js +4454 -0
- package/dist/webgpu-graph-algorithms.js.map +1 -0
- package/package.json +108 -17
- package/src/accelerator.ts +117 -0
- package/src/algorithms/degree.ts +142 -0
- package/src/browser/index.ts +57 -0
- package/src/constants.ts +116 -0
- package/src/context.ts +399 -0
- package/src/device/acquire.ts +256 -0
- package/src/device/caps.ts +122 -0
- package/src/device/error-scope.ts +171 -0
- package/src/device/lost.ts +142 -0
- package/src/device/webgpu-constants.ts +44 -0
- package/src/errors.ts +94 -0
- package/src/index.ts +102 -0
- package/src/kernel/batch.ts +427 -0
- package/src/kernel/dispatch.ts +162 -0
- package/src/kernel/kernel.ts +311 -0
- package/src/kernel/pipeline-cache.ts +288 -0
- package/src/kernel/prelude.ts +229 -0
- package/src/kernel/profiler.ts +148 -0
- package/src/kernel/struct-block.ts +439 -0
- package/src/kernel/uniform-ring.ts +184 -0
- package/src/kernel/wgsl.ts +490 -0
- package/src/kernels.ts +511 -0
- package/src/layouts/force-simulation.ts +2111 -0
- package/src/layouts/forceatlas2.ts +942 -0
- package/src/layouts/inputs.ts +252 -0
- package/src/layouts/repulsion-exact.ts +183 -0
- package/src/layouts/seed.ts +198 -0
- package/src/memory/buffer-pool.ts +204 -0
- package/src/memory/lease.ts +93 -0
- package/src/memory/readback.ts +429 -0
- package/src/memory/residency.ts +753 -0
- package/src/memory/upload-plan.ts +350 -0
- package/src/node/index.ts +230 -0
- package/src/primitives/reduce.ts +233 -0
- package/src/primitives/segmented-reduce.ts +270 -0
- package/src/types/accelerator.ts +236 -0
- package/src/types/context.ts +135 -0
- package/src/types/layout.ts +103 -0
- package/src/types/memory.ts +23 -0
- package/src/types/options.ts +84 -0
- package/src/types/run.ts +13 -0
- package/src/wgsl/degree.wgsl.ts +24 -0
- package/src/wgsl/fa2-attraction.wgsl.ts +37 -0
- package/src/wgsl/fa2-integrate.wgsl.ts +69 -0
- package/src/wgsl/fa2-repulsion-exact.wgsl.ts +78 -0
- package/src/wgsl/fa2-speed-finalize.wgsl.ts +53 -0
- package/src/wgsl/fa2-stats-finalize.wgsl.ts +57 -0
- package/src/wgsl/fa2-to-scene.wgsl.ts +19 -0
- package/src/wgsl/fill.wgsl.ts +13 -0
- package/src/wgsl/reduce.wgsl.ts +62 -0
- package/src/wgsl/segmented-reduce.wgsl.ts +35 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The CommandBatch of spec 5.8: one GPUCommandEncoder, one compute pass per "phase" (a pass may hold
|
|
3
|
+
* many dispatches; dispatches inside a pass are ordered), the staging copies of every readback
|
|
4
|
+
* request at the end, and ONE queue.submit. The batch borrows one slot of the Readback ring for its
|
|
5
|
+
* lifetime (spec 4.4) and returns it when its readback settles -- resolved, discarded or rejected --
|
|
6
|
+
* so the ring never grows because of a slot left pending. mapAsync on that slot is the completion
|
|
7
|
+
* signal; a batch never calls onSubmittedWorkDone.
|
|
8
|
+
*
|
|
9
|
+
* Errors (spec 5.7): under Dawn-node an uncapturederror is delivered SYNCHRONOUSLY inside the API
|
|
10
|
+
* call that fails, so an error pending in the context's slot when submit() runs belongs to this batch
|
|
11
|
+
* and rejects ITS OWN readback (an invalid command buffer is a no-op submit; the staging bytes would be
|
|
12
|
+
* stale). In browsers delivery is asynchronous: the batch takes the slot again after its map completes,
|
|
13
|
+
* and whatever arrives later is thrown by the context's next public call. Device loss is raced against
|
|
14
|
+
* the map, so a readback rejects E_DEVICE_LOST whether the runtime rejects, resolves or never settles
|
|
15
|
+
* the pending map of a destroyed buffer; the slot goes back only once the map has settled (or the grace
|
|
16
|
+
* ran out), because a staging buffer is never unmapped while its map is pending (readback.ts).
|
|
17
|
+
*/
|
|
18
|
+
import type { AllocationTracker } from "../device/error-scope.js";
|
|
19
|
+
import { WebGpuGraphError } from "../errors.js";
|
|
20
|
+
import type { Readback } from "../memory/readback.js";
|
|
21
|
+
import type { Binding } from "../types/memory.js";
|
|
22
|
+
import type { Profiler } from "./profiler.js";
|
|
23
|
+
/** What a CommandBatch needs of its owner (GpuContext satisfies it structurally; kernel/ never imports context.ts). */
|
|
24
|
+
export interface BatchHost {
|
|
25
|
+
readonly device: GPUDevice;
|
|
26
|
+
readonly readback: Readback;
|
|
27
|
+
readonly profiler: Profiler | null;
|
|
28
|
+
readonly allocator: AllocationTracker;
|
|
29
|
+
assertReady(): void;
|
|
30
|
+
takePendingError(): WebGpuGraphError | null;
|
|
31
|
+
nextBatchId(): number;
|
|
32
|
+
/** Registers a device-loss listener and returns the unregister function (GpuContext.onLost, contract 3.5): the batch races its map against loss. PLAN DECISION 1: an amendment to contract 3.9, which declares the seven members above. */
|
|
33
|
+
onLost(listener: (info: GPUDeviceLostInfo) => void): () => void;
|
|
34
|
+
}
|
|
35
|
+
/** A readback scheduled into the batch's staging slot: `offset` is the slot-relative byte offset the caller reads at. */
|
|
36
|
+
export interface ReadbackRequest {
|
|
37
|
+
readonly src: GPUBuffer;
|
|
38
|
+
readonly srcOffset: number;
|
|
39
|
+
readonly byteLength: number;
|
|
40
|
+
readonly offset: number;
|
|
41
|
+
}
|
|
42
|
+
/** What submit() returns (spec 5.8). `readback` resolves with the mapped bytes COPIED out (one ArrayBuffer holding every request at its offset) after allocator.check(); it rejects with E_VALIDATION { batchId } when the pending-error slot held an error right after submit and with E_DEVICE_LOST after loss; a discarded batch resolves an empty ArrayBuffer (see discard()). */
|
|
43
|
+
export interface SubmittedBatch {
|
|
44
|
+
readonly id: number;
|
|
45
|
+
readonly generation: number;
|
|
46
|
+
readonly readback: Promise<ArrayBuffer>;
|
|
47
|
+
/** Marks the batch stale: its readback still awaits mapAsync (so the slot is returned) but resolves with an empty ArrayBuffer and the caller ignores it (spec 7.19 item 6). */
|
|
48
|
+
discard(): void;
|
|
49
|
+
}
|
|
50
|
+
/** Records dispatches / copies into one encoder and submits once (spec 5.8). */
|
|
51
|
+
export declare class CommandBatch {
|
|
52
|
+
readonly id: number;
|
|
53
|
+
readonly generation: number;
|
|
54
|
+
readonly label: string;
|
|
55
|
+
private readonly host;
|
|
56
|
+
private readonly encoder;
|
|
57
|
+
private readonly requests;
|
|
58
|
+
private openPass;
|
|
59
|
+
private dispatchCount;
|
|
60
|
+
private stagingBytes;
|
|
61
|
+
private slot;
|
|
62
|
+
private submitted;
|
|
63
|
+
/**
|
|
64
|
+
* Creates the encoder; the id comes from host.nextBatchId().
|
|
65
|
+
* @param host - the owner (the GpuContext)
|
|
66
|
+
* @param label - names the encoder, its passes and the E_VALIDATION details
|
|
67
|
+
* @param generation - the simulation generation the batch carries (default 0)
|
|
68
|
+
*/
|
|
69
|
+
constructor(host: BatchHost, label: string, generation?: number);
|
|
70
|
+
/**
|
|
71
|
+
* Dispatch count recorded so far (tests bound it).
|
|
72
|
+
* @returns the number of dispatchWorkgroups / dispatchWorkgroupsIndirect calls on this batch's passes
|
|
73
|
+
*/
|
|
74
|
+
get dispatches(): number;
|
|
75
|
+
/**
|
|
76
|
+
* Begins a compute pass (ending the previous one); with a profiler present the pass carries timestampWrites and
|
|
77
|
+
* `label` names it in Profiler.resolveInto / timings.
|
|
78
|
+
* @param label - the pass name
|
|
79
|
+
* @returns the pass encoder kernels dispatch into
|
|
80
|
+
*/
|
|
81
|
+
pass(label: string): GPUComputePassEncoder;
|
|
82
|
+
/** Ends the open pass, if any. */
|
|
83
|
+
endPass(): void;
|
|
84
|
+
/**
|
|
85
|
+
* copyBufferToBuffer between two bindings (after endPass).
|
|
86
|
+
* @param src - the source range
|
|
87
|
+
* @param dst - the destination range
|
|
88
|
+
* @param byteLength - a positive multiple of 4 no larger than either binding
|
|
89
|
+
*/
|
|
90
|
+
copy(src: Binding, dst: Binding, byteLength: number): void;
|
|
91
|
+
/**
|
|
92
|
+
* Schedules a copy of `byteLength` bytes from `src` into the borrowed staging slot; the slot is borrowed at the
|
|
93
|
+
* first request and re-borrowed larger when the sum of requests outgrows it (nothing is recorded before submit).
|
|
94
|
+
* @param src - the source buffer
|
|
95
|
+
* @param srcOffset - a non-negative multiple of 4
|
|
96
|
+
* @param byteLength - a positive multiple of 4 with srcOffset + byteLength <= src.size
|
|
97
|
+
* @returns the request; `offset` is where the caller reads inside the readback bytes
|
|
98
|
+
*/
|
|
99
|
+
readback(src: GPUBuffer, srcOffset: number, byteLength: number): ReadbackRequest;
|
|
100
|
+
/**
|
|
101
|
+
* Ends passes, records the staging copies, submits, checks the pending-error slot (spec 5.7), returns the handle.
|
|
102
|
+
* A batch can be submitted once; submit() after device loss throws E_DEVICE_LOST.
|
|
103
|
+
* @returns the submitted-batch handle
|
|
104
|
+
*/
|
|
105
|
+
submit(): SubmittedBatch;
|
|
106
|
+
private rejectReadback;
|
|
107
|
+
private awaitReadback;
|
|
108
|
+
private classify;
|
|
109
|
+
private attribute;
|
|
110
|
+
private ensureSlot;
|
|
111
|
+
private releaseSlot;
|
|
112
|
+
private countDispatches;
|
|
113
|
+
private assertOpen;
|
|
114
|
+
private checkByteLength;
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=batch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batch.d.ts","sourceRoot":"","sources":["../../../src/kernel/batch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAElE,OAAO,EAAsB,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACpE,OAAO,KAAK,EAAE,QAAQ,EAAe,MAAM,uBAAuB,CAAC;AACnE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAwC9C,uHAAuH;AACvH,MAAM,WAAW,SAAS;IACtB,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;IACnC,QAAQ,CAAC,SAAS,EAAE,iBAAiB,CAAC;IACtC,WAAW,IAAI,IAAI,CAAC;IACpB,gBAAgB,IAAI,gBAAgB,GAAG,IAAI,CAAC;IAC5C,WAAW,IAAI,MAAM,CAAC;IACtB,2OAA2O;IAC3O,MAAM,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,iBAAiB,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;CACnE;AAED,yHAAyH;AACzH,MAAM,WAAW,eAAe;IAC5B,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC;IACxB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CAC3B;AAED,sXA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AAc;YAKR,aAAa;YAiCb,QAAQ;IAwCtB,OAAO,CAAC,SAAS;IAQjB,OAAO,CAAC,UAAU;IAQlB,OAAO,CAAC,WAAW;IAenB,OAAO,CAAC,eAAe;IAevB,OAAO,CAAC,UAAU;IAclB,OAAO,CAAC,eAAe;CAa1B"}
|
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The CommandBatch of spec 5.8: one GPUCommandEncoder, one compute pass per "phase" (a pass may hold
|
|
3
|
+
* many dispatches; dispatches inside a pass are ordered), the staging copies of every readback
|
|
4
|
+
* request at the end, and ONE queue.submit. The batch borrows one slot of the Readback ring for its
|
|
5
|
+
* lifetime (spec 4.4) and returns it when its readback settles -- resolved, discarded or rejected --
|
|
6
|
+
* so the ring never grows because of a slot left pending. mapAsync on that slot is the completion
|
|
7
|
+
* signal; a batch never calls onSubmittedWorkDone.
|
|
8
|
+
*
|
|
9
|
+
* Errors (spec 5.7): under Dawn-node an uncapturederror is delivered SYNCHRONOUSLY inside the API
|
|
10
|
+
* call that fails, so an error pending in the context's slot when submit() runs belongs to this batch
|
|
11
|
+
* and rejects ITS OWN readback (an invalid command buffer is a no-op submit; the staging bytes would be
|
|
12
|
+
* stale). In browsers delivery is asynchronous: the batch takes the slot again after its map completes,
|
|
13
|
+
* and whatever arrives later is thrown by the context's next public call. Device loss is raced against
|
|
14
|
+
* the map, so a readback rejects E_DEVICE_LOST whether the runtime rejects, resolves or never settles
|
|
15
|
+
* the pending map of a destroyed buffer; the slot goes back only once the map has settled (or the grace
|
|
16
|
+
* ran out), because a staging buffer is never unmapped while its map is pending (readback.ts).
|
|
17
|
+
*/
|
|
18
|
+
import { deviceLostError } from "../device/lost.js";
|
|
19
|
+
import { isWebGpuGraphError, WebGpuGraphError } from "../errors.js";
|
|
20
|
+
/** How long a batch waits for the context's loss fan-out after its map rejected with a foreign error (a destroyed buffer rejects before device.lost settles), and for the runtime to settle a pending map after the loss won the race. */
|
|
21
|
+
const LOSS_GRACE_MS = 2000;
|
|
22
|
+
/**
|
|
23
|
+
* Resolves when the promise settles either way, or after the grace (a runtime that never settles a pending map).
|
|
24
|
+
* @param pending - the promise
|
|
25
|
+
* @param graceMs - the ceiling
|
|
26
|
+
*/
|
|
27
|
+
async function settled(pending, graceMs) {
|
|
28
|
+
let timer;
|
|
29
|
+
const grace = new Promise((resolve) => {
|
|
30
|
+
timer = setTimeout(resolve, graceMs);
|
|
31
|
+
});
|
|
32
|
+
await Promise.race([
|
|
33
|
+
pending.then(() => undefined, () => undefined),
|
|
34
|
+
grace,
|
|
35
|
+
]);
|
|
36
|
+
clearTimeout(timer);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* A plain message for a thrown value (the house pattern of graph-io's report.ts).
|
|
40
|
+
* @param error - whatever the runtime rejected with
|
|
41
|
+
* @returns the Error message, the string itself, or a typeof note
|
|
42
|
+
*/
|
|
43
|
+
function messageOf(error) {
|
|
44
|
+
if (error instanceof Error) {
|
|
45
|
+
return error.message;
|
|
46
|
+
}
|
|
47
|
+
if (typeof error === "string") {
|
|
48
|
+
return error;
|
|
49
|
+
}
|
|
50
|
+
return `non-error thrown (${typeof error})`;
|
|
51
|
+
}
|
|
52
|
+
/** Records dispatches / copies into one encoder and submits once (spec 5.8). */
|
|
53
|
+
export class CommandBatch {
|
|
54
|
+
/**
|
|
55
|
+
* Creates the encoder; the id comes from host.nextBatchId().
|
|
56
|
+
* @param host - the owner (the GpuContext)
|
|
57
|
+
* @param label - names the encoder, its passes and the E_VALIDATION details
|
|
58
|
+
* @param generation - the simulation generation the batch carries (default 0)
|
|
59
|
+
*/
|
|
60
|
+
constructor(host, label, generation) {
|
|
61
|
+
this.requests = [];
|
|
62
|
+
this.openPass = null;
|
|
63
|
+
this.dispatchCount = 0;
|
|
64
|
+
this.stagingBytes = 0;
|
|
65
|
+
this.slot = null;
|
|
66
|
+
this.submitted = false;
|
|
67
|
+
this.host = host;
|
|
68
|
+
this.id = host.nextBatchId();
|
|
69
|
+
this.generation = generation ?? 0;
|
|
70
|
+
this.label = label;
|
|
71
|
+
this.encoder = host.device.createCommandEncoder({ label: `batch/${label}#${this.id}` });
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Dispatch count recorded so far (tests bound it).
|
|
75
|
+
* @returns the number of dispatchWorkgroups / dispatchWorkgroupsIndirect calls on this batch's passes
|
|
76
|
+
*/
|
|
77
|
+
get dispatches() {
|
|
78
|
+
return this.dispatchCount;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Begins a compute pass (ending the previous one); with a profiler present the pass carries timestampWrites and
|
|
82
|
+
* `label` names it in Profiler.resolveInto / timings.
|
|
83
|
+
* @param label - the pass name
|
|
84
|
+
* @returns the pass encoder kernels dispatch into
|
|
85
|
+
*/
|
|
86
|
+
pass(label) {
|
|
87
|
+
this.assertOpen("pass");
|
|
88
|
+
this.endPass();
|
|
89
|
+
const descriptor = { label: `batch/${this.label}#${this.id}/${label}` };
|
|
90
|
+
const timestampWrites = this.host.profiler?.beginPass(label);
|
|
91
|
+
if (timestampWrites !== undefined) {
|
|
92
|
+
descriptor.timestampWrites = timestampWrites;
|
|
93
|
+
}
|
|
94
|
+
const pass = this.encoder.beginComputePass(descriptor);
|
|
95
|
+
this.countDispatches(pass);
|
|
96
|
+
this.openPass = pass;
|
|
97
|
+
return pass;
|
|
98
|
+
}
|
|
99
|
+
/** Ends the open pass, if any. */
|
|
100
|
+
endPass() {
|
|
101
|
+
if (this.openPass !== null) {
|
|
102
|
+
this.openPass.end();
|
|
103
|
+
this.openPass = null;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* copyBufferToBuffer between two bindings (after endPass).
|
|
108
|
+
* @param src - the source range
|
|
109
|
+
* @param dst - the destination range
|
|
110
|
+
* @param byteLength - a positive multiple of 4 no larger than either binding
|
|
111
|
+
*/
|
|
112
|
+
copy(src, dst, byteLength) {
|
|
113
|
+
this.assertOpen("copy");
|
|
114
|
+
this.checkByteLength(byteLength);
|
|
115
|
+
if (byteLength > src.size || byteLength > dst.size) {
|
|
116
|
+
throw new WebGpuGraphError("E_INVALID_ARGUMENT", `copy of ${byteLength} bytes exceeds a binding (src ${src.size}, dst ${dst.size})`, {
|
|
117
|
+
argument: "byteLength",
|
|
118
|
+
value: byteLength,
|
|
119
|
+
expected: `<= ${Math.min(src.size, dst.size)}`,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
this.endPass();
|
|
123
|
+
this.encoder.copyBufferToBuffer(src.buffer, src.offset, dst.buffer, dst.offset, byteLength);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Schedules a copy of `byteLength` bytes from `src` into the borrowed staging slot; the slot is borrowed at the
|
|
127
|
+
* first request and re-borrowed larger when the sum of requests outgrows it (nothing is recorded before submit).
|
|
128
|
+
* @param src - the source buffer
|
|
129
|
+
* @param srcOffset - a non-negative multiple of 4
|
|
130
|
+
* @param byteLength - a positive multiple of 4 with srcOffset + byteLength <= src.size
|
|
131
|
+
* @returns the request; `offset` is where the caller reads inside the readback bytes
|
|
132
|
+
*/
|
|
133
|
+
readback(src, srcOffset, byteLength) {
|
|
134
|
+
this.assertOpen("readback");
|
|
135
|
+
this.checkByteLength(byteLength);
|
|
136
|
+
if (!Number.isInteger(srcOffset) || srcOffset < 0 || srcOffset % 4 !== 0 || srcOffset + byteLength > src.size) {
|
|
137
|
+
throw new WebGpuGraphError("E_INVALID_ARGUMENT", `readback of [${srcOffset}, ${srcOffset + byteLength}) is outside the ${src.size}-byte source or not 4-aligned`, {
|
|
138
|
+
argument: "srcOffset",
|
|
139
|
+
value: srcOffset,
|
|
140
|
+
expected: `a multiple of 4 with srcOffset + byteLength <= ${src.size}`,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
const request = { src, srcOffset, byteLength, offset: this.stagingBytes };
|
|
144
|
+
this.requests.push(request);
|
|
145
|
+
this.stagingBytes += byteLength;
|
|
146
|
+
this.ensureSlot(this.stagingBytes);
|
|
147
|
+
return request;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Records `resolveQuerySet` after ending the open pass; used by Profiler.resolveInto only.
|
|
151
|
+
* @internal
|
|
152
|
+
* @param querySet - the timestamp query set
|
|
153
|
+
* @param firstQuery - first query index
|
|
154
|
+
* @param queryCount - number of queries
|
|
155
|
+
* @param destination - a QUERY_RESOLVE | COPY_SRC buffer written at offset 0
|
|
156
|
+
*/
|
|
157
|
+
resolveQuerySet(querySet, firstQuery, queryCount, destination) {
|
|
158
|
+
this.assertOpen("resolveQuerySet");
|
|
159
|
+
this.endPass();
|
|
160
|
+
this.encoder.resolveQuerySet(querySet, firstQuery, queryCount, destination, 0);
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Ends passes, records the staging copies, submits, checks the pending-error slot (spec 5.7), returns the handle.
|
|
164
|
+
* A batch can be submitted once; submit() after device loss throws E_DEVICE_LOST.
|
|
165
|
+
* @returns the submitted-batch handle
|
|
166
|
+
*/
|
|
167
|
+
submit() {
|
|
168
|
+
this.assertOpen("submit");
|
|
169
|
+
this.submitted = true;
|
|
170
|
+
this.endPass();
|
|
171
|
+
const { slot } = this;
|
|
172
|
+
const pendingBefore = this.host.takePendingError();
|
|
173
|
+
try {
|
|
174
|
+
this.host.assertReady();
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
this.releaseSlot();
|
|
178
|
+
throw error;
|
|
179
|
+
}
|
|
180
|
+
if (slot !== null) {
|
|
181
|
+
for (const request of this.requests) {
|
|
182
|
+
this.encoder.copyBufferToBuffer(request.src, request.srcOffset, slot.buffer, request.offset, request.byteLength);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
const commandBuffer = this.encoder.finish({ label: `batch/${this.label}#${this.id}` });
|
|
186
|
+
this.host.device.queue.submit([commandBuffer]);
|
|
187
|
+
// the slot is drained a second time so a finish() / submit() error raised by a command buffer the first error
|
|
188
|
+
// already invalidated never leaks to the next public call; the FIRST error is the one reported
|
|
189
|
+
const pendingAfter = this.host.takePendingError();
|
|
190
|
+
const pending = pendingBefore ?? pendingAfter;
|
|
191
|
+
const state = { discarded: false };
|
|
192
|
+
const readback = pending === null ? this.awaitReadback(slot, state) : this.rejectReadback(pending);
|
|
193
|
+
return {
|
|
194
|
+
id: this.id,
|
|
195
|
+
generation: this.generation,
|
|
196
|
+
readback,
|
|
197
|
+
discard: () => {
|
|
198
|
+
state.discarded = true;
|
|
199
|
+
},
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
rejectReadback(pending) {
|
|
203
|
+
this.releaseSlot();
|
|
204
|
+
return Promise.reject(this.attribute(pending));
|
|
205
|
+
}
|
|
206
|
+
async awaitReadback(slot, state) {
|
|
207
|
+
if (slot === null) {
|
|
208
|
+
await this.host.allocator.check();
|
|
209
|
+
return new ArrayBuffer(0);
|
|
210
|
+
}
|
|
211
|
+
const total = this.stagingBytes;
|
|
212
|
+
let unregister = () => undefined;
|
|
213
|
+
const lost = new Promise((_resolve, reject) => {
|
|
214
|
+
unregister = this.host.onLost((info) => {
|
|
215
|
+
reject(deviceLostError(info));
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
void lost.catch(() => undefined);
|
|
219
|
+
const mapped = this.host.readback.mapSlot(slot, total);
|
|
220
|
+
void mapped.catch(() => undefined);
|
|
221
|
+
let bytes;
|
|
222
|
+
try {
|
|
223
|
+
await Promise.race([mapped, lost]);
|
|
224
|
+
this.host.assertReady();
|
|
225
|
+
bytes = state.discarded ? new ArrayBuffer(0) : slot.buffer.getMappedRange(0, total).slice(0);
|
|
226
|
+
}
|
|
227
|
+
catch (error) {
|
|
228
|
+
// the loss may have won the race: let the runtime settle the map before the slot is unmapped and returned
|
|
229
|
+
await settled(mapped, LOSS_GRACE_MS);
|
|
230
|
+
this.releaseSlot();
|
|
231
|
+
throw await this.classify(error, lost);
|
|
232
|
+
}
|
|
233
|
+
finally {
|
|
234
|
+
unregister();
|
|
235
|
+
}
|
|
236
|
+
this.releaseSlot();
|
|
237
|
+
await this.host.allocator.check();
|
|
238
|
+
return bytes;
|
|
239
|
+
}
|
|
240
|
+
async classify(error, lost) {
|
|
241
|
+
if (isWebGpuGraphError(error)) {
|
|
242
|
+
return error.code === "E_DEVICE_LOST" || error.code === "E_DISPOSED" ? error : this.attribute(error);
|
|
243
|
+
}
|
|
244
|
+
try {
|
|
245
|
+
this.host.assertReady();
|
|
246
|
+
}
|
|
247
|
+
catch (state) {
|
|
248
|
+
if (isWebGpuGraphError(state)) {
|
|
249
|
+
return state.code === "E_DEVICE_LOST" || state.code === "E_DISPOSED" ? state : this.attribute(state);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
let timer;
|
|
253
|
+
const grace = new Promise((resolve) => {
|
|
254
|
+
timer = setTimeout(() => {
|
|
255
|
+
resolve(null);
|
|
256
|
+
}, LOSS_GRACE_MS);
|
|
257
|
+
});
|
|
258
|
+
const late = await Promise.race([
|
|
259
|
+
lost.then(() => null, (reason) => reason),
|
|
260
|
+
grace,
|
|
261
|
+
]);
|
|
262
|
+
clearTimeout(timer);
|
|
263
|
+
if (isWebGpuGraphError(late)) {
|
|
264
|
+
return late;
|
|
265
|
+
}
|
|
266
|
+
const message = messageOf(error);
|
|
267
|
+
return new WebGpuGraphError("E_VALIDATION", `mapAsync failed for batch ${this.id} "${this.label}": ${message}`, {
|
|
268
|
+
label: this.label,
|
|
269
|
+
message,
|
|
270
|
+
batchId: this.id,
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
attribute(error) {
|
|
274
|
+
return new WebGpuGraphError(error.code, `${error.message} (delivered to batch ${this.id} "${this.label}")`, {
|
|
275
|
+
...error.details,
|
|
276
|
+
batchId: this.id,
|
|
277
|
+
batchLabel: this.label,
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
ensureSlot(byteLength) {
|
|
281
|
+
if (this.slot !== null && this.slot.capacity >= byteLength) {
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
this.releaseSlot();
|
|
285
|
+
this.slot = this.host.readback.borrowSlot(byteLength);
|
|
286
|
+
}
|
|
287
|
+
releaseSlot() {
|
|
288
|
+
if (this.slot === null) {
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
const { slot } = this;
|
|
292
|
+
this.slot = null;
|
|
293
|
+
try {
|
|
294
|
+
this.host.readback.returnSlot(slot);
|
|
295
|
+
}
|
|
296
|
+
catch (error) {
|
|
297
|
+
if (!isWebGpuGraphError(error) || error.code !== "E_DISPOSED") {
|
|
298
|
+
throw error;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
countDispatches(pass) {
|
|
303
|
+
const direct = pass.dispatchWorkgroups.bind(pass);
|
|
304
|
+
const indirect = pass.dispatchWorkgroupsIndirect.bind(pass);
|
|
305
|
+
pass.dispatchWorkgroups = (x, y, z) => {
|
|
306
|
+
this.dispatchCount += 1;
|
|
307
|
+
direct(x, y, z);
|
|
308
|
+
return undefined;
|
|
309
|
+
};
|
|
310
|
+
pass.dispatchWorkgroupsIndirect = (buffer, offset) => {
|
|
311
|
+
this.dispatchCount += 1;
|
|
312
|
+
indirect(buffer, offset);
|
|
313
|
+
return undefined;
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
assertOpen(operation) {
|
|
317
|
+
if (this.submitted) {
|
|
318
|
+
throw new WebGpuGraphError("E_INVALID_ARGUMENT", `${operation}() after submit() on batch ${this.id} "${this.label}"`, {
|
|
319
|
+
argument: operation,
|
|
320
|
+
value: this.id,
|
|
321
|
+
expected: "a batch that has not been submitted",
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
checkByteLength(byteLength) {
|
|
326
|
+
if (!Number.isInteger(byteLength) || byteLength <= 0 || byteLength % 4 !== 0) {
|
|
327
|
+
throw new WebGpuGraphError("E_INVALID_ARGUMENT", `byteLength ${byteLength} is not a positive multiple of 4`, {
|
|
328
|
+
argument: "byteLength",
|
|
329
|
+
value: byteLength,
|
|
330
|
+
expected: "a positive multiple of 4",
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
//# sourceMappingURL=batch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batch.js","sourceRoot":"","sources":["../../../src/kernel/batch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAKpE,0OAA0O;AAC1O,MAAM,aAAa,GAAG,IAAI,CAAC;AAE3B;;;;GAIG;AACH,KAAK,UAAU,OAAO,CAAC,OAAyB,EAAE,OAAe;IAC7D,IAAI,KAAgD,CAAC;IACrD,MAAM,KAAK,GAAG,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;QACxC,KAAK,GAAG,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACzC,CAAC,CAAC,CAAC;IACH,MAAM,OAAO,CAAC,IAAI,CAAC;QACf,OAAO,CAAC,IAAI,CACR,GAAG,EAAE,CAAC,SAAS,EACf,GAAG,EAAE,CAAC,SAAS,CAClB;QACD,KAAK;KACR,CAAC,CAAC;IACH,YAAY,CAAC,KAAK,CAAC,CAAC;AACxB,CAAC;AAED;;;;GAIG;AACH,SAAS,SAAS,CAAC,KAAc;IAC7B,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QACzB,OAAO,KAAK,CAAC,OAAO,CAAC;IACzB,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC5B,OAAO,KAAK,CAAC;IACjB,CAAC;IACD,OAAO,qBAAqB,OAAO,KAAK,GAAG,CAAC;AAChD,CAAC;AAqCD,gFAAgF;AAChF,MAAM,OAAO,YAAY;IAarB;;;;;OAKG;IACH,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M,EAAE,MAAM,CAAC,CAAC;YACzB,OAAO,SAAS,CAAC;QACrB,CAAC,CAAC;IACN,CAAC;IAEO,UAAU,CAAC,SAAiB;QAChC,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACjB,MAAM,IAAI,gBAAgB,CACtB,oBAAoB,EACpB,GAAG,SAAS,8BAA8B,IAAI,CAAC,EAAE,KAAK,IAAI,CAAC,KAAK,GAAG,EACnE;gBACI,QAAQ,EAAE,SAAS;gBACnB,KAAK,EAAE,IAAI,CAAC,EAAE;gBACd,QAAQ,EAAE,qCAAqC;aAClD,CACJ,CAAC;QACN,CAAC;IACL,CAAC;IAEO,eAAe,CAAC,UAAkB;QACtC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,UAAU,IAAI,CAAC,IAAI,UAAU,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YAC3E,MAAM,IAAI,gBAAgB,CACtB,oBAAoB,EACpB,cAAc,UAAU,kCAAkC,EAC1D;gBACI,QAAQ,EAAE,YAAY;gBACtB,KAAK,EAAE,UAAU;gBACjB,QAAQ,EAAE,0BAA0B;aACvC,CACJ,CAAC;QACN,CAAC;IACL,CAAC;CACJ"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dispatch planning (spec 5.2; contract 3.9): the 16,776,960 rule. `ceil(items / wg)` workgroups as a 1D dispatch
|
|
3
|
+
* while the count fits one dimension (65,535 groups x 256 = 16,776,960 items, NOT 2^24), else a 2D grid whose
|
|
4
|
+
* kernels linearise their id with the prelude's `linear_id()` and guard `id >= items`. Pure functions with no
|
|
5
|
+
* device: every branch is unit-tested against faked capability tables.
|
|
6
|
+
*/
|
|
7
|
+
import { type PlanCaps } from "../types/context.js";
|
|
8
|
+
/** A dispatch shape (spec 5.2). `stride` is the grid-stride step (null for plain 1D / 2D plans). */
|
|
9
|
+
export interface DispatchPlan {
|
|
10
|
+
readonly x: number;
|
|
11
|
+
readonly y: number;
|
|
12
|
+
readonly z: 1;
|
|
13
|
+
readonly items: number;
|
|
14
|
+
readonly stride: number | null;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* ceil(items / wg) groups as 1D up to MAX_WORKGROUPS_PER_DIM, else a 2D grid; items 0 -> { x: 0, y: 1 }; y above the limit -> E_TOO_LARGE.
|
|
18
|
+
* @param items - the item count
|
|
19
|
+
* @param wg - the workgroup size (a power of two)
|
|
20
|
+
* @param caps - the capability table
|
|
21
|
+
* @returns the plan
|
|
22
|
+
*/
|
|
23
|
+
export declare function plan1d(items: number, wg: number, caps: PlanCaps): DispatchPlan;
|
|
24
|
+
/**
|
|
25
|
+
* The 2D form for a group count (x = MAX_WORKGROUPS_PER_DIM, y = ceil(groups / x)); exported for the indirect finalize kernel's host twin (P4).
|
|
26
|
+
* PLAN DECISION: plan1d's rule applied to a group count (spec 5.4: the finalize kernel uses "the same rule as
|
|
27
|
+
* plan1d") -- 1D `{ x: groups, y: 1 }` up to the per-dimension limit and the `x = limit` split only above it, through
|
|
28
|
+
* the same `grid()` as plan1d so the two cannot drift; P4's finalize WGSL mirrors exactly this rule. `items` of the
|
|
29
|
+
* returned plan is `groups` (the caller knows its own wg); groups 0 -> { x: 0, y: 1 }.
|
|
30
|
+
* @param groups - the workgroup count
|
|
31
|
+
* @param caps - the capability table
|
|
32
|
+
* @returns the plan
|
|
33
|
+
*/
|
|
34
|
+
export declare function plan2d(groups: number, caps: PlanCaps): DispatchPlan;
|
|
35
|
+
/**
|
|
36
|
+
* P7 (spec 5.2): groups = min(groups, maxGroups ?? (caps.software ? 64 : 4096)) with the kernel looping by stride. P1-P3: throws E_UNSUPPORTED { feature: "planGridStride" } (lead f).
|
|
37
|
+
* PLAN DECISION: `maxGroups?` is spelled `?: number` rather than the contract's `?: number | undefined` because the
|
|
38
|
+
* root ESLint rule no-duplicate-type-constituents rejects the explicit undefined on an optional parameter (the call
|
|
39
|
+
* signature is identical).
|
|
40
|
+
* @param items - the item count
|
|
41
|
+
* @param wg - the workgroup size
|
|
42
|
+
* @param caps - the capability table
|
|
43
|
+
* @param maxGroups - the group cap
|
|
44
|
+
*/
|
|
45
|
+
export declare function planGridStride(items: number, wg: number, caps: PlanCaps, maxGroups?: number): DispatchPlan;
|
|
46
|
+
/**
|
|
47
|
+
* P4 (spec 5.4): the (x, y, 1) args a device-side finalize kernel writes for a count. P1-P3: throws E_UNSUPPORTED { feature: "planIndirect" } (lead f).
|
|
48
|
+
* @param count - the device-side count
|
|
49
|
+
* @param wg - the workgroup size
|
|
50
|
+
* @param caps - the capability table
|
|
51
|
+
*/
|
|
52
|
+
export declare function planIndirect(count: number, wg: number, caps: PlanCaps): DispatchPlan;
|
|
53
|
+
/**
|
|
54
|
+
* The workgroup count of a plan (x * y).
|
|
55
|
+
* @param plan - the plan
|
|
56
|
+
* @returns the count
|
|
57
|
+
*/
|
|
58
|
+
export declare function groupsOf(plan: DispatchPlan): number;
|
|
59
|
+
//# sourceMappingURL=dispatch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dispatch.d.ts","sourceRoot":"","sources":["../../../src/kernel/dispatch.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAEpD,oGAAoG;AACpG,MAAM,WAAW,YAAY;IACzB,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC;IACd,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CAClC;AA8ED;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,GAAG,YAAY,CAI9E;AAED;;;;;;;;;GASG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,GAAG,YAAY,CAGnE;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,YAAY,CAK1G;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,GAAG,YAAY,CAKpF;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,YAAY,GAAG,MAAM,CAEnD"}
|