@graphty/webgpu-graph-algorithms 0.5.0 → 0.6.0
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 +104 -52
- package/dist/browser.js +1 -1
- package/dist/chunks/{context-CRbw2Wyo.js → context-BXqgCifx.js} +225 -33
- package/dist/chunks/context-BXqgCifx.js.map +1 -0
- package/dist/node.js +1 -1
- package/dist/src/accelerator.d.ts +12 -10
- package/dist/src/accelerator.d.ts.map +1 -1
- package/dist/src/accelerator.js +32 -10
- package/dist/src/accelerator.js.map +1 -1
- package/dist/src/algorithms/components.d.ts.map +1 -1
- package/dist/src/algorithms/components.js +12 -13
- package/dist/src/algorithms/components.js.map +1 -1
- package/dist/src/algorithms/degree.d.ts +6 -8
- package/dist/src/algorithms/degree.d.ts.map +1 -1
- package/dist/src/algorithms/degree.js +58 -35
- package/dist/src/algorithms/degree.js.map +1 -1
- package/dist/src/algorithms/pagerank.d.ts.map +1 -1
- package/dist/src/algorithms/pagerank.js +16 -14
- package/dist/src/algorithms/pagerank.js.map +1 -1
- package/dist/src/algorithms/power-iteration.d.ts +2 -2
- package/dist/src/algorithms/power-iteration.d.ts.map +1 -1
- package/dist/src/algorithms/power-iteration.js +17 -14
- package/dist/src/algorithms/power-iteration.js.map +1 -1
- package/dist/src/constants.d.ts +85 -8
- package/dist/src/constants.d.ts.map +1 -1
- package/dist/src/constants.js +85 -8
- package/dist/src/constants.js.map +1 -1
- package/dist/src/errors.d.ts +3 -2
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/errors.js +2 -1
- package/dist/src/errors.js.map +1 -1
- package/dist/src/index.d.ts +10 -5
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +14 -5
- package/dist/src/index.js.map +1 -1
- package/dist/src/kernel/dispatch.d.ts +8 -3
- package/dist/src/kernel/dispatch.d.ts.map +1 -1
- package/dist/src/kernel/dispatch.js +18 -7
- package/dist/src/kernel/dispatch.js.map +1 -1
- package/dist/src/kernel/kernel.d.ts +30 -1
- package/dist/src/kernel/kernel.d.ts.map +1 -1
- package/dist/src/kernel/kernel.js +49 -5
- package/dist/src/kernel/kernel.js.map +1 -1
- package/dist/src/kernel/prelude.d.ts.map +1 -1
- package/dist/src/kernel/prelude.js +9 -1
- package/dist/src/kernel/prelude.js.map +1 -1
- package/dist/src/kernel/profiler.d.ts +15 -3
- package/dist/src/kernel/profiler.d.ts.map +1 -1
- package/dist/src/kernel/profiler.js +27 -4
- package/dist/src/kernel/profiler.js.map +1 -1
- package/dist/src/kernels.d.ts +18 -8
- package/dist/src/kernels.d.ts.map +1 -1
- package/dist/src/kernels.js +345 -22
- package/dist/src/kernels.js.map +1 -1
- package/dist/src/layouts/calibrate.d.ts +51 -0
- package/dist/src/layouts/calibrate.d.ts.map +1 -0
- package/dist/src/layouts/calibrate.js +172 -0
- package/dist/src/layouts/calibrate.js.map +1 -0
- package/dist/src/layouts/force-simulation.d.ts +42 -5
- package/dist/src/layouts/force-simulation.d.ts.map +1 -1
- package/dist/src/layouts/force-simulation.js +84 -22
- package/dist/src/layouts/force-simulation.js.map +1 -1
- package/dist/src/layouts/forceatlas2.d.ts +107 -38
- package/dist/src/layouts/forceatlas2.d.ts.map +1 -1
- package/dist/src/layouts/forceatlas2.js +297 -290
- package/dist/src/layouts/forceatlas2.js.map +1 -1
- package/dist/src/layouts/fruchterman-reingold.d.ts +241 -0
- package/dist/src/layouts/fruchterman-reingold.d.ts.map +1 -0
- package/dist/src/layouts/fruchterman-reingold.js +739 -0
- package/dist/src/layouts/fruchterman-reingold.js.map +1 -0
- package/dist/src/layouts/model-common.d.ts +140 -0
- package/dist/src/layouts/model-common.d.ts.map +1 -0
- package/dist/src/layouts/model-common.js +269 -0
- package/dist/src/layouts/model-common.js.map +1 -0
- package/dist/src/layouts/repulsion-grid.d.ts +152 -0
- package/dist/src/layouts/repulsion-grid.d.ts.map +1 -0
- package/dist/src/layouts/repulsion-grid.js +318 -0
- package/dist/src/layouts/repulsion-grid.js.map +1 -0
- package/dist/src/layouts/spring-electrical.d.ts +224 -0
- package/dist/src/layouts/spring-electrical.d.ts.map +1 -0
- package/dist/src/layouts/spring-electrical.js +665 -0
- package/dist/src/layouts/spring-electrical.js.map +1 -0
- package/dist/src/memory/residency.d.ts +6 -2
- package/dist/src/memory/residency.d.ts.map +1 -1
- package/dist/src/memory/residency.js +84 -14
- package/dist/src/memory/residency.js.map +1 -1
- package/dist/src/primitives/core-shape.d.ts +38 -2
- package/dist/src/primitives/core-shape.d.ts.map +1 -1
- package/dist/src/primitives/core-shape.js +71 -3
- package/dist/src/primitives/core-shape.js.map +1 -1
- package/dist/src/primitives/grid-pyramid.d.ts +71 -0
- package/dist/src/primitives/grid-pyramid.d.ts.map +1 -0
- package/dist/src/primitives/grid-pyramid.js +143 -0
- package/dist/src/primitives/grid-pyramid.js.map +1 -0
- package/dist/src/primitives/grid.d.ts +118 -0
- package/dist/src/primitives/grid.d.ts.map +1 -0
- package/dist/src/primitives/grid.js +225 -0
- package/dist/src/primitives/grid.js.map +1 -0
- package/dist/src/primitives/histogram.d.ts +67 -0
- package/dist/src/primitives/histogram.d.ts.map +1 -0
- package/dist/src/primitives/histogram.js +190 -0
- package/dist/src/primitives/histogram.js.map +1 -0
- package/dist/src/primitives/radix-sort.d.ts +75 -0
- package/dist/src/primitives/radix-sort.d.ts.map +1 -0
- package/dist/src/primitives/radix-sort.js +168 -0
- package/dist/src/primitives/radix-sort.js.map +1 -0
- package/dist/src/primitives/scan.d.ts +44 -0
- package/dist/src/primitives/scan.d.ts.map +1 -0
- package/dist/src/primitives/scan.js +151 -0
- package/dist/src/primitives/scan.js.map +1 -0
- package/dist/src/primitives/segmented-reduce.d.ts +25 -17
- package/dist/src/primitives/segmented-reduce.d.ts.map +1 -1
- package/dist/src/primitives/segmented-reduce.js +166 -47
- package/dist/src/primitives/segmented-reduce.js.map +1 -1
- package/dist/src/primitives/spmv.d.ts +18 -14
- package/dist/src/primitives/spmv.d.ts.map +1 -1
- package/dist/src/primitives/spmv.js +94 -58
- package/dist/src/primitives/spmv.js.map +1 -1
- package/dist/src/primitives/verify.d.ts +49 -0
- package/dist/src/primitives/verify.d.ts.map +1 -0
- package/dist/src/primitives/verify.js +229 -0
- package/dist/src/primitives/verify.js.map +1 -0
- package/dist/src/types/accelerator.d.ts +7 -3
- package/dist/src/types/accelerator.d.ts.map +1 -1
- package/dist/src/types/context.d.ts +53 -0
- package/dist/src/types/context.d.ts.map +1 -1
- package/dist/src/types/layout.d.ts +52 -0
- package/dist/src/types/layout.d.ts.map +1 -1
- package/dist/src/types/options.d.ts +43 -1
- package/dist/src/types/options.d.ts.map +1 -1
- package/dist/src/wgsl/counting-scatter.wgsl.d.ts +8 -0
- package/dist/src/wgsl/counting-scatter.wgsl.d.ts.map +1 -0
- package/dist/src/wgsl/counting-scatter.wgsl.js +17 -0
- package/dist/src/wgsl/counting-scatter.wgsl.js.map +1 -0
- package/dist/src/wgsl/fa2-attraction.wgsl.d.ts +23 -8
- package/dist/src/wgsl/fa2-attraction.wgsl.d.ts.map +1 -1
- package/dist/src/wgsl/fa2-attraction.wgsl.js +100 -17
- package/dist/src/wgsl/fa2-attraction.wgsl.js.map +1 -1
- package/dist/src/wgsl/fa2-integrate.wgsl.d.ts +7 -2
- package/dist/src/wgsl/fa2-integrate.wgsl.d.ts.map +1 -1
- package/dist/src/wgsl/fa2-integrate.wgsl.js +28 -2
- package/dist/src/wgsl/fa2-integrate.wgsl.js.map +1 -1
- package/dist/src/wgsl/fa2-repulsion-exact.wgsl.d.ts +4 -2
- package/dist/src/wgsl/fa2-repulsion-exact.wgsl.d.ts.map +1 -1
- package/dist/src/wgsl/fa2-repulsion-exact.wgsl.js +14 -5
- package/dist/src/wgsl/fa2-repulsion-exact.wgsl.js.map +1 -1
- package/dist/src/wgsl/fa2-stats-finalize.wgsl.d.ts +12 -1
- package/dist/src/wgsl/fa2-stats-finalize.wgsl.d.ts.map +1 -1
- package/dist/src/wgsl/fa2-stats-finalize.wgsl.js +54 -0
- package/dist/src/wgsl/fa2-stats-finalize.wgsl.js.map +1 -1
- package/dist/src/wgsl/grid-cell-key.wgsl.d.ts +8 -0
- package/dist/src/wgsl/grid-cell-key.wgsl.d.ts.map +1 -0
- package/dist/src/wgsl/grid-cell-key.wgsl.js +30 -0
- package/dist/src/wgsl/grid-cell-key.wgsl.js.map +1 -0
- package/dist/src/wgsl/grid-centroid-hub.wgsl.d.ts +8 -0
- package/dist/src/wgsl/grid-centroid-hub.wgsl.d.ts.map +1 -0
- package/dist/src/wgsl/grid-centroid-hub.wgsl.js +29 -0
- package/dist/src/wgsl/grid-centroid-hub.wgsl.js.map +1 -0
- package/dist/src/wgsl/grid-centroid.wgsl.d.ts +8 -0
- package/dist/src/wgsl/grid-centroid.wgsl.d.ts.map +1 -0
- package/dist/src/wgsl/grid-centroid.wgsl.js +29 -0
- package/dist/src/wgsl/grid-centroid.wgsl.js.map +1 -0
- package/dist/src/wgsl/grid-downsample.wgsl.d.ts +7 -0
- package/dist/src/wgsl/grid-downsample.wgsl.d.ts.map +1 -0
- package/dist/src/wgsl/grid-downsample.wgsl.js +28 -0
- package/dist/src/wgsl/grid-downsample.wgsl.js.map +1 -0
- package/dist/src/wgsl/grid-far-field.wgsl.d.ts +13 -0
- package/dist/src/wgsl/grid-far-field.wgsl.d.ts.map +1 -0
- package/dist/src/wgsl/grid-far-field.wgsl.js +98 -0
- package/dist/src/wgsl/grid-far-field.wgsl.js.map +1 -0
- package/dist/src/wgsl/grid-near-field.wgsl.d.ts +19 -0
- package/dist/src/wgsl/grid-near-field.wgsl.d.ts.map +1 -0
- package/dist/src/wgsl/grid-near-field.wgsl.js +129 -0
- package/dist/src/wgsl/grid-near-field.wgsl.js.map +1 -0
- package/dist/src/wgsl/histogram.wgsl.d.ts +7 -0
- package/dist/src/wgsl/histogram.wgsl.d.ts.map +1 -0
- package/dist/src/wgsl/histogram.wgsl.js +15 -0
- package/dist/src/wgsl/histogram.wgsl.js.map +1 -0
- package/dist/src/wgsl/indirect-finalize.wgsl.d.ts +8 -0
- package/dist/src/wgsl/indirect-finalize.wgsl.d.ts.map +1 -0
- package/dist/src/wgsl/indirect-finalize.wgsl.js +26 -0
- package/dist/src/wgsl/indirect-finalize.wgsl.js.map +1 -0
- package/dist/src/wgsl/radix-hist.wgsl.d.ts +9 -0
- package/dist/src/wgsl/radix-hist.wgsl.d.ts.map +1 -0
- package/dist/src/wgsl/radix-hist.wgsl.js +31 -0
- package/dist/src/wgsl/radix-hist.wgsl.js.map +1 -0
- package/dist/src/wgsl/radix-scatter.wgsl.d.ts +9 -0
- package/dist/src/wgsl/radix-scatter.wgsl.d.ts.map +1 -0
- package/dist/src/wgsl/radix-scatter.wgsl.js +40 -0
- package/dist/src/wgsl/radix-scatter.wgsl.js.map +1 -0
- package/dist/src/wgsl/scan-add.wgsl.d.ts +6 -0
- package/dist/src/wgsl/scan-add.wgsl.d.ts.map +1 -0
- package/dist/src/wgsl/scan-add.wgsl.js +14 -0
- package/dist/src/wgsl/scan-add.wgsl.js.map +1 -0
- package/dist/src/wgsl/scan-block.wgsl.d.ts +8 -0
- package/dist/src/wgsl/scan-block.wgsl.d.ts.map +1 -0
- package/dist/src/wgsl/scan-block.wgsl.js +30 -0
- package/dist/src/wgsl/scan-block.wgsl.js.map +1 -0
- package/dist/src/wgsl/segmented-reduce.wgsl.d.ts +22 -8
- package/dist/src/wgsl/segmented-reduce.wgsl.d.ts.map +1 -1
- package/dist/src/wgsl/segmented-reduce.wgsl.js +84 -15
- package/dist/src/wgsl/segmented-reduce.wgsl.js.map +1 -1
- package/dist/src/wgsl/spmv-pull.wgsl.d.ts +22 -11
- package/dist/src/wgsl/spmv-pull.wgsl.d.ts.map +1 -1
- package/dist/src/wgsl/spmv-pull.wgsl.js +110 -36
- package/dist/src/wgsl/spmv-pull.wgsl.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/webgpu-graph-algorithms.js +5016 -1130
- package/dist/webgpu-graph-algorithms.js.map +1 -1
- package/package.json +10 -7
- package/src/accelerator.ts +46 -12
- package/src/algorithms/components.ts +12 -16
- package/src/algorithms/degree.ts +58 -43
- package/src/algorithms/pagerank.ts +20 -18
- package/src/algorithms/power-iteration.ts +19 -18
- package/src/constants.ts +108 -8
- package/src/errors.ts +3 -1
- package/src/index.ts +25 -5
- package/src/kernel/dispatch.ts +18 -7
- package/src/kernel/kernel.ts +59 -5
- package/src/kernel/prelude.ts +15 -0
- package/src/kernel/profiler.ts +28 -4
- package/src/kernels.ts +378 -24
- package/src/layouts/calibrate.ts +187 -0
- package/src/layouts/force-simulation.ts +111 -26
- package/src/layouts/forceatlas2.ts +346 -324
- package/src/layouts/fruchterman-reingold.ts +918 -0
- package/src/layouts/model-common.ts +323 -0
- package/src/layouts/repulsion-grid.ts +451 -0
- package/src/layouts/spring-electrical.ts +845 -0
- package/src/memory/residency.ts +126 -20
- package/src/primitives/core-shape.ts +91 -4
- package/src/primitives/grid-pyramid.ts +221 -0
- package/src/primitives/grid.ts +349 -0
- package/src/primitives/histogram.ts +273 -0
- package/src/primitives/radix-sort.ts +246 -0
- package/src/primitives/scan.ts +197 -0
- package/src/primitives/segmented-reduce.ts +214 -56
- package/src/primitives/spmv.ts +125 -65
- package/src/primitives/verify.ts +249 -0
- package/src/types/accelerator.ts +15 -3
- package/src/types/context.ts +56 -0
- package/src/types/layout.ts +58 -0
- package/src/types/options.ts +45 -1
- package/src/wgsl/counting-scatter.wgsl.ts +16 -0
- package/src/wgsl/fa2-attraction.wgsl.ts +100 -17
- package/src/wgsl/fa2-integrate.wgsl.ts +28 -2
- package/src/wgsl/fa2-repulsion-exact.wgsl.ts +14 -5
- package/src/wgsl/fa2-stats-finalize.wgsl.ts +54 -0
- package/src/wgsl/grid-cell-key.wgsl.ts +29 -0
- package/src/wgsl/grid-centroid-hub.wgsl.ts +28 -0
- package/src/wgsl/grid-centroid.wgsl.ts +28 -0
- package/src/wgsl/grid-downsample.wgsl.ts +27 -0
- package/src/wgsl/grid-far-field.wgsl.ts +97 -0
- package/src/wgsl/grid-near-field.wgsl.ts +128 -0
- package/src/wgsl/histogram.wgsl.ts +14 -0
- package/src/wgsl/indirect-finalize.wgsl.ts +25 -0
- package/src/wgsl/radix-hist.wgsl.ts +30 -0
- package/src/wgsl/radix-scatter.wgsl.ts +39 -0
- package/src/wgsl/scan-add.wgsl.ts +13 -0
- package/src/wgsl/scan-block.wgsl.ts +29 -0
- package/src/wgsl/segmented-reduce.wgsl.ts +84 -15
- package/src/wgsl/spmv-pull.wgsl.ts +110 -36
- package/dist/chunks/context-CRbw2Wyo.js.map +0 -1
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The grid-tier repulsion stage of the force models (spec 7.7, 7.4; P4-T10): G1-G3 through the T8 grid build, G4-G5
|
|
3
|
+
* through the T9 pyramid, then G6 (`grid-far-field`) and G7 (`grid-near-field`, K3's pair law and epilogue) over
|
|
4
|
+
* `plan1d(n)`, followed by K4 (`fa2-speed-finalize`) exactly as `RepulsionExact` records it. The named grid buffers
|
|
5
|
+
* are the model's `BufferSpec`s (`buffers()`, so `inspect(name)` reaches them); the anonymous scratch of the sort
|
|
6
|
+
* and the scan and the static params of the pyramid draw on ONE `Lease` of the context's pool taken at `create()`
|
|
7
|
+
* (the scan planner takes its block-sum levels at prepare time) and released by `dispose()` (PD-11, DEP-P4-D: a
|
|
8
|
+
* per-batch lease would rebuild the G2-G4 bind groups every batch; a model creates one stage per bind(), so a stage
|
|
9
|
+
* is bound once). The stage is the ONE class every model reaches the grid tier through (PD-22): the FR and
|
|
10
|
+
* spring-electrical models pass `LAW` 1 / 2 in their override set, which reaches G6's per-cell law and G7's pair law
|
|
11
|
+
* (P4-T13).
|
|
12
|
+
*/
|
|
13
|
+
import { GRID_HUB_CELL } from "../constants.js";
|
|
14
|
+
import { BufferUsage } from "../device/webgpu-constants.js";
|
|
15
|
+
import { WebGpuGraphError } from "../errors.js";
|
|
16
|
+
import { plan1d } from "../kernel/dispatch.js";
|
|
17
|
+
import { INDIRECT_ARGS_STRIDE } from "../kernel/kernel.js";
|
|
18
|
+
import { kernelSpec } from "../kernels.js";
|
|
19
|
+
import { gridPyramidBytes, prepareGridBuild, } from "../primitives/grid.js";
|
|
20
|
+
import { preparePyramid } from "../primitives/grid-pyramid.js";
|
|
21
|
+
/** The stage names the grid tier records, in dispatch order (the `upTo` vocabulary of recordRepulsion). */
|
|
22
|
+
const GRID_STAGES = ["G1", "G2", "G3", "G4", "G5", "G6", "G7"];
|
|
23
|
+
/** The storage usage of every grid buffer. */
|
|
24
|
+
const STORAGE_RW = BufferUsage.STORAGE | BufferUsage.COPY_SRC | BufferUsage.COPY_DST;
|
|
25
|
+
/**
|
|
26
|
+
* The stage's lease, or E_DISPOSED after dispose().
|
|
27
|
+
* @param box - the stage's lease box
|
|
28
|
+
* @returns the lease
|
|
29
|
+
*/
|
|
30
|
+
function leaseOf(box) {
|
|
31
|
+
if (box.lease === null) {
|
|
32
|
+
throw new WebGpuGraphError("E_DISPOSED", "RepulsionGrid: the stage was disposed", { label: "RepulsionGrid" });
|
|
33
|
+
}
|
|
34
|
+
return box.lease;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* A uniform buffer of the lease holding one written record of `block` (the pyramid's static params, PD-11).
|
|
38
|
+
* @param device - the device
|
|
39
|
+
* @param lease - the stage's lease
|
|
40
|
+
* @param block - the uniform block
|
|
41
|
+
* @param values - the values to write
|
|
42
|
+
* @returns the whole-buffer binding and a zero dynamic offset
|
|
43
|
+
*/
|
|
44
|
+
function writeParams(device, lease, block, values) {
|
|
45
|
+
const buffer = lease.uniform(block.byteLength, `grid/${block.name}`);
|
|
46
|
+
const bytes = new ArrayBuffer(block.byteLength);
|
|
47
|
+
block.write(new DataView(bytes), values);
|
|
48
|
+
device.queue.writeBuffer(buffer, 0, bytes);
|
|
49
|
+
return { binding: { buffer, offset: 0, size: block.byteLength, window: null }, offset: 0 };
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The G6 spec of an override set (the law alone).
|
|
53
|
+
* @param overrides - the override set of the stage
|
|
54
|
+
* @returns the spec
|
|
55
|
+
*/
|
|
56
|
+
function farFieldSpec(overrides) {
|
|
57
|
+
return kernelSpec("grid-far-field", { LAW: overrides.LAW });
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The G7 spec of an override set (K3's four).
|
|
61
|
+
* @param overrides - the override set of the stage
|
|
62
|
+
* @returns the spec
|
|
63
|
+
*/
|
|
64
|
+
function nearFieldSpec(overrides) {
|
|
65
|
+
return kernelSpec("grid-near-field", {
|
|
66
|
+
SWING_MODE: overrides.SWING_MODE,
|
|
67
|
+
STRONG_GRAVITY: overrides.STRONG_GRAVITY,
|
|
68
|
+
GRAVITY_CENTER: overrides.GRAVITY_CENTER,
|
|
69
|
+
LAW: overrides.LAW,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/** G1-G7 then K4 (spec 7.7, 7.4): the grid tier's repulsion stage. */
|
|
73
|
+
export class RepulsionGrid {
|
|
74
|
+
/**
|
|
75
|
+
* Holds the planners and kernels; create() is the only caller.
|
|
76
|
+
* @param scope - the context pieces
|
|
77
|
+
* @param workgroupSize - the device's workgroup size (every kernel compiles with it)
|
|
78
|
+
* @param overrides - the override set G6 / G7 / K4 were compiled with
|
|
79
|
+
* @param spec - the grid
|
|
80
|
+
* @param box - the lease box the scope's scratch() and params() read
|
|
81
|
+
* @param build - the T8 planner (G1-G3)
|
|
82
|
+
* @param pyramid - the T9 planner (G4-G5)
|
|
83
|
+
* @param kernels - G6 (`far`), G7 (`near`) and K4 (`speedFinalize`)
|
|
84
|
+
*/
|
|
85
|
+
constructor(scope, workgroupSize, overrides, spec, box, build, pyramid, kernels) {
|
|
86
|
+
this.bound = null;
|
|
87
|
+
this.caps = scope.caps;
|
|
88
|
+
this.box = box;
|
|
89
|
+
this.workgroupSize = workgroupSize;
|
|
90
|
+
this.overrides = Object.freeze({
|
|
91
|
+
SWING_MODE: overrides.SWING_MODE,
|
|
92
|
+
STRONG_GRAVITY: overrides.STRONG_GRAVITY,
|
|
93
|
+
GRAVITY_CENTER: overrides.GRAVITY_CENTER,
|
|
94
|
+
LAW: overrides.LAW,
|
|
95
|
+
});
|
|
96
|
+
this.spec = spec;
|
|
97
|
+
this.build = build;
|
|
98
|
+
this.pyramid = pyramid;
|
|
99
|
+
this.far = kernels.far;
|
|
100
|
+
this.near = kernels.near;
|
|
101
|
+
this.speedFinalize = kernels.speedFinalize;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* The model-owned buffers of the grid tier (spec 7.3; PD-11): `cellKey` / `cellVal` / `sortedKey` / `sortedIdx`
|
|
105
|
+
* 4n, `cellHist` / `cellStart` 4 (cells + 2) zeroed, `hubList` one word per possible hub cell, `hubArgs` one
|
|
106
|
+
* indirect slot, `pyramid` 16 B per pyramid cell zeroed. `hubCounters` (16 B, zeroed) is the MODEL's on every
|
|
107
|
+
* tier (PD-14: K1 binds it on the exact tier too). n = 0 reports one node's worth of bytes (spec 3.6).
|
|
108
|
+
* @param n - the node count
|
|
109
|
+
* @param spec - the grid
|
|
110
|
+
* @returns the specs
|
|
111
|
+
*/
|
|
112
|
+
static buffers(n, spec) {
|
|
113
|
+
const words = 4 * Math.max(1, n);
|
|
114
|
+
return [
|
|
115
|
+
{ name: "cellKey", byteLength: words, usage: STORAGE_RW, zero: false },
|
|
116
|
+
{ name: "cellVal", byteLength: words, usage: STORAGE_RW, zero: false },
|
|
117
|
+
{ name: "sortedKey", byteLength: words, usage: STORAGE_RW, zero: false },
|
|
118
|
+
{ name: "sortedIdx", byteLength: words, usage: STORAGE_RW, zero: false },
|
|
119
|
+
{ name: "cellHist", byteLength: 4 * spec.histWords, usage: STORAGE_RW, zero: true },
|
|
120
|
+
{ name: "cellStart", byteLength: 4 * spec.histWords, usage: STORAGE_RW, zero: true },
|
|
121
|
+
{
|
|
122
|
+
name: "hubList",
|
|
123
|
+
byteLength: 4 * Math.max(1, Math.ceil(n / GRID_HUB_CELL)),
|
|
124
|
+
usage: STORAGE_RW,
|
|
125
|
+
zero: false,
|
|
126
|
+
},
|
|
127
|
+
{ name: "hubArgs", byteLength: INDIRECT_ARGS_STRIDE, usage: STORAGE_RW | BufferUsage.INDIRECT, zero: true },
|
|
128
|
+
{ name: "pyramid", byteLength: gridPyramidBytes(spec), usage: STORAGE_RW, zero: true },
|
|
129
|
+
];
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* The module specs of the grid tier under an override set (for warm() and the compile matrix): the build's
|
|
133
|
+
* (G1, the sort path `spec.deterministic` selects, the histogram, the scan, the fill), the pyramid's (G4, the
|
|
134
|
+
* finalize, G4b, G5), G6, G7 and K4.
|
|
135
|
+
* @param overrides - the override set of the stage
|
|
136
|
+
* @param spec - the grid (only its `deterministic` flag matters: the pipeline key carries no geometry)
|
|
137
|
+
* @returns the specs
|
|
138
|
+
*/
|
|
139
|
+
static specs(overrides, spec) {
|
|
140
|
+
const sort = spec.deterministic
|
|
141
|
+
? [kernelSpec("radix-hist"), kernelSpec("radix-scatter"), kernelSpec("scan-block"), kernelSpec("scan-add")]
|
|
142
|
+
: [kernelSpec("counting-scatter"), kernelSpec("scan-block"), kernelSpec("scan-add")];
|
|
143
|
+
return [
|
|
144
|
+
kernelSpec("grid-cell-key"),
|
|
145
|
+
...sort,
|
|
146
|
+
kernelSpec("histogram"),
|
|
147
|
+
kernelSpec("fill"),
|
|
148
|
+
kernelSpec("grid-centroid"),
|
|
149
|
+
kernelSpec("indirect-finalize"),
|
|
150
|
+
kernelSpec("grid-centroid-hub"),
|
|
151
|
+
kernelSpec("grid-downsample"),
|
|
152
|
+
farFieldSpec(overrides),
|
|
153
|
+
nearFieldSpec(overrides),
|
|
154
|
+
kernelSpec("fa2-speed-finalize", { SWING_MODE: overrides.SWING_MODE }),
|
|
155
|
+
];
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Compiles every kernel of the tier through the cache (sequentially: PipelineCache.get compiles inside a
|
|
159
|
+
* validation scope, one stack per device) over a scope whose scratch and params draw on the stage's lease.
|
|
160
|
+
* @param scope - the context pieces (device, caps, pipelines, pool)
|
|
161
|
+
* @param workgroupSize - the device's workgroup size
|
|
162
|
+
* @param overrides - the SWING_MODE / STRONG_GRAVITY / GRAVITY_CENTER / LAW set of this stage
|
|
163
|
+
* @param spec - the grid
|
|
164
|
+
* @returns the stage, ready for bind()
|
|
165
|
+
*/
|
|
166
|
+
static async create(scope, workgroupSize, overrides, spec) {
|
|
167
|
+
const box = { lease: scope.pool.lease() };
|
|
168
|
+
const reduceScope = {
|
|
169
|
+
device: scope.device,
|
|
170
|
+
caps: scope.caps,
|
|
171
|
+
pipelines: scope.pipelines,
|
|
172
|
+
pool: scope.pool,
|
|
173
|
+
workgroupSize,
|
|
174
|
+
scratch: (byteLength, label) => leaseOf(box).storage(byteLength, label),
|
|
175
|
+
params: (block, values) => writeParams(scope.device, leaseOf(box), block, values),
|
|
176
|
+
};
|
|
177
|
+
try {
|
|
178
|
+
const build = await prepareGridBuild(reduceScope, spec);
|
|
179
|
+
const pyramid = await preparePyramid(reduceScope, spec);
|
|
180
|
+
const far = await scope.pipelines.kernel(farFieldSpec(overrides));
|
|
181
|
+
const near = await scope.pipelines.kernel(nearFieldSpec(overrides));
|
|
182
|
+
const speedFinalize = await scope.pipelines.kernel(kernelSpec("fa2-speed-finalize", { SWING_MODE: overrides.SWING_MODE }));
|
|
183
|
+
return new RepulsionGrid(scope, workgroupSize, overrides, spec, box, build, pyramid, {
|
|
184
|
+
far,
|
|
185
|
+
near,
|
|
186
|
+
speedFinalize,
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
catch (error) {
|
|
190
|
+
leaseOf(box).release();
|
|
191
|
+
throw error;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Builds every bind group once per load(): the build's and the pyramid's bind() (which take their scratch and
|
|
196
|
+
* write their static params through the lease), then G6, G7 and K4 against the named buffers (the 3.10.1
|
|
197
|
+
* binding names). A second bind() takes fresh scratch from the same lease and the first bind()'s scratch stays
|
|
198
|
+
* held until dispose(): the one lease also holds the prepare-time allocations (the scan's block-sum levels), so
|
|
199
|
+
* it cannot be released on a rebind (the model creates one stage per bind(), so a rebind never happens).
|
|
200
|
+
* @param resources - the buffers of spec 7.3 plus the grid's
|
|
201
|
+
*/
|
|
202
|
+
bind(resources) {
|
|
203
|
+
leaseOf(this.box);
|
|
204
|
+
const r = resources;
|
|
205
|
+
this.build.bind({
|
|
206
|
+
pos: r.pos,
|
|
207
|
+
state: r.state,
|
|
208
|
+
params: r.params,
|
|
209
|
+
cellKey: r.cellKey,
|
|
210
|
+
cellVal: r.cellVal,
|
|
211
|
+
sortedKey: r.sortedKey,
|
|
212
|
+
sortedIdx: r.sortedIdx,
|
|
213
|
+
cellHist: r.cellHist,
|
|
214
|
+
cellStart: r.cellStart,
|
|
215
|
+
});
|
|
216
|
+
this.pyramid.bind({
|
|
217
|
+
pos: r.pos,
|
|
218
|
+
params: r.params,
|
|
219
|
+
sortedIdx: r.sortedIdx,
|
|
220
|
+
cellStart: r.cellStart,
|
|
221
|
+
pyramid: r.pyramid,
|
|
222
|
+
hubList: r.hubList,
|
|
223
|
+
hubCounters: r.hubCounters,
|
|
224
|
+
hubArgs: r.hubArgs,
|
|
225
|
+
});
|
|
226
|
+
this.bound = {
|
|
227
|
+
far: this.far.bind({
|
|
228
|
+
pos: r.pos,
|
|
229
|
+
sortedIdx: r.sortedIdx,
|
|
230
|
+
pyramid: r.pyramid,
|
|
231
|
+
S: r.state,
|
|
232
|
+
force: r.force,
|
|
233
|
+
P: r.params,
|
|
234
|
+
}),
|
|
235
|
+
near: this.near.bind({
|
|
236
|
+
pos: r.pos,
|
|
237
|
+
sortedIdx: r.sortedIdx,
|
|
238
|
+
cellStart: r.cellStart,
|
|
239
|
+
S: r.state,
|
|
240
|
+
force: r.force,
|
|
241
|
+
oldForce: r.oldForce,
|
|
242
|
+
fixedMask: r.fixedMask,
|
|
243
|
+
partials: r.partials,
|
|
244
|
+
P: r.params,
|
|
245
|
+
}),
|
|
246
|
+
speedFinalize: this.speedFinalize.bind({ partials: r.partials, S: r.state, T: r.trace, P: r.params }),
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Records G1..G7 for `n` nodes with the params slot's dynamic offset, stopping after `upTo` when given (spec 7.4
|
|
251
|
+
* grid sequence; the inspect() stage split, spec 11.9 item 2): G1-G3 through the build planner, G4-G5 through the
|
|
252
|
+
* pyramid planner, then G6 and G7 over plan1d(n).
|
|
253
|
+
* @param pass - the open compute pass of the batch
|
|
254
|
+
* @param n - the node count (in [1, the capacity of the grid buffers])
|
|
255
|
+
* @param paramsOffset - the dynamic offset of this iteration's Fa2Params slot in the uniform ring
|
|
256
|
+
* @param upTo - the last grid stage to record (default "G7")
|
|
257
|
+
*/
|
|
258
|
+
recordRepulsion(pass, n, paramsOffset, upTo) {
|
|
259
|
+
const bound = this.requireBound("recordRepulsion");
|
|
260
|
+
const stop = GRID_STAGES.indexOf(upTo ?? "G7");
|
|
261
|
+
let buildStop = "G3";
|
|
262
|
+
if (stop === 0) {
|
|
263
|
+
buildStop = "G1";
|
|
264
|
+
}
|
|
265
|
+
else if (stop === 1) {
|
|
266
|
+
buildStop = "G2";
|
|
267
|
+
}
|
|
268
|
+
this.build.record(pass, n, paramsOffset, buildStop);
|
|
269
|
+
if (stop < 3) {
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
this.pyramid.record(pass, paramsOffset, stop === 3 ? "G4" : "G5");
|
|
273
|
+
if (stop < 5) {
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
const plan = plan1d(n, this.workgroupSize, this.caps);
|
|
277
|
+
this.far.dispatch(pass, bound.far, plan, [paramsOffset]);
|
|
278
|
+
if (stop < 6) {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
this.near.dispatch(pass, bound.near, plan, [paramsOffset]);
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Records K4 only (one workgroup).
|
|
285
|
+
* @param pass - the open compute pass
|
|
286
|
+
* @param paramsOffset - the dynamic offset of the Fa2Params slot
|
|
287
|
+
*/
|
|
288
|
+
recordSpeedFinalize(pass, paramsOffset) {
|
|
289
|
+
const bound = this.requireBound("recordSpeedFinalize");
|
|
290
|
+
const one = plan1d(this.speedFinalize.workgroupSize, this.speedFinalize.workgroupSize, this.caps);
|
|
291
|
+
this.speedFinalize.dispatch(pass, bound.speedFinalize, one, [paramsOffset]);
|
|
292
|
+
}
|
|
293
|
+
/** Releases the lease (the sort and scan scratch, the static params) and drops the bind groups; idempotent. */
|
|
294
|
+
dispose() {
|
|
295
|
+
if (this.box.lease !== null) {
|
|
296
|
+
this.box.lease.release();
|
|
297
|
+
this.box.lease = null;
|
|
298
|
+
}
|
|
299
|
+
for (const kernel of [this.far, this.near, this.speedFinalize]) {
|
|
300
|
+
kernel.invalidate();
|
|
301
|
+
}
|
|
302
|
+
this.bound = null;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* The bound groups, or E_NOT_LOADED when bind() has not run.
|
|
306
|
+
* @param method - the caller's name for the message
|
|
307
|
+
* @returns the bound groups
|
|
308
|
+
*/
|
|
309
|
+
requireBound(method) {
|
|
310
|
+
if (this.bound === null) {
|
|
311
|
+
throw new WebGpuGraphError("E_NOT_LOADED", `RepulsionGrid.${method}(): bind() has not been called for this stage`, {
|
|
312
|
+
state: "unbound",
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
return this.bound;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
//# sourceMappingURL=repulsion-grid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repulsion-grid.js","sourceRoot":"","sources":["../../../src/layouts/repulsion-grid.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE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,CAAC,YAAY,CAAC,CAAC,CAAC;IAChF,CAAC;IAED,+GAA+G;IAC/G,OAAO;QACH,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,KAAK,IAAI,EAAE,CAAC;YAC1B,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;YACzB,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC;QAC1B,CAAC;QACD,KAAK,MAAM,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC;YAC7D,MAAM,CAAC,UAAU,EAAE,CAAC;QACxB,CAAC;QACD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACtB,CAAC;IAED;;;;OAIG;IACK,YAAY,CAAC,MAAc;QAC/B,IAAI,IAAI,CAAC,KAAK,KAAK,IAAI,EAAE,CAAC;YACtB,MAAM,IAAI,gBAAgB,CACtB,cAAc,EACd,iBAAiB,MAAM,+CAA+C,EACtE;gBACI,KAAK,EAAE,SAAS;aACnB,CACJ,CAAC;QACN,CAAC;QACD,OAAO,IAAI,CAAC,KAAK,CAAC;IACtB,CAAC;CACJ"}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The spring-electrical preset on the exact or the grid repulsion tier (spec 7.20 "the preset", 7.8; contract 3.13):
|
|
3
|
+
* ngraph.forcelayout's physics under ngraph's option names and defaults -- Coulomb repulsion `-g m_i m_j / d^2` (K3,
|
|
4
|
+
* LAW 2; G6 / G7 with LAW 2 on the grid tier, P4-T13), Hooke springs
|
|
5
|
+
* `k_s (d - L)` (K2, LAW 2), drag and the semi-implicit Euler step with the unit speed clamp over a per-node velocity
|
|
6
|
+
* (K5, APPLY 2), the kinetic energy folded into the trace (K1, STATS_MODE 2; PD-4) -- as the ForceModel that
|
|
7
|
+
* ForceSimulation drives over the four FA2 kernels K1 K2 K3 K5 per iteration and toScene per batch. No K4: there is no
|
|
8
|
+
* speed controller. The velocity is the model's `velocity` buffer bound into the `oldForce` slot of K3 and K5 (PD-2),
|
|
9
|
+
* left alone by the FA2 text because the model compiles `SWING_MODE = 1` (PD-20). Mass is `1 + degree / 3` and the
|
|
10
|
+
* weights are ignored (PD-11); `SpringElectricalOptions.gravity` is ngraph's Coulomb constant, written into
|
|
11
|
+
* `Fa2Params.coulomb` while FA2's centre gravity is 0 (PD-12). Settlement is the shared rule of spec 7.17
|
|
12
|
+
* (DEP-P5-A); `reheat()` leaves the velocities alone (ngraph has no reheat).
|
|
13
|
+
*
|
|
14
|
+
* Model decisions this file shares with forceatlas2.ts: on the exact tier the K1-K5 dispatches of one batch share ONE
|
|
15
|
+
* compute pass and toScene runs in a second pass that ends it; the fill kernel takes its FillParams from a model-owned
|
|
16
|
+
* 256-byte uniform buffer. The grid tier (P4-T13, PD-22) is FA2's: `RepulsionGrid` with `LAW` 2 when `tierFor(tuning,
|
|
17
|
+
* n)` says so (PD-18), the grid buffers from `buffers()`, K1's grid block under `gridMax > 0` (PD-14) over the model's
|
|
18
|
+
* own `hubCounters`, the three passes `se-k1` / `se-attraction` / `se-grid` before `se-to-scene` (PD-16), and the
|
|
19
|
+
* union stage list (PD-17; K4 is never recorded).
|
|
20
|
+
*/
|
|
21
|
+
import { type GraphSnapshot } from "@graphty/graph-format";
|
|
22
|
+
import { type GpuContext } from "../context.js";
|
|
23
|
+
import { type CommandBatch } from "../kernel/batch.js";
|
|
24
|
+
import { type UniformBlock, type UniformValues } from "../kernel/struct-block.js";
|
|
25
|
+
import { type WgslModuleSpec } from "../kernel/wgsl.js";
|
|
26
|
+
import { type GpuLayoutSimulation, type GpuLayoutTuning, type ResolvedLayoutTuning, type SpringElectricalStats } from "../types/layout.js";
|
|
27
|
+
import { type ResolvedSpringElectricalOptions, type SpringElectricalOptions } from "../types/options.js";
|
|
28
|
+
import { type BufferSpec, type ForceModel, type ModelInputs, type ModelResources, type StateWriter } from "./force-simulation.js";
|
|
29
|
+
import { type Overrides } from "./model-common.js";
|
|
30
|
+
/** The stage names of both tiers in dispatch order plus the per-batch toScene (spec 7.20; P4 PD-17: the union list; the exact tier records K1 K2 K3 K5, the grid tier K1 K2 G1..G7 K5, K4 never). */
|
|
31
|
+
declare const SE_STAGES: readonly ["K1", "K2", "K3", "G1", "G2", "G3", "G4", "G5", "G6", "G7", "K4", "K5", "toScene"];
|
|
32
|
+
/**
|
|
33
|
+
* The size factor of the default force constants: 1 up to SE_SCALE_REFERENCE_NODES nodes (ngraph's constants as
|
|
34
|
+
* they are), then SE_SCALE_REFERENCE_NODES / n, so the per-node force stays at the level ngraph's constants were
|
|
35
|
+
* tuned for instead of pinning every node at the unit speed clamp.
|
|
36
|
+
* @param n - the node count
|
|
37
|
+
* @returns the factor in (0, 1]
|
|
38
|
+
*/
|
|
39
|
+
export declare function springSizeFactor(n: number): number;
|
|
40
|
+
/**
|
|
41
|
+
* Applies SE_DEFAULTS to the option record; validates ranges (spec 7.20; ngraph's constraints): `springLength` > 0,
|
|
42
|
+
* `springCoefficient` > 0, `dragCoefficient` >= 0, `timeStep` > 0, `gravity` any finite number (negative repels; ngraph's
|
|
43
|
+
* comment: "if you make it positive nodes start attract each other"). `gravity` and `springCoefficient` left out (or
|
|
44
|
+
* null) resolve to null: ngraph's constant times springSizeFactor(n), applied in paramsFor once n is known. With `previous` the record is a PATCH over it and
|
|
45
|
+
* `maxInFlight` may not change (the uniform ring is sized by it at construction).
|
|
46
|
+
* @param options - the caller's options (or a setParams patch)
|
|
47
|
+
* @param previous - the current resolved record when resolving a patch
|
|
48
|
+
* @returns the frozen resolved record
|
|
49
|
+
*/
|
|
50
|
+
export declare function resolveSpringElectricalOptions(options: SpringElectricalOptions | undefined, previous?: ResolvedSpringElectricalOptions): ResolvedSpringElectricalOptions;
|
|
51
|
+
/** The spring-electrical model (spec 7.20: K1 K2 K3 K5 per iteration on the exact tier, K1 K2 G1..G7 K5 on the grid tier; toScene once per batch). Stages: the union list of PD-17. */
|
|
52
|
+
export declare class SpringElectricalModel implements ForceModel<SpringElectricalOptions, SpringElectricalStats> {
|
|
53
|
+
/** The model kind of spec 7.19. */
|
|
54
|
+
readonly kind = "springElectrical";
|
|
55
|
+
/** The stage names in dispatch order (the `upTo` vocabulary of recordIteration and debugRunStages). */
|
|
56
|
+
readonly stages: typeof SE_STAGES;
|
|
57
|
+
/** Fa2Params: the per-iteration uniform block (the simulation writes the shared fields into it). */
|
|
58
|
+
readonly params: UniformBlock;
|
|
59
|
+
/** Fa2State: the state header block. */
|
|
60
|
+
readonly state: UniformBlock;
|
|
61
|
+
/** Fa2Trace: one record per iteration of a batch. */
|
|
62
|
+
readonly trace: UniformBlock;
|
|
63
|
+
/** The resolved GPU-only tuning this model was created with (only `repulsion` / `exactMaxNodes` / `nearMax` / `extentFactor` matter here). */
|
|
64
|
+
readonly tuning: ResolvedLayoutTuning;
|
|
65
|
+
/** The option record the model holds: the constructor's record, replaced by onSetParams() ONLY (the query hooks never assign it). */
|
|
66
|
+
private current;
|
|
67
|
+
/** The resources of the last bind(), or null before the first. */
|
|
68
|
+
private resources;
|
|
69
|
+
/** The kernels and bind groups of the last bind(), or null before it (and for n === 0). */
|
|
70
|
+
private bound;
|
|
71
|
+
/** The grid of the load inputs() last resolved (null on the exact tier): onLoad() writes its frame, specs() lists its kernels. */
|
|
72
|
+
private nextGrid;
|
|
73
|
+
/** The K1-K5 compute pass of the batch being recorded, keyed by CommandBatch.id; null between batches. */
|
|
74
|
+
private openPass;
|
|
75
|
+
/**
|
|
76
|
+
* Creates the model for one simulation.
|
|
77
|
+
* @param tuning - the resolved GPU-only tuning
|
|
78
|
+
* @param resolved - the resolved option record at creation
|
|
79
|
+
*/
|
|
80
|
+
constructor(tuning: ResolvedLayoutTuning, resolved: ResolvedSpringElectricalOptions);
|
|
81
|
+
/**
|
|
82
|
+
* force 12n (zeroed), velocity 12n (zeroed: every load() starts at rest, `allocate()` / `clearKept()` honour
|
|
83
|
+
* `zero`), the 256-byte FillParams uniform buffer, the 16-byte `hubCounters` K1 binds on every tier (P4 PD-14),
|
|
84
|
+
* and the grid buffers of `RepulsionGrid.buffers` exactly when `tierFor(tuning, n)` is the grid tier (PD-18).
|
|
85
|
+
* n = 0 reports one node's worth of bytes so no zero-length buffer is ever created.
|
|
86
|
+
* @param n - the node count
|
|
87
|
+
* @param dim - the layout dimension (the arrays are stride 3 in both; the grid's geometry differs)
|
|
88
|
+
* @returns the model-owned buffer specs
|
|
89
|
+
*/
|
|
90
|
+
buffers(n: number, dim: 2 | 3): readonly BufferSpec[];
|
|
91
|
+
/**
|
|
92
|
+
* { mass: 1 + degree / 3, weights: none } (PD-11): the preset has no mass or weight option, and K2 compiles
|
|
93
|
+
* HAS_WEIGHTS = false. No `fixed` (setFixed is the live API). Also remembers the grid of this load
|
|
94
|
+
* (`tierFor(tuning, n)`, spec 7.8) for onLoad() and specs(): the simulation calls inputs() first, then onLoad()
|
|
95
|
+
* before bind().
|
|
96
|
+
* @param s - the snapshot being loaded
|
|
97
|
+
* @param options - the simulation's current option record (its dimension picks the grid's geometry)
|
|
98
|
+
* @returns the per-load inputs
|
|
99
|
+
*/
|
|
100
|
+
inputs(s: GraphSnapshot, options: SpringElectricalOptions): ModelInputs;
|
|
101
|
+
/**
|
|
102
|
+
* The constant SE_OVERRIDES (PD-1): no option changes a law, so setParams never recompiles.
|
|
103
|
+
* @param _options - an option record (unused)
|
|
104
|
+
* @returns the model's own override set
|
|
105
|
+
*/
|
|
106
|
+
overrides(_options: SpringElectricalOptions): Overrides;
|
|
107
|
+
/**
|
|
108
|
+
* The six module specs of an override set in dispatch order -- K1, K2, K3, K5, toScene, fill -- each with only the
|
|
109
|
+
* override names its entry declares (K2 also USE_PERM / HAS_WEIGHTS), for warm() and the compile matrix,
|
|
110
|
+
* followed by the grid tier's specs (`RepulsionGrid.specs` under SE_GRID_OVERRIDES) when the load inputs() last
|
|
111
|
+
* resolved is a grid load (the pipeline key carries no geometry).
|
|
112
|
+
* @param overrides - the merged override set (the model's plus USE_PERM / HAS_WEIGHTS)
|
|
113
|
+
* @param _subgroups - accepted for the ForceModel interface and unused (the composer picks the twin from caps)
|
|
114
|
+
* @returns the specs
|
|
115
|
+
*/
|
|
116
|
+
specs(overrides: Overrides, _subgroups: boolean): readonly WgslModuleSpec[];
|
|
117
|
+
/**
|
|
118
|
+
* Compiles (through the cache) and binds every kernel against the buffers of this load(): K1, K2 over the degree
|
|
119
|
+
* tiers through bindAttraction (or the fill of force when arcCount === 0), K3 on the exact tier or G1-G7 through
|
|
120
|
+
* RepulsionGrid on the grid tier (PD-18), K5, with the velocity in the `oldForce` slot of K3 / G7 / K5 (PD-2),
|
|
121
|
+
* toScene; writes the FillParams { count: 3n, value: 0, mode: 0 } into the model's uniform buffer. With n === 0
|
|
122
|
+
* nothing is bound. The K2 TIER 1 / 2 pipelines compile on the first load whose degrees need them (P4 PD-7).
|
|
123
|
+
* @param resources - the graph, the shared and model buffers, the ring and the cache
|
|
124
|
+
* @param overrides - the merged override set
|
|
125
|
+
*/
|
|
126
|
+
bind(resources: ModelResources, overrides: Overrides): Promise<void>;
|
|
127
|
+
/**
|
|
128
|
+
* The Fa2Params values of one iteration: the shared fields, the FA2 fields at 0 (no centre gravity, PD-12; no
|
|
129
|
+
* FR temperature) and ngraph's five constants with `gravity` in `coulomb`.
|
|
130
|
+
* @param iteration - the global iteration index
|
|
131
|
+
* @param options - the simulation's current option record
|
|
132
|
+
* @returns the uniform values
|
|
133
|
+
*/
|
|
134
|
+
paramsFor(iteration: number, options: SpringElectricalOptions): UniformValues;
|
|
135
|
+
/**
|
|
136
|
+
* Records one iteration into the batch, stopping after stage `upTo` when given (PD-17: `upTo` names a position
|
|
137
|
+
* in the union list and the recording stops after the last stage recorded at or before it, so "K3" on the grid
|
|
138
|
+
* tier stops after K2 and "G5" on the exact tier after K3). The exact tier: K1, K2 (or the fill of force when
|
|
139
|
+
* arcCount === 0), K3, K5 in the batch's ONE compute pass, then toScene in a second pass that ends it. The grid
|
|
140
|
+
* tier (PD-16): the passes `se-k1` (K1), `se-attraction` (K2's tiers) and `se-grid` (G1-G7, K5) per iteration,
|
|
141
|
+
* then `se-to-scene`. With n === 0 nothing is recorded; a call before bind() completed is E_NOT_LOADED.
|
|
142
|
+
* @param batch - the batch being recorded
|
|
143
|
+
* @param slot - the UniformRing slot holding this iteration's Fa2Params
|
|
144
|
+
* @param tier - the tier the simulation resolved at load() (the same rule bind() applied, PD-18)
|
|
145
|
+
* @param upTo - a stage name to stop after; undefined records every stage including toScene
|
|
146
|
+
*/
|
|
147
|
+
recordIteration(batch: CommandBatch, slot: number, tier: "exact" | "grid", upTo?: string): void;
|
|
148
|
+
/**
|
|
149
|
+
* The grid tier's iteration (PD-16): three compute passes before toScene; no K4.
|
|
150
|
+
* @param batch - the batch being recorded
|
|
151
|
+
* @param bound - the bound model
|
|
152
|
+
* @param offset - the Fa2Params dynamic offset of the iteration
|
|
153
|
+
* @param stop - the SE_STAGES index to stop after
|
|
154
|
+
*/
|
|
155
|
+
private recordGridIteration;
|
|
156
|
+
/**
|
|
157
|
+
* K2's tier dispatches, or the fill of force when the graph has no arcs (spec 7.5).
|
|
158
|
+
* @param pass - the open compute pass
|
|
159
|
+
* @param bound - the bound model
|
|
160
|
+
* @param offset - the Fa2Params dynamic offset
|
|
161
|
+
*/
|
|
162
|
+
private recordK2;
|
|
163
|
+
/**
|
|
164
|
+
* The toScene pass that ends the iteration's pass; the batch is complete after it, so nothing reuses the pass.
|
|
165
|
+
* @param batch - the batch
|
|
166
|
+
* @param bound - the bound model
|
|
167
|
+
* @param offset - the Fa2Params dynamic offset
|
|
168
|
+
*/
|
|
169
|
+
private recordToScene;
|
|
170
|
+
/**
|
|
171
|
+
* kineticEnergy = 0 and temperature = 0 in the header (the velocities start at 0 through the buffer's `zero`);
|
|
172
|
+
* on a grid load the frame of the first build (K1 folds nothing on the first iteration).
|
|
173
|
+
* @param state - the state writer of the simulation
|
|
174
|
+
*/
|
|
175
|
+
onLoad(state: StateWriter): void;
|
|
176
|
+
/**
|
|
177
|
+
* Nothing: the velocities carry on (ngraph has no reheat; a drag lands in the next batch through the override
|
|
178
|
+
* list, spec 7.12).
|
|
179
|
+
* @param _state - the state writer of the simulation (unused)
|
|
180
|
+
*/
|
|
181
|
+
onReheat(_state: StateWriter): void;
|
|
182
|
+
/**
|
|
183
|
+
* Replaces the record with the patch applied (every option is a numeric tweak; nothing recompiles, no reset).
|
|
184
|
+
* @param patch - the setParams patch
|
|
185
|
+
* @param _state - the state writer of the simulation (unused)
|
|
186
|
+
*/
|
|
187
|
+
onSetParams(patch: Partial<SpringElectricalOptions>, _state: StateWriter): void;
|
|
188
|
+
/**
|
|
189
|
+
* Decodes the state header and the k trace records of a completed batch into SpringElectricalStats:
|
|
190
|
+
* `repulsionTier` is the bound tier, the grid fields are the header's on the grid tier and null on the exact
|
|
191
|
+
* tier; msPerIteration null (the simulation owns the clock); `kineticEnergy` is the last folded value (one
|
|
192
|
+
* iteration behind the last integrate, PD-4).
|
|
193
|
+
* @param state - a DataView over the 256-byte state header
|
|
194
|
+
* @param trace - a DataView over the k Fa2Trace records of the batch
|
|
195
|
+
* @returns the stats
|
|
196
|
+
*/
|
|
197
|
+
readStats(state: DataView, trace: DataView): SpringElectricalStats;
|
|
198
|
+
/**
|
|
199
|
+
* The resources of the last bind(), or E_NOT_LOADED before it.
|
|
200
|
+
* @returns the resources
|
|
201
|
+
*/
|
|
202
|
+
private requireResources;
|
|
203
|
+
/**
|
|
204
|
+
* The index of a stage name in SE_STAGES, or E_INVALID_ARGUMENT.
|
|
205
|
+
* @param upTo - the stage name
|
|
206
|
+
* @returns its index
|
|
207
|
+
*/
|
|
208
|
+
private stageIndex;
|
|
209
|
+
/** Releases the grid stage's lease and the bind groups (the simulation calls it from dispose() once every in-flight batch has settled). */
|
|
210
|
+
dispose(): void;
|
|
211
|
+
/** Drops the bind groups of the previous bind() (the buffers changed), releases the grid stage's lease and forgets the pass of a batch recorded before the rebind. */
|
|
212
|
+
private dropBound;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Spec 3.3 createSpringElectrical, verbatim: a GpuLayoutSimulation running ngraph's spring-electrical model on the
|
|
216
|
+
* exact or the grid repulsion tier (spec 7.8) with ngraph's defaults (spec 7.20) and the GPU-only tuning of
|
|
217
|
+
* GpuLayoutTuning.
|
|
218
|
+
* @param ctx - the context (E_DISPOSED / E_DEVICE_LOST through assertReady)
|
|
219
|
+
* @param options - the spring-electrical options and the GPU-only tuning knobs in one record
|
|
220
|
+
* @returns the simulation in state "created"; load() next
|
|
221
|
+
*/
|
|
222
|
+
export declare function createSpringElectrical(ctx: GpuContext, options?: SpringElectricalOptions & GpuLayoutTuning): GpuLayoutSimulation<SpringElectricalOptions, SpringElectricalStats>;
|
|
223
|
+
export {};
|
|
224
|
+
//# sourceMappingURL=spring-electrical.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spring-electrical.d.ts","sourceRoot":"","sources":["../../../src/layouts/spring-electrical.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAS3D,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;AAGhD,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGvD,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAClF,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAIxD,OAAO,EACH,KAAK,mBAAmB,EACxB,KAAK,eAAe,EACpB,KAAK,oBAAoB,EACzB,KAAK,qBAAqB,EAE7B,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,KAAK,+BAA+B,EAAE,KAAK,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AACzG,OAAO,EACH,KAAK,UAAU,EACf,KAAK,UA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