@graphty/webgpu-graph-algorithms 0.6.20 → 0.6.22
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 +1 -1
- package/dist/browser.js +1 -1
- package/dist/chunks/{context-VIvatQOo.js → context-B40Z6lV_.js} +39 -30
- package/dist/chunks/context-B40Z6lV_.js.map +1 -0
- package/dist/node.js +1 -1
- package/dist/src/accelerator.d.ts +1 -1
- package/dist/src/accelerator.d.ts.map +1 -1
- package/dist/src/accelerator.js +20 -1
- package/dist/src/accelerator.js.map +1 -1
- package/dist/src/algorithms/mst.d.ts +50 -0
- package/dist/src/algorithms/mst.d.ts.map +1 -0
- package/dist/src/algorithms/mst.js +245 -0
- package/dist/src/algorithms/mst.js.map +1 -0
- package/dist/src/constants.d.ts +6 -1
- package/dist/src/constants.d.ts.map +1 -1
- package/dist/src/constants.js +6 -1
- package/dist/src/constants.js.map +1 -1
- package/dist/src/index.d.ts +3 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/kernel/prelude.d.ts.map +1 -1
- package/dist/src/kernel/prelude.js +7 -1
- package/dist/src/kernel/prelude.js.map +1 -1
- package/dist/src/kernels.d.ts +5 -2
- package/dist/src/kernels.d.ts.map +1 -1
- package/dist/src/kernels.js +58 -2
- package/dist/src/kernels.js.map +1 -1
- package/dist/src/types/accelerator.d.ts +7 -5
- package/dist/src/types/accelerator.d.ts.map +1 -1
- package/dist/src/types/structure.d.ts +17 -0
- package/dist/src/types/structure.d.ts.map +1 -1
- package/dist/src/wgsl/mst-best.wgsl.d.ts +13 -0
- package/dist/src/wgsl/mst-best.wgsl.d.ts.map +1 -0
- package/dist/src/wgsl/mst-best.wgsl.js +32 -0
- package/dist/src/wgsl/mst-best.wgsl.js.map +1 -0
- package/dist/src/wgsl/mst-link.wgsl.d.ts +14 -0
- package/dist/src/wgsl/mst-link.wgsl.d.ts.map +1 -0
- package/dist/src/wgsl/mst-link.wgsl.js +39 -0
- package/dist/src/wgsl/mst-link.wgsl.js.map +1 -0
- package/dist/webgpu-graph-algorithms.js +473 -162
- package/dist/webgpu-graph-algorithms.js.map +1 -1
- package/package.json +3 -3
- package/src/accelerator.ts +22 -2
- package/src/algorithms/mst.ts +269 -0
- package/src/constants.ts +6 -1
- package/src/index.ts +3 -1
- package/src/kernel/prelude.ts +7 -0
- package/src/kernels.ts +64 -3
- package/src/types/accelerator.ts +7 -3
- package/src/types/structure.ts +18 -0
- package/src/wgsl/mst-best.wgsl.ts +31 -0
- package/src/wgsl/mst-link.wgsl.ts +38 -0
- package/dist/chunks/context-VIvatQOo.js.map +0 -1
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `mst-link` kernel body (design 8.5; the P11 plan's P11-T4): one vertex per invocation after `mst-best`'s two
|
|
3
|
+
* passes. A component root `c` whose `bestEdge` exists hooks itself onto the component at the edge's other end and
|
|
4
|
+
* records the edge in `treeEdge[c]`. Under the total edge order two components can only choose each other through
|
|
5
|
+
* the SAME edge, so the one cycle possible is a two-cycle; the LOWER root of it keeps its label and only the higher
|
|
6
|
+
* one hooks and records, so the edge is recorded once. Only a root writes its own `comp` word, so a concurrent reader
|
|
7
|
+
* sees either the root or the root's new parent, both inside the component the round merges; `comp` is atomic
|
|
8
|
+
* because WGSL forbids mixing atomic and plain access to one element. Every root hooks at most once in a run (it is
|
|
9
|
+
* no longer a root afterwards), so `treeEdge` ends holding each forest edge exactly once, at the root that chose it.
|
|
10
|
+
* The edges recorded are added to `counters[P.counterIndex]` with one atomic per workgroup; a round that records
|
|
11
|
+
* none ends the run. Body only (spec 3.5, D9); normative text: a sabotage mutation is a textual edit of it.
|
|
12
|
+
*/
|
|
13
|
+
export const mstLinkWgsl = /* wgsl */ `
|
|
14
|
+
var<workgroup> added: atomic<u32>;
|
|
15
|
+
|
|
16
|
+
@compute @workgroup_size(WG)
|
|
17
|
+
fn mst_link(@builtin(workgroup_id) wid: vec3<u32>, @builtin(local_invocation_id) lid: vec3<u32>) {
|
|
18
|
+
if (lid.x == 0u) { atomicStore(&added, 0u); }
|
|
19
|
+
workgroupBarrier();
|
|
20
|
+
let c = linear_id(wid, lid.x);
|
|
21
|
+
if (c < P.count) {
|
|
22
|
+
let e = bestEdge[c];
|
|
23
|
+
if (e != INVALID_INDEX) {
|
|
24
|
+
let a = atomicLoad(&comp[edgeSrc[e]]);
|
|
25
|
+
let b = atomicLoad(&comp[edgeDst[e]]);
|
|
26
|
+
let other = select(a, b, a == c);
|
|
27
|
+
let keep = bestEdge[other] == e && c <= other; // the lower root of a two-cycle stays
|
|
28
|
+
if (!keep) { atomicStore(&comp[c], other); }
|
|
29
|
+
if (!keep) { treeEdge[c] = e; atomicAdd(&added, 1u); }
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
workgroupBarrier(); // every lane, unconditionally
|
|
33
|
+
if (lid.x == 0u) {
|
|
34
|
+
let k = atomicLoad(&added);
|
|
35
|
+
if (k > 0u) { atomicAdd(&counters[P.counterIndex], k); } // one atomic per workgroup
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
`;
|