@luma.gl/graph 10.0.0-alpha.14 → 10.0.0-alpha.15

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 (179) hide show
  1. package/dist/arrow/gpu/arrow-column-gpu-vector.cjs +27 -8
  2. package/dist/arrow/gpu/arrow-column-gpu-vector.d.ts +11 -1
  3. package/dist/arrow/gpu/arrow-column-gpu-vector.d.ts.map +1 -1
  4. package/dist/arrow/gpu/arrow-column-gpu-vector.js +33 -8
  5. package/dist/arrow/gpu/arrow-column-gpu-vector.js.map +1 -1
  6. package/dist/arrow/index.cjs +2 -0
  7. package/dist/arrow/index.cjs.map +1 -1
  8. package/dist/arrow/index.d.ts +1 -1
  9. package/dist/arrow/index.d.ts.map +1 -1
  10. package/dist/arrow/index.js +1 -1
  11. package/dist/arrow/index.js.map +1 -1
  12. package/dist/dist.dev.js +79 -39
  13. package/dist/dist.min.js +61 -61
  14. package/dist/experimental/index.cjs.map +1 -1
  15. package/dist/experimental/simulation/index.cjs.map +1 -1
  16. package/dist/geospatial/gpu-point-spatial-query.cjs +2 -15
  17. package/dist/geospatial/gpu-point-spatial-query.d.ts.map +1 -1
  18. package/dist/geospatial/gpu-point-spatial-query.js +2 -15
  19. package/dist/geospatial/gpu-point-spatial-query.js.map +1 -1
  20. package/dist/geospatial/index.cjs.map +2 -2
  21. package/dist/gpu-a5/index.cjs.map +1 -1
  22. package/dist/gpu-core/gpu-command-graph-compiler.cjs +11 -2
  23. package/dist/gpu-core/gpu-command-graph-compiler.d.ts +2 -1
  24. package/dist/gpu-core/gpu-command-graph-compiler.d.ts.map +1 -1
  25. package/dist/gpu-core/gpu-command-graph-compiler.js +13 -2
  26. package/dist/gpu-core/gpu-command-graph-compiler.js.map +1 -1
  27. package/dist/gpu-core/gpu-command-graph-types.d.ts +16 -1
  28. package/dist/gpu-core/gpu-command-graph-types.d.ts.map +1 -1
  29. package/dist/gpu-core/gpu-command-graph-types.js.map +1 -1
  30. package/dist/gpu-core/gpu-command-graph.cjs +6 -4
  31. package/dist/gpu-core/gpu-command-graph.d.ts +4 -4
  32. package/dist/gpu-core/gpu-command-graph.d.ts.map +1 -1
  33. package/dist/gpu-core/gpu-command-graph.js +6 -4
  34. package/dist/gpu-core/gpu-command-graph.js.map +1 -1
  35. package/dist/gpu-core/gpu-dispatch-utils.cjs +7 -3
  36. package/dist/gpu-core/gpu-dispatch-utils.d.ts +2 -0
  37. package/dist/gpu-core/gpu-dispatch-utils.d.ts.map +1 -1
  38. package/dist/gpu-core/gpu-dispatch-utils.js +4 -1
  39. package/dist/gpu-core/gpu-dispatch-utils.js.map +1 -1
  40. package/dist/gpu-core/gpu-grid-aggregation.cjs +2 -5
  41. package/dist/gpu-core/gpu-grid-aggregation.d.ts.map +1 -1
  42. package/dist/gpu-core/gpu-grid-aggregation.js +2 -5
  43. package/dist/gpu-core/gpu-grid-aggregation.js.map +1 -1
  44. package/dist/gpu-core/gpu-grid-binning.cjs +2 -5
  45. package/dist/gpu-core/gpu-grid-binning.d.ts.map +1 -1
  46. package/dist/gpu-core/gpu-grid-binning.js +2 -5
  47. package/dist/gpu-core/gpu-grid-binning.js.map +1 -1
  48. package/dist/gpu-core/gpu-grid-coordinate.cjs +41 -0
  49. package/dist/gpu-core/gpu-grid-coordinate.d.ts +7 -0
  50. package/dist/gpu-core/gpu-grid-coordinate.d.ts.map +1 -0
  51. package/dist/gpu-core/gpu-grid-coordinate.js +24 -0
  52. package/dist/gpu-core/gpu-grid-coordinate.js.map +1 -0
  53. package/dist/gpu-core/gpu-grid-index-internals.cjs +2 -15
  54. package/dist/gpu-core/gpu-grid-index-internals.d.ts.map +1 -1
  55. package/dist/gpu-core/gpu-grid-index-internals.js +2 -15
  56. package/dist/gpu-core/gpu-grid-index-internals.js.map +1 -1
  57. package/dist/gpu-core/gpu-grid-index-query.cjs +2 -16
  58. package/dist/gpu-core/gpu-grid-index-query.d.ts.map +1 -1
  59. package/dist/gpu-core/gpu-grid-index-query.js +2 -16
  60. package/dist/gpu-core/gpu-grid-index-query.js.map +1 -1
  61. package/dist/gpu-core/gpu-scan.cjs +46 -32
  62. package/dist/gpu-core/gpu-scan.d.ts.map +1 -1
  63. package/dist/gpu-core/gpu-scan.js +56 -44
  64. package/dist/gpu-core/gpu-scan.js.map +1 -1
  65. package/dist/gpu-core/gpu-segmented-reduction.cjs +12 -9
  66. package/dist/gpu-core/gpu-segmented-reduction.d.ts +1 -1
  67. package/dist/gpu-core/gpu-segmented-reduction.d.ts.map +1 -1
  68. package/dist/gpu-core/gpu-segmented-reduction.js +12 -9
  69. package/dist/gpu-core/gpu-segmented-reduction.js.map +1 -1
  70. package/dist/gpu-core/gpu-segmented-scan.cjs +73 -16
  71. package/dist/gpu-core/gpu-segmented-scan.d.ts.map +1 -1
  72. package/dist/gpu-core/gpu-segmented-scan.js +73 -16
  73. package/dist/gpu-core/gpu-segmented-scan.js.map +1 -1
  74. package/dist/gpu-core/index.cjs +18 -0
  75. package/dist/gpu-core/index.cjs.map +3 -3
  76. package/dist/gpu-core/index.d.ts +13 -1
  77. package/dist/gpu-core/index.d.ts.map +1 -1
  78. package/dist/gpu-core/index.js +6 -0
  79. package/dist/gpu-core/index.js.map +1 -1
  80. package/dist/gpu-data/gpu-vector-wgsl-layout.cjs +50 -0
  81. package/dist/gpu-data/gpu-vector-wgsl-layout.d.ts +41 -0
  82. package/dist/gpu-data/gpu-vector-wgsl-layout.d.ts.map +1 -0
  83. package/dist/gpu-data/gpu-vector-wgsl-layout.js +45 -0
  84. package/dist/gpu-data/gpu-vector-wgsl-layout.js.map +1 -0
  85. package/dist/gpu-data/index.cjs +3 -0
  86. package/dist/gpu-data/index.cjs.map +2 -2
  87. package/dist/gpu-data/index.d.ts +1 -0
  88. package/dist/gpu-data/index.d.ts.map +1 -1
  89. package/dist/gpu-data/index.js +1 -0
  90. package/dist/gpu-data/index.js.map +1 -1
  91. package/dist/gpu-dataframe/gpu-data-frame-query.cjs +1 -16
  92. package/dist/gpu-dataframe/gpu-data-frame-query.d.ts.map +1 -1
  93. package/dist/gpu-dataframe/gpu-data-frame-query.js +1 -23
  94. package/dist/gpu-dataframe/gpu-data-frame-query.js.map +1 -1
  95. package/dist/gpu-dataframe/gpu-expression.cjs +91 -2
  96. package/dist/gpu-dataframe/gpu-expression.d.ts +37 -0
  97. package/dist/gpu-dataframe/gpu-expression.d.ts.map +1 -1
  98. package/dist/gpu-dataframe/gpu-expression.js +106 -0
  99. package/dist/gpu-dataframe/gpu-expression.js.map +1 -1
  100. package/dist/gpu-dataframe/index.cjs +12 -2
  101. package/dist/gpu-dataframe/index.cjs.map +3 -3
  102. package/dist/gpu-dataframe/index.d.ts +4 -0
  103. package/dist/gpu-dataframe/index.d.ts.map +1 -1
  104. package/dist/gpu-dataframe/index.js +2 -0
  105. package/dist/gpu-dataframe/index.js.map +1 -1
  106. package/dist/gpu-dataframe/portable-expression.cjs +103 -0
  107. package/dist/gpu-dataframe/portable-expression.d.ts +19 -0
  108. package/dist/gpu-dataframe/portable-expression.d.ts.map +1 -0
  109. package/dist/gpu-dataframe/portable-expression.js +98 -0
  110. package/dist/gpu-dataframe/portable-expression.js.map +1 -0
  111. package/dist/gpu-dggs/benchmarks.cjs.map +1 -1
  112. package/dist/gpu-dggs/index.cjs.map +1 -1
  113. package/dist/gpu-geometry/index.cjs.map +1 -1
  114. package/dist/gpu-graph/index.cjs.map +1 -1
  115. package/dist/gpu-graph-algorithms/benchmarks.cjs.map +2 -2
  116. package/dist/gpu-graph-algorithms/gpu-graph-spatial-force-layout-internals.cjs +2 -15
  117. package/dist/gpu-graph-algorithms/gpu-graph-spatial-force-layout-internals.d.ts.map +1 -1
  118. package/dist/gpu-graph-algorithms/gpu-graph-spatial-force-layout-internals.js +2 -15
  119. package/dist/gpu-graph-algorithms/gpu-graph-spatial-force-layout-internals.js.map +1 -1
  120. package/dist/gpu-graph-algorithms/index.cjs.map +2 -2
  121. package/dist/gpu-h3/index.cjs.map +1 -1
  122. package/dist/gpu-physics/gpu-rigid-body-world.cjs +3 -1
  123. package/dist/gpu-physics/gpu-rigid-body-world.d.ts +4 -0
  124. package/dist/gpu-physics/gpu-rigid-body-world.d.ts.map +1 -1
  125. package/dist/gpu-physics/gpu-rigid-body-world.js +3 -1
  126. package/dist/gpu-physics/gpu-rigid-body-world.js.map +1 -1
  127. package/dist/gpu-physics/index.cjs.map +1 -1
  128. package/dist/gpu-physics/rigid-body-parallel-shaders.cjs +24 -9
  129. package/dist/gpu-physics/rigid-body-parallel-shaders.d.ts +1 -1
  130. package/dist/gpu-physics/rigid-body-parallel-shaders.d.ts.map +1 -1
  131. package/dist/gpu-physics/rigid-body-parallel-shaders.js +28 -9
  132. package/dist/gpu-physics/rigid-body-parallel-shaders.js.map +1 -1
  133. package/dist/gpu-physics/rigid-body-shaders.cjs +2 -2
  134. package/dist/gpu-physics/rigid-body-shaders.d.ts +1 -1
  135. package/dist/gpu-physics/rigid-body-shaders.d.ts.map +1 -1
  136. package/dist/gpu-physics/rigid-body-shaders.js +2 -2
  137. package/dist/gpu-physics/rigid-body-shaders.js.map +1 -1
  138. package/dist/gpu-pointcloud/index.cjs.map +1 -1
  139. package/dist/gpu-project/graph.cjs.map +1 -1
  140. package/dist/gpu-simple-graph/index.cjs.map +1 -1
  141. package/dist/gpu-sql/gpu-sql.cjs +97 -4
  142. package/dist/gpu-sql/gpu-sql.d.ts.map +1 -1
  143. package/dist/gpu-sql/gpu-sql.js +100 -5
  144. package/dist/gpu-sql/gpu-sql.js.map +1 -1
  145. package/dist/gpu-sql/index.cjs.map +2 -2
  146. package/dist/gpu-timeseries/index.cjs.map +1 -1
  147. package/dist/index.cjs.map +1 -1
  148. package/dist/index.d.ts +1 -1
  149. package/dist/index.d.ts.map +1 -1
  150. package/dist/index.js.map +1 -1
  151. package/package.json +8 -8
  152. package/src/arrow/gpu/arrow-column-gpu-vector.ts +67 -14
  153. package/src/arrow/index.ts +2 -0
  154. package/src/geospatial/gpu-point-spatial-query.ts +2 -15
  155. package/src/gpu-core/gpu-command-graph-compiler.ts +25 -2
  156. package/src/gpu-core/gpu-command-graph-types.ts +20 -0
  157. package/src/gpu-core/gpu-command-graph.ts +11 -4
  158. package/src/gpu-core/gpu-dispatch-utils.ts +13 -1
  159. package/src/gpu-core/gpu-grid-aggregation.ts +2 -5
  160. package/src/gpu-core/gpu-grid-binning.ts +2 -5
  161. package/src/gpu-core/gpu-grid-coordinate.ts +24 -0
  162. package/src/gpu-core/gpu-grid-index-internals.ts +2 -15
  163. package/src/gpu-core/gpu-grid-index-query.ts +2 -16
  164. package/src/gpu-core/gpu-scan.ts +59 -45
  165. package/src/gpu-core/gpu-segmented-reduction.ts +20 -10
  166. package/src/gpu-core/gpu-segmented-scan.ts +82 -17
  167. package/src/gpu-core/index.ts +21 -0
  168. package/src/gpu-data/gpu-vector-wgsl-layout.ts +79 -0
  169. package/src/gpu-data/index.ts +7 -0
  170. package/src/gpu-dataframe/gpu-data-frame-query.ts +6 -26
  171. package/src/gpu-dataframe/gpu-expression.ts +135 -0
  172. package/src/gpu-dataframe/index.ts +11 -0
  173. package/src/gpu-dataframe/portable-expression.ts +117 -0
  174. package/src/gpu-graph-algorithms/gpu-graph-spatial-force-layout-internals.ts +2 -15
  175. package/src/gpu-physics/gpu-rigid-body-world.ts +8 -1
  176. package/src/gpu-physics/rigid-body-parallel-shaders.ts +32 -9
  177. package/src/gpu-physics/rigid-body-shaders.ts +3 -2
  178. package/src/gpu-sql/gpu-sql.ts +105 -5
  179. package/src/index.ts +2 -0
@@ -4,7 +4,7 @@
4
4
 
5
5
  import {setGPUComputeDispatchWorkgroups} from './gpu-command-dispatch-metadata';
6
6
  import {type GPUCommandNode, createGPUComputeCommandNode} from './gpu-command-node';
7
- import {type Binding, type Device} from '@luma.gl/core';
7
+ import {type Binding, type Device, type ComputeShaderLayout} from '@luma.gl/core';
8
8
  import {Kernel} from '../execution/compute/kernel';
9
9
  import {GPUCommandGraph, type GraphDataView, GraphVectorView} from './gpu-command-graph';
10
10
  import {
@@ -602,9 +602,39 @@ ${props.segmentFlags ? `var<workgroup> segmentScratch: array<u32, ${SCAN_WORKGRO
602
602
  ? getSubgroupBlockScanSource(props, sumOutput, sumBinding)
603
603
  : portableSource;
604
604
 
605
+ const shaderLayout: ComputeShaderLayout = {
606
+ bindings: [
607
+ {name: 'inputValues', type: 'storage', group: 0, location: 0},
608
+ {name: 'outputValues', type: 'storage', group: 0, location: 1},
609
+ ...(sumOutput ? [{name: 'sumValues', type: 'storage' as const, group: 0, location: 2}] : []),
610
+ ...(props.segmentFlags
611
+ ? [{name: 'segmentFlags', type: 'storage' as const, group: 0, location: 3}]
612
+ : []),
613
+ ...(props.segmentPrefixes
614
+ ? [{name: 'segmentPrefixes', type: 'storage' as const, group: 0, location: 4}]
615
+ : []),
616
+ ...(segmentFlagOutput
617
+ ? [
618
+ {
619
+ name: 'summarySegmentFlags',
620
+ type: 'storage' as const,
621
+ group: 0,
622
+ location: 5
623
+ }
624
+ ]
625
+ : [])
626
+ ]
627
+ };
628
+
605
629
  nodes.push(
606
630
  createGPUComputeCommandNode<Parameters>({
607
631
  id: props.id,
632
+ kernel: {
633
+ entryPoint: 'main',
634
+ workgroupSize: [SCAN_WORKGROUP_SIZE, 1, 1],
635
+ bindings: shaderLayout.bindings,
636
+ source
637
+ },
608
638
  workload: {
609
639
  operation: 'GPUScan',
610
640
  variant: strategy,
@@ -637,31 +667,7 @@ ${props.segmentFlags ? `var<workgroup> segmentScratch: array<u32, ${SCAN_WORKGRO
637
667
  const kernel = new Kernel(device, {
638
668
  id: props.id,
639
669
  source,
640
- shaderLayout: {
641
- bindings: [
642
- {name: 'inputValues', type: 'storage', group: 0, location: 0},
643
- {name: 'outputValues', type: 'storage', group: 0, location: 1},
644
- ...(sumOutput
645
- ? [{name: 'sumValues', type: 'storage' as const, group: 0, location: 2}]
646
- : []),
647
- ...(props.segmentFlags
648
- ? [{name: 'segmentFlags', type: 'storage' as const, group: 0, location: 3}]
649
- : []),
650
- ...(props.segmentPrefixes
651
- ? [{name: 'segmentPrefixes', type: 'storage' as const, group: 0, location: 4}]
652
- : []),
653
- ...(segmentFlagOutput
654
- ? [
655
- {
656
- name: 'summarySegmentFlags',
657
- type: 'storage' as const,
658
- group: 0,
659
- location: 5
660
- }
661
- ]
662
- : [])
663
- ]
664
- }
670
+ shaderLayout
665
671
  });
666
672
  return {
667
673
  encode: ({computePass, getBuffer}) => {
@@ -854,9 +860,35 @@ ${props.offsetSegmentPrefixes ? '@group(0) @binding(3) var<storage, read> offset
854
860
  ${props.segmentPrefixes && props.offsetSegmentPrefixes ? 'segmentPrefixes[SEGMENT_PREFIXES_OFFSET + index] = segmentPrefix | offsetSegmentPrefix;' : ''}
855
861
  }
856
862
  }`;
863
+ const shaderLayout: ComputeShaderLayout = {
864
+ bindings: [
865
+ {name: 'outputValues', type: 'storage', group: 0, location: 0},
866
+ {name: 'offsets', type: 'storage', group: 0, location: 1},
867
+ ...(props.segmentPrefixes
868
+ ? [{name: 'segmentPrefixes', type: 'storage' as const, group: 0, location: 2}]
869
+ : []),
870
+ ...(props.offsetSegmentPrefixes
871
+ ? [
872
+ {
873
+ name: 'offsetSegmentPrefixes',
874
+ type: 'storage' as const,
875
+ group: 0,
876
+ location: 3
877
+ }
878
+ ]
879
+ : [])
880
+ ]
881
+ };
882
+
857
883
  nodes.push(
858
884
  createGPUComputeCommandNode<Parameters>({
859
885
  id: props.id,
886
+ kernel: {
887
+ entryPoint: 'main',
888
+ workgroupSize: [SCAN_WORKGROUP_SIZE, 1, 1],
889
+ bindings: shaderLayout.bindings,
890
+ source
891
+ },
860
892
  workload: {
861
893
  operation: 'GPUScan',
862
894
  commandCount: 1,
@@ -889,25 +921,7 @@ ${props.offsetSegmentPrefixes ? '@group(0) @binding(3) var<storage, read> offset
889
921
  const kernel = new Kernel(device, {
890
922
  id: props.id,
891
923
  source,
892
- shaderLayout: {
893
- bindings: [
894
- {name: 'outputValues', type: 'storage', group: 0, location: 0},
895
- {name: 'offsets', type: 'storage', group: 0, location: 1},
896
- ...(props.segmentPrefixes
897
- ? [{name: 'segmentPrefixes', type: 'storage' as const, group: 0, location: 2}]
898
- : []),
899
- ...(props.offsetSegmentPrefixes
900
- ? [
901
- {
902
- name: 'offsetSegmentPrefixes',
903
- type: 'storage' as const,
904
- group: 0,
905
- location: 3
906
- }
907
- ]
908
- : [])
909
- ]
910
- }
924
+ shaderLayout
911
925
  });
912
926
  return {
913
927
  encode: ({computePass, getBuffer}) => {
@@ -6,6 +6,7 @@ import {type GPUCommandNode, createGPUComputeCommandNode} from './gpu-command-no
6
6
  import type {Binding} from '@luma.gl/core';
7
7
  import {Kernel} from '../execution/compute/kernel';
8
8
  import {GPUCommandGraph, type GraphDataView} from './gpu-command-graph';
9
+ import {getBoundedWorkgroupLayout, type GPUBoundedDispatchLayout} from './gpu-dispatch-utils';
9
10
  import {
10
11
  getViewBinding,
11
12
  getViewElementOffset,
@@ -22,7 +23,7 @@ export type GPUSegmentedReductionOperation = 'sum' | 'min' | 'max';
22
23
  export type GPUSegmentedReductionProps<T extends GPUScalarFormat = GPUScalarFormat> = {
23
24
  id?: string;
24
25
  input: GraphDataView<T>;
25
- /** CSR-style element offsets. Length must equal output.length + 1. */
26
+ /** Nondecreasing element offsets relative to input. Length must equal output.length + 1. */
26
27
  segmentOffsets: GraphDataView<'uint32'>;
27
28
  output: GraphDataView<T>;
28
29
  operation: GPUSegmentedReductionOperation;
@@ -73,15 +74,20 @@ export class GPUSegmentedReduction<T extends GPUScalarFormat = GPUScalarFormat>
73
74
  }
74
75
  if (this.output.length === 0) return nodes;
75
76
 
76
- const source = makeShaderSource(this);
77
+ const dispatch = getBoundedWorkgroupLayout(
78
+ this.id,
79
+ this.output.length,
80
+ graph.device.limits.maxComputeWorkgroupsPerDimension
81
+ );
82
+ const source = makeShaderSource(this, dispatch);
77
83
  nodes.push(
78
84
  createGPUComputeCommandNode<Parameters>({
79
85
  id: this.id,
80
86
  workload: {
81
87
  operation: 'GPUSegmentedReduction',
82
88
  commandCount: 1,
83
- maximumWorkgroupCount: this.output.length,
84
- maximumInvocationCount: this.output.length * WORKGROUP_SIZE,
89
+ maximumWorkgroupCount: dispatch.x * dispatch.y * dispatch.z,
90
+ maximumInvocationCount: dispatch.x * dispatch.y * dispatch.z * WORKGROUP_SIZE,
85
91
  readByteLength: this.input.length * 4 + this.segmentOffsets.length * 4,
86
92
  writeByteLength: this.output.length * 4
87
93
  },
@@ -110,7 +116,7 @@ export class GPUSegmentedReduction<T extends GPUScalarFormat = GPUScalarFormat>
110
116
  outputValues: getViewBinding(this.output, getBuffer)
111
117
  };
112
118
 
113
- kernel.dispatch(computePass, {bindings, x: this.output.length, y: 1, z: 1});
119
+ kernel.dispatch(computePass, {bindings, ...dispatch});
114
120
  },
115
121
  destroy: () => kernel.destroy()
116
122
  };
@@ -122,7 +128,10 @@ export class GPUSegmentedReduction<T extends GPUScalarFormat = GPUScalarFormat>
122
128
  }
123
129
  }
124
130
 
125
- function makeShaderSource(reduction: GPUSegmentedReduction): string {
131
+ function makeShaderSource(
132
+ reduction: GPUSegmentedReduction,
133
+ dispatch: GPUBoundedDispatchLayout
134
+ ): string {
126
135
  const type =
127
136
  reduction.input.format === 'uint32'
128
137
  ? 'u32'
@@ -161,9 +170,10 @@ var<workgroup> scratch: array<${type}, ${WORKGROUP_SIZE}>;
161
170
  fn combine(a: ${type}, b: ${type}) -> ${type} { return ${combine}; }
162
171
  @compute @workgroup_size(${WORKGROUP_SIZE})
163
172
  fn main(@builtin(workgroup_id) wg: vec3u, @builtin(local_invocation_index) lane: u32) {
164
- let segment = wg.x;
165
- let begin = segmentOffsets[SEGMENT_OFFSET + segment];
166
- let end = segmentOffsets[SEGMENT_OFFSET + segment + 1u];
173
+ let segment = (wg.z * ${dispatch.y}u + wg.y) * ${dispatch.x}u + wg.x;
174
+ if (segment >= ${reduction.output.length}u) { return; }
175
+ let begin = min(segmentOffsets[SEGMENT_OFFSET + segment], ${reduction.input.length}u);
176
+ let end = min(segmentOffsets[SEGMENT_OFFSET + segment + 1u], ${reduction.input.length}u);
167
177
  var value: ${type} = ${identity};
168
178
  var i = begin + lane;
169
179
  loop {
@@ -181,7 +191,7 @@ fn main(@builtin(workgroup_id) wg: vec3u, @builtin(local_invocation_index) lane:
181
191
  stride = stride / 2u;
182
192
  }
183
193
  if (lane == 0u) {
184
- outputValues[OUTPUT_OFFSET + segment] = select(scratch[0], ${type}(${reduction.operation === 'sum' ? '0' : '0'}), begin == end);
194
+ outputValues[OUTPUT_OFFSET + segment] = select(scratch[0], ${type}(0), begin >= end);
185
195
  }
186
196
  }`;
187
197
  }
@@ -3,9 +3,10 @@
3
3
  // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
 
5
5
  import {type GPUCommandNode, createGPUComputeCommandNode} from './gpu-command-node';
6
- import type {Binding} from '@luma.gl/core';
6
+ import type {Binding, ComputeShaderLayout} from '@luma.gl/core';
7
7
  import {Kernel} from '../execution/compute/kernel';
8
8
  import {GPUCommandGraph, type GraphDataView} from './gpu-command-graph';
9
+ import {getBoundedWorkgroupLayout, type GPUBoundedDispatchLayout} from './gpu-dispatch-utils';
9
10
  import {
10
11
  getViewBinding,
11
12
  getViewElementOffset,
@@ -66,16 +67,35 @@ export class GPUSegmentedScan {
66
67
  throw new Error(`${this.id} views must belong to target graph`);
67
68
  }
68
69
  const segmentCount = this.segmentOffsets.length - 1;
69
- if (segmentCount === 0) return nodes;
70
- const source = makeShaderSource(this);
70
+ if (segmentCount === 0 || this.input.length === 0) return nodes;
71
+ const dispatch = getBoundedWorkgroupLayout(
72
+ this.id,
73
+ segmentCount,
74
+ graph.device.limits.maxComputeWorkgroupsPerDimension
75
+ );
76
+ const workgroupCount = dispatch.x * dispatch.y * dispatch.z;
77
+ const source = makeShaderSource(this, dispatch, segmentCount);
78
+ const shaderLayout: ComputeShaderLayout = {
79
+ bindings: [
80
+ {name: 'inputValues', type: 'read-only-storage', group: 0, location: 0},
81
+ {name: 'segmentOffsets', type: 'read-only-storage', group: 0, location: 1},
82
+ {name: 'outputValues', type: 'storage', group: 0, location: 2}
83
+ ]
84
+ };
71
85
  nodes.push(
72
86
  createGPUComputeCommandNode<Parameters>({
73
87
  id: this.id,
88
+ kernel: {
89
+ entryPoint: 'main',
90
+ workgroupSize: [WORKGROUP_SIZE, 1, 1],
91
+ bindings: shaderLayout.bindings,
92
+ source
93
+ },
74
94
  workload: {
75
95
  operation: 'GPUSegmentedScan',
76
96
  commandCount: 1,
77
- maximumWorkgroupCount: segmentCount,
78
- maximumInvocationCount: segmentCount * WORKGROUP_SIZE,
97
+ maximumWorkgroupCount: workgroupCount,
98
+ maximumInvocationCount: workgroupCount * WORKGROUP_SIZE,
79
99
  readByteLength: this.input.length * 4 + this.segmentOffsets.length * 4,
80
100
  writeByteLength: this.output.length * 4
81
101
  },
@@ -88,13 +108,7 @@ export class GPUSegmentedScan {
88
108
  const kernel = new Kernel(device, {
89
109
  id: this.id,
90
110
  source,
91
- shaderLayout: {
92
- bindings: [
93
- {name: 'inputValues', type: 'read-only-storage', group: 0, location: 0},
94
- {name: 'segmentOffsets', type: 'read-only-storage', group: 0, location: 1},
95
- {name: 'outputValues', type: 'storage', group: 0, location: 2}
96
- ]
97
- }
111
+ shaderLayout
98
112
  });
99
113
  return {
100
114
  encode: ({computePass, getBuffer}) => {
@@ -104,7 +118,7 @@ export class GPUSegmentedScan {
104
118
  outputValues: getViewBinding(this.output, getBuffer)
105
119
  };
106
120
 
107
- kernel.dispatch(computePass, {bindings, x: segmentCount, y: 1, z: 1});
121
+ kernel.dispatch(computePass, {bindings, ...dispatch});
108
122
  },
109
123
  destroy: () => kernel.destroy()
110
124
  };
@@ -116,8 +130,59 @@ export class GPUSegmentedScan {
116
130
  }
117
131
  }
118
132
 
119
- function makeShaderSource(scan: GPUSegmentedScan): string {
120
- return `const INPUT_OFFSET:u32=${getViewElementOffset(scan.input)}u; const SEGMENT_OFFSET:u32=${getViewElementOffset(scan.segmentOffsets)}u; const OUTPUT_OFFSET:u32=${getViewElementOffset(scan.output)}u; const INCLUSIVE:bool=${scan.mode === 'inclusive'};
121
- @group(0) @binding(0) var<storage,read> inputValues:array<u32>; @group(0) @binding(1) var<storage,read> segmentOffsets:array<u32>; @group(0) @binding(2) var<storage,read_write> outputValues:array<u32>;
122
- @compute @workgroup_size(${WORKGROUP_SIZE}) fn main(@builtin(workgroup_id) wg:vec3u,@builtin(local_invocation_index) lane:u32){let segment=wg.x;let begin=segmentOffsets[SEGMENT_OFFSET+segment];let end=segmentOffsets[SEGMENT_OFFSET+segment+1u];if(lane!=0u){return;}var sum=0u;var i=begin;loop{if(i>=end){break;}let value=inputValues[INPUT_OFFSET+i];outputValues[OUTPUT_OFFSET+i]=select(sum,sum+value,INCLUSIVE);sum+=value;i+=1u;}}`;
133
+ function makeShaderSource(
134
+ scan: GPUSegmentedScan,
135
+ dispatch: GPUBoundedDispatchLayout,
136
+ segmentCount: number
137
+ ): string {
138
+ return `const INPUT_OFFSET: u32 = ${getViewElementOffset(scan.input)}u;
139
+ const SEGMENT_OFFSET: u32 = ${getViewElementOffset(scan.segmentOffsets)}u;
140
+ const OUTPUT_OFFSET: u32 = ${getViewElementOffset(scan.output)}u;
141
+ const INPUT_LENGTH: u32 = ${scan.input.length}u;
142
+ @group(0) @binding(0) var<storage, read> inputValues: array<u32>;
143
+ @group(0) @binding(1) var<storage, read> segmentOffsets: array<u32>;
144
+ @group(0) @binding(2) var<storage, read_write> outputValues: array<u32>;
145
+ var<workgroup> prefixes: array<u32, ${WORKGROUP_SIZE}>;
146
+ var<workgroup> segmentBounds: array<u32, 2>;
147
+
148
+
149
+ @compute @workgroup_size(${WORKGROUP_SIZE})
150
+ fn main(
151
+ @builtin(workgroup_id) workgroup: vec3u,
152
+ @builtin(local_invocation_index) lane: u32
153
+ ) {
154
+ let segment = (workgroup.z * ${dispatch.y}u + workgroup.y) * ${dispatch.x}u + workgroup.x;
155
+ if (segment >= ${segmentCount}u) { return; }
156
+ if (lane == 0u) {
157
+ segmentBounds[0] = min(segmentOffsets[SEGMENT_OFFSET + segment], INPUT_LENGTH);
158
+ segmentBounds[1] = min(segmentOffsets[SEGMENT_OFFSET + segment + 1u], INPUT_LENGTH);
159
+ }
160
+ let begin = workgroupUniformLoad(&segmentBounds[0]);
161
+ let end = workgroupUniformLoad(&segmentBounds[1]);
162
+ var carry = 0u;
163
+ for (var tile = begin; tile < end;) {
164
+ let tileLength = min(end - tile, ${WORKGROUP_SIZE}u);
165
+ var value = 0u;
166
+ if (lane < tileLength) {
167
+ value = inputValues[INPUT_OFFSET + tile + lane];
168
+ }
169
+ prefixes[lane] = value;
170
+ workgroupBarrier();
171
+
172
+ for (var stride = 1u; stride < ${WORKGROUP_SIZE}u; stride *= 2u) {
173
+ var previous = 0u;
174
+ if (lane >= stride) { previous = prefixes[lane - stride]; }
175
+ workgroupBarrier();
176
+ prefixes[lane] += previous;
177
+ workgroupBarrier();
178
+ }
179
+
180
+ if (lane < tileLength) {
181
+ outputValues[OUTPUT_OFFSET + tile + lane] = carry + prefixes[lane]${scan.mode === 'exclusive' ? ' - value' : ''};
182
+ }
183
+ carry += prefixes[${WORKGROUP_SIZE - 1}u];
184
+ workgroupBarrier();
185
+ tile += tileLength;
186
+ }
187
+ }`;
123
188
  }
@@ -46,6 +46,8 @@ export type {
46
46
  GPUCommandGraphNodeTiming,
47
47
  GPUCommandGraphNodeType,
48
48
  GPUCommandGraphNodePreflight,
49
+ GPUCommandGraphCompileOptions,
50
+ GPUCommandGraphKernelMetadata,
49
51
  GPUCommandGraphResourceSummary,
50
52
  GPUCommandGraphNodePublication,
51
53
  GPUCommandGraphNodeWorkloadEstimate,
@@ -140,6 +142,8 @@ export {GPUByteRangeGather} from './gpu-byte-range-gather';
140
142
  export type {GPUByteRangeGatherProps} from './gpu-byte-range-gather';
141
143
  export {GPUGather} from './gpu-gather';
142
144
  export type {GPUGatherFormat, GPUGatherProps} from './gpu-gather';
145
+ export {GPUScatter} from './gpu-scatter';
146
+ export type {GPUScatterFormat, GPUScatterProps} from './gpu-scatter';
143
147
  export {
144
148
  GPULZByteDecompressor,
145
149
  GPU_LZ_BYTE_DESCRIPTOR_WORDS,
@@ -177,6 +181,15 @@ export type {
177
181
  GPUWorkgroupReductionBenchmarkReport,
178
182
  GPUWorkgroupReductionBenchmarkStrategy
179
183
  } from './gpu-workgroup-reduction-benchmark';
184
+ export {GPUSegmentedScan} from './gpu-segmented-scan';
185
+ export type {GPUSegmentedScanMode, GPUSegmentedScanProps} from './gpu-segmented-scan';
186
+
187
+ export {GPUSegmentedReduction} from './gpu-segmented-reduction';
188
+ export type {
189
+ GPUSegmentedReductionOperation,
190
+ GPUSegmentedReductionProps
191
+ } from './gpu-segmented-reduction';
192
+
180
193
  export {GPUSegmentedSort} from './gpu-segmented-sort';
181
194
  export type {GPUSegmentedSortProps, GPUSortSegment} from './gpu-segmented-sort';
182
195
  export {GPUCompaction} from './gpu-compaction';
@@ -392,6 +405,8 @@ export type {
392
405
  GPUHistogramProps
393
406
  } from './gpu-histogram';
394
407
 
408
+ export {GPU_GRID_COORDINATE_WGSL} from './gpu-grid-coordinate';
409
+
395
410
  export {GPUGridBinning} from './gpu-grid-binning';
396
411
  export type {
397
412
  GPUGridBinningBounds,
@@ -637,6 +652,12 @@ export {GPUGraphDotProduct, GPUGraphVectorMADD} from './gpu-semantic-vector-oper
637
652
  export {GPUGraphCSRMatrix, GPUGraphSpMV} from './gpu-semantic-spmv';
638
653
  export {createGPUConjugateGradientGraph} from './gpu-conjugate-gradient-program';
639
654
 
655
+ export {GPUAdaptiveSpMV} from './gpu-adaptive-spmv';
656
+ export type {GPUAdaptiveSpMVProps} from './gpu-adaptive-spmv';
657
+ export type {GPUSpMVRowStatistics, GPUSpMVStrategyId} from './gpu-spmv-strategy';
658
+ export {GPUJacobiPCG} from './gpu-pcg';
659
+ export type {GPUJacobiPCGProps, GPUJacobiPCGResult} from './gpu-pcg';
660
+
640
661
  export {GPUCOOToCSR} from './gpu-coo-to-csr';
641
662
  export type {GPUCOOToCSRProps} from './gpu-coo-to-csr';
642
663
  export {GPURunLengthEncode, GPUUnique} from './gpu-run-length-encode';
@@ -0,0 +1,79 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ import {getLeafLayoutInfo, makeShaderBlockLayout} from '@luma.gl/shaders/types';
6
+ import {getGPUVectorFormatInfo} from './gpu-vector-format';
7
+
8
+ /** Scalar formats with matching 32-bit WGSL component representations. */
9
+ export type GPUVectorWGSLScalarFormat = 'float32' | 'sint32' | 'uint32';
10
+
11
+ /** Packed 32-bit numeric formats with a corresponding WGSL value type. */
12
+ export type GPUVectorWGSLFormat =
13
+ | GPUVectorWGSLScalarFormat
14
+ | `${GPUVectorWGSLScalarFormat}x${2 | 3 | 4}`;
15
+
16
+ /** Packed row metadata and the layout of the corresponding native WGSL storage value. */
17
+ export type GPUVectorWGSLLayout = {
18
+ /** The packed GPUVector format. */
19
+ format: GPUVectorWGSLFormat;
20
+ /** Number of scalar components in a row. */
21
+ components: 1 | 2 | 3 | 4;
22
+ /** GPUVector format of an individual component. */
23
+ componentType: GPUVectorWGSLScalarFormat;
24
+ /** WGSL type of an individual component. */
25
+ scalarType: 'f32' | 'i32' | 'u32';
26
+ /** WGSL scalar or vector type for one row. */
27
+ shaderType: 'f32' | 'i32' | 'u32' | `vec${2 | 3 | 4}<${'f32' | 'i32' | 'u32'}>`;
28
+ /** Number of bytes occupied by the components of one row. */
29
+ byteLength: number;
30
+ /** Distance in bytes between rows in a tightly packed GPUVector. */
31
+ packedByteStride: number;
32
+ /** Required byte alignment of the value in a native WGSL storage buffer. */
33
+ storageAlignment: number;
34
+ /** Distance in bytes between elements in a native WGSL storage array of this value type. */
35
+ nativeArrayByteStride: number;
36
+ };
37
+
38
+ /**
39
+ * Describes packed GPUVector rows and the corresponding native WGSL storage array.
40
+ *
41
+ * @param format - Packed 32-bit scalar or vector format.
42
+ * @returns Layout metadata in bytes. The helper does not allocate or modify storage.
43
+ * @throws If the format has no supported 32-bit WGSL representation.
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * const layout = getGPUVectorWGSLLayout('float32x3');
48
+ * layout.packedByteStride; // 12
49
+ * layout.nativeArrayByteStride; // 16
50
+ * ```
51
+ */
52
+ export function getGPUVectorWGSLLayout(format: GPUVectorWGSLFormat): GPUVectorWGSLLayout {
53
+ const {components, signedDataType, primitiveType, byteLength, elementFormat, normalized} =
54
+ getGPUVectorFormatInfo(format);
55
+ if (
56
+ normalized ||
57
+ elementFormat !== format ||
58
+ (signedDataType !== 'float32' && signedDataType !== 'sint32' && signedDataType !== 'uint32') ||
59
+ primitiveType === 'f16'
60
+ ) {
61
+ throw new Error('Expected a packed 32-bit numeric vector format');
62
+ }
63
+ const scalarType = primitiveType;
64
+ const shaderType = components === 1 ? scalarType : (`vec${components}<${scalarType}>` as const);
65
+ const layout = 'wgsl-storage';
66
+ const {alignment} = getLeafLayoutInfo(shaderType, layout);
67
+ const arrayLayout = makeShaderBlockLayout({values: [shaderType, 2]}, {layout});
68
+ return {
69
+ format,
70
+ components,
71
+ componentType: signedDataType,
72
+ scalarType,
73
+ shaderType,
74
+ byteLength,
75
+ packedByteStride: byteLength,
76
+ storageAlignment: alignment * Uint32Array.BYTES_PER_ELEMENT,
77
+ nativeArrayByteStride: arrayLayout.byteLength / 2
78
+ };
79
+ }
@@ -74,5 +74,12 @@ export {CPUVector, type CPUVectorProps} from './cpu-vector';
74
74
 
75
75
  export {makeGPUVectorFromCPUVector, makeCPUVectorFromGPUVector} from './cpu-gpu-vector-transfer';
76
76
 
77
+ export {
78
+ getGPUVectorWGSLLayout,
79
+ type GPUVectorWGSLFormat,
80
+ type GPUVectorWGSLLayout,
81
+ type GPUVectorWGSLScalarFormat
82
+ } from './gpu-vector-wgsl-layout';
83
+
77
84
  export {convertCPUColors, resolveColorOutputFormat} from './color-conversion';
78
85
  export type {ColorOutputFormat, ColorConversionOptions} from './color-conversion';
@@ -6,7 +6,12 @@
6
6
  import type {GPUTypeMap} from '@luma.gl/graph/gpu-tables';
7
7
  import type {GPUCommandGraph} from '@luma.gl/graph/gpu-core';
8
8
  import type {GPUDataFrame} from './gpu-data-frame';
9
- import {getGPUExpressionColumnNames, GPUExpression, type GPUExpressionNode} from './gpu-expression';
9
+ import {
10
+ getGPUExpressionColumnNames,
11
+ GPUExpression,
12
+ isBooleanExpressionNode,
13
+ type GPUExpressionNode
14
+ } from './gpu-expression';
10
15
  import {
11
16
  GPUDataFrameAggregationQuery,
12
17
  type GPUDataFrameGlobalAggregationDefinitions,
@@ -434,28 +439,3 @@ function isNumericExpressionNode(node: GPUExpressionNode): boolean {
434
439
  return false;
435
440
  }
436
441
  }
437
-
438
- function isBooleanExpressionNode(node: GPUExpressionNode): boolean {
439
- switch (node.kind) {
440
- case 'column':
441
- return false;
442
- case 'literal':
443
- case 'parameter':
444
- return typeof node.value === 'boolean';
445
- case 'unary':
446
- return node.operator === 'not' || node.operator === 'is-valid' || node.operator === 'is-null';
447
- case 'binary':
448
- return (
449
- node.operator === 'equal' ||
450
- node.operator === 'not-equal' ||
451
- node.operator === 'greater-than' ||
452
- node.operator === 'greater-than-or-equal' ||
453
- node.operator === 'less-than' ||
454
- node.operator === 'less-than-or-equal' ||
455
- node.operator === 'and' ||
456
- node.operator === 'or'
457
- );
458
- default:
459
- return false;
460
- }
461
- }