@graphty/webgpu-graph-algorithms 0.5.1 → 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.
Files changed (243) hide show
  1. package/README.md +98 -52
  2. package/dist/browser.js +1 -1
  3. package/dist/chunks/{context-BR7fx3vR.js → context-BXqgCifx.js} +190 -40
  4. package/dist/chunks/context-BXqgCifx.js.map +1 -0
  5. package/dist/node.js +1 -1
  6. package/dist/src/algorithms/components.d.ts.map +1 -1
  7. package/dist/src/algorithms/components.js +12 -13
  8. package/dist/src/algorithms/components.js.map +1 -1
  9. package/dist/src/algorithms/degree.d.ts +6 -8
  10. package/dist/src/algorithms/degree.d.ts.map +1 -1
  11. package/dist/src/algorithms/degree.js +58 -35
  12. package/dist/src/algorithms/degree.js.map +1 -1
  13. package/dist/src/algorithms/pagerank.d.ts.map +1 -1
  14. package/dist/src/algorithms/pagerank.js +16 -14
  15. package/dist/src/algorithms/pagerank.js.map +1 -1
  16. package/dist/src/algorithms/power-iteration.d.ts +2 -2
  17. package/dist/src/algorithms/power-iteration.d.ts.map +1 -1
  18. package/dist/src/algorithms/power-iteration.js +17 -14
  19. package/dist/src/algorithms/power-iteration.js.map +1 -1
  20. package/dist/src/constants.d.ts +38 -8
  21. package/dist/src/constants.d.ts.map +1 -1
  22. package/dist/src/constants.js +38 -8
  23. package/dist/src/constants.js.map +1 -1
  24. package/dist/src/errors.d.ts +3 -2
  25. package/dist/src/errors.d.ts.map +1 -1
  26. package/dist/src/errors.js +2 -1
  27. package/dist/src/errors.js.map +1 -1
  28. package/dist/src/index.d.ts +6 -4
  29. package/dist/src/index.d.ts.map +1 -1
  30. package/dist/src/index.js +8 -3
  31. package/dist/src/index.js.map +1 -1
  32. package/dist/src/kernel/dispatch.d.ts +8 -3
  33. package/dist/src/kernel/dispatch.d.ts.map +1 -1
  34. package/dist/src/kernel/dispatch.js +18 -7
  35. package/dist/src/kernel/dispatch.js.map +1 -1
  36. package/dist/src/kernel/kernel.d.ts +30 -1
  37. package/dist/src/kernel/kernel.d.ts.map +1 -1
  38. package/dist/src/kernel/kernel.js +49 -5
  39. package/dist/src/kernel/kernel.js.map +1 -1
  40. package/dist/src/kernel/prelude.d.ts.map +1 -1
  41. package/dist/src/kernel/prelude.js +6 -1
  42. package/dist/src/kernel/prelude.js.map +1 -1
  43. package/dist/src/kernel/profiler.d.ts +15 -3
  44. package/dist/src/kernel/profiler.d.ts.map +1 -1
  45. package/dist/src/kernel/profiler.js +27 -4
  46. package/dist/src/kernel/profiler.js.map +1 -1
  47. package/dist/src/kernels.d.ts +17 -7
  48. package/dist/src/kernels.d.ts.map +1 -1
  49. package/dist/src/kernels.js +323 -16
  50. package/dist/src/kernels.js.map +1 -1
  51. package/dist/src/layouts/calibrate.d.ts +51 -0
  52. package/dist/src/layouts/calibrate.d.ts.map +1 -0
  53. package/dist/src/layouts/calibrate.js +172 -0
  54. package/dist/src/layouts/calibrate.js.map +1 -0
  55. package/dist/src/layouts/force-simulation.d.ts +39 -4
  56. package/dist/src/layouts/force-simulation.d.ts.map +1 -1
  57. package/dist/src/layouts/force-simulation.js +71 -19
  58. package/dist/src/layouts/force-simulation.js.map +1 -1
  59. package/dist/src/layouts/forceatlas2.d.ts +107 -36
  60. package/dist/src/layouts/forceatlas2.d.ts.map +1 -1
  61. package/dist/src/layouts/forceatlas2.js +296 -100
  62. package/dist/src/layouts/forceatlas2.js.map +1 -1
  63. package/dist/src/layouts/fruchterman-reingold.d.ts +73 -27
  64. package/dist/src/layouts/fruchterman-reingold.d.ts.map +1 -1
  65. package/dist/src/layouts/fruchterman-reingold.js +230 -70
  66. package/dist/src/layouts/fruchterman-reingold.js.map +1 -1
  67. package/dist/src/layouts/model-common.d.ts +41 -3
  68. package/dist/src/layouts/model-common.d.ts.map +1 -1
  69. package/dist/src/layouts/model-common.js +74 -3
  70. package/dist/src/layouts/model-common.js.map +1 -1
  71. package/dist/src/layouts/repulsion-grid.d.ts +152 -0
  72. package/dist/src/layouts/repulsion-grid.d.ts.map +1 -0
  73. package/dist/src/layouts/repulsion-grid.js +318 -0
  74. package/dist/src/layouts/repulsion-grid.js.map +1 -0
  75. package/dist/src/layouts/spring-electrical.d.ts +75 -30
  76. package/dist/src/layouts/spring-electrical.d.ts.map +1 -1
  77. package/dist/src/layouts/spring-electrical.js +231 -74
  78. package/dist/src/layouts/spring-electrical.js.map +1 -1
  79. package/dist/src/memory/residency.d.ts +6 -2
  80. package/dist/src/memory/residency.d.ts.map +1 -1
  81. package/dist/src/memory/residency.js +84 -14
  82. package/dist/src/memory/residency.js.map +1 -1
  83. package/dist/src/primitives/core-shape.d.ts +38 -2
  84. package/dist/src/primitives/core-shape.d.ts.map +1 -1
  85. package/dist/src/primitives/core-shape.js +71 -3
  86. package/dist/src/primitives/core-shape.js.map +1 -1
  87. package/dist/src/primitives/grid-pyramid.d.ts +71 -0
  88. package/dist/src/primitives/grid-pyramid.d.ts.map +1 -0
  89. package/dist/src/primitives/grid-pyramid.js +143 -0
  90. package/dist/src/primitives/grid-pyramid.js.map +1 -0
  91. package/dist/src/primitives/grid.d.ts +118 -0
  92. package/dist/src/primitives/grid.d.ts.map +1 -0
  93. package/dist/src/primitives/grid.js +225 -0
  94. package/dist/src/primitives/grid.js.map +1 -0
  95. package/dist/src/primitives/histogram.d.ts +67 -0
  96. package/dist/src/primitives/histogram.d.ts.map +1 -0
  97. package/dist/src/primitives/histogram.js +190 -0
  98. package/dist/src/primitives/histogram.js.map +1 -0
  99. package/dist/src/primitives/radix-sort.d.ts +75 -0
  100. package/dist/src/primitives/radix-sort.d.ts.map +1 -0
  101. package/dist/src/primitives/radix-sort.js +168 -0
  102. package/dist/src/primitives/radix-sort.js.map +1 -0
  103. package/dist/src/primitives/scan.d.ts +44 -0
  104. package/dist/src/primitives/scan.d.ts.map +1 -0
  105. package/dist/src/primitives/scan.js +151 -0
  106. package/dist/src/primitives/scan.js.map +1 -0
  107. package/dist/src/primitives/segmented-reduce.d.ts +25 -17
  108. package/dist/src/primitives/segmented-reduce.d.ts.map +1 -1
  109. package/dist/src/primitives/segmented-reduce.js +166 -47
  110. package/dist/src/primitives/segmented-reduce.js.map +1 -1
  111. package/dist/src/primitives/spmv.d.ts +18 -14
  112. package/dist/src/primitives/spmv.d.ts.map +1 -1
  113. package/dist/src/primitives/spmv.js +94 -58
  114. package/dist/src/primitives/spmv.js.map +1 -1
  115. package/dist/src/primitives/verify.d.ts +49 -0
  116. package/dist/src/primitives/verify.d.ts.map +1 -0
  117. package/dist/src/primitives/verify.js +229 -0
  118. package/dist/src/primitives/verify.js.map +1 -0
  119. package/dist/src/types/context.d.ts +53 -0
  120. package/dist/src/types/context.d.ts.map +1 -1
  121. package/dist/src/types/layout.d.ts +20 -0
  122. package/dist/src/types/layout.d.ts.map +1 -1
  123. package/dist/src/wgsl/counting-scatter.wgsl.d.ts +8 -0
  124. package/dist/src/wgsl/counting-scatter.wgsl.d.ts.map +1 -0
  125. package/dist/src/wgsl/counting-scatter.wgsl.js +17 -0
  126. package/dist/src/wgsl/counting-scatter.wgsl.js.map +1 -0
  127. package/dist/src/wgsl/fa2-attraction.wgsl.d.ts +23 -11
  128. package/dist/src/wgsl/fa2-attraction.wgsl.d.ts.map +1 -1
  129. package/dist/src/wgsl/fa2-attraction.wgsl.js +98 -20
  130. package/dist/src/wgsl/fa2-attraction.wgsl.js.map +1 -1
  131. package/dist/src/wgsl/fa2-stats-finalize.wgsl.d.ts +6 -2
  132. package/dist/src/wgsl/fa2-stats-finalize.wgsl.d.ts.map +1 -1
  133. package/dist/src/wgsl/fa2-stats-finalize.wgsl.js +22 -1
  134. package/dist/src/wgsl/fa2-stats-finalize.wgsl.js.map +1 -1
  135. package/dist/src/wgsl/grid-cell-key.wgsl.d.ts +8 -0
  136. package/dist/src/wgsl/grid-cell-key.wgsl.d.ts.map +1 -0
  137. package/dist/src/wgsl/grid-cell-key.wgsl.js +30 -0
  138. package/dist/src/wgsl/grid-cell-key.wgsl.js.map +1 -0
  139. package/dist/src/wgsl/grid-centroid-hub.wgsl.d.ts +8 -0
  140. package/dist/src/wgsl/grid-centroid-hub.wgsl.d.ts.map +1 -0
  141. package/dist/src/wgsl/grid-centroid-hub.wgsl.js +29 -0
  142. package/dist/src/wgsl/grid-centroid-hub.wgsl.js.map +1 -0
  143. package/dist/src/wgsl/grid-centroid.wgsl.d.ts +8 -0
  144. package/dist/src/wgsl/grid-centroid.wgsl.d.ts.map +1 -0
  145. package/dist/src/wgsl/grid-centroid.wgsl.js +29 -0
  146. package/dist/src/wgsl/grid-centroid.wgsl.js.map +1 -0
  147. package/dist/src/wgsl/grid-downsample.wgsl.d.ts +7 -0
  148. package/dist/src/wgsl/grid-downsample.wgsl.d.ts.map +1 -0
  149. package/dist/src/wgsl/grid-downsample.wgsl.js +28 -0
  150. package/dist/src/wgsl/grid-downsample.wgsl.js.map +1 -0
  151. package/dist/src/wgsl/grid-far-field.wgsl.d.ts +13 -0
  152. package/dist/src/wgsl/grid-far-field.wgsl.d.ts.map +1 -0
  153. package/dist/src/wgsl/grid-far-field.wgsl.js +98 -0
  154. package/dist/src/wgsl/grid-far-field.wgsl.js.map +1 -0
  155. package/dist/src/wgsl/grid-near-field.wgsl.d.ts +19 -0
  156. package/dist/src/wgsl/grid-near-field.wgsl.d.ts.map +1 -0
  157. package/dist/src/wgsl/grid-near-field.wgsl.js +129 -0
  158. package/dist/src/wgsl/grid-near-field.wgsl.js.map +1 -0
  159. package/dist/src/wgsl/histogram.wgsl.d.ts +7 -0
  160. package/dist/src/wgsl/histogram.wgsl.d.ts.map +1 -0
  161. package/dist/src/wgsl/histogram.wgsl.js +15 -0
  162. package/dist/src/wgsl/histogram.wgsl.js.map +1 -0
  163. package/dist/src/wgsl/indirect-finalize.wgsl.d.ts +8 -0
  164. package/dist/src/wgsl/indirect-finalize.wgsl.d.ts.map +1 -0
  165. package/dist/src/wgsl/indirect-finalize.wgsl.js +26 -0
  166. package/dist/src/wgsl/indirect-finalize.wgsl.js.map +1 -0
  167. package/dist/src/wgsl/radix-hist.wgsl.d.ts +9 -0
  168. package/dist/src/wgsl/radix-hist.wgsl.d.ts.map +1 -0
  169. package/dist/src/wgsl/radix-hist.wgsl.js +31 -0
  170. package/dist/src/wgsl/radix-hist.wgsl.js.map +1 -0
  171. package/dist/src/wgsl/radix-scatter.wgsl.d.ts +9 -0
  172. package/dist/src/wgsl/radix-scatter.wgsl.d.ts.map +1 -0
  173. package/dist/src/wgsl/radix-scatter.wgsl.js +40 -0
  174. package/dist/src/wgsl/radix-scatter.wgsl.js.map +1 -0
  175. package/dist/src/wgsl/scan-add.wgsl.d.ts +6 -0
  176. package/dist/src/wgsl/scan-add.wgsl.d.ts.map +1 -0
  177. package/dist/src/wgsl/scan-add.wgsl.js +14 -0
  178. package/dist/src/wgsl/scan-add.wgsl.js.map +1 -0
  179. package/dist/src/wgsl/scan-block.wgsl.d.ts +8 -0
  180. package/dist/src/wgsl/scan-block.wgsl.d.ts.map +1 -0
  181. package/dist/src/wgsl/scan-block.wgsl.js +30 -0
  182. package/dist/src/wgsl/scan-block.wgsl.js.map +1 -0
  183. package/dist/src/wgsl/segmented-reduce.wgsl.d.ts +22 -8
  184. package/dist/src/wgsl/segmented-reduce.wgsl.d.ts.map +1 -1
  185. package/dist/src/wgsl/segmented-reduce.wgsl.js +84 -15
  186. package/dist/src/wgsl/segmented-reduce.wgsl.js.map +1 -1
  187. package/dist/src/wgsl/spmv-pull.wgsl.d.ts +22 -11
  188. package/dist/src/wgsl/spmv-pull.wgsl.d.ts.map +1 -1
  189. package/dist/src/wgsl/spmv-pull.wgsl.js +110 -36
  190. package/dist/src/wgsl/spmv-pull.wgsl.js.map +1 -1
  191. package/dist/tsconfig.build.tsbuildinfo +1 -1
  192. package/dist/webgpu-graph-algorithms.js +3815 -1003
  193. package/dist/webgpu-graph-algorithms.js.map +1 -1
  194. package/package.json +5 -4
  195. package/src/algorithms/components.ts +12 -16
  196. package/src/algorithms/degree.ts +58 -43
  197. package/src/algorithms/pagerank.ts +20 -18
  198. package/src/algorithms/power-iteration.ts +19 -18
  199. package/src/constants.ts +38 -8
  200. package/src/errors.ts +3 -1
  201. package/src/index.ts +14 -4
  202. package/src/kernel/dispatch.ts +18 -7
  203. package/src/kernel/kernel.ts +59 -5
  204. package/src/kernel/prelude.ts +9 -0
  205. package/src/kernel/profiler.ts +28 -4
  206. package/src/kernels.ts +356 -18
  207. package/src/layouts/calibrate.ts +187 -0
  208. package/src/layouts/force-simulation.ts +91 -23
  209. package/src/layouts/forceatlas2.ts +331 -106
  210. package/src/layouts/fruchterman-reingold.ts +255 -74
  211. package/src/layouts/model-common.ts +98 -3
  212. package/src/layouts/repulsion-grid.ts +451 -0
  213. package/src/layouts/spring-electrical.ts +257 -78
  214. package/src/memory/residency.ts +126 -20
  215. package/src/primitives/core-shape.ts +91 -4
  216. package/src/primitives/grid-pyramid.ts +221 -0
  217. package/src/primitives/grid.ts +349 -0
  218. package/src/primitives/histogram.ts +273 -0
  219. package/src/primitives/radix-sort.ts +246 -0
  220. package/src/primitives/scan.ts +197 -0
  221. package/src/primitives/segmented-reduce.ts +214 -56
  222. package/src/primitives/spmv.ts +125 -65
  223. package/src/primitives/verify.ts +249 -0
  224. package/src/types/context.ts +56 -0
  225. package/src/types/layout.ts +22 -0
  226. package/src/wgsl/counting-scatter.wgsl.ts +16 -0
  227. package/src/wgsl/fa2-attraction.wgsl.ts +98 -20
  228. package/src/wgsl/fa2-stats-finalize.wgsl.ts +22 -1
  229. package/src/wgsl/grid-cell-key.wgsl.ts +29 -0
  230. package/src/wgsl/grid-centroid-hub.wgsl.ts +28 -0
  231. package/src/wgsl/grid-centroid.wgsl.ts +28 -0
  232. package/src/wgsl/grid-downsample.wgsl.ts +27 -0
  233. package/src/wgsl/grid-far-field.wgsl.ts +97 -0
  234. package/src/wgsl/grid-near-field.wgsl.ts +128 -0
  235. package/src/wgsl/histogram.wgsl.ts +14 -0
  236. package/src/wgsl/indirect-finalize.wgsl.ts +25 -0
  237. package/src/wgsl/radix-hist.wgsl.ts +30 -0
  238. package/src/wgsl/radix-scatter.wgsl.ts +39 -0
  239. package/src/wgsl/scan-add.wgsl.ts +13 -0
  240. package/src/wgsl/scan-block.wgsl.ts +29 -0
  241. package/src/wgsl/segmented-reduce.wgsl.ts +84 -15
  242. package/src/wgsl/spmv-pull.wgsl.ts +110 -36
  243. package/dist/chunks/context-BR7fx3vR.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scan.js","sourceRoot":"","sources":["../../../src/primitives/scan.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAqB,QAAQ,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE5E,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AA0BxD,uEAAuE;AACvE,MAAM,OAAO,GAAG,UAAU,CAAC;AAE3B;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,KAAkB;IAChD,MAAM,KAAK,GAAG,MAAM,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC;IACrE,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC;IACjE,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC;IAC3C,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,EAAE,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5D,OAAO,IAAI,eAAe,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,IAAI,EAA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EAAE,CAAC,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;YAC1G,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;QAChE,CAAC;QACD,IAAI,CAAC,UAAU,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;QACxC,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QACtC,OAAO,EAAE,OAAO,EAAE,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;IAC3C,CAAC;IAED;;;;;OAKG;IACK,OAAO,CAAC,KAAa,EAAE,KAAa;QACxC,MAAM,IAAI,GAAG,CAAC,GAAG,KAAK,CAAC;QACvB,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;IACrD,CAAC;CACJ"}
@@ -1,20 +1,23 @@
1
1
  /**
2
- * The segmented (per-row) reduction primitive of spec 6 row 3 in its thread-per-row tier (P2-P3): one invocation per
3
- * CSR row folds the caller's VALUE snippet over the row's arcs into `out[row]` (f32), a row with no arcs receiving
4
- * the identity element. The degree tiers of degreeOrder() (subgroup-per-row for the mid tier, workgroup-per-row for
5
- * the high tier) land at P4; until then `tiers !== null` is E_UNSUPPORTED and USE_PERM is always false (the perm
6
- * slot carries the rowPtr dummy of graphBindings). The row and arc counts come from the core's binding sizes: the
7
- * residency binds every array at its exact byte length (contract 3.8), so rowPtr is 4(n + 1) bytes and colIdx
8
- * 4 x arcCount.
2
+ * The segmented (per-row) reduction primitive of spec 6 row 3: the caller's VALUE snippet folded over every CSR
3
+ * row's arcs into `out[row]` (f32), a row with no arcs receiving the identity element. Without tiers it is ONE
4
+ * thread-per-row dispatch (TIER 0, USE_PERM false: the perm slot carries the rowPtr dummy of graphBindings). With
5
+ * the degree tiers of degreeOrder() (P4-T5, PD-6) it is up to three dispatches over the permuted rows: TIER 2, one
6
+ * workgroup per row of degree >= 1024 over [0, hiEnd); TIER 1, 32 lanes per row of degree 32..1023 over [hiEnd,
7
+ * midEnd); TIER 0, one thread per row over [midEnd, n) -- each compiled only when its range is non-empty. The row
8
+ * and arc counts come from the core's binding sizes: the residency binds every array at its exact byte length
9
+ * (contract 3.8), so rowPtr is 4(n + 1) bytes and colIdx 4 x arcCount. On a windowed core (spec 4.2, P4-T7, PD-8)
10
+ * the dispatches repeat per window with `arcBase = w.start`, `arcEnd = w.end` and `accumulate = 1` over an out
11
+ * pre-filled with the identity element (unless the caller asked to accumulate), so a row split across windows
12
+ * combines its partials: the untiered dispatch covers the window's rows [rowFirst, rowLast], while every tier
13
+ * dispatch covers its FULL tier range (permutation positions, not comparable with the window's node rows; a row
14
+ * whose arcs lie outside the window folds nothing and `finish` writes comb(out[i], identity) = out[i]).
9
15
  */
10
16
  import { type CoreBinding } from "../memory/residency.js";
11
17
  import { type Binding } from "../types/memory.js";
18
+ import { type DegreeTiers } from "./core-shape.js";
12
19
  import { type ReduceOp, type ReduceScope } from "./reduce.js";
13
- /** The degree tiers of degreeOrder(): the permutation binding and the CPU-side segmentOffsets [0, hiEnd, midEnd, lowEnd, n]. */
14
- export interface DegreeTiers {
15
- readonly perm: Binding;
16
- readonly segmentOffsets: readonly [number, number, number, number, number];
17
- }
20
+ export { type DegreeTiers } from "./core-shape.js";
18
21
  /** Options of segmentedReduce. `valueSnippet` is the Gunrock-style functor: WGSL statements assigning `v` from (row, arc, nbr, weight) (4.5; `nbr` because `target` is a WGSL reserved word). */
19
22
  export interface SegmentedReduceOptions {
20
23
  readonly op: ReduceOp;
@@ -22,16 +25,21 @@ export interface SegmentedReduceOptions {
22
25
  readonly tiers: DegreeTiers | null;
23
26
  readonly accumulate?: boolean | undefined;
24
27
  }
25
- /** A prepared segmented reduce (P2-P3: the thread-per-row tier only; `tiers !== null` -> E_UNSUPPORTED { feature: "segmentedReduce.tiers" } until P4). */
28
+ /** A prepared segmented reduce: one thread-per-row dispatch without tiers, up to three tier dispatches with them (times the windows of a windowed core, plus its identity fill). */
26
29
  export interface SegmentedReducePlanner {
27
- /** Records one dispatch over rows [0, n) (tiers null) writing out[i] (f32) per row; a row with no arcs gets the identity element. */
30
+ /** Records the dispatches over rows [0, n) writing out[i] (f32) per row; a row with no arcs gets the identity element. */
28
31
  record(pass: GPUComputePassEncoder, core: CoreBinding, out: Binding): void;
32
+ /** Dispatches the last record() issued (0 for n = 0; 1 without tiers; 1 to 3 with them; on a windowed core the identity fill plus that many per window). */
33
+ readonly lastDispatches: number;
29
34
  }
30
35
  /**
31
- * Prepares the thread-per-row pipeline for a snapshot's dummy pattern (USE_PERM, HAS_WEIGHTS) and snippet.
36
+ * Prepares the tier pipelines for a snapshot's dummy pattern (USE_PERM = tiers !== null, HAS_WEIGHTS) and snippet:
37
+ * TIER 0 always; TIER 1 iff a row of degree 32..1023 exists (segmentOffsets[2] > segmentOffsets[1]); TIER 2 iff a
38
+ * row of degree >= 1024 exists (segmentOffsets[1] > 0). The mid tier folds 32 lanes per row, so a device whose
39
+ * workgroup size is below 32 is E_UNSUPPORTED { feature: "segmentedReduce.tiers" }.
32
40
  * @param scope - the reduce scope (pipelines, pool, params writer)
33
- * @param core - the core whose weights pattern selects HAS_WEIGHTS (USE_PERM is false: no tiers at P2)
34
- * @param options - operator, snippet, tiers (must be null), accumulate
41
+ * @param core - the core whose weights pattern selects HAS_WEIGHTS
42
+ * @param options - operator, snippet, tiers (null: the single thread-per-row dispatch), accumulate
35
43
  * @returns the planner
36
44
  */
37
45
  export declare function prepareSegmentedReduce(scope: ReduceScope, core: CoreBinding, options: SegmentedReduceOptions): Promise<SegmentedReducePlanner>;
@@ -1 +1 @@
1
- {"version":3,"file":"segmented-reduce.d.ts","sourceRoot":"","sources":["../../../src/primitives/segmented-reduce.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAMH,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAE9D,gIAAgI;AAChI,MAAM,WAAW,WAAW;IACxB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,cAAc,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9E;AAED,iMAAiM;AACjM,MAAM,WAAW,sBAAsB;IACnC,QAAQ,CAAC,EAAE,EAAE,QAAQ,CAAC;IACtB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI,CAAC;IACnC,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAC7C;AAED,0JAA0J;AAC1J,MAAM,WAAW,sBAAsB;IACnC,qIAAqI;IACrI,MAAM,CAAC,IAAI,EAAE,qBAAqB,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE,OAAO,GAAG,IAAI,CAAC;CAC9E;AAgLD;;;;;;GAMG;AACH,wBAAsB,sBAAsB,CACxC,KAAK,EAAE,WAAW,EAClB,IAAI,EAAE,WAAW,EACjB,OAAO,EAAE,sBAAsB,GAChC,OAAO,CAAC,sBAAsB,CAAC,CAajC"}
1
+ {"version":3,"file":"segmented-reduce.d.ts","sourceRoot":"","sources":["../../../src/primitives/segmented-reduce.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAMH,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAkB,KAAK,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,EAAc,KAAK,WAAW,EAA6C,MAAM,iBAAiB,CAAC;AAC1G,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAE9D,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEnD,iMAAiM;AACjM,MAAM,WAAW,sBAAsB;IACnC,QAAQ,CAAC,EAAE,EAAE,QAAQ,CAAC;IACtB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI,CAAC;IACnC,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAC7C;AAED,oLAAoL;AACpL,MAAM,WAAW,sBAAsB;IACnC,0HAA0H;IAC1H,MAAM,CAAC,IAAI,EAAE,qBAAqB,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE,OAAO,GAAG,IAAI,CAAC;IAC3E,4JAA4J;IAC5J,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;CACnC;AA6SD;;;;;;;;;GASG;AACH,wBAAsB,sBAAsB,CACxC,KAAK,EAAE,WAAW,EAClB,IAAI,EAAE,WAAW,EACjB,OAAO,EAAE,sBAAsB,GAChC,OAAO,CAAC,sBAAsB,CAAC,CAuCjC"}
@@ -1,16 +1,42 @@
1
1
  /**
2
- * The segmented (per-row) reduction primitive of spec 6 row 3 in its thread-per-row tier (P2-P3): one invocation per
3
- * CSR row folds the caller's VALUE snippet over the row's arcs into `out[row]` (f32), a row with no arcs receiving
4
- * the identity element. The degree tiers of degreeOrder() (subgroup-per-row for the mid tier, workgroup-per-row for
5
- * the high tier) land at P4; until then `tiers !== null` is E_UNSUPPORTED and USE_PERM is always false (the perm
6
- * slot carries the rowPtr dummy of graphBindings). The row and arc counts come from the core's binding sizes: the
7
- * residency binds every array at its exact byte length (contract 3.8), so rowPtr is 4(n + 1) bytes and colIdx
8
- * 4 x arcCount.
2
+ * The segmented (per-row) reduction primitive of spec 6 row 3: the caller's VALUE snippet folded over every CSR
3
+ * row's arcs into `out[row]` (f32), a row with no arcs receiving the identity element. Without tiers it is ONE
4
+ * thread-per-row dispatch (TIER 0, USE_PERM false: the perm slot carries the rowPtr dummy of graphBindings). With
5
+ * the degree tiers of degreeOrder() (P4-T5, PD-6) it is up to three dispatches over the permuted rows: TIER 2, one
6
+ * workgroup per row of degree >= 1024 over [0, hiEnd); TIER 1, 32 lanes per row of degree 32..1023 over [hiEnd,
7
+ * midEnd); TIER 0, one thread per row over [midEnd, n) -- each compiled only when its range is non-empty. The row
8
+ * and arc counts come from the core's binding sizes: the residency binds every array at its exact byte length
9
+ * (contract 3.8), so rowPtr is 4(n + 1) bytes and colIdx 4 x arcCount. On a windowed core (spec 4.2, P4-T7, PD-8)
10
+ * the dispatches repeat per window with `arcBase = w.start`, `arcEnd = w.end` and `accumulate = 1` over an out
11
+ * pre-filled with the identity element (unless the caller asked to accumulate), so a row split across windows
12
+ * combines its partials: the untiered dispatch covers the window's rows [rowFirst, rowLast], while every tier
13
+ * dispatch covers its FULL tier range (permutation positions, not comparable with the window's node rows; a row
14
+ * whose arcs lie outside the window folds nothing and `finish` writes comb(out[i], identity) = out[i]).
9
15
  */
10
16
  import { WebGpuGraphError } from "../errors.js";
11
17
  import { plan1d } from "../kernel/dispatch.js";
12
- import { graphBindings, graphOverrides, kernelSpec, RANGE_PARAMS } from "../kernels.js";
13
- import { assertNotWindowed, rowCountOf } from "./core-shape.js";
18
+ import { FILL_PARAMS, graphBindings, graphOverrides, kernelSpec, RANGE_PARAMS } from "../kernels.js";
19
+ import { arcCountOf, MID_TIER_LANES, rowCountOf, windowBinding } from "./core-shape.js";
20
+ /** The largest finite f32, 0x1.fffffep+127 (the prelude's F32_MAX): the min identity; its negation the max identity. */
21
+ const F32_MAX = 2 ** 128 - 2 ** 104;
22
+ /**
23
+ * The u32 bit pattern the `fill` kernel writes so every out word holds the identity element of the operator before
24
+ * the windowed dispatches accumulate into it (PD-8).
25
+ * @param op - the operator
26
+ * @returns the bits of 0 (sum), F32_MAX (min) or -F32_MAX (max)
27
+ */
28
+ function identityFillWord(op) {
29
+ let identity = 0;
30
+ if (op === "min") {
31
+ identity = F32_MAX;
32
+ }
33
+ else if (op === "max") {
34
+ identity = -F32_MAX;
35
+ }
36
+ const view = new DataView(new ArrayBuffer(4));
37
+ view.setFloat32(0, identity, true);
38
+ return view.getUint32(0, true);
39
+ }
14
40
  /** The identifiers a VALUE snippet may name (contract 3.11, 4.5); every other identifier is rejected textually before compose. */
15
41
  const VALUE_SNIPPET_VOCABULARY = new Set(["row", "arc", "nbr", "weight", "v"]);
16
42
  /**
@@ -106,30 +132,49 @@ function validateValueSnippet(snippet) {
106
132
  throw new WebGpuGraphError("E_SHADER_COMPILE", `segmentedReduce: the VALUE snippet names "${token}"; the only identifiers allowed are row, arc, nbr, weight and v`, { id: "segmented-reduce", stage: "compose", slot: "VALUE", identifier: token });
107
133
  }
108
134
  }
109
- /** The thread-per-row planner: ONE `segmented-reduce` dispatch with TIER 0 over every row. */
110
- class ThreadPerRowPlanner {
135
+ /**
136
+ * The tiered planner: without tiers ONE `segmented-reduce` dispatch with TIER 0 over [0, n); with tiers TIER 2 over
137
+ * [0, hiEnd) (one workgroup per row), then TIER 1 over [hiEnd, midEnd) (WG / 32 rows per workgroup), then TIER 0
138
+ * over [midEnd, n), each with its own RangeParams record and the perm binding.
139
+ */
140
+ class TieredPlanner {
111
141
  /**
112
- * Wraps a compiled thread-per-row pipeline with the pattern it was compiled for.
113
- * @param scope - the scope the pipeline was prepared in
114
- * @param kernel - the compiled kernel
115
- * @param hasWeights - the HAS_WEIGHTS the pipeline was compiled with
142
+ * Wraps the compiled tier pipelines with the pattern they were compiled for.
143
+ * @param scope - the scope the pipelines were prepared in
144
+ * @param tiers - the compiled tiers in dispatch order (TIER 2, 1, 0; only the non-empty ones)
145
+ * @param fill - the `fill` pipeline of the identity pre-fill of a windowed core
146
+ * @param perm - the degreeOrder permutation binding (null: USE_PERM false, rows are node indices)
147
+ * @param hasWeights - the HAS_WEIGHTS the pipelines were compiled with
116
148
  * @param accumulate - whether record() combines into out instead of overwriting
149
+ * @param identityWord - the u32 bits of the operator's identity element (identityFillWord)
117
150
  */
118
- constructor(scope, kernel, hasWeights, accumulate) {
151
+ constructor(scope, tiers, fill, perm, hasWeights, accumulate, identityWord) {
152
+ this.dispatches = 0;
119
153
  this.scope = scope;
120
- this.kernel = kernel;
154
+ this.tiers = tiers;
155
+ this.fill = fill;
156
+ this.perm = perm;
121
157
  this.hasWeights = hasWeights;
122
158
  this.accumulate = accumulate;
159
+ this.identityWord = identityWord;
123
160
  }
124
161
  /**
125
- * Records the dispatch: rows [0, n), arcs [0, arcCount), plan1d(n); nothing for n = 0 (no zero-length binding is
126
- * ever created).
162
+ * Dispatches the last record() issued.
163
+ * @returns 0 for n = 0, else the number of non-empty tier ranges
164
+ */
165
+ get lastDispatches() {
166
+ return this.dispatches;
167
+ }
168
+ /**
169
+ * Records the dispatches: every tier's rows over the arcs [0, arcCount), each with its own params record;
170
+ * nothing for n = 0 (no zero-length binding is ever created). On a windowed core: the identity fill (unless
171
+ * accumulating into the caller's out), then the dispatches once per window (PD-8).
127
172
  * @param pass - the pass to record into
128
- * @param core - a core with the SAME weights pattern as the one prepared (any snapshot)
173
+ * @param core - a core with the SAME weights pattern as the one prepared (any snapshot; with tiers, the one the
174
+ * tiers were built from)
129
175
  * @param out - at least 4n bytes of f32
130
176
  */
131
177
  record(pass, core, out) {
132
- assertNotWindowed(core, "segmentedReduce");
133
178
  if ((core.weights !== null) !== this.hasWeights) {
134
179
  throw new WebGpuGraphError("E_INVALID_ARGUMENT", "segmentedReduce: the core's weights pattern differs from the one prepared", {
135
180
  argument: "core",
@@ -138,10 +183,6 @@ class ThreadPerRowPlanner {
138
183
  });
139
184
  }
140
185
  const n = rowCountOf(core, "segmentedReduce");
141
- if (n === 0) {
142
- return;
143
- }
144
- const arcCount = core.colIdx === null ? 0 : core.colIdx.size / 4;
145
186
  if (out.size < 4 * n) {
146
187
  throw new WebGpuGraphError("E_INVALID_ARGUMENT", `segmentedReduce: out holds ${out.size} bytes, ${4 * n} needed`, {
147
188
  argument: "out",
@@ -149,37 +190,115 @@ class ThreadPerRowPlanner {
149
190
  expected: `>= ${4 * n}`,
150
191
  });
151
192
  }
152
- const params = this.scope.params(RANGE_PARAMS, {
153
- start: 0,
154
- end: n,
155
- arcBase: 0,
156
- arcEnd: arcCount,
157
- accumulate: this.accumulate ? 1 : 0,
158
- n,
193
+ this.dispatches = 0;
194
+ if (n === 0) {
195
+ return;
196
+ }
197
+ if (core.windows === null) {
198
+ this.recordWindow(pass, core, out, n, null, 0);
199
+ return;
200
+ }
201
+ if (!this.accumulate) {
202
+ const params = this.scope.params(FILL_PARAMS, { count: n, value: this.identityWord, mode: 0 });
203
+ const bound = this.fill.bind({ dst: out, P: params.binding });
204
+ this.fill.dispatch(pass, bound, plan1d(n, this.scope.workgroupSize, this.scope.caps), [params.offset]);
205
+ this.dispatches++;
206
+ }
207
+ const { windows } = core;
208
+ windows.forEach((w, k) => {
209
+ const windowed = {
210
+ ...core,
211
+ colIdx: windowBinding(core, "colIdx", w),
212
+ weights: core.weights === null ? null : windowBinding(core, "weights", w),
213
+ };
214
+ this.recordWindow(pass, windowed, out, n, w, k + 1 < windows.length ? windows[k + 1].start : w.end);
159
215
  });
160
- const bound = this.kernel.bind({ ...graphBindings(core, null), out, P: params.binding });
161
- this.kernel.dispatch(pass, bound, plan1d(n, this.scope.workgroupSize, this.scope.caps), [params.offset]);
216
+ }
217
+ /**
218
+ * The tier dispatches over one arc window (or the whole core when `w` is null): every non-empty tier over its
219
+ * full range, except the untiered TIER 0 dispatch, which covers exactly the window's rows. Consecutive windows
220
+ * overlap by up to ARC_WINDOW_ALIGN - 1 arcs (the next window opens at the aligned-down end of this one), and a
221
+ * tier dispatch visits EVERY row, so the tiers fold [w.start, nextStart) and leave the overlap to the next
222
+ * window; the untiered dispatch keeps [w.start, w.end): its rows [rowFirst, rowLast] are exactly the rows whose
223
+ * arcs end inside this window, and the next window's rows start after them.
224
+ * @param pass - the pass to record into
225
+ * @param core - the core with the window's colIdx / weights bound
226
+ * @param out - the output binding
227
+ * @param n - the row count
228
+ * @param w - the window, or null for the single whole-core dispatch
229
+ * @param nextStart - the next window's first arc (w.end for the last window)
230
+ */
231
+ recordWindow(pass, core, out, n, w, nextStart) {
232
+ const wg = this.scope.workgroupSize;
233
+ for (const { tier, kernel, start, end } of this.tiers) {
234
+ let first = start;
235
+ let last = tier === 0 ? n : end;
236
+ let arcEnd = w === null ? arcCountOf(core) : Math.min(w.end, nextStart);
237
+ if (w !== null && this.perm === null) {
238
+ first = w.rowFirst;
239
+ last = w.rowLast + 1;
240
+ arcEnd = w.end;
241
+ }
242
+ const rows = last - first;
243
+ if (rows <= 0) {
244
+ continue;
245
+ }
246
+ const params = this.scope.params(RANGE_PARAMS, {
247
+ start: first,
248
+ end: last,
249
+ arcBase: w === null ? 0 : w.start,
250
+ arcEnd,
251
+ accumulate: w !== null || this.accumulate ? 1 : 0,
252
+ n,
253
+ });
254
+ const bound = kernel.bind({ ...graphBindings(core, this.perm), out, P: params.binding });
255
+ let rowsPerGroup = wg;
256
+ if (tier === 2) {
257
+ rowsPerGroup = 1;
258
+ }
259
+ else if (tier === 1) {
260
+ rowsPerGroup = wg / MID_TIER_LANES;
261
+ }
262
+ kernel.dispatch(pass, bound, plan1d(rows, rowsPerGroup, this.scope.caps), [params.offset]);
263
+ this.dispatches++;
264
+ }
162
265
  }
163
266
  }
164
267
  /**
165
- * Prepares the thread-per-row pipeline for a snapshot's dummy pattern (USE_PERM, HAS_WEIGHTS) and snippet.
268
+ * Prepares the tier pipelines for a snapshot's dummy pattern (USE_PERM = tiers !== null, HAS_WEIGHTS) and snippet:
269
+ * TIER 0 always; TIER 1 iff a row of degree 32..1023 exists (segmentOffsets[2] > segmentOffsets[1]); TIER 2 iff a
270
+ * row of degree >= 1024 exists (segmentOffsets[1] > 0). The mid tier folds 32 lanes per row, so a device whose
271
+ * workgroup size is below 32 is E_UNSUPPORTED { feature: "segmentedReduce.tiers" }.
166
272
  * @param scope - the reduce scope (pipelines, pool, params writer)
167
- * @param core - the core whose weights pattern selects HAS_WEIGHTS (USE_PERM is false: no tiers at P2)
168
- * @param options - operator, snippet, tiers (must be null), accumulate
273
+ * @param core - the core whose weights pattern selects HAS_WEIGHTS
274
+ * @param options - operator, snippet, tiers (null: the single thread-per-row dispatch), accumulate
169
275
  * @returns the planner
170
276
  */
171
277
  export async function prepareSegmentedReduce(scope, core, options) {
172
- if (options.tiers !== null) {
173
- throw new WebGpuGraphError("E_UNSUPPORTED", "segmentedReduce: the degree tiers land at P4; pass tiers: null", {
174
- feature: "segmentedReduce.tiers",
175
- });
176
- }
177
- assertNotWindowed(core, "segmentedReduce");
178
278
  const op = opCode(options.op);
179
279
  validateValueSnippet(options.valueSnippet);
180
- const overrides = { ...graphOverrides(core, null), OP: op, TIER: 0 };
181
- const spec = kernelSpec("segmented-reduce", overrides, { VALUE: options.valueSnippet });
182
- const kernel = await scope.pipelines.kernel(spec);
183
- return new ThreadPerRowPlanner(scope, kernel, core.weights !== null, options.accumulate === true);
280
+ const { tiers } = options;
281
+ const perm = tiers?.perm ?? null;
282
+ if (tiers !== null && scope.workgroupSize < MID_TIER_LANES) {
283
+ throw new WebGpuGraphError("E_UNSUPPORTED", `segmentedReduce: the mid tier folds ${MID_TIER_LANES} lanes per row, more than the workgroup size ${scope.workgroupSize}`, { feature: "segmentedReduce.tiers" });
284
+ }
285
+ const ranges = tiers === null
286
+ ? [{ tier: 0, start: 0, end: rowCountOf(core, "segmentedReduce") }]
287
+ : [
288
+ { tier: 2, start: 0, end: tiers.segmentOffsets[1] },
289
+ { tier: 1, start: tiers.segmentOffsets[1], end: tiers.segmentOffsets[2] },
290
+ { tier: 0, start: tiers.segmentOffsets[2], end: tiers.segmentOffsets[4] },
291
+ ];
292
+ const compiled = [];
293
+ for (const range of ranges) {
294
+ if (range.tier !== 0 && range.end <= range.start) {
295
+ continue;
296
+ }
297
+ const overrides = { ...graphOverrides(core, perm), OP: op, TIER: range.tier };
298
+ const spec = kernelSpec("segmented-reduce", overrides, { VALUE: options.valueSnippet });
299
+ compiled.push({ ...range, kernel: await scope.pipelines.kernel(spec) });
300
+ }
301
+ const fill = await scope.pipelines.kernel(kernelSpec("fill"));
302
+ return new TieredPlanner(scope, compiled, fill, perm, core.weights !== null, options.accumulate === true, identityFillWord(options.op));
184
303
  }
185
304
  //# sourceMappingURL=segmented-reduce.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"segmented-reduce.js","sourceRoot":"","sources":["../../../src/primitives/segmented-reduce.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE/C,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAGxF,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAuBhE,kIAAkI;AAClI,MAAM,wBAAwB,GAAwB,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC;AAEpG;;;;;GAKG;AACH,MAAM,wBAAwB,GAAwB,IAAI,GAAG,CAAC;IAC1D,IAAI;IACJ,MAAM;IACN,KAAK;IACL,KAAK;IACL,OAAO;IACP,MAAM;IACN,OAAO;IACP,KAAK;IACL,KAAK;IACL,KAAK;IACL,MAAM;IACN,KAAK;IACL,MAAM;IACN,OAAO;IACP,KAAK;IACL,MAAM;IACN,OAAO;IACP,OAAO;IACP,aAAa;IACb,KAAK;IACL,MAAM;I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AAC,IAAI,KAAK,CAAC,IAAI,KAAK,CAAC,GAAG,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;YAC/C,SAAS;QACb,CAAC;QACD,MAAM,SAAS,GAAG,EAAE,GAAG,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC;QAC9E,MAAM,IAAI,GAAG,UAAU,CAAC,kBAAkB,EAAE,SAAS,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC;QACxF,QAAQ,CAAC,IAAI,CAAC,EAAE,GAAG,KAAK,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC5E,CAAC;IACD,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;IAC9D,OAAO,IAAI,aAAa,CACpB,KAAK,EACL,QAAQ,EACR,IAAI,EACJ,IAAI,EACJ,IAAI,CAAC,OAAO,KAAK,IAAI,EACrB,OAAO,CAAC,UAAU,KAAK,IAAI,EAC3B,gBAAgB,CAAC,OAAO,CAAC,EAAE,CAAC,CAC/B,CAAC;AACN,CAAC"}
@@ -1,7 +1,6 @@
1
1
  /**
2
- * The pull SpMV primitive of spec 6 row 9 / 8.2 in its thread-per-row tier (P7; M8b plan PD-1 / PD-2): one
3
- * grid-stride dispatch of the `spmv-pull` module over the rows of a REVERSE adjacency, each invocation folding
4
- * `weight * xNorm[nbr]` over its row's in-arcs (Kahan-compensated, f32) and writing
2
+ * The pull SpMV primitive of spec 6 row 9 / 8.2 (P7; M8b plan PD-1 / PD-2): the `spmv-pull` module over the rows of
3
+ * a REVERSE adjacency, each row folding `weight * xNorm[nbr]` over its in-arcs (a two-level f32 sum) and writing
5
4
  * `rankOut[v] = beta * pv + alpha * (sum + danglingMass * pv)`, where `pv` is `personalization[v]` under
6
5
  * HAS_PERSONALIZATION and the uniform `P.uniformP` otherwise, and `danglingMass` is `partials[0].danglingMass`
7
6
  * under USE_DANGLING. PageRank sets alpha to the damping, beta to 1 - alpha and USE_DANGLING; HITS and eigenvector
@@ -9,14 +8,16 @@
9
8
  *
10
9
  * It is its own registry entry rather than a `segmentedReduce` VALUE snippet (PD-1): the snippet vocabulary is
11
10
  * `row, arc, nbr, weight, v` and cannot read `xNorm[nbr]`, and the design's binding table gives the kernel eight
12
- * storage bindings of its own. The in-degree tiers of `reverseDegreeOrder()` land at P4 (PD-2): `tiers !== null` is
13
- * E_UNSUPPORTED and USE_PERM is always false (the perm slot carries the rowPtr dummy of graphBindings). The row and
14
- * arc counts come from the core's binding sizes exactly as segmentedReduce derives them.
11
+ * storage bindings of its own. Without tiers it is ONE grid-stride dispatch (TIER 0, USE_PERM false: the perm slot
12
+ * carries the rowPtr dummy of graphBindings); with the in-degree tiers of `reverseDegreeOrder()` (P4-T5, PD-6) it
13
+ * is up to three dispatches over the permuted rows -- TIER 2 one workgroup per row over [0, hiEnd), TIER 1 32 lanes
14
+ * per row over [hiEnd, midEnd), TIER 0 grid-stride over [midEnd, n) -- each compiled only when its range is
15
+ * non-empty. The row and arc counts come from the core's binding sizes exactly as segmentedReduce derives them.
15
16
  */
16
17
  import { type CoreBinding } from "../memory/residency.js";
17
18
  import { type Binding } from "../types/memory.js";
19
+ import { type DegreeTiers } from "./core-shape.js";
18
20
  import { type ReduceScope } from "./reduce.js";
19
- import { type DegreeTiers } from "./segmented-reduce.js";
20
21
  /** The group-1 bindings of one pull: the pre-scaled input, the output, the personalization (null binds xNorm as the dummy) and the PrPartial block whose header carries danglingMass. */
21
22
  export interface SpmvResources {
22
23
  readonly xNorm: Binding;
@@ -30,7 +31,7 @@ export interface SpmvCoefficients {
30
31
  readonly beta: number;
31
32
  readonly uniformP: number;
32
33
  }
33
- /** Options of prepareSpmvPull: the two variant flags, the weights binding and the tiers (must be null at P7). */
34
+ /** Options of prepareSpmvPull: the two variant flags, the weights binding and the in-degree tiers (null: one grid-stride dispatch). */
34
35
  export interface SpmvPullOptions {
35
36
  readonly personalization: boolean;
36
37
  readonly dangling: boolean;
@@ -38,18 +39,21 @@ export interface SpmvPullOptions {
38
39
  readonly weights?: Binding | null | undefined;
39
40
  readonly tiers: DegreeTiers | null;
40
41
  }
41
- /** A prepared pull: records ONE grid-stride dispatch over the rows of a reverse core into a pass. */
42
+ /** A prepared pull: records one grid-stride dispatch (no tiers) or up to three tier dispatches over the rows of a reverse core into a pass. */
42
43
  export interface SpmvPullPlanner {
43
- /** Records the dispatch over rows [0, n) of `rev` writing rankOut[v] (f32) per row; nothing for n = 0. */
44
+ /** Records the dispatches over rows [0, n) of `rev` writing rankOut[v] (f32) per row; nothing for n = 0. */
44
45
  record(pass: GPUComputePassEncoder, rev: CoreBinding, resources: SpmvResources, coefficients: SpmvCoefficients): void;
45
- /** Dispatches the last record() issued (1, or 0 for n = 0). */
46
+ /** Dispatches the last record() issued (0 for n = 0; 1 without tiers; 1 to 3 with them). */
46
47
  readonly lastDispatches: number;
47
48
  }
48
49
  /**
49
- * Prepares the thread-per-row pull pipeline for a reverse core's weights pattern and the two variant flags.
50
+ * Prepares the pull pipelines for a reverse core's weights pattern and the two variant flags: TIER 0 always
51
+ * (USE_PERM = tiers !== null); TIER 1 iff a row of in-degree 32..1023 exists (segmentOffsets[2] >
52
+ * segmentOffsets[1]); TIER 2 iff a row of in-degree >= 1024 exists (segmentOffsets[1] > 0). The mid tier folds 32
53
+ * lanes per row, so a device whose workgroup size is below 32 is E_UNSUPPORTED { feature: "spmvPull.tiers" }.
50
54
  * @param scope - the reduce scope (pipelines, params writer)
51
- * @param rev - the reverse core whose weights pattern selects HAS_WEIGHTS (USE_PERM is false: no tiers at P7)
52
- * @param options - personalization, dangling, weights, tiers (must be null)
55
+ * @param rev - the reverse core whose weights pattern selects HAS_WEIGHTS
56
+ * @param options - personalization, dangling, weights, tiers (null: the single grid-stride dispatch)
53
57
  * @returns the planner
54
58
  */
55
59
  export declare function prepareSpmvPull(scope: ReduceScope, rev: CoreBinding, options: SpmvPullOptions): Promise<SpmvPullPlanner>;
@@ -1 +1 @@
1
- {"version":3,"file":"spmv.d.ts","sourceRoot":"","sources":["../../../src/primitives/spmv.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAMH,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEzD,yLAAyL;AACzL,MAAM,WAAW,aAAa;IAC1B,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,eAAe,EAAE,OAAO,GAAG,IAAI,CAAC;IACzC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;CAC9B;AAED,gFAAgF;AAChF,MAAM,WAAW,gBAAgB;IAC7B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC7B;AAED,iHAAiH;AACjH,MAAM,WAAW,eAAe;IAC5B,QAAQ,CAAC,eAAe,EAAE,OAAO,CAAC;IAClC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,iHAAiH;IACjH,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC;IAC9C,QAAQ,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI,CAAC;CACtC;AAED,qGAAqG;AACrG,MAAM,WAAW,eAAe;IAC5B,0GAA0G;IAC1G,MA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