@luma.gl/graph 10.0.0-alpha.12 → 10.0.0-alpha.14
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/LICENSE +4 -4
- package/THIRD-PARTY-NOTICES.md +19 -0
- package/dist/arrow/arrow-colors.cjs +99 -18
- package/dist/arrow/arrow-colors.d.ts +27 -10
- package/dist/arrow/arrow-colors.d.ts.map +1 -1
- package/dist/arrow/arrow-colors.js +107 -24
- package/dist/arrow/arrow-colors.js.map +1 -1
- package/dist/arrow/gpu/arrow-gpu-vector-adapters.cjs +8 -6
- package/dist/arrow/gpu/arrow-gpu-vector-adapters.d.ts +1 -0
- package/dist/arrow/gpu/arrow-gpu-vector-adapters.d.ts.map +1 -1
- package/dist/arrow/gpu/arrow-gpu-vector-adapters.js +17 -7
- package/dist/arrow/gpu/arrow-gpu-vector-adapters.js.map +1 -1
- package/dist/arrow/gpu/arrow-gpu-vector-conversion.cjs +35 -5
- package/dist/arrow/gpu/arrow-gpu-vector-conversion.d.ts +6 -1
- package/dist/arrow/gpu/arrow-gpu-vector-conversion.d.ts.map +1 -1
- package/dist/arrow/gpu/arrow-gpu-vector-conversion.js +40 -5
- package/dist/arrow/gpu/arrow-gpu-vector-conversion.js.map +1 -1
- package/dist/arrow/index.cjs.map +3 -3
- package/dist/arrow/internal.cjs.map +2 -2
- package/dist/dist.dev.js +1506 -163
- package/dist/dist.min.js +401 -105
- package/dist/gpu-core/gpu-expression-operation.cjs +1 -1
- package/dist/gpu-core/gpu-expression-operation.d.ts +1 -1
- package/dist/gpu-core/gpu-expression-operation.d.ts.map +1 -1
- package/dist/gpu-core/gpu-expression-operation.js +1 -1
- package/dist/gpu-core/gpu-expression-operation.js.map +1 -1
- package/dist/gpu-core/gpu-graph-compiler.cjs +48 -0
- package/dist/gpu-core/gpu-graph-compiler.d.ts +1 -0
- package/dist/gpu-core/gpu-graph-compiler.d.ts.map +1 -1
- package/dist/gpu-core/gpu-graph-compiler.js +50 -0
- package/dist/gpu-core/gpu-graph-compiler.js.map +1 -1
- package/dist/gpu-core/gpu-group-aggregation.cjs +7 -15
- package/dist/gpu-core/gpu-group-aggregation.d.ts.map +1 -1
- package/dist/gpu-core/gpu-group-aggregation.js +7 -18
- package/dist/gpu-core/gpu-group-aggregation.js.map +1 -1
- package/dist/gpu-core/gpu-reduction.cjs +6 -14
- package/dist/gpu-core/gpu-reduction.d.ts.map +1 -1
- package/dist/gpu-core/gpu-reduction.js +6 -15
- package/dist/gpu-core/gpu-reduction.js.map +1 -1
- package/dist/gpu-core/gpu-semantic-aggregation-operation.cjs +112 -0
- package/dist/gpu-core/gpu-semantic-aggregation-operation.d.ts +71 -0
- package/dist/gpu-core/gpu-semantic-aggregation-operation.d.ts.map +1 -0
- package/dist/gpu-core/gpu-semantic-aggregation-operation.js +92 -0
- package/dist/gpu-core/gpu-semantic-aggregation-operation.js.map +1 -0
- package/dist/gpu-core/index.cjs +5 -0
- package/dist/gpu-core/index.cjs.map +3 -3
- package/dist/gpu-core/index.d.ts +2 -0
- package/dist/gpu-core/index.d.ts.map +1 -1
- package/dist/gpu-core/index.js +1 -0
- package/dist/gpu-core/index.js.map +1 -1
- package/dist/gpu-data/color-conversion.cjs +105 -0
- package/dist/gpu-data/color-conversion.d.ts +30 -0
- package/dist/gpu-data/color-conversion.d.ts.map +1 -0
- package/dist/gpu-data/color-conversion.js +109 -0
- package/dist/gpu-data/color-conversion.js.map +1 -0
- package/dist/gpu-data/cpu-gpu-vector-transfer.cjs +7 -2
- package/dist/gpu-data/cpu-gpu-vector-transfer.d.ts.map +1 -1
- package/dist/gpu-data/cpu-gpu-vector-transfer.js +9 -6
- package/dist/gpu-data/cpu-gpu-vector-transfer.js.map +1 -1
- package/dist/gpu-data/gpu-data-buffer-props.cjs +41 -0
- package/dist/gpu-data/gpu-data-buffer-props.d.ts +5 -0
- package/dist/gpu-data/gpu-data-buffer-props.d.ts.map +1 -0
- package/dist/gpu-data/gpu-data-buffer-props.js +19 -0
- package/dist/gpu-data/gpu-data-buffer-props.js.map +1 -0
- package/dist/gpu-data/index.cjs +7 -2
- package/dist/gpu-data/index.cjs.map +3 -3
- package/dist/gpu-data/index.d.ts +2 -0
- package/dist/gpu-data/index.d.ts.map +1 -1
- package/dist/gpu-data/index.js +1 -0
- package/dist/gpu-data/index.js.map +1 -1
- package/dist/gpu-graph/index.cjs +5 -0
- package/dist/gpu-graph/index.cjs.map +3 -3
- package/dist/gpu-graph/index.d.ts +2 -0
- package/dist/gpu-graph/index.d.ts.map +1 -1
- package/dist/gpu-graph/index.js +1 -0
- package/dist/gpu-graph/index.js.map +1 -1
- package/dist/gpu-graph-algorithms/benchmarks.cjs.map +1 -1
- package/dist/gpu-graph-algorithms/index.cjs.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/graph.cjs.map +3 -3
- package/dist/gpu-project/index.cjs.map +2 -2
- package/dist/gpu-simple-graph/index.cjs.map +3 -3
- package/dist/gpu-simple-graph/index.d.ts +1 -1
- package/dist/gpu-simple-graph/index.d.ts.map +1 -1
- package/dist/gpu-simple-graph/index.js.map +1 -1
- package/dist/gpu-simple-graph/operation/gpu-data-evaluator.cjs +2 -0
- package/dist/gpu-simple-graph/operation/gpu-data-evaluator.js +3 -0
- package/dist/gpu-simple-graph/operation/gpu-data-evaluator.js.map +1 -1
- package/dist/gpu-simple-graph/operations/convert-colors.cjs +6 -6
- package/dist/gpu-simple-graph/operations/convert-colors.d.ts +5 -1
- package/dist/gpu-simple-graph/operations/convert-colors.d.ts.map +1 -1
- package/dist/gpu-simple-graph/operations/convert-colors.js +12 -7
- package/dist/gpu-simple-graph/operations/convert-colors.js.map +1 -1
- package/dist/gpu-simple-graph/operations/cpu/convert-colors.cjs +16 -33
- package/dist/gpu-simple-graph/operations/cpu/convert-colors.d.ts.map +1 -1
- package/dist/gpu-simple-graph/operations/cpu/convert-colors.js +22 -35
- package/dist/gpu-simple-graph/operations/cpu/convert-colors.js.map +1 -1
- package/dist/gpu-simple-graph/operations/cpu/index.cjs.map +3 -3
- package/dist/gpu-simple-graph/operations/webgl/index.cjs.map +3 -3
- package/dist/gpu-simple-graph/operations/webgpu/convert-colors.cjs +31 -13
- package/dist/gpu-simple-graph/operations/webgpu/convert-colors.d.ts.map +1 -1
- package/dist/gpu-simple-graph/operations/webgpu/convert-colors.js +42 -13
- package/dist/gpu-simple-graph/operations/webgpu/convert-colors.js.map +1 -1
- package/dist/gpu-simple-graph/operations/webgpu/index.cjs.map +1 -1
- package/dist/gpu-sql/gpu-sql.cjs +112 -100
- package/dist/gpu-sql/gpu-sql.d.ts +1 -1
- package/dist/gpu-sql/gpu-sql.d.ts.map +1 -1
- package/dist/gpu-sql/gpu-sql.js +120 -102
- package/dist/gpu-sql/gpu-sql.js.map +1 -1
- package/dist/gpu-sql/index.cjs.map +2 -2
- package/dist/gpu-tables/index.cjs.map +2 -2
- package/dist/gpu-tables/table/gpu-table.cjs +2 -2
- package/dist/gpu-tables/table/gpu-table.d.ts.map +1 -1
- package/dist/gpu-tables/table/gpu-table.js +2 -2
- package/dist/gpu-tables/table/gpu-table.js.map +1 -1
- package/dist/index.cjs +5 -0
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +11 -8
- package/src/arrow/arrow-colors.ts +194 -33
- package/src/arrow/gpu/arrow-gpu-vector-adapters.ts +20 -7
- package/src/arrow/gpu/arrow-gpu-vector-conversion.ts +49 -6
- package/src/gpu-core/gpu-expression-operation.ts +1 -1
- package/src/gpu-core/gpu-graph-compiler.ts +61 -0
- package/src/gpu-core/gpu-group-aggregation.ts +38 -50
- package/src/gpu-core/gpu-reduction.ts +32 -42
- package/src/gpu-core/gpu-semantic-aggregation-operation.ts +150 -0
- package/src/gpu-core/index.ts +6 -0
- package/src/gpu-data/color-conversion.ts +158 -0
- package/src/gpu-data/cpu-gpu-vector-transfer.ts +10 -7
- package/src/gpu-data/gpu-data-buffer-props.ts +25 -0
- package/src/gpu-data/index.ts +3 -0
- package/src/gpu-graph/index.ts +9 -0
- package/src/gpu-simple-graph/index.ts +1 -0
- package/src/gpu-simple-graph/operation/gpu-data-evaluator.ts +2 -0
- package/src/gpu-simple-graph/operations/convert-colors.ts +22 -7
- package/src/gpu-simple-graph/operations/cpu/convert-colors.ts +31 -48
- package/src/gpu-simple-graph/operations/webgpu/convert-colors.ts +47 -13
- package/src/gpu-sql/gpu-sql.ts +130 -103
- package/src/gpu-tables/table/gpu-table.ts +2 -1
- package/src/index.ts +9 -0
package/src/gpu-graph/index.ts
CHANGED
|
@@ -82,3 +82,12 @@ export type {
|
|
|
82
82
|
GPUCPUVector,
|
|
83
83
|
GPUCPUResult
|
|
84
84
|
} from '../gpu-core/gpu-cpu-operation';
|
|
85
|
+
|
|
86
|
+
export {
|
|
87
|
+
GPUGraphGroupAggregation,
|
|
88
|
+
GPUGraphReduction
|
|
89
|
+
} from '../gpu-core/gpu-semantic-aggregation-operation';
|
|
90
|
+
export type {
|
|
91
|
+
GPUGraphGroupAggregationProps,
|
|
92
|
+
GPUGraphReductionProps
|
|
93
|
+
} from '../gpu-core/gpu-semantic-aggregation-operation';
|
|
@@ -929,6 +929,8 @@ function getVertexFormat(
|
|
|
929
929
|
if (size < 1 || size > 4) {
|
|
930
930
|
throw new Error(`Cannot synthesize a GPUVector vertex format with ${size} components`);
|
|
931
931
|
}
|
|
932
|
+
// Binary16 RGB has no vertex format; retain byte-identical packed storage for compute readers.
|
|
933
|
+
if (type === 'float16' && size === 3 && !normalized) return 'uint16x3-webgl';
|
|
932
934
|
let baseFormat: string = type;
|
|
933
935
|
if (normalized) {
|
|
934
936
|
switch (type) {
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
type GPUDataEvaluatorInput
|
|
9
9
|
} from '../operation/gpu-data-evaluator';
|
|
10
10
|
import {Operation} from '../operation/operation';
|
|
11
|
+
import type {ColorOutputFormat} from '../../gpu-data/color-conversion';
|
|
11
12
|
|
|
12
13
|
export type ColorInputFormat =
|
|
13
14
|
| 'uint8x3'
|
|
@@ -17,13 +18,17 @@ export type ColorInputFormat =
|
|
|
17
18
|
| 'float32x3'
|
|
18
19
|
| 'float32x4';
|
|
19
20
|
|
|
21
|
+
export type {ColorOutputFormat} from '../../gpu-data/color-conversion';
|
|
22
|
+
|
|
20
23
|
export type ConvertColorsProps = {
|
|
24
|
+
format?: ColorOutputFormat;
|
|
21
25
|
inputFormat?: ColorInputFormat;
|
|
22
26
|
};
|
|
23
27
|
|
|
24
28
|
export type ConvertColorsInputs = {
|
|
25
29
|
source: GPUDataEvaluator;
|
|
26
30
|
inputFormat: ColorInputFormat;
|
|
31
|
+
outputFormat: ColorOutputFormat;
|
|
27
32
|
};
|
|
28
33
|
|
|
29
34
|
class ConvertColorsOperation extends Operation<ConvertColorsInputs> {
|
|
@@ -31,15 +36,24 @@ class ConvertColorsOperation extends Operation<ConvertColorsInputs> {
|
|
|
31
36
|
|
|
32
37
|
output: GPUDataEvaluator;
|
|
33
38
|
|
|
34
|
-
constructor(
|
|
35
|
-
|
|
39
|
+
constructor(
|
|
40
|
+
source: GPUDataEvaluator,
|
|
41
|
+
inputFormat: ColorInputFormat,
|
|
42
|
+
outputFormat: ColorOutputFormat
|
|
43
|
+
) {
|
|
44
|
+
super({source, inputFormat, outputFormat});
|
|
36
45
|
|
|
37
46
|
this.output = new GPUDataEvaluator({
|
|
38
47
|
id: `convertColors(${source})`,
|
|
39
|
-
type:
|
|
48
|
+
type:
|
|
49
|
+
outputFormat === 'unorm8x4'
|
|
50
|
+
? 'uint8'
|
|
51
|
+
: outputFormat === 'float16x4'
|
|
52
|
+
? 'float16'
|
|
53
|
+
: 'float32',
|
|
40
54
|
size: 4,
|
|
41
|
-
normalized:
|
|
42
|
-
format:
|
|
55
|
+
normalized: outputFormat === 'unorm8x4',
|
|
56
|
+
format: outputFormat,
|
|
43
57
|
length: source.length,
|
|
44
58
|
source: this
|
|
45
59
|
});
|
|
@@ -50,14 +64,15 @@ class ConvertColorsOperation extends Operation<ConvertColorsInputs> {
|
|
|
50
64
|
}
|
|
51
65
|
}
|
|
52
66
|
|
|
53
|
-
/** Converts one fixed-width
|
|
67
|
+
/** Converts one fixed-width color range to RGBA8, binary16 or binary32 RGBA storage. */
|
|
54
68
|
export function convertColorData(
|
|
55
69
|
source: GPUDataEvaluatorInput,
|
|
56
70
|
props: ConvertColorsProps = {}
|
|
57
71
|
): GPUDataEvaluator {
|
|
58
72
|
const sourceEvaluator = getGPUDataEvaluator(source);
|
|
59
73
|
const inputFormat = props.inputFormat ?? getColorInputFormat(sourceEvaluator);
|
|
60
|
-
return new ConvertColorsOperation(sourceEvaluator, inputFormat)
|
|
74
|
+
return new ConvertColorsOperation(sourceEvaluator, inputFormat, props.format ?? 'unorm8x4')
|
|
75
|
+
.output;
|
|
61
76
|
}
|
|
62
77
|
|
|
63
78
|
function getColorInputFormat(source: GPUDataEvaluator): ColorInputFormat {
|
|
@@ -2,55 +2,38 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
5
|
+
import {CPUData} from '../../../gpu-data/cpu-data';
|
|
6
|
+
import {convertCPUColorData} from '../../../gpu-data/color-conversion';
|
|
7
7
|
import type {OperationHandler} from '../../operation/operation';
|
|
8
8
|
import type {ConvertColorsInputs} from '../convert-colors';
|
|
9
9
|
|
|
10
|
-
export const convertColors: OperationHandler<ConvertColorsInputs> = async ({
|
|
11
|
-
inputs
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
10
|
+
export const convertColors: OperationHandler<ConvertColorsInputs> = async ({inputs, target}) => {
|
|
11
|
+
const {source, inputFormat, outputFormat} = inputs;
|
|
12
|
+
const values = await source.ensureCPUValue();
|
|
13
|
+
const format =
|
|
14
|
+
source.format ??
|
|
15
|
+
(inputFormat === 'uint8x3'
|
|
16
|
+
? 'uint8x3-webgl'
|
|
17
|
+
: inputFormat === 'float16x3'
|
|
18
|
+
? 'uint16x3-webgl'
|
|
19
|
+
: inputFormat);
|
|
20
|
+
const converted = convertCPUColorData(
|
|
21
|
+
new CPUData({
|
|
22
|
+
buffer: values,
|
|
23
|
+
format,
|
|
24
|
+
length: source.length,
|
|
25
|
+
byteOffset: source.offset,
|
|
26
|
+
byteStride: source.stride
|
|
27
|
+
}),
|
|
28
|
+
outputFormat,
|
|
29
|
+
inputFormat
|
|
30
|
+
);
|
|
31
|
+
const bytes = new Uint8Array(
|
|
32
|
+
converted.buffer,
|
|
33
|
+
converted.byteOffset,
|
|
34
|
+
converted.length * converted.byteStride
|
|
35
|
+
);
|
|
36
|
+
target.write(bytes);
|
|
37
|
+
// Let the evaluator decode the target in its own Float16Array/Uint16Array representation.
|
|
38
|
+
return {success: true};
|
|
35
39
|
};
|
|
36
|
-
|
|
37
|
-
function convertColorChannel(values: TypedArray, index: number, inputFormat: string): number {
|
|
38
|
-
if (inputFormat.startsWith('uint8')) {
|
|
39
|
-
return values[index];
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const value = inputFormat.startsWith('float16') ? getFloat16Value(values, index) : values[index];
|
|
43
|
-
return Math.round(Math.min(Math.max(value, 0), 1) * 255);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function getFloat16Value(values: TypedArray, index: number): number {
|
|
47
|
-
const Float16ArrayConstructor = getNativeFloat16ArrayConstructor();
|
|
48
|
-
if (Float16ArrayConstructor && values.constructor === Float16ArrayConstructor) {
|
|
49
|
-
return values[index];
|
|
50
|
-
}
|
|
51
|
-
return fromHalfFloat(values[index]);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function getNativeFloat16ArrayConstructor(): unknown {
|
|
55
|
-
return (globalThis as typeof globalThis & {Float16Array?: unknown}).Float16Array;
|
|
56
|
-
}
|
|
@@ -13,11 +13,19 @@ const COMPUTATION_RUNS = 'Computation Runs';
|
|
|
13
13
|
export const convertColors: OperationHandler<ConvertColorsInputs> = async ({
|
|
14
14
|
inputs,
|
|
15
15
|
output,
|
|
16
|
-
target
|
|
16
|
+
target,
|
|
17
|
+
scope
|
|
17
18
|
}) => {
|
|
18
19
|
const {source, inputFormat} = inputs;
|
|
20
|
+
if (output.length === 0) return {success: true};
|
|
19
21
|
const kernel = new Kernel(target.device, {
|
|
20
|
-
source: getConvertColorsWGSL(
|
|
22
|
+
source: getConvertColorsWGSL(
|
|
23
|
+
inputFormat,
|
|
24
|
+
source.offset,
|
|
25
|
+
source.stride,
|
|
26
|
+
output.length,
|
|
27
|
+
inputs.outputFormat
|
|
28
|
+
),
|
|
21
29
|
shaderLayout: {
|
|
22
30
|
bindings: [
|
|
23
31
|
{name: 'source', type: 'storage' as const, group: 0, location: 0},
|
|
@@ -31,23 +39,38 @@ export const convertColors: OperationHandler<ConvertColorsInputs> = async ({
|
|
|
31
39
|
result: target
|
|
32
40
|
};
|
|
33
41
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
42
|
+
if (scope) scope.retain(() => kernel.destroy());
|
|
43
|
+
try {
|
|
44
|
+
const computePass = scope
|
|
45
|
+
? scope.commandEncoder.beginComputePass({})
|
|
46
|
+
: target.device.beginComputePass({});
|
|
47
|
+
try {
|
|
48
|
+
target.device.statsManager
|
|
49
|
+
.getStats(GPGPU_OPERATION_STATS)
|
|
50
|
+
.get(COMPUTATION_RUNS)
|
|
51
|
+
.incrementCount();
|
|
52
|
+
kernel.dispatch(computePass, {
|
|
53
|
+
bindings: kernelBindings,
|
|
54
|
+
x: Math.ceil(output.length / WORKGROUP_SIZE)
|
|
55
|
+
});
|
|
56
|
+
} finally {
|
|
57
|
+
computePass.end();
|
|
58
|
+
}
|
|
59
|
+
if (!scope) target.device.submit();
|
|
60
|
+
} finally {
|
|
61
|
+
if (!scope) kernel.destroy();
|
|
62
|
+
}
|
|
63
|
+
|
|
43
64
|
return {success: true};
|
|
44
65
|
};
|
|
66
|
+
convertColors.supportsEvaluationScope = true;
|
|
45
67
|
|
|
46
68
|
function getConvertColorsWGSL(
|
|
47
69
|
inputFormat: ConvertColorsInputs['inputFormat'],
|
|
48
70
|
byteOffset: number,
|
|
49
71
|
byteStride: number,
|
|
50
|
-
length: number
|
|
72
|
+
length: number,
|
|
73
|
+
outputFormat: ConvertColorsInputs['outputFormat']
|
|
51
74
|
): string {
|
|
52
75
|
return /* wgsl */ `\
|
|
53
76
|
@group(0) @binding(0) var<storage, read> source: array<u32>;
|
|
@@ -90,7 +113,18 @@ ${getReadColorWGSL(inputFormat)}
|
|
|
90
113
|
return;
|
|
91
114
|
}
|
|
92
115
|
|
|
93
|
-
|
|
116
|
+
let color = readColor(rowIndex);
|
|
117
|
+
${
|
|
118
|
+
outputFormat === 'unorm8x4'
|
|
119
|
+
? ' result[rowIndex] = pack4x8unorm(color);'
|
|
120
|
+
: outputFormat === 'float16x4'
|
|
121
|
+
? ` result[rowIndex * 2u] = pack2x16float(color.xy);
|
|
122
|
+
result[rowIndex * 2u + 1u] = pack2x16float(color.zw);`
|
|
123
|
+
: ` result[rowIndex * 4u] = bitcast<u32>(color.x);
|
|
124
|
+
result[rowIndex * 4u + 1u] = bitcast<u32>(color.y);
|
|
125
|
+
result[rowIndex * 4u + 2u] = bitcast<u32>(color.z);
|
|
126
|
+
result[rowIndex * 4u + 3u] = bitcast<u32>(color.w);`
|
|
127
|
+
}
|
|
94
128
|
}
|
|
95
129
|
`;
|
|
96
130
|
}
|
package/src/gpu-sql/gpu-sql.ts
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
4
|
// SPDX-FileComment: Independently implemented for WebGPU; inspired by relational SQL semantics.
|
|
5
5
|
|
|
6
|
+
import {parseSQLExpression} from '@math.gl/expressions/sql';
|
|
7
|
+
import type {Expression} from '@math.gl/expressions';
|
|
6
8
|
import type {GPUCommandGraph} from '@luma.gl/graph/gpu-core';
|
|
7
9
|
import {GPUDataFrame} from '../gpu-dataframe/gpu-data-frame';
|
|
8
10
|
import {GPUDataFrameQuery} from '../gpu-dataframe/gpu-data-frame-query';
|
|
@@ -21,7 +23,6 @@ import type {
|
|
|
21
23
|
|
|
22
24
|
const MAXIMUM_SQL_LENGTH = 65_536;
|
|
23
25
|
const MAXIMUM_SQL_TOKENS = 4_096;
|
|
24
|
-
const MAXIMUM_EXPRESSION_DEPTH = 64;
|
|
25
26
|
|
|
26
27
|
/** Explicit GPU dataframe registrations; Arrow remains exclusively an adapter boundary. */
|
|
27
28
|
export type GPUSQLTables = Readonly<Record<string, GPUDataFrame>>;
|
|
@@ -97,7 +98,7 @@ type GPUSQLDynamicQuery = GPUSQLCompiledPlan & {
|
|
|
97
98
|
};
|
|
98
99
|
|
|
99
100
|
/**
|
|
100
|
-
*
|
|
101
|
+
* SQL frontend over explicitly registered, already GPU-resident dataframes.
|
|
101
102
|
*
|
|
102
103
|
* Parsing and planning never upload data, submit work, or read GPU buffers. Arrow upload/output
|
|
103
104
|
* remain explicit `@luma.gl/graph/arrow` operations around the shared GPU table execution core.
|
|
@@ -245,15 +246,14 @@ function buildGPUSQLPlan(
|
|
|
245
246
|
}
|
|
246
247
|
|
|
247
248
|
if (statement.orderBy) {
|
|
248
|
-
const
|
|
249
|
-
|
|
250
|
-
resolve(statement.orderBy.column);
|
|
249
|
+
const {column: requested, direction, nulls} = statement.orderBy;
|
|
250
|
+
const orderColumn = selected.includes(requested) ? requested : resolve(requested);
|
|
251
251
|
if (!selected.includes(orderColumn)) {
|
|
252
252
|
throw new Error('GPUSQL ORDER BY requires the sort column in the SELECT projection');
|
|
253
253
|
}
|
|
254
254
|
const sort = query.select(selected).sortByGlobal(orderColumn, {
|
|
255
|
-
direction
|
|
256
|
-
...(
|
|
255
|
+
direction,
|
|
256
|
+
...(nulls ? {nulls} : {})
|
|
257
257
|
});
|
|
258
258
|
return statement.limit === undefined ? sort : sort.topK(statement.limit);
|
|
259
259
|
}
|
|
@@ -285,9 +285,8 @@ function resolveGPUSQLColumn(name: string, qualifier: string, columns: readonly
|
|
|
285
285
|
throw new Error(`GPUSQL column "${name}" has an unknown table qualifier`);
|
|
286
286
|
}
|
|
287
287
|
const requested = parts[parts.length - 1];
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
return matches[0];
|
|
288
|
+
if (!columns.includes(requested)) throw new Error(`GPUSQL column "${name}" does not exist`);
|
|
289
|
+
return requested;
|
|
291
290
|
}
|
|
292
291
|
|
|
293
292
|
function resolveGPUSQLExpression(
|
|
@@ -330,7 +329,7 @@ class GPUSQLParser {
|
|
|
330
329
|
const table = this.parseIdentifier();
|
|
331
330
|
const alias = this.parseOptionalTableAlias();
|
|
332
331
|
const join = this.parseOptionalJoin();
|
|
333
|
-
const predicate = this.takeKeyword('WHERE') ? this.parseExpression(
|
|
332
|
+
const predicate = this.takeKeyword('WHERE') ? this.parseExpression() : undefined;
|
|
334
333
|
let groupBy: string | undefined;
|
|
335
334
|
if (this.takeKeyword('GROUP')) {
|
|
336
335
|
this.expectKeyword('BY');
|
|
@@ -402,7 +401,7 @@ class GPUSQLParser {
|
|
|
402
401
|
...(this.takeKeyword('AS') ? {alias: this.parseIdentifier()} : {})
|
|
403
402
|
};
|
|
404
403
|
}
|
|
405
|
-
const expression = this.parseExpression(
|
|
404
|
+
const expression = this.parseExpression();
|
|
406
405
|
return {
|
|
407
406
|
...(expression ? {expression} : {}),
|
|
408
407
|
...(this.takeKeyword('AS') ? {alias: this.parseIdentifier()} : {})
|
|
@@ -434,67 +433,50 @@ class GPUSQLParser {
|
|
|
434
433
|
return {type, table, ...(alias ? {alias} : {}), left, right};
|
|
435
434
|
}
|
|
436
435
|
|
|
437
|
-
private parseExpression(
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
let
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
kind
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
436
|
+
private parseExpression(): GPUExpressionNode {
|
|
437
|
+
const tokens: string[] = [];
|
|
438
|
+
let depth = 0;
|
|
439
|
+
let expectsOperand: boolean = true;
|
|
440
|
+
for (let token = this.peek(); token; token = this.peek()) {
|
|
441
|
+
const value = token.value;
|
|
442
|
+
if (depth === 0) {
|
|
443
|
+
if (token.kind === 'symbol' && (value === ',' || value === ';')) break;
|
|
444
|
+
if (
|
|
445
|
+
token.kind === 'identifier' &&
|
|
446
|
+
!expectsOperand &&
|
|
447
|
+
/^(AS|FROM|GROUP|ORDER|LIMIT)$/i.test(value)
|
|
448
|
+
) {
|
|
449
|
+
break;
|
|
450
|
+
}
|
|
451
451
|
}
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
return expression;
|
|
477
|
-
}
|
|
478
|
-
const token = this.take();
|
|
479
|
-
if (!token) throw new Error('GPUSQL expected an expression');
|
|
480
|
-
if (token.kind === 'number') {
|
|
481
|
-
const value = Number(token.value);
|
|
482
|
-
if (!Number.isFinite(value)) throw new Error('GPUSQL numeric literals must be finite');
|
|
483
|
-
return literal(value).node;
|
|
484
|
-
}
|
|
485
|
-
if (token.kind === 'parameter') {
|
|
486
|
-
if (!Object.hasOwn(this.parameters, token.value)) {
|
|
487
|
-
throw new Error(`GPUSQL parameter ":${token.value}" requires an explicit default`);
|
|
452
|
+
switch (token.kind) {
|
|
453
|
+
case 'parameter':
|
|
454
|
+
// The shared AST leaves parameter binding to the GPU planner.
|
|
455
|
+
tokens.push(`":${value}"`);
|
|
456
|
+
expectsOperand = false;
|
|
457
|
+
break;
|
|
458
|
+
case 'identifier': {
|
|
459
|
+
const operator: boolean =
|
|
460
|
+
/^NOT$/i.test(value) || (!expectsOperand && /^(AND|OR|IS)$/i.test(value));
|
|
461
|
+
const keyword = operator || /^(NULL|TRUE|FALSE)$/i.test(value);
|
|
462
|
+
tokens.push(keyword ? value : `"${value}"`);
|
|
463
|
+
expectsOperand = operator;
|
|
464
|
+
break;
|
|
465
|
+
}
|
|
466
|
+
case 'symbol':
|
|
467
|
+
if (value === '(') depth++;
|
|
468
|
+
if (value === ')') depth--;
|
|
469
|
+
tokens.push(value);
|
|
470
|
+
expectsOperand = value !== ')';
|
|
471
|
+
break;
|
|
472
|
+
case 'number':
|
|
473
|
+
tokens.push(value);
|
|
474
|
+
expectsOperand = false;
|
|
475
|
+
break;
|
|
488
476
|
}
|
|
489
|
-
|
|
490
|
-
}
|
|
491
|
-
if (token.kind === 'identifier') {
|
|
492
|
-
if (/^NULL$/i.test(token.value)) return literal(null).node;
|
|
493
|
-
if (/^TRUE$/i.test(token.value)) return literal(true).node;
|
|
494
|
-
if (/^FALSE$/i.test(token.value)) return literal(false).node;
|
|
495
|
-
return column(token.value).node;
|
|
477
|
+
this.take();
|
|
496
478
|
}
|
|
497
|
-
|
|
479
|
+
return lowerSQLExpression(parseSQLExpression(tokens.join(' ')), this.parameters);
|
|
498
480
|
}
|
|
499
481
|
|
|
500
482
|
private parseOptionalTableAlias(): string | undefined {
|
|
@@ -570,39 +552,84 @@ function tokenizeGPUSQL(source: string): GPUSQLToken[] {
|
|
|
570
552
|
return tokens;
|
|
571
553
|
}
|
|
572
554
|
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
case '
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
555
|
+
const SQL_BINARY_OPERATORS: Readonly<
|
|
556
|
+
Partial<Record<string, Extract<GPUExpressionNode, {kind: 'binary'}>['operator']>>
|
|
557
|
+
> = {
|
|
558
|
+
'||': 'or',
|
|
559
|
+
'&&': 'and',
|
|
560
|
+
'==': 'equal',
|
|
561
|
+
'!=': 'not-equal',
|
|
562
|
+
'>': 'greater-than',
|
|
563
|
+
'>=': 'greater-than-or-equal',
|
|
564
|
+
'<': 'less-than',
|
|
565
|
+
'<=': 'less-than-or-equal',
|
|
566
|
+
'+': 'add',
|
|
567
|
+
'-': 'subtract',
|
|
568
|
+
'*': 'multiply',
|
|
569
|
+
'/': 'divide'
|
|
570
|
+
};
|
|
571
|
+
|
|
572
|
+
function lowerSQLExpression(
|
|
573
|
+
node: Extract<Expression, {type: 'BinaryExpression'}>['left'],
|
|
574
|
+
parameters: GPUDataFrameQueryParameters
|
|
575
|
+
): GPUExpressionNode {
|
|
576
|
+
// math.gl types child nodes as generic expressions, though the SQL parser emits the AST union.
|
|
577
|
+
const expression = node as Expression;
|
|
578
|
+
switch (expression.type) {
|
|
579
|
+
case 'Identifier': {
|
|
580
|
+
if (!expression.name.startsWith(':')) return column(expression.name).node;
|
|
581
|
+
const name = expression.name.slice(1);
|
|
582
|
+
if (!Object.hasOwn(parameters, name)) {
|
|
583
|
+
throw new Error(`GPUSQL parameter ":${name}" requires an explicit default`);
|
|
584
|
+
}
|
|
585
|
+
return parameter(name, parameters[name]).node;
|
|
586
|
+
}
|
|
587
|
+
case 'Literal': {
|
|
588
|
+
const value = expression.value;
|
|
589
|
+
if (
|
|
590
|
+
value === null ||
|
|
591
|
+
typeof value === 'boolean' ||
|
|
592
|
+
(typeof value === 'number' && Number.isFinite(value))
|
|
593
|
+
) {
|
|
594
|
+
return literal(value).node;
|
|
595
|
+
}
|
|
596
|
+
break;
|
|
597
|
+
}
|
|
598
|
+
case 'UnaryExpression':
|
|
599
|
+
if (expression.operator === '!' || expression.operator === '-') {
|
|
600
|
+
return {
|
|
601
|
+
kind: 'unary',
|
|
602
|
+
operator: expression.operator === '!' ? 'not' : 'negate',
|
|
603
|
+
operand: lowerSQLExpression(expression.argument, parameters)
|
|
604
|
+
};
|
|
605
|
+
}
|
|
606
|
+
break;
|
|
607
|
+
case 'BinaryExpression': {
|
|
608
|
+
const operator = SQL_BINARY_OPERATORS[expression.operator];
|
|
609
|
+
if (operator) {
|
|
610
|
+
return {
|
|
611
|
+
kind: 'binary',
|
|
612
|
+
operator,
|
|
613
|
+
left: lowerSQLExpression(expression.left, parameters),
|
|
614
|
+
right: lowerSQLExpression(expression.right, parameters)
|
|
615
|
+
};
|
|
616
|
+
}
|
|
617
|
+
break;
|
|
618
|
+
}
|
|
619
|
+
case 'CallExpression':
|
|
620
|
+
if (
|
|
621
|
+
expression.arguments.length === 1 &&
|
|
622
|
+
(expression.callee['name'] === 'isNull' || expression.callee['name'] === 'isNotNull')
|
|
623
|
+
) {
|
|
624
|
+
return {
|
|
625
|
+
kind: 'unary',
|
|
626
|
+
operator: expression.callee['name'] === 'isNull' ? 'is-null' : 'is-valid',
|
|
627
|
+
operand: lowerSQLExpression(expression.arguments[0], parameters)
|
|
628
|
+
};
|
|
629
|
+
}
|
|
630
|
+
break;
|
|
605
631
|
default:
|
|
606
|
-
|
|
632
|
+
break;
|
|
607
633
|
}
|
|
634
|
+
throw new Error(`GPUSQL does not support SQL expression "${expression.type}"`);
|
|
608
635
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
+
import {getGPUDataBufferProps} from '../../gpu-data/gpu-data-buffer-props';
|
|
5
6
|
import {Buffer, type BufferLayout, type VertexFormat} from '@luma.gl/core';
|
|
6
7
|
import {DynamicBuffer} from '@luma.gl/core/dynamic';
|
|
7
8
|
import type {GPUField, GPUSchema, GPUTypeMap} from './gpu-schema';
|
|
@@ -545,7 +546,7 @@ function createPackedGPURecordBatch(
|
|
|
545
546
|
0
|
|
546
547
|
);
|
|
547
548
|
const buffer = device.createBuffer({
|
|
548
|
-
|
|
549
|
+
...getGPUDataBufferProps(device, firstData.format === 'uint16' ? 'uint16' : 'uint32'),
|
|
549
550
|
byteLength
|
|
550
551
|
});
|
|
551
552
|
let destinationOffset = 0;
|
package/src/index.ts
CHANGED
|
@@ -216,3 +216,12 @@ export type {
|
|
|
216
216
|
GPUCPUVector,
|
|
217
217
|
GPUCPUResult
|
|
218
218
|
} from './gpu-core/gpu-cpu-operation';
|
|
219
|
+
|
|
220
|
+
export {
|
|
221
|
+
GPUGraphGroupAggregation,
|
|
222
|
+
GPUGraphReduction
|
|
223
|
+
} from './gpu-core/gpu-semantic-aggregation-operation';
|
|
224
|
+
export type {
|
|
225
|
+
GPUGraphGroupAggregationProps,
|
|
226
|
+
GPUGraphReductionProps
|
|
227
|
+
} from './gpu-core/gpu-semantic-aggregation-operation';
|