graphwise 1.9.1 → 1.11.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/dist/async/index.cjs +98 -1
- package/dist/async/index.cjs.map +1 -0
- package/dist/async/index.d.ts +1 -0
- package/dist/async/index.d.ts.map +1 -1
- package/dist/async/index.js +96 -2
- package/dist/async/index.js.map +1 -0
- package/dist/async/ops.d.ts +2 -0
- package/dist/async/ops.d.ts.map +1 -1
- package/dist/async/protocol.d.ts +14 -0
- package/dist/async/protocol.d.ts.map +1 -1
- package/dist/async/runner-batched.d.ts +21 -0
- package/dist/async/runner-batched.d.ts.map +1 -0
- package/dist/async/runner-batched.unit.test.d.ts +2 -0
- package/dist/async/runner-batched.unit.test.d.ts.map +1 -0
- package/dist/async/runners.d.ts.map +1 -1
- package/dist/expansion/base-core.d.ts.map +1 -1
- package/dist/expansion/fuse.d.ts +24 -1
- package/dist/expansion/fuse.d.ts.map +1 -1
- package/dist/expansion/index.cjs +9 -1
- package/dist/expansion/index.js +2 -2
- package/dist/expansion/lace.d.ts +23 -2
- package/dist/expansion/lace.d.ts.map +1 -1
- package/dist/expansion/priority-helpers.d.ts +20 -1
- package/dist/expansion/priority-helpers.d.ts.map +1 -1
- package/dist/expansion/sift.d.ts +24 -1
- package/dist/expansion/sift.d.ts.map +1 -1
- package/dist/expansion/types.d.ts +30 -0
- package/dist/expansion/types.d.ts.map +1 -1
- package/dist/{expansion-DaTroIyv.cjs → expansion--UuRowv-.cjs} +267 -4
- package/dist/expansion--UuRowv-.cjs.map +1 -0
- package/dist/{expansion-ClDhlMK8.js → expansion-CZLNK6Pr.js} +220 -5
- package/dist/expansion-CZLNK6Pr.js.map +1 -0
- package/dist/gpu/csr-graph.d.ts +68 -0
- package/dist/gpu/csr-graph.d.ts.map +1 -0
- package/dist/gpu/csr-graph.unit.test.d.ts +2 -0
- package/dist/gpu/csr-graph.unit.test.d.ts.map +1 -0
- package/dist/gpu/index.cjs +220 -15
- package/dist/gpu/index.cjs.map +1 -0
- package/dist/gpu/index.d.ts +1 -0
- package/dist/gpu/index.d.ts.map +1 -1
- package/dist/gpu/index.js +204 -2
- package/dist/gpu/index.js.map +1 -0
- package/dist/gpu/kernels/adamic-adar/kernel.d.ts +39 -0
- package/dist/gpu/kernels/adamic-adar/kernel.d.ts.map +1 -0
- package/dist/gpu/kernels/intersection/kernel.d.ts +50 -0
- package/dist/gpu/kernels/intersection/kernel.d.ts.map +1 -0
- package/dist/gpu/kernels/intersection/logic.d.ts +87 -0
- package/dist/gpu/kernels/intersection/logic.d.ts.map +1 -0
- package/dist/gpu/kernels/intersection/logic.unit.test.d.ts +2 -0
- package/dist/gpu/kernels/intersection/logic.unit.test.d.ts.map +1 -0
- package/dist/gpu/kernels/kmeans/index.d.ts +6 -0
- package/dist/gpu/kernels/kmeans/index.d.ts.map +1 -0
- package/dist/gpu/kernels/kmeans/kernel.d.ts +34 -0
- package/dist/gpu/kernels/kmeans/kernel.d.ts.map +1 -0
- package/dist/gpu/kernels/kmeans/logic.d.ts +111 -0
- package/dist/gpu/kernels/kmeans/logic.d.ts.map +1 -0
- package/dist/gpu/kernels/kmeans/logic.unit.test.d.ts +5 -0
- package/dist/gpu/kernels/kmeans/logic.unit.test.d.ts.map +1 -0
- package/dist/gpu/operations.d.ts +52 -0
- package/dist/gpu/operations.d.ts.map +1 -1
- package/dist/index/index.cjs +42 -19
- package/dist/index/index.js +11 -9
- package/dist/{jaccard-Bys9_dGW.cjs → jaccard-Bdw4B0i4.cjs} +1 -1
- package/dist/{jaccard-Bys9_dGW.cjs.map → jaccard-Bdw4B0i4.cjs.map} +1 -1
- package/dist/{jaccard-3rCdilwm.js → jaccard-BwC_NuQu.js} +1 -1
- package/dist/{jaccard-3rCdilwm.js.map → jaccard-BwC_NuQu.js.map} +1 -1
- package/dist/kernel-2oH4Cn32.cjs +1001 -0
- package/dist/kernel-2oH4Cn32.cjs.map +1 -0
- package/dist/kernel-6deK9fh1.js +724 -0
- package/dist/kernel-6deK9fh1.js.map +1 -0
- package/dist/kernel-CXeGBH3s.cjs +467 -0
- package/dist/kernel-CXeGBH3s.cjs.map +1 -0
- package/dist/kernel-CigCjrts.js +467 -0
- package/dist/kernel-CigCjrts.js.map +1 -0
- package/dist/kernel-CvnRsF7E.js +1001 -0
- package/dist/kernel-CvnRsF7E.js.map +1 -0
- package/dist/kernel-DukrXtVb.cjs +724 -0
- package/dist/kernel-DukrXtVb.cjs.map +1 -0
- package/dist/{kmeans-B8x9D1kt.cjs → kmeans-CZ7tJFYw.cjs} +1 -1
- package/dist/{kmeans-B8x9D1kt.cjs.map → kmeans-CZ7tJFYw.cjs.map} +1 -1
- package/dist/{kmeans-DKkL9rAN.js → kmeans-DLrlrp6i.js} +1 -1
- package/dist/{kmeans-DKkL9rAN.js.map → kmeans-DLrlrp6i.js.map} +1 -1
- package/dist/logic-Dbyfb_-7.cjs +289 -0
- package/dist/logic-Dbyfb_-7.cjs.map +1 -0
- package/dist/logic-DyBzRg1A.js +242 -0
- package/dist/logic-DyBzRg1A.js.map +1 -0
- package/dist/operations-D-RB67WP.cjs +2269 -0
- package/dist/operations-D-RB67WP.cjs.map +1 -0
- package/dist/operations-D9otVlIH.js +2198 -0
- package/dist/operations-D9otVlIH.js.map +1 -0
- package/dist/{ops-upIi6JIi.js → ops-D5xZr4fV.js} +60 -2
- package/dist/ops-D5xZr4fV.js.map +1 -0
- package/dist/{ops-djAsQQSh.cjs → ops-paa1Nvlf.cjs} +71 -1
- package/dist/ops-paa1Nvlf.cjs.map +1 -0
- package/dist/ranking/baselines/communicability.d.ts +12 -0
- package/dist/ranking/baselines/communicability.d.ts.map +1 -1
- package/dist/ranking/baselines/katz.d.ts +12 -0
- package/dist/ranking/baselines/katz.d.ts.map +1 -1
- package/dist/ranking/baselines/pagerank.d.ts +15 -0
- package/dist/ranking/baselines/pagerank.d.ts.map +1 -1
- package/dist/ranking/baselines/types.d.ts +3 -0
- package/dist/ranking/baselines/types.d.ts.map +1 -1
- package/dist/ranking/index.cjs +5 -2
- package/dist/ranking/index.js +3 -3
- package/dist/ranking/mi/index.cjs +1 -1
- package/dist/ranking/mi/index.js +1 -1
- package/dist/ranking/parse-gpu.d.ts +31 -0
- package/dist/ranking/parse-gpu.d.ts.map +1 -0
- package/dist/ranking/parse-gpu.unit.test.d.ts +5 -0
- package/dist/ranking/parse-gpu.unit.test.d.ts.map +1 -0
- package/dist/ranking/parse.d.ts.map +1 -1
- package/dist/{ranking-3ez5m67U.js → ranking-DOKDBcIR.js} +237 -11
- package/dist/ranking-DOKDBcIR.js.map +1 -0
- package/dist/{ranking-DVvajgUZ.cjs → ranking-pe5UaxKg.cjs} +254 -10
- package/dist/ranking-pe5UaxKg.cjs.map +1 -0
- package/dist/schemas/graph.d.ts +1 -1
- package/dist/seeds/crest.d.ts +48 -0
- package/dist/seeds/crest.d.ts.map +1 -0
- package/dist/seeds/crest.unit.test.d.ts +2 -0
- package/dist/seeds/crest.unit.test.d.ts.map +1 -0
- package/dist/seeds/crisp.d.ts +57 -0
- package/dist/seeds/crisp.d.ts.map +1 -0
- package/dist/seeds/crisp.unit.test.d.ts +2 -0
- package/dist/seeds/crisp.unit.test.d.ts.map +1 -0
- package/dist/seeds/grasp-gpu.d.ts +40 -0
- package/dist/seeds/grasp-gpu.d.ts.map +1 -0
- package/dist/seeds/index.cjs +715 -5
- package/dist/seeds/index.cjs.map +1 -1
- package/dist/seeds/index.d.ts +4 -0
- package/dist/seeds/index.d.ts.map +1 -1
- package/dist/seeds/index.js +712 -6
- package/dist/seeds/index.js.map +1 -1
- package/dist/seeds/spine.d.ts +50 -0
- package/dist/seeds/spine.d.ts.map +1 -0
- package/dist/seeds/spine.unit.test.d.ts +2 -0
- package/dist/seeds/spine.unit.test.d.ts.map +1 -0
- package/dist/seeds/stride.d.ts +55 -0
- package/dist/seeds/stride.d.ts.map +1 -0
- package/dist/seeds/stride.unit.test.d.ts +2 -0
- package/dist/seeds/stride.unit.test.d.ts.map +1 -0
- package/dist/{gpu-CHiCN0wa.js → typegpu-Dq5FfUB8.cjs} +16 -2041
- package/dist/typegpu-Dq5FfUB8.cjs.map +1 -0
- package/dist/{gpu-Y6owRVMi.cjs → typegpu-DwnJf28i.js} +2 -2127
- package/dist/typegpu-DwnJf28i.js.map +1 -0
- package/dist/utils/index.cjs +1 -1
- package/dist/utils/index.js +1 -1
- package/package.json +1 -1
- package/dist/expansion-ClDhlMK8.js.map +0 -1
- package/dist/expansion-DaTroIyv.cjs.map +0 -1
- package/dist/gpu-CHiCN0wa.js.map +0 -1
- package/dist/gpu-Y6owRVMi.cjs.map +0 -1
- package/dist/ops-djAsQQSh.cjs.map +0 -1
- package/dist/ops-upIi6JIi.js.map +0 -1
- package/dist/ranking-3ez5m67U.js.map +0 -1
- package/dist/ranking-DVvajgUZ.cjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kernel-6deK9fh1.js","names":[],"sources":["../src/gpu/kernels/intersection/kernel.ts"],"sourcesContent":["/**\n * TypeGPU compute kernel for batch neighbourhood intersection.\n *\n * Computes intersection size and neighbourhood sizes for multiple node pairs.\n * One thread per pair: iterates the smaller neighbourhood and binary-searches the other.\n *\n * @module gpu/kernels/intersection/kernel\n */\n\nimport tgpu, { d, type StorageFlag, type TgpuBuffer } from \"typegpu\";\nimport type { TypedBufferGroup } from \"../../csr\";\nimport type { GraphwiseGPURoot } from \"../../root\";\n\n/**\n * Bind group layout for Intersection kernel.\n */\nconst IntersectionLayout = tgpu.bindGroupLayout({\n\trowOffsets: { storage: d.arrayOf(d.u32) },\n\tcolIndices: { storage: d.arrayOf(d.u32) },\n\tpairsU: { storage: d.arrayOf(d.u32) },\n\tpairsV: { storage: d.arrayOf(d.u32) },\n\tintersections: { storage: d.arrayOf(d.u32), access: \"mutable\" },\n\tsizeUs: { storage: d.arrayOf(d.u32), access: \"mutable\" },\n\tsizeVs: { storage: d.arrayOf(d.u32), access: \"mutable\" },\n\tpairCount: { uniform: d.u32 },\n});\n\n/**\n * Intersection compute pipeline: one thread per pair.\n *\n * For each pair (u, v):\n * - Count intersection by iterating smaller neighbourhood\n * - Binary search in larger neighbourhood\n * - Write intersection, sizeU, sizeV to output buffers\n */\nconst intersectionPipeline = (pairIdx: number): void => {\n\t\"use gpu\";\n\tconst u = IntersectionLayout.$.pairsU[pairIdx] ?? 0;\n\tconst v = IntersectionLayout.$.pairsV[pairIdx] ?? 0;\n\n\tconst uStart = IntersectionLayout.$.rowOffsets[u] ?? 0;\n\tconst uEnd = IntersectionLayout.$.rowOffsets[u + 1] ?? 0;\n\tconst vStart = IntersectionLayout.$.rowOffsets[v] ?? 0;\n\tconst vEnd = IntersectionLayout.$.rowOffsets[v + 1] ?? 0;\n\n\tconst degU = uEnd - uStart;\n\tconst degV = vEnd - vStart;\n\n\t// Write sizes first\n\tIntersectionLayout.$.sizeUs[pairIdx] = degU;\n\tIntersectionLayout.$.sizeVs[pairIdx] = degV;\n\n\t// Empty neighbourhoods → intersection = 0\n\tif (degU === 0 || degV === 0) {\n\t\tIntersectionLayout.$.intersections[pairIdx] = 0;\n\t\treturn;\n\t}\n\n\tlet intersection = 0;\n\n\tif (degU <= degV) {\n\t\t// Iterate u's neighbours, search in v's\n\t\tfor (let i = uStart; i < uEnd; i = i + 1) {\n\t\t\tconst neighbour = IntersectionLayout.$.colIndices[i] ?? 0;\n\t\t\t// Binary search in v's neighbourhood\n\t\t\tlet lo = vStart;\n\t\t\tlet hi = vEnd;\n\t\t\twhile (lo < hi) {\n\t\t\t\tconst mid = lo + (hi - lo) / 2;\n\t\t\t\tconst midVal = IntersectionLayout.$.colIndices[mid] ?? 0;\n\t\t\t\tif (midVal === neighbour) {\n\t\t\t\t\tintersection = intersection + 1;\n\t\t\t\t\tlo = hi; // break\n\t\t\t\t} else if (midVal < neighbour) {\n\t\t\t\t\tlo = mid + 1;\n\t\t\t\t} else {\n\t\t\t\t\thi = mid;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t} else {\n\t\t// Iterate v's neighbours, search in u's\n\t\tfor (let i = vStart; i < vEnd; i = i + 1) {\n\t\t\tconst neighbour = IntersectionLayout.$.colIndices[i] ?? 0;\n\t\t\t// Binary search in u's neighbourhood\n\t\t\tlet lo = uStart;\n\t\t\tlet hi = uEnd;\n\t\t\twhile (lo < hi) {\n\t\t\t\tconst mid = lo + (hi - lo) / 2;\n\t\t\t\tconst midVal = IntersectionLayout.$.colIndices[mid] ?? 0;\n\t\t\t\tif (midVal === neighbour) {\n\t\t\t\t\tintersection = intersection + 1;\n\t\t\t\t\tlo = hi; // break\n\t\t\t\t} else if (midVal < neighbour) {\n\t\t\t\t\tlo = mid + 1;\n\t\t\t\t} else {\n\t\t\t\t\thi = mid;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tIntersectionLayout.$.intersections[pairIdx] = intersection;\n};\n\n/**\n * Dispatch batch intersection on GPU.\n *\n * @param root - TypeGPU root instance\n * @param csrBuffers - CSR matrix as typed buffers\n * @param pairsU - First node of each pair (u32 array)\n * @param pairsV - Second node of each pair (u32 array)\n * @param intersections - Output intersections (u32 array, mutable)\n * @param sizeUs - Output sizeU per pair (u32 array, mutable)\n * @param sizeVs - Output sizeV per pair (u32 array, mutable)\n * @param pairCount - Number of pairs to compute\n */\nexport function dispatchIntersection(\n\troot: GraphwiseGPURoot,\n\tcsrBuffers: TypedBufferGroup,\n\tpairsU: TgpuBuffer<ReturnType<typeof d.arrayOf<typeof d.u32>>> & StorageFlag,\n\tpairsV: TgpuBuffer<ReturnType<typeof d.arrayOf<typeof d.u32>>> & StorageFlag,\n\tintersections: TgpuBuffer<ReturnType<typeof d.arrayOf<typeof d.u32>>> &\n\t\tStorageFlag,\n\tsizeUs: TgpuBuffer<ReturnType<typeof d.arrayOf<typeof d.u32>>> & StorageFlag,\n\tsizeVs: TgpuBuffer<ReturnType<typeof d.arrayOf<typeof d.u32>>> & StorageFlag,\n\tpairCount: number,\n): void {\n\tconst pipeline = root.createGuardedComputePipeline(intersectionPipeline);\n\n\tconst pairCountBuffer = root.createBuffer(d.u32, pairCount).$usage(\"uniform\");\n\n\tconst bindGroup = root.createBindGroup(IntersectionLayout, {\n\t\trowOffsets: csrBuffers.rowOffsets,\n\t\tcolIndices: csrBuffers.colIndices,\n\t\tpairsU,\n\t\tpairsV,\n\t\tintersections,\n\t\tsizeUs,\n\t\tsizeVs,\n\t\tpairCount: pairCountBuffer,\n\t});\n\n\tpipeline.with(bindGroup).dispatchThreads(pairCount);\n}\n\nexport { IntersectionLayout };\n"],"mappings":";;;;;;;;;;;;;AAgBA,IAAM,sBAAA,WAAA,0BAAA,MAAA,IAAqB,YAAK,gBAAgB;CAC/C,YAAY,EAAE,SAAS,aAAE,QAAQ,aAAE,IAAI,EAAE;CACzC,YAAY,EAAE,SAAS,aAAE,QAAQ,aAAE,IAAI,EAAE;CACzC,QAAQ,EAAE,SAAS,aAAE,QAAQ,aAAE,IAAI,EAAE;CACrC,QAAQ,EAAE,SAAS,aAAE,QAAQ,aAAE,IAAI,EAAE;CACrC,eAAe;EAAE,SAAS,aAAE,QAAQ,aAAE,IAAI;EAAE,QAAQ;EAAW;CAC/D,QAAQ;EAAE,SAAS,aAAE,QAAQ,aAAE,IAAI;EAAE,QAAQ;EAAW;CACxD,QAAQ;EAAE,SAAS,aAAE,QAAQ,aAAE,IAAI;EAAE,QAAQ;EAAW;CACxD,WAAW,EAAE,SAAS,aAAE,KAAA;CACxB,CAAA,EAAA,qBAAA;;;;;;;;;AAUD,IAAM,yBAAA,OAAA,WAAA,qCAAA,IAAA,SAAA,EAAA,IAAA,EAAA,MAAwB,YAA0B;AACvD;CACA,MAAM,IAAI,mBAAmB,EAAE,OAAO,YAAY;CAClD,MAAM,IAAI,mBAAmB,EAAE,OAAO,YAAY;CAElD,MAAM,SAAS,mBAAmB,EAAE,WAAW,MAAM;CACrD,MAAM,OAAO,mBAAmB,EAAE,WAAW,aAAA,GAAA,EAAI,KAAM;CACvD,MAAM,SAAS,mBAAmB,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gpu/kernels/kmeans/kernel.ts
|
|
3
|
+
/**
|
|
4
|
+
* TypeGPU compute kernel for K-means assignment step.
|
|
5
|
+
*
|
|
6
|
+
* Assigns each point to its nearest centroid in parallel.
|
|
7
|
+
* This is the most parallelizable operation in K-means clustering.
|
|
8
|
+
*
|
|
9
|
+
* @module gpu/kernels/kmeans/kernel
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Bind group layout for K-means assignment kernel.
|
|
13
|
+
*/
|
|
14
|
+
var KMeansAssignLayout = (globalThis.__TYPEGPU_AUTONAME__ ?? ((a) => a))(require_typegpu.src_default.bindGroupLayout({
|
|
15
|
+
points: { storage: require_typegpu.data_exports.arrayOf(require_typegpu.data_exports.arrayOf(require_typegpu.data_exports.f32, 3)) },
|
|
16
|
+
centroids: { storage: require_typegpu.data_exports.arrayOf(require_typegpu.data_exports.arrayOf(require_typegpu.data_exports.f32, 3)) },
|
|
17
|
+
assignments: {
|
|
18
|
+
storage: require_typegpu.data_exports.arrayOf(require_typegpu.data_exports.u32),
|
|
19
|
+
access: "mutable"
|
|
20
|
+
},
|
|
21
|
+
distances: {
|
|
22
|
+
storage: require_typegpu.data_exports.arrayOf(require_typegpu.data_exports.f32),
|
|
23
|
+
access: "mutable"
|
|
24
|
+
},
|
|
25
|
+
pointCount: { uniform: require_typegpu.data_exports.u32 },
|
|
26
|
+
k: { uniform: require_typegpu.data_exports.u32 }
|
|
27
|
+
}), "KMeansAssignLayout");
|
|
28
|
+
/**
|
|
29
|
+
* K-means assignment compute pipeline: one thread per point.
|
|
30
|
+
*
|
|
31
|
+
* For each point:
|
|
32
|
+
* - Compute distance to all centroids
|
|
33
|
+
* - Assign to nearest centroid
|
|
34
|
+
* - Store squared distance
|
|
35
|
+
*/
|
|
36
|
+
var kmeansAssignPipeline = (($) => (globalThis.__TYPEGPU_META__ ??= /* @__PURE__ */ new WeakMap()).set($.f = ((pointIdx) => {
|
|
37
|
+
"use gpu";
|
|
38
|
+
if (pointIdx >= KMeansAssignLayout.$.pointCount) return;
|
|
39
|
+
const point = KMeansAssignLayout.$.points[pointIdx];
|
|
40
|
+
if (point === void 0) {
|
|
41
|
+
KMeansAssignLayout.$.assignments[pointIdx] = 0;
|
|
42
|
+
KMeansAssignLayout.$.distances[pointIdx] = 0;
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const px = point[0] ?? 0;
|
|
46
|
+
const py = point[1] ?? 0;
|
|
47
|
+
const pz = point[2] ?? 0;
|
|
48
|
+
let minDist = 1e9;
|
|
49
|
+
let minIdx = 0;
|
|
50
|
+
for (let c = 0; c < KMeansAssignLayout.$.k; c = __tsover_add(c, 1)) {
|
|
51
|
+
const centroid = KMeansAssignLayout.$.centroids[c];
|
|
52
|
+
if (centroid === void 0) continue;
|
|
53
|
+
const cx = centroid[0] ?? 0;
|
|
54
|
+
const cy = centroid[1] ?? 0;
|
|
55
|
+
const cz = centroid[2] ?? 0;
|
|
56
|
+
const dx = __tsover_sub(px, cx);
|
|
57
|
+
const dy = __tsover_sub(py, cy);
|
|
58
|
+
const dz = __tsover_sub(pz, cz);
|
|
59
|
+
const distSq = __tsover_add(__tsover_add(__tsover_mul(dx, dx), __tsover_mul(dy, dy)), __tsover_mul(dz, dz));
|
|
60
|
+
if (distSq < minDist) {
|
|
61
|
+
minDist = distSq;
|
|
62
|
+
minIdx = c;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
KMeansAssignLayout.$.assignments[pointIdx] = minIdx;
|
|
66
|
+
KMeansAssignLayout.$.distances[pointIdx] = minDist;
|
|
67
|
+
}), {
|
|
68
|
+
v: 1,
|
|
69
|
+
name: "kmeansAssignPipeline",
|
|
70
|
+
ast: {
|
|
71
|
+
"params": [{
|
|
72
|
+
"type": "i",
|
|
73
|
+
"name": "pointIdx"
|
|
74
|
+
}],
|
|
75
|
+
"body": [0, [
|
|
76
|
+
[
|
|
77
|
+
11,
|
|
78
|
+
[
|
|
79
|
+
1,
|
|
80
|
+
"pointIdx",
|
|
81
|
+
">=",
|
|
82
|
+
[
|
|
83
|
+
7,
|
|
84
|
+
[
|
|
85
|
+
7,
|
|
86
|
+
"KMeansAssignLayout",
|
|
87
|
+
"$"
|
|
88
|
+
],
|
|
89
|
+
"pointCount"
|
|
90
|
+
]
|
|
91
|
+
],
|
|
92
|
+
[10]
|
|
93
|
+
],
|
|
94
|
+
[
|
|
95
|
+
13,
|
|
96
|
+
"point",
|
|
97
|
+
[
|
|
98
|
+
8,
|
|
99
|
+
[
|
|
100
|
+
7,
|
|
101
|
+
[
|
|
102
|
+
7,
|
|
103
|
+
"KMeansAssignLayout",
|
|
104
|
+
"$"
|
|
105
|
+
],
|
|
106
|
+
"points"
|
|
107
|
+
],
|
|
108
|
+
"pointIdx"
|
|
109
|
+
]
|
|
110
|
+
],
|
|
111
|
+
[
|
|
112
|
+
11,
|
|
113
|
+
[
|
|
114
|
+
1,
|
|
115
|
+
"point",
|
|
116
|
+
"===",
|
|
117
|
+
"undefined"
|
|
118
|
+
],
|
|
119
|
+
[0, [
|
|
120
|
+
[
|
|
121
|
+
2,
|
|
122
|
+
[
|
|
123
|
+
8,
|
|
124
|
+
[
|
|
125
|
+
7,
|
|
126
|
+
[
|
|
127
|
+
7,
|
|
128
|
+
"KMeansAssignLayout",
|
|
129
|
+
"$"
|
|
130
|
+
],
|
|
131
|
+
"assignments"
|
|
132
|
+
],
|
|
133
|
+
"pointIdx"
|
|
134
|
+
],
|
|
135
|
+
"=",
|
|
136
|
+
[5, "0"]
|
|
137
|
+
],
|
|
138
|
+
[
|
|
139
|
+
2,
|
|
140
|
+
[
|
|
141
|
+
8,
|
|
142
|
+
[
|
|
143
|
+
7,
|
|
144
|
+
[
|
|
145
|
+
7,
|
|
146
|
+
"KMeansAssignLayout",
|
|
147
|
+
"$"
|
|
148
|
+
],
|
|
149
|
+
"distances"
|
|
150
|
+
],
|
|
151
|
+
"pointIdx"
|
|
152
|
+
],
|
|
153
|
+
"=",
|
|
154
|
+
[5, "0"]
|
|
155
|
+
],
|
|
156
|
+
[10]
|
|
157
|
+
]]
|
|
158
|
+
],
|
|
159
|
+
[
|
|
160
|
+
13,
|
|
161
|
+
"px",
|
|
162
|
+
[
|
|
163
|
+
3,
|
|
164
|
+
[
|
|
165
|
+
8,
|
|
166
|
+
"point",
|
|
167
|
+
[5, "0"]
|
|
168
|
+
],
|
|
169
|
+
"??",
|
|
170
|
+
[5, "0"]
|
|
171
|
+
]
|
|
172
|
+
],
|
|
173
|
+
[
|
|
174
|
+
13,
|
|
175
|
+
"py",
|
|
176
|
+
[
|
|
177
|
+
3,
|
|
178
|
+
[
|
|
179
|
+
8,
|
|
180
|
+
"point",
|
|
181
|
+
[5, "1"]
|
|
182
|
+
],
|
|
183
|
+
"??",
|
|
184
|
+
[5, "0"]
|
|
185
|
+
]
|
|
186
|
+
],
|
|
187
|
+
[
|
|
188
|
+
13,
|
|
189
|
+
"pz",
|
|
190
|
+
[
|
|
191
|
+
3,
|
|
192
|
+
[
|
|
193
|
+
8,
|
|
194
|
+
"point",
|
|
195
|
+
[5, "2"]
|
|
196
|
+
],
|
|
197
|
+
"??",
|
|
198
|
+
[5, "0"]
|
|
199
|
+
]
|
|
200
|
+
],
|
|
201
|
+
[
|
|
202
|
+
12,
|
|
203
|
+
"minDist",
|
|
204
|
+
[5, "1000000000"]
|
|
205
|
+
],
|
|
206
|
+
[
|
|
207
|
+
12,
|
|
208
|
+
"minIdx",
|
|
209
|
+
[5, "0"]
|
|
210
|
+
],
|
|
211
|
+
[
|
|
212
|
+
14,
|
|
213
|
+
[
|
|
214
|
+
12,
|
|
215
|
+
"c",
|
|
216
|
+
[5, "0"]
|
|
217
|
+
],
|
|
218
|
+
[
|
|
219
|
+
1,
|
|
220
|
+
"c",
|
|
221
|
+
"<",
|
|
222
|
+
[
|
|
223
|
+
7,
|
|
224
|
+
[
|
|
225
|
+
7,
|
|
226
|
+
"KMeansAssignLayout",
|
|
227
|
+
"$"
|
|
228
|
+
],
|
|
229
|
+
"k"
|
|
230
|
+
]
|
|
231
|
+
],
|
|
232
|
+
[
|
|
233
|
+
2,
|
|
234
|
+
"c",
|
|
235
|
+
"=",
|
|
236
|
+
[
|
|
237
|
+
1,
|
|
238
|
+
"c",
|
|
239
|
+
"+",
|
|
240
|
+
[5, "1"]
|
|
241
|
+
]
|
|
242
|
+
],
|
|
243
|
+
[0, [
|
|
244
|
+
[
|
|
245
|
+
13,
|
|
246
|
+
"centroid",
|
|
247
|
+
[
|
|
248
|
+
8,
|
|
249
|
+
[
|
|
250
|
+
7,
|
|
251
|
+
[
|
|
252
|
+
7,
|
|
253
|
+
"KMeansAssignLayout",
|
|
254
|
+
"$"
|
|
255
|
+
],
|
|
256
|
+
"centroids"
|
|
257
|
+
],
|
|
258
|
+
"c"
|
|
259
|
+
]
|
|
260
|
+
],
|
|
261
|
+
[
|
|
262
|
+
11,
|
|
263
|
+
[
|
|
264
|
+
1,
|
|
265
|
+
"centroid",
|
|
266
|
+
"===",
|
|
267
|
+
"undefined"
|
|
268
|
+
],
|
|
269
|
+
[16]
|
|
270
|
+
],
|
|
271
|
+
[
|
|
272
|
+
13,
|
|
273
|
+
"cx",
|
|
274
|
+
[
|
|
275
|
+
3,
|
|
276
|
+
[
|
|
277
|
+
8,
|
|
278
|
+
"centroid",
|
|
279
|
+
[5, "0"]
|
|
280
|
+
],
|
|
281
|
+
"??",
|
|
282
|
+
[5, "0"]
|
|
283
|
+
]
|
|
284
|
+
],
|
|
285
|
+
[
|
|
286
|
+
13,
|
|
287
|
+
"cy",
|
|
288
|
+
[
|
|
289
|
+
3,
|
|
290
|
+
[
|
|
291
|
+
8,
|
|
292
|
+
"centroid",
|
|
293
|
+
[5, "1"]
|
|
294
|
+
],
|
|
295
|
+
"??",
|
|
296
|
+
[5, "0"]
|
|
297
|
+
]
|
|
298
|
+
],
|
|
299
|
+
[
|
|
300
|
+
13,
|
|
301
|
+
"cz",
|
|
302
|
+
[
|
|
303
|
+
3,
|
|
304
|
+
[
|
|
305
|
+
8,
|
|
306
|
+
"centroid",
|
|
307
|
+
[5, "2"]
|
|
308
|
+
],
|
|
309
|
+
"??",
|
|
310
|
+
[5, "0"]
|
|
311
|
+
]
|
|
312
|
+
],
|
|
313
|
+
[
|
|
314
|
+
13,
|
|
315
|
+
"dx",
|
|
316
|
+
[
|
|
317
|
+
1,
|
|
318
|
+
"px",
|
|
319
|
+
"-",
|
|
320
|
+
"cx"
|
|
321
|
+
]
|
|
322
|
+
],
|
|
323
|
+
[
|
|
324
|
+
13,
|
|
325
|
+
"dy",
|
|
326
|
+
[
|
|
327
|
+
1,
|
|
328
|
+
"py",
|
|
329
|
+
"-",
|
|
330
|
+
"cy"
|
|
331
|
+
]
|
|
332
|
+
],
|
|
333
|
+
[
|
|
334
|
+
13,
|
|
335
|
+
"dz",
|
|
336
|
+
[
|
|
337
|
+
1,
|
|
338
|
+
"pz",
|
|
339
|
+
"-",
|
|
340
|
+
"cz"
|
|
341
|
+
]
|
|
342
|
+
],
|
|
343
|
+
[
|
|
344
|
+
13,
|
|
345
|
+
"distSq",
|
|
346
|
+
[
|
|
347
|
+
1,
|
|
348
|
+
[
|
|
349
|
+
1,
|
|
350
|
+
[
|
|
351
|
+
1,
|
|
352
|
+
"dx",
|
|
353
|
+
"*",
|
|
354
|
+
"dx"
|
|
355
|
+
],
|
|
356
|
+
"+",
|
|
357
|
+
[
|
|
358
|
+
1,
|
|
359
|
+
"dy",
|
|
360
|
+
"*",
|
|
361
|
+
"dy"
|
|
362
|
+
]
|
|
363
|
+
],
|
|
364
|
+
"+",
|
|
365
|
+
[
|
|
366
|
+
1,
|
|
367
|
+
"dz",
|
|
368
|
+
"*",
|
|
369
|
+
"dz"
|
|
370
|
+
]
|
|
371
|
+
]
|
|
372
|
+
],
|
|
373
|
+
[
|
|
374
|
+
11,
|
|
375
|
+
[
|
|
376
|
+
1,
|
|
377
|
+
"distSq",
|
|
378
|
+
"<",
|
|
379
|
+
"minDist"
|
|
380
|
+
],
|
|
381
|
+
[0, [[
|
|
382
|
+
2,
|
|
383
|
+
"minDist",
|
|
384
|
+
"=",
|
|
385
|
+
"distSq"
|
|
386
|
+
], [
|
|
387
|
+
2,
|
|
388
|
+
"minIdx",
|
|
389
|
+
"=",
|
|
390
|
+
"c"
|
|
391
|
+
]]]
|
|
392
|
+
]
|
|
393
|
+
]]
|
|
394
|
+
],
|
|
395
|
+
[
|
|
396
|
+
2,
|
|
397
|
+
[
|
|
398
|
+
8,
|
|
399
|
+
[
|
|
400
|
+
7,
|
|
401
|
+
[
|
|
402
|
+
7,
|
|
403
|
+
"KMeansAssignLayout",
|
|
404
|
+
"$"
|
|
405
|
+
],
|
|
406
|
+
"assignments"
|
|
407
|
+
],
|
|
408
|
+
"pointIdx"
|
|
409
|
+
],
|
|
410
|
+
"=",
|
|
411
|
+
"minIdx"
|
|
412
|
+
],
|
|
413
|
+
[
|
|
414
|
+
2,
|
|
415
|
+
[
|
|
416
|
+
8,
|
|
417
|
+
[
|
|
418
|
+
7,
|
|
419
|
+
[
|
|
420
|
+
7,
|
|
421
|
+
"KMeansAssignLayout",
|
|
422
|
+
"$"
|
|
423
|
+
],
|
|
424
|
+
"distances"
|
|
425
|
+
],
|
|
426
|
+
"pointIdx"
|
|
427
|
+
],
|
|
428
|
+
"=",
|
|
429
|
+
"minDist"
|
|
430
|
+
]
|
|
431
|
+
]],
|
|
432
|
+
"externalNames": ["KMeansAssignLayout", "undefined"]
|
|
433
|
+
},
|
|
434
|
+
externals: () => ({
|
|
435
|
+
KMeansAssignLayout,
|
|
436
|
+
undefined: void 0
|
|
437
|
+
})
|
|
438
|
+
}) && $.f)({});
|
|
439
|
+
/**
|
|
440
|
+
* Dispatch K-means assignment on GPU.
|
|
441
|
+
*
|
|
442
|
+
* @param root - TypeGPU root
|
|
443
|
+
* @param pointsBuffer - Buffer of 3D points
|
|
444
|
+
* @param centroidsBuffer - Buffer of centroids
|
|
445
|
+
* @param assignmentsBuffer - Output buffer for assignments
|
|
446
|
+
* @param distancesBuffer - Output buffer for distances
|
|
447
|
+
* @param pointCount - Number of points
|
|
448
|
+
* @param k - Number of centroids
|
|
449
|
+
*/
|
|
450
|
+
function dispatchKMeansAssign(root, pointsBuffer, centroidsBuffer, assignmentsBuffer, distancesBuffer, pointCount, k) {
|
|
451
|
+
const pipeline = (globalThis.__TYPEGPU_AUTONAME__ ?? ((a) => a))(root.createGuardedComputePipeline(kmeansAssignPipeline), "pipeline");
|
|
452
|
+
const pairCountBuffer = (globalThis.__TYPEGPU_AUTONAME__ ?? ((a) => a))(root.createBuffer(require_typegpu.data_exports.u32, pointCount).$usage("uniform"), "pairCountBuffer");
|
|
453
|
+
const kBuffer = (globalThis.__TYPEGPU_AUTONAME__ ?? ((a) => a))(root.createBuffer(require_typegpu.data_exports.u32, k).$usage("uniform"), "kBuffer");
|
|
454
|
+
const bindGroup = root.createBindGroup(KMeansAssignLayout, {
|
|
455
|
+
points: pointsBuffer,
|
|
456
|
+
centroids: centroidsBuffer,
|
|
457
|
+
assignments: assignmentsBuffer,
|
|
458
|
+
distances: distancesBuffer,
|
|
459
|
+
pointCount: pairCountBuffer,
|
|
460
|
+
k: kBuffer
|
|
461
|
+
});
|
|
462
|
+
pipeline.with(bindGroup).dispatchThreads(pointCount);
|
|
463
|
+
}
|
|
464
|
+
//#endregion
|
|
465
|
+
exports.dispatchKMeansAssign = dispatchKMeansAssign;
|
|
466
|
+
|
|
467
|
+
//# sourceMappingURL=kernel-CXeGBH3s.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kernel-CXeGBH3s.cjs","names":[],"sources":["../src/gpu/kernels/kmeans/kernel.ts"],"sourcesContent":["/**\n * TypeGPU compute kernel for K-means assignment step.\n *\n * Assigns each point to its nearest centroid in parallel.\n * This is the most parallelizable operation in K-means clustering.\n *\n * @module gpu/kernels/kmeans/kernel\n */\n\nimport tgpu, { d } from \"typegpu\";\nimport type { GraphwiseGPURoot } from \"../../root\";\n\n/**\n * K-means assignment kernel buffers.\n *\n * Buffer types are complex TypeGPU types that are difficult to express in TypeScript.\n * Using `any` here is intentional to avoid verbose generic constraints.\n */\nexport interface KMeansAssignBuffers {\n\t/** Points buffer (3D vectors) */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\treadonly pointsBuffer: any;\n\t/** Centroids buffer (3D vectors) */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\treadonly centroidsBuffer: any;\n\t/** Assignments output buffer (cluster indices) */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\treadonly assignmentsBuffer: any;\n\t/** Distances output buffer (distances to assigned centroid) */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\treadonly distancesBuffer: any;\n}\n\n/**\n * Bind group layout for K-means assignment kernel.\n */\nconst KMeansAssignLayout = tgpu.bindGroupLayout({\n\tpoints: { storage: d.arrayOf(d.arrayOf(d.f32, 3)) }, // 3D points for GRASP\n\tcentroids: { storage: d.arrayOf(d.arrayOf(d.f32, 3)) },\n\tassignments: { storage: d.arrayOf(d.u32), access: \"mutable\" },\n\tdistances: { storage: d.arrayOf(d.f32), access: \"mutable\" },\n\tpointCount: { uniform: d.u32 },\n\tk: { uniform: d.u32 },\n});\n\n/**\n * K-means assignment compute pipeline: one thread per point.\n *\n * For each point:\n * - Compute distance to all centroids\n * - Assign to nearest centroid\n * - Store squared distance\n */\nconst kmeansAssignPipeline = (pointIdx: number): void => {\n\t\"use gpu\";\n\n\tif (pointIdx >= KMeansAssignLayout.$.pointCount) return;\n\n\t// Load point coordinates\n\tconst point = KMeansAssignLayout.$.points[pointIdx];\n\tif (point === undefined) {\n\t\tKMeansAssignLayout.$.assignments[pointIdx] = 0;\n\t\tKMeansAssignLayout.$.distances[pointIdx] = 0;\n\t\treturn;\n\t}\n\n\tconst px = point[0] ?? 0;\n\tconst py = point[1] ?? 0;\n\tconst pz = point[2] ?? 0;\n\n\t// Find nearest centroid\n\tlet minDist = 1000000000;\n\tlet minIdx = 0;\n\n\tfor (let c = 0; c < KMeansAssignLayout.$.k; c = c + 1) {\n\t\tconst centroid = KMeansAssignLayout.$.centroids[c];\n\t\tif (centroid === undefined) continue;\n\n\t\tconst cx = centroid[0] ?? 0;\n\t\tconst cy = centroid[1] ?? 0;\n\t\tconst cz = centroid[2] ?? 0;\n\n\t\tconst dx = px - cx;\n\t\tconst dy = py - cy;\n\t\tconst dz = pz - cz;\n\t\tconst distSq = dx * dx + dy * dy + dz * dz;\n\n\t\tif (distSq < minDist) {\n\t\t\tminDist = distSq;\n\t\t\tminIdx = c;\n\t\t}\n\t}\n\n\tKMeansAssignLayout.$.assignments[pointIdx] = minIdx;\n\tKMeansAssignLayout.$.distances[pointIdx] = minDist;\n};\n\n/**\n * Dispatch K-means assignment on GPU.\n *\n * @param root - TypeGPU root\n * @param pointsBuffer - Buffer of 3D points\n * @param centroidsBuffer - Buffer of centroids\n * @param assignmentsBuffer - Output buffer for assignments\n * @param distancesBuffer - Output buffer for distances\n * @param pointCount - Number of points\n * @param k - Number of centroids\n */\nexport function dispatchKMeansAssign(\n\troot: GraphwiseGPURoot,\n\t// TypeGPU buffer types are complex and not easily expressible in TypeScript\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tpointsBuffer: any,\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tcentroidsBuffer: any,\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tassignmentsBuffer: any,\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tdistancesBuffer: any,\n\tpointCount: number,\n\tk: number,\n): void {\n\t// TypeGPU kernel function with \"use gpu\" directive\n\n\tconst pipeline = root.createGuardedComputePipeline(\n\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions, @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any\n\t\tkmeansAssignPipeline as any,\n\t);\n\n\tconst pairCountBuffer = root\n\t\t.createBuffer(d.u32, pointCount)\n\t\t.$usage(\"uniform\");\n\tconst kBuffer = root.createBuffer(d.u32, k).$usage(\"uniform\");\n\n\tconst bindGroup = root.createBindGroup(KMeansAssignLayout, {\n\t\tpoints: pointsBuffer,\n\t\tcentroids: centroidsBuffer,\n\t\tassignments: assignmentsBuffer,\n\t\tdistances: distancesBuffer,\n\t\tpointCount: pairCountBuffer,\n\t\tk: kBuffer,\n\t});\n\n\tpipeline.with(bindGroup).dispatchThreads(pointCount);\n}\n\n/**\n * Create buffers for K-means assignment.\n */\nexport function createKMeansAssignBuffers(\n\troot: GraphwiseGPURoot,\n\tpoints: readonly (readonly [number, number, number])[],\n\tcentroids: readonly (readonly [number, number, number])[],\n): KMeansAssignBuffers {\n\tconst pointCount = points.length;\n\tconst k = centroids.length;\n\n\t// Convert readonly arrays to mutable for TypeGPU buffer creation\n\n\tconst pointsBuffer = root\n\t\t.createBuffer(\n\t\t\td.arrayOf(d.vec3f, pointCount),\n\t\t\t// TypeGPU type constraints are complex; TypedArrays are compatible with buffer initialization\n\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions, @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any\n\t\t\tArray.from(points) as any,\n\t\t)\n\t\t.$usage(\"storage\");\n\n\tconst centroidsBuffer = root\n\t\t.createBuffer(\n\t\t\td.arrayOf(d.vec3f, k),\n\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions, @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any\n\t\t\tArray.from(centroids) as any,\n\t\t)\n\t\t.$usage(\"storage\");\n\n\tconst assignmentsBuffer = root\n\t\t.createBuffer(d.arrayOf(d.u32, pointCount))\n\t\t.$usage(\"storage\");\n\n\tconst distancesBuffer = root\n\t\t.createBuffer(d.arrayOf(d.f32, pointCount))\n\t\t.$usage(\"storage\");\n\n\treturn {\n\t\tpointsBuffer,\n\t\tcentroidsBuffer,\n\t\tassignmentsBuffer,\n\t\tdistancesBuffer,\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;AAoCA,IAAM,sBAAA,WAAA,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