@graphty/webgpu-graph-algorithms 0.6.14 → 0.6.16

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.
Files changed (197) hide show
  1. package/README.md +52 -52
  2. package/dist/browser.js +1 -1
  3. package/dist/chunks/{context-Bi6AhScG.js → context-VIvatQOo.js} +69 -34
  4. package/dist/chunks/context-VIvatQOo.js.map +1 -0
  5. package/dist/node.js +1 -1
  6. package/dist/src/accelerator.d.ts +5 -3
  7. package/dist/src/accelerator.d.ts.map +1 -1
  8. package/dist/src/accelerator.js +101 -5
  9. package/dist/src/accelerator.js.map +1 -1
  10. package/dist/src/algorithms/all-pairs.d.ts +41 -0
  11. package/dist/src/algorithms/all-pairs.d.ts.map +1 -0
  12. package/dist/src/algorithms/all-pairs.js +181 -0
  13. package/dist/src/algorithms/all-pairs.js.map +1 -0
  14. package/dist/src/algorithms/betweenness.d.ts +70 -0
  15. package/dist/src/algorithms/betweenness.d.ts.map +1 -0
  16. package/dist/src/algorithms/betweenness.js +538 -0
  17. package/dist/src/algorithms/betweenness.js.map +1 -0
  18. package/dist/src/algorithms/closeness.d.ts +15 -5
  19. package/dist/src/algorithms/closeness.d.ts.map +1 -1
  20. package/dist/src/algorithms/closeness.js +112 -26
  21. package/dist/src/algorithms/closeness.js.map +1 -1
  22. package/dist/src/algorithms/components.d.ts +9 -1
  23. package/dist/src/algorithms/components.d.ts.map +1 -1
  24. package/dist/src/algorithms/components.js +2 -2
  25. package/dist/src/algorithms/components.js.map +1 -1
  26. package/dist/src/algorithms/label-propagation.d.ts +31 -0
  27. package/dist/src/algorithms/label-propagation.d.ts.map +1 -0
  28. package/dist/src/algorithms/label-propagation.js +254 -0
  29. package/dist/src/algorithms/label-propagation.js.map +1 -0
  30. package/dist/src/algorithms/simple-symmetric.d.ts +88 -0
  31. package/dist/src/algorithms/simple-symmetric.d.ts.map +1 -0
  32. package/dist/src/algorithms/simple-symmetric.js +347 -0
  33. package/dist/src/algorithms/simple-symmetric.js.map +1 -0
  34. package/dist/src/algorithms/triangles.d.ts +34 -0
  35. package/dist/src/algorithms/triangles.d.ts.map +1 -0
  36. package/dist/src/algorithms/triangles.js +203 -0
  37. package/dist/src/algorithms/triangles.js.map +1 -0
  38. package/dist/src/constants.d.ts +53 -0
  39. package/dist/src/constants.d.ts.map +1 -1
  40. package/dist/src/constants.js +53 -0
  41. package/dist/src/constants.js.map +1 -1
  42. package/dist/src/index.d.ts +12 -3
  43. package/dist/src/index.d.ts.map +1 -1
  44. package/dist/src/index.js +8 -1
  45. package/dist/src/index.js.map +1 -1
  46. package/dist/src/kernel/prelude.d.ts.map +1 -1
  47. package/dist/src/kernel/prelude.js +4 -1
  48. package/dist/src/kernel/prelude.js.map +1 -1
  49. package/dist/src/kernels.d.ts +24 -6
  50. package/dist/src/kernels.d.ts.map +1 -1
  51. package/dist/src/kernels.js +373 -7
  52. package/dist/src/kernels.js.map +1 -1
  53. package/dist/src/memory/residency.js +15 -4
  54. package/dist/src/memory/residency.js.map +1 -1
  55. package/dist/src/primitives/coo-to-csr.d.ts +73 -0
  56. package/dist/src/primitives/coo-to-csr.d.ts.map +1 -0
  57. package/dist/src/primitives/coo-to-csr.js +183 -0
  58. package/dist/src/primitives/coo-to-csr.js.map +1 -0
  59. package/dist/src/primitives/frontier.d.ts +2 -0
  60. package/dist/src/primitives/frontier.d.ts.map +1 -1
  61. package/dist/src/primitives/frontier.js +2 -0
  62. package/dist/src/primitives/frontier.js.map +1 -1
  63. package/dist/src/primitives/group-by-key.d.ts +82 -0
  64. package/dist/src/primitives/group-by-key.d.ts.map +1 -0
  65. package/dist/src/primitives/group-by-key.js +147 -0
  66. package/dist/src/primitives/group-by-key.js.map +1 -0
  67. package/dist/src/types/accelerator.d.ts +19 -7
  68. package/dist/src/types/accelerator.d.ts.map +1 -1
  69. package/dist/src/types/algorithms.d.ts +4 -0
  70. package/dist/src/types/algorithms.d.ts.map +1 -1
  71. package/dist/src/types/all-pairs.d.ts +35 -0
  72. package/dist/src/types/all-pairs.d.ts.map +1 -0
  73. package/dist/src/types/all-pairs.js +8 -0
  74. package/dist/src/types/all-pairs.js.map +1 -0
  75. package/dist/src/types/betweenness.d.ts +35 -0
  76. package/dist/src/types/betweenness.d.ts.map +1 -0
  77. package/dist/src/types/betweenness.js +7 -0
  78. package/dist/src/types/betweenness.js.map +1 -0
  79. package/dist/src/types/community.d.ts +18 -0
  80. package/dist/src/types/community.d.ts.map +1 -0
  81. package/dist/src/types/community.js +5 -0
  82. package/dist/src/types/community.js.map +1 -0
  83. package/dist/src/types/structure.d.ts +27 -0
  84. package/dist/src/types/structure.d.ts.map +1 -0
  85. package/dist/src/types/structure.js +8 -0
  86. package/dist/src/types/structure.js.map +1 -0
  87. package/dist/src/wgsl/apsp-fw.wgsl.d.ts +25 -0
  88. package/dist/src/wgsl/apsp-fw.wgsl.d.ts.map +1 -0
  89. package/dist/src/wgsl/apsp-fw.wgsl.js +113 -0
  90. package/dist/src/wgsl/apsp-fw.wgsl.js.map +1 -0
  91. package/dist/src/wgsl/apsp-init.wgsl.d.ts +12 -0
  92. package/dist/src/wgsl/apsp-init.wgsl.d.ts.map +1 -0
  93. package/dist/src/wgsl/apsp-init.wgsl.js +26 -0
  94. package/dist/src/wgsl/apsp-init.wgsl.js.map +1 -0
  95. package/dist/src/wgsl/bc-backward.wgsl.d.ts +15 -0
  96. package/dist/src/wgsl/bc-backward.wgsl.d.ts.map +1 -0
  97. package/dist/src/wgsl/bc-backward.wgsl.js +34 -0
  98. package/dist/src/wgsl/bc-backward.wgsl.js.map +1 -0
  99. package/dist/src/wgsl/bc-edge-gather.wgsl.d.ts +12 -0
  100. package/dist/src/wgsl/bc-edge-gather.wgsl.d.ts.map +1 -0
  101. package/dist/src/wgsl/bc-edge-gather.wgsl.js +36 -0
  102. package/dist/src/wgsl/bc-edge-gather.wgsl.js.map +1 -0
  103. package/dist/src/wgsl/bc-finalize.wgsl.d.ts +21 -0
  104. package/dist/src/wgsl/bc-finalize.wgsl.d.ts.map +1 -0
  105. package/dist/src/wgsl/bc-finalize.wgsl.js +47 -0
  106. package/dist/src/wgsl/bc-finalize.wgsl.js.map +1 -0
  107. package/dist/src/wgsl/bc-forward-edge.wgsl.d.ts +15 -0
  108. package/dist/src/wgsl/bc-forward-edge.wgsl.d.ts.map +1 -0
  109. package/dist/src/wgsl/bc-forward-edge.wgsl.js +76 -0
  110. package/dist/src/wgsl/bc-forward-edge.wgsl.js.map +1 -0
  111. package/dist/src/wgsl/bc-forward.wgsl.d.ts +23 -0
  112. package/dist/src/wgsl/bc-forward.wgsl.d.ts.map +1 -0
  113. package/dist/src/wgsl/bc-forward.wgsl.js +106 -0
  114. package/dist/src/wgsl/bc-forward.wgsl.js.map +1 -0
  115. package/dist/src/wgsl/bc-gather.wgsl.d.ts +9 -0
  116. package/dist/src/wgsl/bc-gather.wgsl.d.ts.map +1 -0
  117. package/dist/src/wgsl/bc-gather.wgsl.js +20 -0
  118. package/dist/src/wgsl/bc-gather.wgsl.js.map +1 -0
  119. package/dist/src/wgsl/closeness-reduce.wgsl.d.ts +4 -1
  120. package/dist/src/wgsl/closeness-reduce.wgsl.d.ts.map +1 -1
  121. package/dist/src/wgsl/closeness-reduce.wgsl.js +8 -4
  122. package/dist/src/wgsl/closeness-reduce.wgsl.js.map +1 -1
  123. package/dist/src/wgsl/closeness-sweep.wgsl.d.ts +4 -2
  124. package/dist/src/wgsl/closeness-sweep.wgsl.d.ts.map +1 -1
  125. package/dist/src/wgsl/closeness-sweep.wgsl.js +12 -2
  126. package/dist/src/wgsl/closeness-sweep.wgsl.js.map +1 -1
  127. package/dist/src/wgsl/coo-emit.wgsl.d.ts +10 -0
  128. package/dist/src/wgsl/coo-emit.wgsl.d.ts.map +1 -0
  129. package/dist/src/wgsl/coo-emit.wgsl.js +33 -0
  130. package/dist/src/wgsl/coo-emit.wgsl.js.map +1 -0
  131. package/dist/src/wgsl/coo-scatter.wgsl.d.ts +15 -0
  132. package/dist/src/wgsl/coo-scatter.wgsl.d.ts.map +1 -0
  133. package/dist/src/wgsl/coo-scatter.wgsl.js +32 -0
  134. package/dist/src/wgsl/coo-scatter.wgsl.js.map +1 -0
  135. package/dist/src/wgsl/group-by-key-row.wgsl.d.ts +26 -0
  136. package/dist/src/wgsl/group-by-key-row.wgsl.d.ts.map +1 -0
  137. package/dist/src/wgsl/group-by-key-row.wgsl.js +146 -0
  138. package/dist/src/wgsl/group-by-key-row.wgsl.js.map +1 -0
  139. package/dist/src/wgsl/lpa-step.wgsl.d.ts +10 -0
  140. package/dist/src/wgsl/lpa-step.wgsl.d.ts.map +1 -0
  141. package/dist/src/wgsl/lpa-step.wgsl.js +35 -0
  142. package/dist/src/wgsl/lpa-step.wgsl.js.map +1 -0
  143. package/dist/src/wgsl/orient-flags.wgsl.d.ts +9 -0
  144. package/dist/src/wgsl/orient-flags.wgsl.d.ts.map +1 -0
  145. package/dist/src/wgsl/orient-flags.wgsl.js +21 -0
  146. package/dist/src/wgsl/orient-flags.wgsl.js.map +1 -0
  147. package/dist/src/wgsl/run-flags.wgsl.d.ts +8 -0
  148. package/dist/src/wgsl/run-flags.wgsl.d.ts.map +1 -0
  149. package/dist/src/wgsl/run-flags.wgsl.js +18 -0
  150. package/dist/src/wgsl/run-flags.wgsl.js.map +1 -0
  151. package/dist/src/wgsl/tri-intersect.wgsl.d.ts +11 -0
  152. package/dist/src/wgsl/tri-intersect.wgsl.d.ts.map +1 -0
  153. package/dist/src/wgsl/tri-intersect.wgsl.js +64 -0
  154. package/dist/src/wgsl/tri-intersect.wgsl.js.map +1 -0
  155. package/dist/webgpu-graph-algorithms.js +2828 -321
  156. package/dist/webgpu-graph-algorithms.js.map +1 -1
  157. package/package.json +5 -5
  158. package/src/accelerator.ts +130 -7
  159. package/src/algorithms/all-pairs.ts +228 -0
  160. package/src/algorithms/betweenness.ts +739 -0
  161. package/src/algorithms/closeness.ts +124 -32
  162. package/src/algorithms/components.ts +2 -2
  163. package/src/algorithms/label-propagation.ts +280 -0
  164. package/src/algorithms/simple-symmetric.ts +409 -0
  165. package/src/algorithms/triangles.ts +240 -0
  166. package/src/constants.ts +53 -0
  167. package/src/index.ts +20 -1
  168. package/src/kernel/prelude.ts +6 -0
  169. package/src/kernels.ts +411 -10
  170. package/src/memory/residency.ts +15 -4
  171. package/src/primitives/coo-to-csr.ts +251 -0
  172. package/src/primitives/frontier.ts +4 -0
  173. package/src/primitives/group-by-key.ts +209 -0
  174. package/src/types/accelerator.ts +26 -6
  175. package/src/types/algorithms.ts +5 -0
  176. package/src/types/all-pairs.ts +37 -0
  177. package/src/types/betweenness.ts +38 -0
  178. package/src/types/community.ts +18 -0
  179. package/src/types/structure.ts +28 -0
  180. package/src/wgsl/apsp-fw.wgsl.ts +112 -0
  181. package/src/wgsl/apsp-init.wgsl.ts +25 -0
  182. package/src/wgsl/bc-backward.wgsl.ts +33 -0
  183. package/src/wgsl/bc-edge-gather.wgsl.ts +35 -0
  184. package/src/wgsl/bc-finalize.wgsl.ts +46 -0
  185. package/src/wgsl/bc-forward-edge.wgsl.ts +75 -0
  186. package/src/wgsl/bc-forward.wgsl.ts +105 -0
  187. package/src/wgsl/bc-gather.wgsl.ts +19 -0
  188. package/src/wgsl/closeness-reduce.wgsl.ts +8 -4
  189. package/src/wgsl/closeness-sweep.wgsl.ts +12 -2
  190. package/src/wgsl/coo-emit.wgsl.ts +32 -0
  191. package/src/wgsl/coo-scatter.wgsl.ts +31 -0
  192. package/src/wgsl/group-by-key-row.wgsl.ts +145 -0
  193. package/src/wgsl/lpa-step.wgsl.ts +34 -0
  194. package/src/wgsl/orient-flags.wgsl.ts +20 -0
  195. package/src/wgsl/run-flags.wgsl.ts +17 -0
  196. package/src/wgsl/tri-intersect.wgsl.ts +63 -0
  197. package/dist/chunks/context-Bi6AhScG.js.map +0 -1
@@ -0,0 +1,254 @@
1
+ /**
2
+ * Label propagation (design 8.6, 3.3 line 807; the P11 plan's P11-T6) over the simple symmetric graph of the
3
+ * snapshot (`buildSimpleSymmetric`). Every vertex starts with its own index as its label; each pass,
4
+ * `group-by-key-row` finds every vertex's weighted mode of its neighbours' labels (the lowest label on a tie) and
5
+ * `lpa-step` adopts it synchronously -- but only in the pass's direction: down to a lower label on even passes, up to
6
+ * a higher one on odd passes (cuGraph's swap-avoidance rule), which is what stops two neighbours trading labels
7
+ * forever. A pass that moves nothing in either direction after one that moved nothing in the other is a fixed point,
8
+ * and the run stops there or at `maxIterations` passes.
9
+ *
10
+ * Passes are recorded LABEL_PROP_PASSES_PER_SUBMIT to a submit with one readback of their move counts, because a
11
+ * readback per pass costs more than the passes on a small graph; the passes after the fixed point inside the last
12
+ * submit change nothing, so the labels are those of the fixed point. The first submit is the graph build's second.
13
+ * The labels are renumbered in first-seen order on the host (`renumberPartition`), as connected components' are.
14
+ *
15
+ * The result is bitwise reproducible on one device and between devices: the grouping is order-independent and every
16
+ * sum is an integer.
17
+ */
18
+ import { renumberPartition } from "@graphty/graph-format";
19
+ import { LABEL_PROP_PASSES_PER_SUBMIT } from "../constants.js";
20
+ import { WebGpuGraphError } from "../errors.js";
21
+ import { CommandBatch } from "../kernel/batch.js";
22
+ import { plan1d } from "../kernel/dispatch.js";
23
+ import { FILL_PARAMS, kernelSpec, LPA_PARAMS } from "../kernels.js";
24
+ import { planGroupRows, prepareGroupByKeyRow } from "../primitives/group-by-key.js";
25
+ import { assertDeviceComputes } from "../primitives/verify.js";
26
+ import { labelResult } from "./components.js";
27
+ import { algorithmScope } from "./scope.js";
28
+ import { assertBindable, assertBuildSorted, buildSimpleSymmetric } from "./simple-symmetric.js";
29
+ const ALGORITHM = "labelPropagation";
30
+ /** The default pass cap, as in `@graphty/algorithms`' labelPropagation. */
31
+ const DEFAULT_MAX_ITERATIONS = 100;
32
+ /** Params slots of the largest batch: the graph build's second submit plus one batch of passes. */
33
+ const RING_SLOTS = 1024;
34
+ /**
35
+ * Validates `options.dest` for a label result of `n` elements.
36
+ * @param dest - the caller's destination array, if any
37
+ * @param n - the node count
38
+ * @returns the destination as a U32, or null when none was given
39
+ */
40
+ function checkDest(dest, n) {
41
+ if (dest === undefined) {
42
+ return null;
43
+ }
44
+ if (dest instanceof Uint32Array && dest.length === n && dest.buffer instanceof ArrayBuffer) {
45
+ return dest;
46
+ }
47
+ throw new WebGpuGraphError("E_INVALID_ARGUMENT", `${ALGORITHM}: dest must be a Uint32Array of length ${n} over an ArrayBuffer`, {
48
+ argument: "dest",
49
+ value: `${dest.constructor.name}(${dest.length})`,
50
+ expected: `Uint32Array(${n}) over an ArrayBuffer`,
51
+ });
52
+ }
53
+ /**
54
+ * The pass cap.
55
+ * @param value - options.maxIterations
56
+ * @returns the cap
57
+ */
58
+ function maxIterationsOf(value) {
59
+ if (value === undefined) {
60
+ return DEFAULT_MAX_ITERATIONS;
61
+ }
62
+ if (!Number.isSafeInteger(value) || value < 0) {
63
+ throw new WebGpuGraphError("E_INVALID_ARGUMENT", `${ALGORITHM}: maxIterations must be a non-negative integer`, {
64
+ argument: "maxIterations",
65
+ value,
66
+ expected: "a non-negative integer",
67
+ });
68
+ }
69
+ return value;
70
+ }
71
+ /**
72
+ * An upper bound of every vertex's number of distinct neighbours in the simple symmetric graph: its arcs in both
73
+ * directions, which the merge of parallel edges and the drop of self-loops can only shrink.
74
+ * @param s - the snapshot
75
+ * @returns one bound per vertex
76
+ */
77
+ function neighbourBound(s) {
78
+ const out = s.outDegree();
79
+ if (!s.directed) {
80
+ return out;
81
+ }
82
+ const inDegree = s.inDegree();
83
+ const bound = new Uint32Array(s.nodeCount);
84
+ for (let v = 0; v < bound.length; v++) {
85
+ bound[v] = out[v] + inDegree[v];
86
+ }
87
+ return bound;
88
+ }
89
+ /**
90
+ * The labels as a result: every label must be a node index (a device bug otherwise), then renumbered first-seen.
91
+ * @param raw - the labels the device produced
92
+ * @param dest - the caller's destination, if any
93
+ * @returns the result
94
+ */
95
+ function resultOf(raw, dest) {
96
+ const n = raw.length;
97
+ for (let v = 0; v < n; v++) {
98
+ if (raw[v] >= n) {
99
+ throw new WebGpuGraphError("E_VALIDATION", `${ALGORITHM}: labels[${v}] = ${raw[v]} is not a node index`, {
100
+ label: `${ALGORITHM}/labels`,
101
+ message: `the device produced a label outside [0, ${n})`,
102
+ });
103
+ }
104
+ }
105
+ const { labels, count } = renumberPartition(raw, dest ?? undefined);
106
+ return labelResult(labels, count);
107
+ }
108
+ /**
109
+ * The identity labelling: every vertex its own community.
110
+ * @param n - the node count
111
+ * @param dest - the caller's destination, if any
112
+ * @returns the result
113
+ */
114
+ function identityResult(n, dest) {
115
+ const labels = dest ?? new Uint32Array(n);
116
+ for (let v = 0; v < n; v++) {
117
+ labels[v] = v;
118
+ }
119
+ return labelResult(labels, n);
120
+ }
121
+ /**
122
+ * Label propagation on the device (see the file header).
123
+ * @param ctx - the context whose device runs the kernels
124
+ * @param s - the snapshot (its edge list is uploaded through ctx.residency, or found there)
125
+ * @param options - maxIterations (default 100), weighted (default true), plus dest / signal / onProgress
126
+ * @returns the labels, dense in first-seen order, the community count and groups()
127
+ */
128
+ export async function labelPropagation(ctx, s, options) {
129
+ ctx.assertReady();
130
+ await assertDeviceComputes(ctx);
131
+ const n = s.nodeCount;
132
+ const dest = checkDest(options?.dest, n);
133
+ const maxIterations = maxIterationsOf(options?.maxIterations);
134
+ const weighted = options?.weighted !== false;
135
+ if (options?.signal?.aborted) {
136
+ throw new WebGpuGraphError("E_ABORTED", `${ALGORITHM}: the signal was aborted before any work started`, {});
137
+ }
138
+ if (n === 0 || s.edgeCount === 0 || maxIterations === 0) {
139
+ options?.onProgress?.(1, 1);
140
+ return identityResult(n, dest);
141
+ }
142
+ // the hash region of the workgroup tier is bound whole: refuse a graph it outgrows before any device work
143
+ const plan = planGroupRows(neighbourBound(s));
144
+ assertBindable(ctx, 4 * plan.regionWords, "the group-by hash region", ALGORITHM);
145
+ const scope = algorithmScope(ctx, ALGORITHM, RING_SLOTS);
146
+ try {
147
+ const build = await buildSimpleSymmetric(ctx, s, scope, weighted, ALGORITHM);
148
+ const { graph } = build;
149
+ if (graph.colIdx === null) {
150
+ // only self-loops: no vertex has a neighbour, so nothing ever moves
151
+ scope.flush();
152
+ const bytes = await build.batch.submit().readback;
153
+ ctx.assertReady();
154
+ assertBuildSorted(bytes, build, ALGORITHM);
155
+ options?.onProgress?.(1, 1);
156
+ return identityResult(n, dest);
157
+ }
158
+ const wg = ctx.workgroupSize;
159
+ const words = (count, label) => {
160
+ const size = 4 * Math.max(1, count);
161
+ return { buffer: scope.scratch(size, label), offset: 0, size, window: null };
162
+ };
163
+ const rows = words(plan.words.length, "rows");
164
+ const region = words(plan.regionWords, "hashRegion");
165
+ const labelsA = words(n, "labelsA");
166
+ const labelsB = words(n, "labelsB");
167
+ const bestKey = words(n, "bestKey");
168
+ const bestScore = words(n, "bestScore");
169
+ const counters = words(LABEL_PROP_PASSES_PER_SUBMIT, "counters");
170
+ await ctx.allocator.check();
171
+ const { queue } = ctx.device;
172
+ queue.writeBuffer(rows.buffer, 0, plan.words);
173
+ queue.writeBuffer(region.buffer, 0, new Uint32Array(1));
174
+ const groupBy = await prepareGroupByKeyRow(scope);
175
+ const step = await ctx.pipelines.kernel(kernelSpec("lpa-step"));
176
+ const fill = await ctx.pipelines.kernel(kernelSpec("fill"));
177
+ const nodePlan = plan1d(n, wg, ctx.caps);
178
+ let { batch } = build;
179
+ let first = true;
180
+ let cur = labelsA;
181
+ let next = labelsB;
182
+ let done = 0;
183
+ let previousLast = -1;
184
+ for (;;) {
185
+ const k = Math.min(LABEL_PROP_PASSES_PER_SUBMIT, maxIterations - done);
186
+ queue.writeBuffer(counters.buffer, 0, new Uint32Array(k));
187
+ const pass = batch.pass("passes");
188
+ if (first) {
189
+ const iota = scope.params(FILL_PARAMS, { count: n, value: 0, mode: 1, pad0: 0 });
190
+ fill.dispatch(pass, fill.bind({ dst: labelsA, P: iota.binding }), nodePlan, [iota.offset]);
191
+ }
192
+ for (let i = 0; i < k; i++) {
193
+ groupBy.record(pass, {
194
+ rowPtr: graph.rowPtr,
195
+ colIdx: graph.colIdx,
196
+ weights: weighted ? graph.weights : null,
197
+ keyIn: cur,
198
+ plan,
199
+ rows,
200
+ hashRegion: region,
201
+ bestKey,
202
+ bestScore,
203
+ });
204
+ const params = scope.params(LPA_PARAMS, {
205
+ n,
206
+ direction: (done + i) % 2,
207
+ counterIndex: i,
208
+ pad0: 0,
209
+ });
210
+ step.dispatch(pass, step.bind({ labelsIn: cur, bestKey, labelsOut: next, counters, P: params.binding }), nodePlan, [params.offset]);
211
+ [cur, next] = [next, cur];
212
+ }
213
+ batch.endPass();
214
+ const movesRequest = batch.readback(counters.buffer, 0, 4 * k);
215
+ const exhaustedRequest = batch.readback(region.buffer, 0, 4);
216
+ scope.flush();
217
+ const submitted = batch.submit();
218
+ const bytes = await submitted.readback;
219
+ ctx.assertReady();
220
+ if (first) {
221
+ assertBuildSorted(bytes, build, ALGORITHM);
222
+ first = false;
223
+ }
224
+ if (new Uint32Array(bytes, exhaustedRequest.offset, 1)[0] !== 0) {
225
+ throw new WebGpuGraphError("E_VALIDATION", `${ALGORITHM}: a hash probe exhausted its bound`, {
226
+ label: `${ALGORITHM}/group-by-key`,
227
+ message: "a compare-exchange loop of the workgroup tier ran out of steps",
228
+ });
229
+ }
230
+ const moves = new Uint32Array(bytes, movesRequest.offset, k);
231
+ done += k;
232
+ const lastTwo = k >= 2 ? moves[k - 2] + moves[k - 1] : previousLast + moves[0];
233
+ previousLast = moves[k - 1];
234
+ if (options?.signal?.aborted) {
235
+ throw new WebGpuGraphError("E_ABORTED", `${ALGORITHM}: the signal was aborted`, {
236
+ batchId: submitted.id,
237
+ });
238
+ }
239
+ options?.onProgress?.(done, maxIterations);
240
+ if (lastTwo === 0 || done >= maxIterations) {
241
+ break;
242
+ }
243
+ batch = new CommandBatch(ctx, `${ALGORITHM}/passes`);
244
+ }
245
+ const raw = new Uint32Array(n);
246
+ await ctx.readback.read(cur.buffer, 4 * n, raw);
247
+ ctx.assertReady();
248
+ return resultOf(raw, dest);
249
+ }
250
+ finally {
251
+ scope.dispose();
252
+ }
253
+ }
254
+ //# sourceMappingURL=label-propagation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"label-propagation.js","sourceRoot":"","sources":["../../../src/algorithms/label-propagation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAsB,iBAAiB,EAAY,MAAM,uBAAuB,CAAC;AAExF,OAAO,EAAE,4BAA4B,EAAE,MAAM,iBAAiB,CAAC;AAE/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AACpF,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAK/D,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAEhG,MAAM,SAAS,GAAG,kBAAkB,CAAC;AACrC,2EAA2E;AAC3E,MAAM,sBAAsB,GAAG,GAAG,CAAC;AACnC,mGAAmG;AACnG,MAAM,UAAU,GAAG,IAAI,CAAC;AAExB;;;;;GAKG;AACH,SAAS,SAAS,CAAC,IAA4C,EAAE,CAAS;IACtE,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACrB,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,IAAI,IAAI,YAAY,WAAW,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,CAAC,MAAM,YAAY,WAAW,EAAE,CAAC;QACzF,OAAO,IAAW,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AAC,CAAC,GAAG,CAAC,CAAC,CAAC;YAC5B,IAAI,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;gBAC3B,MAAM,IAAI,gBAAgB,CAAC,WAAW,EAAE,GAAG,SAAS,0BAA0B,EAAE;oBAC5E,OAAO,EAAE,SAAS,CAAC,EAAE;iBACxB,CAAC,CAAC;YACP,CAAC;YACD,OAAO,EAAE,UAAU,EAAE,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;YAC3C,IAAI,OAAO,KAAK,CAAC,IAAI,IAAI,IAAI,aAAa,EAAE,CAAC;gBACzC,MAAM;YACV,CAAC;YACD,KAAK,GAAG,IAAI,YAAY,CAAC,GAAG,EAAE,GAAG,SAAS,SAAS,CAAC,CAAC;QACzD,CAAC;QACD,MAAM,GAAG,GAAG,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC;QAC/B,MAAM,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;QAChD,GAAG,CAAC,WAAW,EAAE,CAAC;QAClB,OAAO,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAC/B,CAAC;YAAS,CAAC;QACP,KAAK,CAAC,OAAO,EAAE,CAAC;IACpB,CAAC;AACL,CAAC"}
@@ -0,0 +1,88 @@
1
+ /**
2
+ * The simple symmetric graph (the P11 plan's PD-4): triangle counting and label propagation are defined over an
3
+ * undirected graph with no parallel edges and no self-loops, and a snapshot may be directed, may carry parallel
4
+ * edges and may carry self-loops. This builds that graph on the device from the snapshot's edge list:
5
+ *
6
+ * 1. `coo-emit` writes two arcs per logical edge -- the edge as declared and its reverse -- and drops a self-loop
7
+ * by writing both of its arcs as `INVALID_INDEX`, which sorts last.
8
+ * 2. Two stable radix sorts order the arcs by (source, target): by target first, then by source, the second sort's
9
+ * stability keeping the first's order among equal sources. Between and after them `coo-emit` re-reads the edge
10
+ * list through the sorted permutation (INDEXED), so no gather kernel is needed.
11
+ * 3. `run-flags` marks the first arc of every run of equal pairs; the scan of the flags counts the runs, which is
12
+ * the number of distinct arcs `U` -- read back once, because every later size depends on it.
13
+ * 4. Three `compact`s keep the first arc of every run (its source, its target and its position), and a segmented
14
+ * sum over the runs merges the weights of parallel arcs in input order (so the merged weight is bitwise
15
+ * reproducible).
16
+ * 5. `cooToCsr` in its sorted-input mode builds the rows, which come out sorted by target.
17
+ *
18
+ * The first submit ends at step 3; steps 4 and 5 are recorded into a batch that is RETURNED OPEN, so the caller
19
+ * records its own first work into the same submit and saves a synchronisation. The caller must check the
20
+ * precondition flag of `cooToCsr` with `assertBuildSorted` after that submit.
21
+ *
22
+ * Every intermediate array is `2 x edgeCount` words and is bound whole, so a snapshot whose arcs exceed one storage
23
+ * binding is refused with `E_TOO_LARGE` before any upload. A weighted build refuses, with `E_UNSUPPORTED`, a pair
24
+ * joined by more than PARALLEL_MERGE_LIMIT parallel edges (see the constant).
25
+ *
26
+ * ponytail: about nine of the arrays are alive at the peak (72 bytes per logical edge); reuse buffers across the
27
+ * steps if a 1M-node / 10M-edge build needs the room.
28
+ */
29
+ import { type GraphSnapshot } from "@graphty/graph-format";
30
+ import { type GpuContext } from "../context.js";
31
+ import { CommandBatch, type ReadbackRequest } from "../kernel/batch.js";
32
+ import { type Binding } from "../types/memory.js";
33
+ import { type AlgorithmScope } from "./scope.js";
34
+ /**
35
+ * The simple symmetric graph on the device.
36
+ * @public
37
+ */
38
+ export interface SimpleGraph {
39
+ readonly n: number;
40
+ /** Arcs: twice the undirected edges of the simple graph. */
41
+ readonly arcCount: number;
42
+ /** `n + 1` words. */
43
+ readonly rowPtr: Binding;
44
+ /** `arcCount` words, each row sorted ascending; null when there are no arcs. */
45
+ readonly colIdx: Binding | null;
46
+ /** `arcCount` f32, the summed weight of the parallel edges each arc merges (1 per edge on an unweighted snapshot); null when there are no arcs or weights were not asked for. */
47
+ readonly weights: Binding | null;
48
+ /** The source of every arc (`arcCount` words, non-decreasing); null when there are no arcs. */
49
+ readonly src: Binding | null;
50
+ }
51
+ /**
52
+ * The open second batch of a build: record more work into it, submit it, then call `assertBuildSorted`.
53
+ * @public
54
+ */
55
+ export interface SimpleGraphBuild {
56
+ readonly graph: SimpleGraph;
57
+ readonly batch: CommandBatch;
58
+ /** The readback of the sorted-input flag of `cooToCsr`, already scheduled on `batch`. */
59
+ readonly flag: ReadbackRequest;
60
+ }
61
+ /**
62
+ * Throws `E_TOO_LARGE` when a buffer the caller binds whole is larger than one storage binding of the device.
63
+ * @param ctx - the context whose limit applies
64
+ * @param needed - the bytes of the largest whole binding
65
+ * @param path - what does not fit
66
+ * @param algorithm - the algorithm, for the error
67
+ */
68
+ export declare function assertBindable(ctx: GpuContext, needed: number, path: string, algorithm: string): void;
69
+ /**
70
+ * Throws `E_VALIDATION` when the device found the build's arcs out of source order, which would mean a bug in the
71
+ * sorts: the rows would be scrambled and every intersection over them wrong.
72
+ * @param bytes - the batch's readback bytes
73
+ * @param build - the build whose flag was read
74
+ * @param label - the algorithm, for the error
75
+ */
76
+ export declare function assertBuildSorted(bytes: ArrayBuffer, build: SimpleGraphBuild, label: string): void;
77
+ /**
78
+ * Builds the simple symmetric graph of `s` (see the file header): submits the first batch and waits for its
79
+ * four-byte readback, then records the rest into a batch it returns open.
80
+ * @param ctx - the context
81
+ * @param s - the snapshot (its edge list is uploaded through the residency, or found there)
82
+ * @param scope - the caller's scope: every buffer of the graph is its scratch
83
+ * @param withWeights - merge and keep the weights (label propagation) or not (triangle counting)
84
+ * @param label - the batch label prefix
85
+ * @returns the graph and the open batch
86
+ */
87
+ export declare function buildSimpleSymmetric(ctx: GpuContext, s: GraphSnapshot, scope: AlgorithmScope, withWeights: boolean, label: string): Promise<SimpleGraphBuild>;
88
+ //# sourceMappingURL=simple-symmetric.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"simple-symmetric.d.ts","sourceRoot":"","sources":["../../../src/algorithms/simple-symmetric.ts"],"names":[],"mappings":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