@luma.gl/graph 10.0.0-beta.2 → 10.0.0-beta.3
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/arrow/gpu/arrow-gpu-analytics-adapters.cjs +22 -9
- package/dist/arrow/gpu/arrow-gpu-analytics-adapters.d.ts +11 -2
- package/dist/arrow/gpu/arrow-gpu-analytics-adapters.d.ts.map +1 -1
- package/dist/arrow/gpu/arrow-gpu-analytics-adapters.js +27 -10
- package/dist/arrow/gpu/arrow-gpu-analytics-adapters.js.map +1 -1
- package/dist/arrow/gpu/arrow-gpu-analytics-readback.cjs +24 -13
- package/dist/arrow/gpu/arrow-gpu-analytics-readback.d.ts +9 -1
- package/dist/arrow/gpu/arrow-gpu-analytics-readback.d.ts.map +1 -1
- package/dist/arrow/gpu/arrow-gpu-analytics-readback.js +41 -14
- package/dist/arrow/gpu/arrow-gpu-analytics-readback.js.map +1 -1
- package/dist/arrow/gpu/arrow-gpu-table-conversion.cjs +24 -1
- package/dist/arrow/gpu/arrow-gpu-table-conversion.d.ts +10 -1
- package/dist/arrow/gpu/arrow-gpu-table-conversion.d.ts.map +1 -1
- package/dist/arrow/gpu/arrow-gpu-table-conversion.js +29 -1
- package/dist/arrow/gpu/arrow-gpu-table-conversion.js.map +1 -1
- package/dist/arrow/index.cjs +2 -0
- package/dist/arrow/index.cjs.map +3 -3
- package/dist/arrow/index.d.ts +1 -1
- package/dist/arrow/index.d.ts.map +1 -1
- package/dist/arrow/index.js +1 -1
- package/dist/arrow/index.js.map +1 -1
- package/dist/gpu-core/gpu-bvh-bounds.cjs +63 -0
- package/dist/gpu-core/gpu-bvh-bounds.d.ts +32 -0
- package/dist/gpu-core/gpu-bvh-bounds.d.ts.map +1 -0
- package/dist/gpu-core/gpu-bvh-bounds.js +56 -0
- package/dist/gpu-core/gpu-bvh-bounds.js.map +1 -0
- package/dist/gpu-core/gpu-command-graph-submission-pacer.cjs +92 -0
- package/dist/gpu-core/gpu-command-graph-submission-pacer.d.ts +41 -0
- package/dist/gpu-core/gpu-command-graph-submission-pacer.d.ts.map +1 -0
- package/dist/gpu-core/gpu-command-graph-submission-pacer.js +85 -0
- package/dist/gpu-core/gpu-command-graph-submission-pacer.js.map +1 -0
- package/dist/gpu-core/index.cjs +6 -0
- package/dist/gpu-core/index.cjs.map +3 -3
- package/dist/gpu-core/index.d.ts +4 -0
- package/dist/gpu-core/index.d.ts.map +1 -1
- package/dist/gpu-core/index.js +2 -0
- package/dist/gpu-core/index.js.map +1 -1
- package/dist/gpu-dataframe/gpu-analytics-compiler-utils.cjs +6 -6
- package/dist/gpu-dataframe/gpu-analytics-compiler-utils.d.ts +1 -1
- package/dist/gpu-dataframe/gpu-analytics-compiler-utils.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-analytics-compiler-utils.js +6 -6
- package/dist/gpu-dataframe/gpu-analytics-compiler-utils.js.map +1 -1
- package/dist/gpu-dataframe/gpu-data-frame-query.cjs +55 -14
- package/dist/gpu-dataframe/gpu-data-frame-query.d.ts +13 -2
- package/dist/gpu-dataframe/gpu-data-frame-query.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-data-frame-query.js +58 -17
- package/dist/gpu-dataframe/gpu-data-frame-query.js.map +1 -1
- package/dist/gpu-dataframe/gpu-data-frame.cjs +1 -3
- package/dist/gpu-dataframe/gpu-data-frame.d.ts +10 -0
- package/dist/gpu-dataframe/gpu-data-frame.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-data-frame.js +1 -3
- package/dist/gpu-dataframe/gpu-data-frame.js.map +1 -1
- package/dist/gpu-dataframe/gpu-expression-shader.cjs +94 -44
- package/dist/gpu-dataframe/gpu-expression-shader.d.ts +8 -5
- package/dist/gpu-dataframe/gpu-expression-shader.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-expression-shader.js +110 -47
- package/dist/gpu-dataframe/gpu-expression-shader.js.map +1 -1
- package/dist/gpu-dataframe/gpu-expression.cjs +14 -8
- package/dist/gpu-dataframe/gpu-expression.d.ts +12 -1
- package/dist/gpu-dataframe/gpu-expression.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-expression.js +11 -6
- package/dist/gpu-dataframe/gpu-expression.js.map +1 -1
- package/dist/gpu-dataframe/gpu-global-aggregation-compiler.cjs +2 -2
- package/dist/gpu-dataframe/gpu-global-aggregation-compiler.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-global-aggregation-compiler.js +4 -2
- package/dist/gpu-dataframe/gpu-global-aggregation-compiler.js.map +1 -1
- package/dist/gpu-dataframe/gpu-global-aggregation-query.cjs +2 -2
- package/dist/gpu-dataframe/gpu-global-aggregation-query.d.ts +5 -1
- package/dist/gpu-dataframe/gpu-global-aggregation-query.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-global-aggregation-query.js +6 -2
- package/dist/gpu-dataframe/gpu-global-aggregation-query.js.map +1 -1
- package/dist/gpu-dataframe/gpu-global-sort-compiler.cjs +113 -88
- package/dist/gpu-dataframe/gpu-global-sort-compiler.d.ts +6 -1
- package/dist/gpu-dataframe/gpu-global-sort-compiler.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-global-sort-compiler.js +111 -85
- package/dist/gpu-dataframe/gpu-global-sort-compiler.js.map +1 -1
- package/dist/gpu-dataframe/gpu-group-aggregation-compiler.cjs +286 -48
- package/dist/gpu-dataframe/gpu-group-aggregation-compiler.d.ts +17 -2
- package/dist/gpu-dataframe/gpu-group-aggregation-compiler.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-group-aggregation-compiler.js +290 -39
- package/dist/gpu-dataframe/gpu-group-aggregation-compiler.js.map +1 -1
- package/dist/gpu-dataframe/gpu-group-by-query.cjs +8 -6
- package/dist/gpu-dataframe/gpu-group-by-query.d.ts +7 -1
- package/dist/gpu-dataframe/gpu-group-by-query.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-group-by-query.js +9 -5
- package/dist/gpu-dataframe/gpu-group-by-query.js.map +1 -1
- package/dist/gpu-dataframe/gpu-join-compiler.cjs +8 -6
- package/dist/gpu-dataframe/gpu-join-compiler.d.ts +1 -1
- package/dist/gpu-dataframe/gpu-join-compiler.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-join-compiler.js +9 -7
- package/dist/gpu-dataframe/gpu-join-compiler.js.map +1 -1
- package/dist/gpu-dataframe/gpu-query-compiler.cjs +37 -11
- package/dist/gpu-dataframe/gpu-query-compiler.d.ts +3 -1
- package/dist/gpu-dataframe/gpu-query-compiler.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-query-compiler.js +36 -10
- package/dist/gpu-dataframe/gpu-query-compiler.js.map +1 -1
- package/dist/gpu-dataframe/index.cjs +4 -2
- package/dist/gpu-dataframe/index.cjs.map +3 -3
- package/dist/gpu-dataframe/index.d.ts +1 -1
- package/dist/gpu-dataframe/index.d.ts.map +1 -1
- package/dist/gpu-dataframe/index.js +1 -1
- package/dist/gpu-dataframe/index.js.map +1 -1
- package/dist/gpu-physics/gpu-physics-batch.cjs +11 -10
- package/dist/gpu-physics/gpu-physics-batch.d.ts +1 -0
- package/dist/gpu-physics/gpu-physics-batch.d.ts.map +1 -1
- package/dist/gpu-physics/gpu-physics-batch.js +14 -10
- package/dist/gpu-physics/gpu-physics-batch.js.map +1 -1
- package/dist/gpu-physics/gpu-physics-ensemble.cjs +9 -4
- package/dist/gpu-physics/gpu-physics-ensemble.d.ts +10 -1
- package/dist/gpu-physics/gpu-physics-ensemble.d.ts.map +1 -1
- package/dist/gpu-physics/gpu-physics-ensemble.js +11 -4
- package/dist/gpu-physics/gpu-physics-ensemble.js.map +1 -1
- package/dist/gpu-physics/gpu-rigid-body-world.cjs +261 -68
- package/dist/gpu-physics/gpu-rigid-body-world.d.ts +47 -2
- package/dist/gpu-physics/gpu-rigid-body-world.d.ts.map +1 -1
- package/dist/gpu-physics/gpu-rigid-body-world.js +324 -75
- package/dist/gpu-physics/gpu-rigid-body-world.js.map +1 -1
- package/dist/gpu-physics/index.cjs.map +3 -3
- package/dist/gpu-physics/index.d.ts +2 -1
- package/dist/gpu-physics/index.d.ts.map +1 -1
- package/dist/gpu-physics/index.js.map +1 -1
- package/dist/gpu-physics/rigid-body-cache-shaders.cjs +10 -6
- package/dist/gpu-physics/rigid-body-cache-shaders.d.ts +2 -1
- package/dist/gpu-physics/rigid-body-cache-shaders.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-cache-shaders.js +15 -6
- package/dist/gpu-physics/rigid-body-cache-shaders.js.map +1 -1
- package/dist/gpu-physics/rigid-body-capacity.cjs +15 -2
- package/dist/gpu-physics/rigid-body-capacity.d.ts +3 -1
- package/dist/gpu-physics/rigid-body-capacity.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-capacity.js +21 -2
- package/dist/gpu-physics/rigid-body-capacity.js.map +1 -1
- package/dist/gpu-physics/rigid-body-cast-index.cjs +192 -0
- package/dist/gpu-physics/rigid-body-cast-index.d.ts +44 -0
- package/dist/gpu-physics/rigid-body-cast-index.d.ts.map +1 -0
- package/dist/gpu-physics/rigid-body-cast-index.js +194 -0
- package/dist/gpu-physics/rigid-body-cast-index.js.map +1 -0
- package/dist/gpu-physics/rigid-body-ensemble-layout.cjs +4 -2
- package/dist/gpu-physics/rigid-body-ensemble-layout.d.ts +2 -1
- package/dist/gpu-physics/rigid-body-ensemble-layout.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-ensemble-layout.js +5 -2
- package/dist/gpu-physics/rigid-body-ensemble-layout.js.map +1 -1
- package/dist/gpu-physics/rigid-body-ensemble-reset.cjs +11 -9
- package/dist/gpu-physics/rigid-body-ensemble-reset.d.ts +1 -1
- package/dist/gpu-physics/rigid-body-ensemble-reset.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-ensemble-reset.js +13 -9
- package/dist/gpu-physics/rigid-body-ensemble-reset.js.map +1 -1
- package/dist/gpu-physics/rigid-body-ensemble-shaders.cjs +14 -7
- package/dist/gpu-physics/rigid-body-ensemble-shaders.d.ts +5 -0
- package/dist/gpu-physics/rigid-body-ensemble-shaders.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-ensemble-shaders.js +17 -7
- package/dist/gpu-physics/rigid-body-ensemble-shaders.js.map +1 -1
- package/dist/gpu-physics/rigid-body-ensemble-transaction.cjs +21 -11
- package/dist/gpu-physics/rigid-body-ensemble-transaction.d.ts +2 -2
- package/dist/gpu-physics/rigid-body-ensemble-transaction.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-ensemble-transaction.js +28 -12
- package/dist/gpu-physics/rigid-body-ensemble-transaction.js.map +1 -1
- package/dist/gpu-physics/rigid-body-event-compaction.cjs +184 -0
- package/dist/gpu-physics/rigid-body-event-compaction.d.ts +35 -0
- package/dist/gpu-physics/rigid-body-event-compaction.d.ts.map +1 -0
- package/dist/gpu-physics/rigid-body-event-compaction.js +168 -0
- package/dist/gpu-physics/rigid-body-event-compaction.js.map +1 -0
- package/dist/gpu-physics/rigid-body-event-snapshot.cjs +51 -0
- package/dist/gpu-physics/rigid-body-event-snapshot.d.ts +33 -0
- package/dist/gpu-physics/rigid-body-event-snapshot.d.ts.map +1 -0
- package/dist/gpu-physics/rigid-body-event-snapshot.js +34 -0
- package/dist/gpu-physics/rigid-body-event-snapshot.js.map +1 -0
- package/dist/gpu-physics/rigid-body-events.cjs +57 -25
- package/dist/gpu-physics/rigid-body-events.d.ts +2 -1
- package/dist/gpu-physics/rigid-body-events.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-events.js +60 -25
- package/dist/gpu-physics/rigid-body-events.js.map +1 -1
- package/dist/gpu-physics/rigid-body-joints.cjs +8 -3
- package/dist/gpu-physics/rigid-body-joints.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-joints.js +10 -6
- package/dist/gpu-physics/rigid-body-joints.js.map +1 -1
- package/dist/gpu-physics/rigid-body-queries.cjs +159 -16
- package/dist/gpu-physics/rigid-body-queries.d.ts +24 -1
- package/dist/gpu-physics/rigid-body-queries.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-queries.js +166 -14
- package/dist/gpu-physics/rigid-body-queries.js.map +1 -1
- package/dist/gpu-physics/rigid-body-shaders.cjs +3 -3
- package/dist/gpu-physics/rigid-body-shaders.d.ts +1 -1
- package/dist/gpu-physics/rigid-body-shaders.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-shaders.js +3 -3
- package/dist/gpu-physics/rigid-body-shaders.js.map +1 -1
- package/dist/gpu-physics/rigid-body-triggers.cjs +53 -15
- package/dist/gpu-physics/rigid-body-triggers.d.ts +1 -0
- package/dist/gpu-physics/rigid-body-triggers.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-triggers.js +55 -15
- package/dist/gpu-physics/rigid-body-triggers.js.map +1 -1
- package/dist/gpu-physics/sphere-world-shaders.cjs +48 -20
- package/dist/gpu-physics/sphere-world-shaders.d.ts.map +1 -1
- package/dist/gpu-physics/sphere-world-shaders.js +51 -21
- package/dist/gpu-physics/sphere-world-shaders.js.map +1 -1
- package/dist/gpu-project/benchmarks.cjs.map +2 -2
- package/dist/gpu-project/crs.cjs.map +2 -2
- package/dist/gpu-project/index.cjs.map +2 -2
- package/dist/gpu-project/projection-program.cjs +2 -9
- package/dist/gpu-project/projection-program.d.ts.map +1 -1
- package/dist/gpu-project/projection-program.js +1 -8
- package/dist/gpu-project/projection-program.js.map +1 -1
- package/dist/gpu-sql/gpu-sql.cjs +203 -59
- package/dist/gpu-sql/gpu-sql.d.ts +36 -1
- package/dist/gpu-sql/gpu-sql.d.ts.map +1 -1
- package/dist/gpu-sql/gpu-sql.js +225 -62
- package/dist/gpu-sql/gpu-sql.js.map +1 -1
- package/dist/gpu-sql/index.cjs.map +3 -3
- package/dist/gpu-sql/index.d.ts +1 -1
- package/dist/gpu-sql/index.d.ts.map +1 -1
- package/dist/utils/float32.cjs +35 -0
- package/dist/utils/float32.d.ts +3 -0
- package/dist/utils/float32.d.ts.map +1 -0
- package/dist/utils/float32.js +16 -0
- package/dist/utils/float32.js.map +1 -0
- package/package.json +4 -4
- package/src/arrow/gpu/arrow-gpu-analytics-adapters.ts +77 -25
- package/src/arrow/gpu/arrow-gpu-analytics-readback.ts +52 -16
- package/src/arrow/gpu/arrow-gpu-table-conversion.ts +46 -1
- package/src/arrow/index.ts +1 -0
- package/src/gpu-core/gpu-bvh-bounds.ts +84 -0
- package/src/gpu-core/gpu-command-graph-submission-pacer.ts +102 -0
- package/src/gpu-core/index.ts +5 -0
- package/src/gpu-dataframe/gpu-analytics-compiler-utils.ts +7 -10
- package/src/gpu-dataframe/gpu-data-frame-query.ts +106 -25
- package/src/gpu-dataframe/gpu-data-frame.ts +35 -2
- package/src/gpu-dataframe/gpu-expression-shader.ts +172 -58
- package/src/gpu-dataframe/gpu-expression.ts +62 -9
- package/src/gpu-dataframe/gpu-global-aggregation-compiler.ts +6 -2
- package/src/gpu-dataframe/gpu-global-aggregation-query.ts +12 -3
- package/src/gpu-dataframe/gpu-global-sort-compiler.ts +151 -93
- package/src/gpu-dataframe/gpu-group-aggregation-compiler.ts +469 -52
- package/src/gpu-dataframe/gpu-group-by-query.ts +24 -10
- package/src/gpu-dataframe/gpu-join-compiler.ts +12 -6
- package/src/gpu-dataframe/gpu-query-compiler.ts +60 -18
- package/src/gpu-dataframe/index.ts +1 -1
- package/src/gpu-physics/gpu-physics-batch.ts +19 -13
- package/src/gpu-physics/gpu-physics-ensemble.ts +20 -4
- package/src/gpu-physics/gpu-rigid-body-world.ts +421 -93
- package/src/gpu-physics/index.ts +9 -0
- package/src/gpu-physics/rigid-body-cache-shaders.ts +18 -6
- package/src/gpu-physics/rigid-body-capacity.ts +25 -4
- package/src/gpu-physics/rigid-body-cast-index.ts +277 -0
- package/src/gpu-physics/rigid-body-ensemble-layout.ts +6 -2
- package/src/gpu-physics/rigid-body-ensemble-reset.ts +21 -9
- package/src/gpu-physics/rigid-body-ensemble-shaders.ts +18 -7
- package/src/gpu-physics/rigid-body-ensemble-transaction.ts +31 -13
- package/src/gpu-physics/rigid-body-event-compaction.ts +252 -0
- package/src/gpu-physics/rigid-body-event-snapshot.ts +76 -0
- package/src/gpu-physics/rigid-body-events.ts +63 -25
- package/src/gpu-physics/rigid-body-joints.ts +9 -11
- package/src/gpu-physics/rigid-body-queries.ts +202 -14
- package/src/gpu-physics/rigid-body-shaders.ts +4 -3
- package/src/gpu-physics/rigid-body-triggers.ts +64 -20
- package/src/gpu-physics/sphere-world-shaders.ts +53 -21
- package/src/gpu-project/projection-program.ts +1 -9
- package/src/gpu-sql/gpu-sql.ts +405 -91
- package/src/gpu-sql/index.ts +1 -1
- package/src/utils/float32.ts +16 -0
|
@@ -6,14 +6,32 @@
|
|
|
6
6
|
import {Buffer, type Device} from '@luma.gl/core';
|
|
7
7
|
import {GPUData, GPUVector} from '@luma.gl/graph/gpu-data';
|
|
8
8
|
import {GPURecordBatch, GPUTable, type GPUField, type GPUTypeMap} from '@luma.gl/graph/gpu-tables';
|
|
9
|
-
import {
|
|
10
|
-
|
|
9
|
+
import {
|
|
10
|
+
GraphVectorView,
|
|
11
|
+
type GPUCommandGraph,
|
|
12
|
+
type GraphDataView,
|
|
13
|
+
type GraphBufferUse
|
|
14
|
+
} from '@luma.gl/graph/gpu-core';
|
|
15
|
+
import {
|
|
16
|
+
GPUGroupAggregation,
|
|
17
|
+
GPUGather,
|
|
18
|
+
GPUReduction,
|
|
19
|
+
GPUScan,
|
|
20
|
+
GPUSort,
|
|
21
|
+
createTransientView
|
|
22
|
+
} from '@luma.gl/graph/gpu-core';
|
|
11
23
|
import {GPUMask} from '@luma.gl/graph/gpu-core';
|
|
12
|
-
import {
|
|
24
|
+
import {
|
|
25
|
+
createTransientVectorView,
|
|
26
|
+
getViewElementOffset,
|
|
27
|
+
validatePackedUint32View
|
|
28
|
+
} from '@luma.gl/graph/gpu-core';
|
|
13
29
|
import {
|
|
14
30
|
LU_ANALYTICS_WORKGROUP_SIZE,
|
|
31
|
+
type GPUAnalyticsScalarFormat,
|
|
15
32
|
addGPUAnalyticsComputePass,
|
|
16
33
|
getGPUAnalyticsInvocationIndexSource,
|
|
34
|
+
getGPUAnalyticsSelectionMask,
|
|
17
35
|
validateGPUAnalyticsOutputLength
|
|
18
36
|
} from './gpu-analytics-compiler-utils';
|
|
19
37
|
import type {GPUDataFrame, GPUDataFrameDictionaries, GPUDataFrameValidity} from './gpu-data-frame';
|
|
@@ -42,7 +60,7 @@ type GPUGroupedMetricState = {
|
|
|
42
60
|
export class CompiledGPUDataFrameGroupedAggregation<
|
|
43
61
|
T extends GPUTypeMap = GPUTypeMap
|
|
44
62
|
> extends CompiledGPUDataFrameQuery<T> {
|
|
45
|
-
/**
|
|
63
|
+
/** Result table capacity. Observed grouping publishes the actual count in selectedCounts. */
|
|
46
64
|
readonly groupCount: number;
|
|
47
65
|
|
|
48
66
|
/** @internal */
|
|
@@ -52,6 +70,45 @@ export class CompiledGPUDataFrameGroupedAggregation<
|
|
|
52
70
|
}
|
|
53
71
|
}
|
|
54
72
|
|
|
73
|
+
/** Output names and order for grouped SQL projections. @internal */
|
|
74
|
+
export type GPUGroupedOutputProjection = Readonly<{
|
|
75
|
+
/** Name of the grouped key in the output schema. */
|
|
76
|
+
key: string;
|
|
77
|
+
/** Output names in SELECT order. */
|
|
78
|
+
columns: readonly string[];
|
|
79
|
+
}>;
|
|
80
|
+
|
|
81
|
+
/** Ordered source keys and their corresponding output fields. */
|
|
82
|
+
type GPUGroupingKeys = readonly Readonly<{source: string; output?: string}>[];
|
|
83
|
+
|
|
84
|
+
/** Adds observed numeric and composite grouping bounded by the source row count. @internal */
|
|
85
|
+
export function compileGPUDataFrameObservedAggregation(
|
|
86
|
+
source: GPUDataFrame,
|
|
87
|
+
predicates: readonly GPUExpression<boolean, string>[],
|
|
88
|
+
selectedColumns: readonly string[],
|
|
89
|
+
derivedColumns: readonly GPUDataFrameDerivedColumn[],
|
|
90
|
+
keys: GPUGroupingKeys,
|
|
91
|
+
definitions: readonly GPUDataFrameAggregationDefinition[],
|
|
92
|
+
graph: GPUCommandGraph<GPUDataFrameQueryParameters>,
|
|
93
|
+
columns: readonly string[]
|
|
94
|
+
): CompiledGPUDataFrameGroupedAggregation {
|
|
95
|
+
if (source.numRows > 0) validateGPUGroupingCapacity(source, source.numRows, graph);
|
|
96
|
+
validateGPUGroupingSourceColumns(
|
|
97
|
+
source,
|
|
98
|
+
keys.map(key => key.source),
|
|
99
|
+
definitions
|
|
100
|
+
);
|
|
101
|
+
return compileGPUDataFrameQuery<
|
|
102
|
+
GPUTypeMap,
|
|
103
|
+
GPUTypeMap,
|
|
104
|
+
GPUTypeMap,
|
|
105
|
+
CompiledGPUDataFrameGroupedAggregation
|
|
106
|
+
>(source, predicates, selectedColumns, graph, derivedColumns, {
|
|
107
|
+
prepare: context =>
|
|
108
|
+
addGPUGroupedAggregationToGraph(context, keys, source.numRows, definitions, columns, true)
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
55
112
|
/** Adds dense categorical aggregation to source-row work before the shared graph is frozen. */
|
|
56
113
|
export function compileGPUDataFrameGroupedAggregation<
|
|
57
114
|
Source extends GPUTypeMap,
|
|
@@ -65,10 +122,11 @@ export function compileGPUDataFrameGroupedAggregation<
|
|
|
65
122
|
key: keyof Selection & string,
|
|
66
123
|
groupCount: number,
|
|
67
124
|
definitions: readonly GPUDataFrameAggregationDefinition[],
|
|
68
|
-
graph: GPUCommandGraph<GPUDataFrameQueryParameters
|
|
125
|
+
graph: GPUCommandGraph<GPUDataFrameQueryParameters>,
|
|
126
|
+
projection?: GPUGroupedOutputProjection
|
|
69
127
|
): CompiledGPUDataFrameGroupedAggregation<Result> {
|
|
70
128
|
validateGPUGroupingCapacity(source, groupCount, graph);
|
|
71
|
-
validateGPUGroupingSourceColumns(source, key, definitions);
|
|
129
|
+
validateGPUGroupingSourceColumns(source, [key], definitions);
|
|
72
130
|
return compileGPUDataFrameQuery<
|
|
73
131
|
Source,
|
|
74
132
|
Selection,
|
|
@@ -76,19 +134,27 @@ export function compileGPUDataFrameGroupedAggregation<
|
|
|
76
134
|
CompiledGPUDataFrameGroupedAggregation<Result>
|
|
77
135
|
>(source, predicates, selectedColumns, graph, derivedColumns, {
|
|
78
136
|
prepare: context =>
|
|
79
|
-
addGPUGroupedAggregationToGraph<Selection, Result>(
|
|
137
|
+
addGPUGroupedAggregationToGraph<Selection, Result>(
|
|
138
|
+
context,
|
|
139
|
+
[{source: key, output: projection?.key ?? key}],
|
|
140
|
+
groupCount,
|
|
141
|
+
definitions,
|
|
142
|
+
projection?.columns
|
|
143
|
+
)
|
|
80
144
|
});
|
|
81
145
|
}
|
|
82
146
|
|
|
83
147
|
/** Rejects unsupported constants and explicitly unknown source nullability before GPU allocation. */
|
|
84
148
|
function validateGPUGroupingSourceColumns<Source extends GPUTypeMap>(
|
|
85
149
|
source: GPUDataFrame<Source>,
|
|
86
|
-
|
|
150
|
+
keys: readonly string[],
|
|
87
151
|
definitions: readonly GPUDataFrameAggregationDefinition[]
|
|
88
152
|
): void {
|
|
89
153
|
const columnNames = new Set([
|
|
90
|
-
|
|
91
|
-
...definitions.flatMap(definition =>
|
|
154
|
+
...keys,
|
|
155
|
+
...definitions.flatMap(definition =>
|
|
156
|
+
definition.operation !== 'count' && definition.column ? [definition.column] : []
|
|
157
|
+
)
|
|
92
158
|
]);
|
|
93
159
|
for (const name of columnNames) {
|
|
94
160
|
if (source.table.gpuConstants[name]) {
|
|
@@ -126,9 +192,11 @@ function validateGPUGroupingCapacity<Source extends GPUTypeMap>(
|
|
|
126
192
|
/** Creates grouped buffers, null-aware masks, and one cross-batch primitive per requested metric. */
|
|
127
193
|
function addGPUGroupedAggregationToGraph<Selection extends GPUTypeMap, Result extends GPUTypeMap>(
|
|
128
194
|
context: GPUDataFrameQueryExtensionContext<Selection>,
|
|
129
|
-
|
|
195
|
+
groupingKeys: GPUGroupingKeys,
|
|
130
196
|
groupCount: number,
|
|
131
|
-
definitions: readonly GPUDataFrameAggregationDefinition[]
|
|
197
|
+
definitions: readonly GPUDataFrameAggregationDefinition[],
|
|
198
|
+
columns?: readonly string[],
|
|
199
|
+
observed = false
|
|
132
200
|
): GPUDataFrameQueryExtensionResult<Result, CompiledGPUDataFrameGroupedAggregation<Result>> {
|
|
133
201
|
const graph = context.graph;
|
|
134
202
|
const prefix = `${context.queryId}-group`;
|
|
@@ -136,30 +204,88 @@ function addGPUGroupedAggregationToGraph<Selection extends GPUTypeMap, Result ex
|
|
|
136
204
|
let resultTable: GPUTable<Result> | undefined;
|
|
137
205
|
|
|
138
206
|
try {
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
207
|
+
const inputs = groupingKeys.map(({source}, index) =>
|
|
208
|
+
graph.importGPUVector(
|
|
209
|
+
`${prefix}-key-${index}`,
|
|
210
|
+
getGPUGroupingVector(
|
|
211
|
+
context,
|
|
212
|
+
source,
|
|
213
|
+
observed ? getGPUGroupingFormat(context.table, source) : 'uint32'
|
|
214
|
+
)
|
|
215
|
+
)
|
|
216
|
+
);
|
|
217
|
+
const outputVectors = new Map<string, GPUVector<GPUAnalyticsScalarFormat>>();
|
|
218
|
+
const outputs = groupingKeys.map(({output}, index) => {
|
|
219
|
+
if (output === undefined) return undefined;
|
|
220
|
+
const vector = createGPUGroupedOutputVector(
|
|
221
|
+
graph.device,
|
|
222
|
+
`${prefix}-output-key-${index}`,
|
|
223
|
+
groupCount,
|
|
224
|
+
inputs[index].format
|
|
225
|
+
);
|
|
226
|
+
ownedVectors.push(vector);
|
|
227
|
+
outputVectors.set(output, vector);
|
|
228
|
+
return graph.importGPUVector(`${prefix}-output-key-view-${index}`, vector).data[0];
|
|
229
|
+
});
|
|
230
|
+
const keyValidity = observed
|
|
231
|
+
? undefined
|
|
232
|
+
: getGPUGroupingValidity(context, groupingKeys[0].source, inputs[0]);
|
|
142
233
|
const baseMask = keyValidity
|
|
143
234
|
? combineGPUGroupingMasks(graph, `${prefix}-key-validity`, context.selectionMask, keyValidity)
|
|
144
235
|
: context.selectionMask;
|
|
145
|
-
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
236
|
+
const validity: Record<string, GPUVector<'uint32'>> = {};
|
|
237
|
+
const nullableKeys = observed
|
|
238
|
+
? groupingKeys.map(({source, output}, index) => {
|
|
239
|
+
const field = context.table.schema.fields.find(field => field.name === source);
|
|
240
|
+
if (!field?.nullable) return undefined;
|
|
241
|
+
const input = getGPUGroupingValidity(context, source, inputs[index]);
|
|
242
|
+
if (output === undefined) return {input};
|
|
243
|
+
const mask = createGPUGroupedOutputVector(
|
|
244
|
+
graph.device,
|
|
245
|
+
prefix + '-key-mask-' + index,
|
|
246
|
+
groupCount,
|
|
247
|
+
'uint32'
|
|
248
|
+
);
|
|
249
|
+
ownedVectors.push(mask);
|
|
250
|
+
validity[output] = mask;
|
|
251
|
+
return {
|
|
252
|
+
input,
|
|
253
|
+
output: graph.importGPUVector(prefix + '-key-mask-view-' + index, mask).data[0]
|
|
254
|
+
};
|
|
255
|
+
})
|
|
256
|
+
: [];
|
|
257
|
+
const rowSelection = observed
|
|
258
|
+
? addGPUObservedGroups(context, prefix, inputs, outputs, nullableKeys, ownedVectors)
|
|
259
|
+
: undefined;
|
|
260
|
+
const keys = rowSelection?.keys ?? (inputs[0] as GraphVectorView<'uint32'>);
|
|
261
|
+
if (!observed)
|
|
262
|
+
addGPUGroupIdentityPass(
|
|
263
|
+
graph,
|
|
264
|
+
`${prefix}-output-key-identity`,
|
|
265
|
+
outputs[0] as GraphDataView<'uint32'>
|
|
266
|
+
);
|
|
157
267
|
|
|
158
268
|
const metricStates = new Map<string, GPUGroupedMetricState>();
|
|
159
|
-
const validity: Record<string, GPUVector<'uint32'>> = {};
|
|
160
269
|
|
|
161
270
|
for (const [definitionIndex, definition] of definitions.entries()) {
|
|
162
271
|
const metricId = `${prefix}-metric-${definitionIndex}`;
|
|
272
|
+
if (groupCount === 0) {
|
|
273
|
+
const format = definition.operation === 'count' ? 'uint32' : 'float32';
|
|
274
|
+
const output = createGPUGroupedOutputVector(graph.device, metricId, 0, format);
|
|
275
|
+
ownedVectors.push(output);
|
|
276
|
+
outputVectors.set(definition.name, output as GPUVector<'uint32'> | GPUVector<'float32'>);
|
|
277
|
+
if (definition.operation !== 'count') {
|
|
278
|
+
const mask = createGPUGroupedOutputVector(
|
|
279
|
+
graph.device,
|
|
280
|
+
`${metricId}-validity`,
|
|
281
|
+
0,
|
|
282
|
+
'uint32'
|
|
283
|
+
);
|
|
284
|
+
ownedVectors.push(mask);
|
|
285
|
+
validity[definition.name] = mask;
|
|
286
|
+
}
|
|
287
|
+
continue;
|
|
288
|
+
}
|
|
163
289
|
if (definition.operation === 'count') {
|
|
164
290
|
const output = createGPUGroupedOutputVector(graph.device, metricId, groupCount, 'uint32');
|
|
165
291
|
ownedVectors.push(output);
|
|
@@ -168,7 +294,9 @@ function addGPUGroupedAggregationToGraph<Selection extends GPUTypeMap, Result ex
|
|
|
168
294
|
new GPUGroupAggregation({
|
|
169
295
|
id: metricId,
|
|
170
296
|
keys,
|
|
171
|
-
mask:
|
|
297
|
+
mask: definition.column
|
|
298
|
+
? getGPUAnalyticsSelectionMask(context, definition.column, metricId, baseMask)
|
|
299
|
+
: baseMask,
|
|
172
300
|
output: graph.importGPUVector(`${metricId}-output`, output).data[0],
|
|
173
301
|
operation: 'count'
|
|
174
302
|
})
|
|
@@ -212,14 +340,21 @@ function addGPUGroupedAggregationToGraph<Selection extends GPUTypeMap, Result ex
|
|
|
212
340
|
|
|
213
341
|
resultTable = createGPUGroupedResultTable<Selection, Result>(
|
|
214
342
|
context.table,
|
|
215
|
-
|
|
343
|
+
groupingKeys,
|
|
216
344
|
definitions,
|
|
217
|
-
outputVectors
|
|
345
|
+
outputVectors,
|
|
346
|
+
columns,
|
|
347
|
+
observed
|
|
218
348
|
);
|
|
219
|
-
const
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
349
|
+
const dictionaries = Object.freeze(
|
|
350
|
+
Object.fromEntries(
|
|
351
|
+
groupingKeys.flatMap(({source, output}) => {
|
|
352
|
+
if (output === undefined) return [];
|
|
353
|
+
const dictionary = context.dictionaries[source as keyof Selection & string];
|
|
354
|
+
return dictionary ? [[output, dictionary]] : [];
|
|
355
|
+
})
|
|
356
|
+
)
|
|
357
|
+
) as Readonly<GPUDataFrameDictionaries<Result>>;
|
|
223
358
|
|
|
224
359
|
return {
|
|
225
360
|
table: resultTable,
|
|
@@ -227,7 +362,29 @@ function addGPUGroupedAggregationToGraph<Selection extends GPUTypeMap, Result ex
|
|
|
227
362
|
dictionaries,
|
|
228
363
|
ownedTables: [resultTable],
|
|
229
364
|
ownedVectors,
|
|
230
|
-
createCompiled: props =>
|
|
365
|
+
createCompiled: props =>
|
|
366
|
+
new CompiledGPUDataFrameGroupedAggregation(
|
|
367
|
+
rowSelection
|
|
368
|
+
? {
|
|
369
|
+
...props,
|
|
370
|
+
rowIndices: rowSelection.rows,
|
|
371
|
+
selectedCounts: rowSelection.count,
|
|
372
|
+
selectionMask: rowSelection.mask,
|
|
373
|
+
ownedVectors: [
|
|
374
|
+
...(props.ownedVectors ?? []).filter(
|
|
375
|
+
vector =>
|
|
376
|
+
vector !== rowSelection.rows &&
|
|
377
|
+
vector !== rowSelection.mask &&
|
|
378
|
+
vector !== rowSelection.count
|
|
379
|
+
),
|
|
380
|
+
props.rowIndices,
|
|
381
|
+
props.selectedCounts,
|
|
382
|
+
props.selectionMask
|
|
383
|
+
]
|
|
384
|
+
}
|
|
385
|
+
: props,
|
|
386
|
+
groupCount
|
|
387
|
+
)
|
|
231
388
|
};
|
|
232
389
|
} catch (error) {
|
|
233
390
|
resultTable?.destroy();
|
|
@@ -238,8 +395,260 @@ function addGPUGroupedAggregationToGraph<Selection extends GPUTypeMap, Result ex
|
|
|
238
395
|
}
|
|
239
396
|
}
|
|
240
397
|
|
|
241
|
-
/**
|
|
242
|
-
function
|
|
398
|
+
/** Groups observed rows by stable sorts of each value and its separate validity class. */
|
|
399
|
+
function addGPUObservedGroups(
|
|
400
|
+
context: Pick<GPUDataFrameQueryExtensionContext<GPUTypeMap>, 'graph' | 'selectionMask'>,
|
|
401
|
+
prefix: string,
|
|
402
|
+
inputs: readonly GraphVectorView<GPUAnalyticsScalarFormat>[],
|
|
403
|
+
outputs: readonly (GraphDataView<GPUAnalyticsScalarFormat> | undefined)[],
|
|
404
|
+
nullableKeys: readonly (
|
|
405
|
+
| {input?: GraphVectorView<'uint32'>; output?: GraphDataView<'uint32'>}
|
|
406
|
+
| undefined
|
|
407
|
+
)[],
|
|
408
|
+
ownedVectors: GPUVector[]
|
|
409
|
+
): {
|
|
410
|
+
keys: GraphVectorView<'uint32'>;
|
|
411
|
+
rows: GPUVector<'uint32'>;
|
|
412
|
+
count: GPUVector<'uint32'>;
|
|
413
|
+
mask: GPUVector<'uint32'>;
|
|
414
|
+
} {
|
|
415
|
+
const {graph, selectionMask} = context;
|
|
416
|
+
const length = selectionMask.length;
|
|
417
|
+
const allocate = (name: string, size: number) => {
|
|
418
|
+
const vector = createGPUGroupedOutputVector(graph.device, prefix + name, size, 'uint32');
|
|
419
|
+
ownedVectors.push(vector);
|
|
420
|
+
return vector;
|
|
421
|
+
};
|
|
422
|
+
const rows = allocate('-result-rows', length);
|
|
423
|
+
const mask = allocate('-result-mask', length);
|
|
424
|
+
const count = allocate('-result-count', 1);
|
|
425
|
+
const countView = graph.importGPUVector(prefix + '-count-view', count).data[0];
|
|
426
|
+
if (length === 0) {
|
|
427
|
+
addGPUGroupingPass(graph, prefix + '-empty', 1, {}, {count: countView}, 'count[0] = 0u;');
|
|
428
|
+
return {keys: selectionMask, rows, count, mask};
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
const words = (view: GraphDataView<GPUAnalyticsScalarFormat>) => {
|
|
432
|
+
const packed = graph.createDataView(view.buffer, {
|
|
433
|
+
format: 'uint32',
|
|
434
|
+
length: view.length,
|
|
435
|
+
byteOffset: view.byteOffset,
|
|
436
|
+
byteStride: view.byteStride
|
|
437
|
+
});
|
|
438
|
+
validatePackedUint32View(packed, prefix + '-key');
|
|
439
|
+
return packed;
|
|
440
|
+
};
|
|
441
|
+
const scratch = (name: string) => createTransientView(graph, prefix + name, 'uint32', length);
|
|
442
|
+
const staged = inputs.map((input, index) => ({
|
|
443
|
+
input,
|
|
444
|
+
values: scratch('-values-' + index),
|
|
445
|
+
classes: scratch('-classes-' + index)
|
|
446
|
+
}));
|
|
447
|
+
const orders = [scratch('-order-a'), scratch('-order-b')];
|
|
448
|
+
const gathered = scratch('-gathered');
|
|
449
|
+
const sortedValues = scratch('-sorted-values');
|
|
450
|
+
const heads = scratch('-heads');
|
|
451
|
+
const ranks = scratch('-ranks');
|
|
452
|
+
const groupIds = scratch('-group-ids');
|
|
453
|
+
|
|
454
|
+
let offset = 0;
|
|
455
|
+
for (const [batchIndex, selection] of selectionMask.data.entries()) {
|
|
456
|
+
if (selection.length > 0) {
|
|
457
|
+
for (const [index, {input, values, classes}] of staged.entries()) {
|
|
458
|
+
const validity = nullableKeys[index]?.input?.data[batchIndex];
|
|
459
|
+
addGPUGroupingPass(
|
|
460
|
+
graph,
|
|
461
|
+
prefix + '-stage-' + batchIndex + '-' + index,
|
|
462
|
+
selection.length,
|
|
463
|
+
{
|
|
464
|
+
input: words(input.data[batchIndex]),
|
|
465
|
+
...(index === 0 ? {selection} : {}),
|
|
466
|
+
...(validity ? {validity} : {})
|
|
467
|
+
},
|
|
468
|
+
{values, classes, ...(index === 0 ? {ordinals: orders[0]} : {})},
|
|
469
|
+
`
|
|
470
|
+
let row = ${offset}u + index;
|
|
471
|
+
let raw = input[index];
|
|
472
|
+
let valid = ${validity ? 'validity[index] != 0u' : 'true'};
|
|
473
|
+
let category = ${index === 0 ? 'select(2u, u32(!valid), selection[index] != 0u)' : 'u32(!valid)'};
|
|
474
|
+
${
|
|
475
|
+
input.format === 'float32'
|
|
476
|
+
? `
|
|
477
|
+
let magnitude = raw & 0x7fffffffu;
|
|
478
|
+
let canonical = select(select(raw, 0u, magnitude == 0u), 0x7fc00000u, magnitude > 0x7f800000u);
|
|
479
|
+
`
|
|
480
|
+
: 'let canonical = raw;'
|
|
481
|
+
}
|
|
482
|
+
values[row] = select(0u, canonical, valid);
|
|
483
|
+
classes[row] = category;
|
|
484
|
+
${index === 0 ? 'ordinals[row] = row;' : ''}
|
|
485
|
+
`
|
|
486
|
+
);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
offset += selection.length;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
let orderIndex = 0;
|
|
493
|
+
for (let index = staged.length - 1; index >= 0; index--) {
|
|
494
|
+
const {values, classes} = staged[index];
|
|
495
|
+
const sortKeys = index === 0 || nullableKeys[index] ? [values, classes] : [values];
|
|
496
|
+
for (const [passIndex, source] of sortKeys.entries()) {
|
|
497
|
+
const id = prefix + '-order-' + index + '-' + passIndex;
|
|
498
|
+
graph.add(
|
|
499
|
+
new GPUGather({id: id + '-gather', source, indices: orders[orderIndex], output: gathered})
|
|
500
|
+
);
|
|
501
|
+
graph.add(
|
|
502
|
+
new GPUSort({
|
|
503
|
+
id,
|
|
504
|
+
keys: gathered,
|
|
505
|
+
values: orders[orderIndex],
|
|
506
|
+
outputKeys: sortedValues,
|
|
507
|
+
outputValues: orders[1 - orderIndex]
|
|
508
|
+
})
|
|
509
|
+
);
|
|
510
|
+
orderIndex = 1 - orderIndex;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
const order = orders[orderIndex];
|
|
514
|
+
const first = staged[0];
|
|
515
|
+
for (const [index, {values, classes}] of staged.entries()) {
|
|
516
|
+
const firstKey = index === 0;
|
|
517
|
+
addGPUGroupingPass(
|
|
518
|
+
graph,
|
|
519
|
+
prefix + '-heads-' + index,
|
|
520
|
+
length,
|
|
521
|
+
{order, values, classes, ...(firstKey ? {} : {firstClasses: first.classes})},
|
|
522
|
+
{heads},
|
|
523
|
+
`
|
|
524
|
+
let row = order[index];
|
|
525
|
+
let previous = order[max(index, 1u) - 1u];
|
|
526
|
+
let changed = classes[row] != classes[previous] || values[row] != values[previous];
|
|
527
|
+
let selected = ${firstKey ? 'classes' : 'firstClasses'}[row] != 2u;
|
|
528
|
+
heads[index] = u32(selected && (${firstKey ? 'index == 0u' : 'heads[index] != 0u'} || changed));
|
|
529
|
+
`
|
|
530
|
+
);
|
|
531
|
+
}
|
|
532
|
+
graph.add(
|
|
533
|
+
new GPUScan({id: prefix + '-scan-heads', input: heads, output: ranks, mode: 'inclusive'})
|
|
534
|
+
);
|
|
535
|
+
graph.add(
|
|
536
|
+
new GPUReduction({
|
|
537
|
+
id: prefix + '-count-heads',
|
|
538
|
+
input: heads,
|
|
539
|
+
output: countView,
|
|
540
|
+
operation: 'sum'
|
|
541
|
+
})
|
|
542
|
+
);
|
|
543
|
+
addGPUGroupingPass(
|
|
544
|
+
graph,
|
|
545
|
+
prefix + '-scatter-ids',
|
|
546
|
+
length,
|
|
547
|
+
{order, classes: first.classes, ranks},
|
|
548
|
+
{groupIds},
|
|
549
|
+
`
|
|
550
|
+
let row = order[index];
|
|
551
|
+
groupIds[row] = select(0u, ranks[index] - 1u, classes[row] != 2u);
|
|
552
|
+
`
|
|
553
|
+
);
|
|
554
|
+
for (const [index, {values, classes}] of staged.entries()) {
|
|
555
|
+
const output = outputs[index];
|
|
556
|
+
if (!output) continue;
|
|
557
|
+
const validity = nullableKeys[index]?.output;
|
|
558
|
+
addGPUGroupingPass(
|
|
559
|
+
graph,
|
|
560
|
+
prefix + '-publish-key-' + index,
|
|
561
|
+
length,
|
|
562
|
+
{order, heads, ranks, values, ...(validity ? {classes} : {})},
|
|
563
|
+
{output: words(output), ...(validity ? {validity} : {})},
|
|
564
|
+
`
|
|
565
|
+
if (heads[index] != 0u) {
|
|
566
|
+
let row = order[index];
|
|
567
|
+
let group = ranks[index] - 1u;
|
|
568
|
+
output[group] = values[row];
|
|
569
|
+
${validity ? 'validity[group] = u32(classes[row] == 0u);' : ''}
|
|
570
|
+
}
|
|
571
|
+
`
|
|
572
|
+
);
|
|
573
|
+
}
|
|
574
|
+
addGPUGroupingPass(
|
|
575
|
+
graph,
|
|
576
|
+
prefix + '-result-selection',
|
|
577
|
+
length,
|
|
578
|
+
{count: countView},
|
|
579
|
+
{
|
|
580
|
+
rows: graph.importGPUVector(prefix + '-rows-view', rows).data[0],
|
|
581
|
+
mask: graph.importGPUVector(prefix + '-mask-view', mask).data[0]
|
|
582
|
+
},
|
|
583
|
+
'rows[index] = index; mask[index] = u32(index < count[0]);'
|
|
584
|
+
);
|
|
585
|
+
|
|
586
|
+
let byteOffset = 0;
|
|
587
|
+
const data = selectionMask.data.map(chunk => {
|
|
588
|
+
const view = graph.createDataView(groupIds.buffer, {
|
|
589
|
+
format: 'uint32',
|
|
590
|
+
length: chunk.length,
|
|
591
|
+
byteOffset
|
|
592
|
+
});
|
|
593
|
+
byteOffset += chunk.length * UINT32_BYTE_LENGTH;
|
|
594
|
+
return view;
|
|
595
|
+
});
|
|
596
|
+
const keys = new GraphVectorView({...selectionMask, id: prefix + '-ids', data});
|
|
597
|
+
return {keys, rows, count, mask};
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
/** Binds packed uint32 views and accounts for source chunk offsets in grouping shaders. */
|
|
601
|
+
function addGPUGroupingPass(
|
|
602
|
+
graph: GPUCommandGraph<GPUDataFrameQueryParameters>,
|
|
603
|
+
id: string,
|
|
604
|
+
length: number,
|
|
605
|
+
reads: Record<string, GraphDataView<'uint32'>>,
|
|
606
|
+
writes: Record<string, GraphDataView<'uint32'>>,
|
|
607
|
+
body: string
|
|
608
|
+
): void {
|
|
609
|
+
const bindings = {...reads, ...writes};
|
|
610
|
+
const resources: GraphBufferUse[] = [];
|
|
611
|
+
const declarations = Object.entries(bindings).map(([name, view], binding) => {
|
|
612
|
+
const write = Object.hasOwn(writes, name);
|
|
613
|
+
resources.push({buffer: view, usage: write ? 'storage-write' : 'storage-read'});
|
|
614
|
+
body = body.replaceAll(name + '[', name + '[' + getViewElementOffset(view) + 'u + ');
|
|
615
|
+
return `@group(0) @binding(${binding}) var<storage, ${write ? 'read_write' : 'read'}> ${name}: array<u32>;`;
|
|
616
|
+
});
|
|
617
|
+
addGPUAnalyticsComputePass(graph, {
|
|
618
|
+
id,
|
|
619
|
+
bindings,
|
|
620
|
+
resources,
|
|
621
|
+
length,
|
|
622
|
+
source: /* wgsl */ `
|
|
623
|
+
${declarations.join('\n')}
|
|
624
|
+
@compute @workgroup_size(${LU_ANALYTICS_WORKGROUP_SIZE})
|
|
625
|
+
fn main(@builtin(local_invocation_index) localInvocationIndex: u32,
|
|
626
|
+
@builtin(workgroup_id) workgroupId: vec3<u32>) {
|
|
627
|
+
${getGPUAnalyticsInvocationIndexSource(graph, length)}
|
|
628
|
+
if (index >= ${length}u) { return; }
|
|
629
|
+
${body}
|
|
630
|
+
}
|
|
631
|
+
`
|
|
632
|
+
});
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
/** Resolves the scalar storage format of an observed key. */
|
|
636
|
+
function getGPUGroupingFormat<T extends GPUTypeMap>(
|
|
637
|
+
table: GPUTable<T>,
|
|
638
|
+
name: string
|
|
639
|
+
): GPUAnalyticsScalarFormat {
|
|
640
|
+
const format = table.schema.fields.find(field => field.name === name)?.format;
|
|
641
|
+
if (format !== 'uint32' && format !== 'sint32' && format !== 'float32') {
|
|
642
|
+
throw new Error('GPUDataFrame grouping requires 32-bit numeric keys');
|
|
643
|
+
}
|
|
644
|
+
return format;
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
/** Resolves one batch-aligned grouped input, including empty sources. */
|
|
648
|
+
function getGPUGroupingVector<
|
|
649
|
+
Selection extends GPUTypeMap,
|
|
650
|
+
Format extends GPUAnalyticsScalarFormat
|
|
651
|
+
>(
|
|
243
652
|
context: GPUDataFrameQueryExtensionContext<Selection>,
|
|
244
653
|
name: string,
|
|
245
654
|
format: Format
|
|
@@ -340,7 +749,7 @@ function createGPUGroupedMetricState<Selection extends GPUTypeMap>(
|
|
|
340
749
|
}
|
|
341
750
|
|
|
342
751
|
/** Creates one owned dense, renderer-compatible result vector with one physical GPU chunk. */
|
|
343
|
-
function createGPUGroupedOutputVector<Format extends
|
|
752
|
+
function createGPUGroupedOutputVector<Format extends GPUAnalyticsScalarFormat>(
|
|
344
753
|
device: Device,
|
|
345
754
|
name: string,
|
|
346
755
|
length: number,
|
|
@@ -363,21 +772,26 @@ function createGPUGroupedOutputVector<Format extends 'uint32' | 'float32'>(
|
|
|
363
772
|
/** Produces one explicit dense categorical batch with independently borrowed output wrappers. */
|
|
364
773
|
function createGPUGroupedResultTable<Source extends GPUTypeMap, Result extends GPUTypeMap>(
|
|
365
774
|
source: GPUTable<Source>,
|
|
366
|
-
|
|
775
|
+
keys: GPUGroupingKeys,
|
|
367
776
|
definitions: readonly GPUDataFrameAggregationDefinition[],
|
|
368
|
-
vectors: ReadonlyMap<string, GPUVector<
|
|
777
|
+
vectors: ReadonlyMap<string, GPUVector<GPUAnalyticsScalarFormat>>,
|
|
778
|
+
columns?: readonly string[],
|
|
779
|
+
observed = false
|
|
369
780
|
): GPUTable<Result> {
|
|
370
|
-
const
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
781
|
+
const outputFields: GPUField[] = [
|
|
782
|
+
...keys.flatMap(({source: name, output}) => {
|
|
783
|
+
if (output === undefined) return [];
|
|
784
|
+
const field = source.schema.fields.find(candidate => candidate.name === name);
|
|
785
|
+
if (!field) throw new Error('GPUDataFrame grouped result requires an existing key field');
|
|
786
|
+
return [
|
|
787
|
+
{
|
|
788
|
+
name: output,
|
|
789
|
+
format: observed ? getGPUGroupingFormat(source, name) : 'uint32',
|
|
790
|
+
nullable: observed && field.nullable === true,
|
|
791
|
+
metadata: new Map(field.metadata)
|
|
792
|
+
}
|
|
793
|
+
];
|
|
794
|
+
}),
|
|
381
795
|
...definitions.map(definition => ({
|
|
382
796
|
name: definition.name,
|
|
383
797
|
format: definition.operation === 'count' ? ('uint32' as const) : ('float32' as const),
|
|
@@ -385,6 +799,9 @@ function createGPUGroupedResultTable<Source extends GPUTypeMap, Result extends G
|
|
|
385
799
|
metadata: new Map<string, string>()
|
|
386
800
|
}))
|
|
387
801
|
];
|
|
802
|
+
const fields = columns
|
|
803
|
+
? columns.map(name => outputFields.find(field => field.name === name)!)
|
|
804
|
+
: outputFields;
|
|
388
805
|
const gpuData: Record<string, GPUData> = {};
|
|
389
806
|
for (const field of fields) {
|
|
390
807
|
const sourceData = vectors.get(field.name)?.data[0];
|