@luma.gl/graph 10.0.0-alpha.5 → 10.0.0-alpha.6
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 +38 -0
- package/README.md +7 -1
- package/dist/arrow/dggs/dggs-gpu-polygons.cjs +667 -0
- package/dist/arrow/dggs/dggs-gpu-polygons.d.ts +75 -0
- package/dist/arrow/dggs/dggs-gpu-polygons.d.ts.map +1 -0
- package/dist/arrow/dggs/dggs-gpu-polygons.js +651 -0
- package/dist/arrow/dggs/dggs-gpu-polygons.js.map +1 -0
- package/dist/arrow/geoarrow/arrow-geoarrow-adapter.cjs +411 -0
- package/dist/arrow/geoarrow/arrow-geoarrow-adapter.d.ts +31 -0
- package/dist/arrow/geoarrow/arrow-geoarrow-adapter.d.ts.map +1 -0
- package/dist/arrow/geoarrow/arrow-geoarrow-adapter.js +395 -0
- package/dist/arrow/geoarrow/arrow-geoarrow-adapter.js.map +1 -0
- package/dist/arrow/geoarrow/arrow-geoarrow-conversion.cjs +304 -0
- package/dist/arrow/geoarrow/arrow-geoarrow-conversion.d.ts +32 -0
- package/dist/arrow/geoarrow/arrow-geoarrow-conversion.d.ts.map +1 -0
- package/dist/arrow/geoarrow/arrow-geoarrow-conversion.js +293 -0
- package/dist/arrow/geoarrow/arrow-geoarrow-conversion.js.map +1 -0
- package/dist/arrow/geoarrow/arrow-polygon-tessellation.cjs +232 -0
- package/dist/arrow/geoarrow/arrow-polygon-tessellation.d.ts +54 -0
- package/dist/arrow/geoarrow/arrow-polygon-tessellation.d.ts.map +1 -0
- package/dist/arrow/geoarrow/arrow-polygon-tessellation.js +222 -0
- package/dist/arrow/geoarrow/arrow-polygon-tessellation.js.map +1 -0
- package/dist/arrow/gpu/arrow-gpu-analytics-adapters.cjs +314 -0
- package/dist/arrow/gpu/arrow-gpu-analytics-adapters.d.ts +42 -0
- package/dist/arrow/gpu/arrow-gpu-analytics-adapters.d.ts.map +1 -0
- package/dist/arrow/gpu/arrow-gpu-analytics-adapters.js +318 -0
- package/dist/arrow/gpu/arrow-gpu-analytics-adapters.js.map +1 -0
- package/dist/arrow/gpu/arrow-gpu-analytics-readback.cjs +204 -0
- package/dist/arrow/gpu/arrow-gpu-analytics-readback.d.ts +30 -0
- package/dist/arrow/gpu/arrow-gpu-analytics-readback.d.ts.map +1 -0
- package/dist/arrow/gpu/arrow-gpu-analytics-readback.js +195 -0
- package/dist/arrow/gpu/arrow-gpu-analytics-readback.js.map +1 -0
- package/dist/arrow/gpu/arrow-gpu-table-adapters.cjs +257 -0
- package/dist/arrow/gpu/arrow-gpu-table-adapters.d.ts +45 -0
- package/dist/arrow/gpu/arrow-gpu-table-adapters.d.ts.map +1 -0
- package/dist/arrow/gpu/arrow-gpu-table-adapters.js +257 -0
- package/dist/arrow/gpu/arrow-gpu-table-adapters.js.map +1 -0
- package/dist/arrow/gpu/arrow-gpu-table-conversion.cjs +230 -0
- package/dist/arrow/gpu/arrow-gpu-table-conversion.d.ts +71 -0
- package/dist/arrow/gpu/arrow-gpu-table-conversion.d.ts.map +1 -0
- package/dist/arrow/gpu/arrow-gpu-table-conversion.js +215 -0
- package/dist/arrow/gpu/arrow-gpu-table-conversion.js.map +1 -0
- package/dist/arrow/gpu/arrow-input-schema.cjs +36 -0
- package/dist/arrow/gpu/arrow-input-schema.d.ts +41 -0
- package/dist/arrow/gpu/arrow-input-schema.d.ts.map +1 -0
- package/dist/arrow/gpu/arrow-input-schema.js +17 -0
- package/dist/arrow/gpu/arrow-input-schema.js.map +1 -0
- package/dist/arrow/index.cjs +90 -0
- package/dist/arrow/index.cjs.map +6 -0
- package/dist/arrow/index.d.ts +9 -0
- package/dist/arrow/index.d.ts.map +1 -0
- package/dist/arrow/index.js +12 -0
- package/dist/arrow/index.js.map +1 -0
- package/dist/arrow/internal.cjs +30 -0
- package/dist/arrow/internal.cjs.map +6 -0
- package/dist/arrow/internal.d.ts +19 -0
- package/dist/arrow/internal.d.ts.map +1 -0
- package/dist/arrow/internal.js +7 -0
- package/dist/arrow/internal.js.map +1 -0
- package/dist/dist.dev.js +283 -12
- package/dist/dist.min.js +29 -29
- package/dist/geospatial/geospatial-utils.cjs +12 -11
- package/dist/geospatial/geospatial-utils.d.ts +1 -1
- package/dist/geospatial/geospatial-utils.d.ts.map +1 -1
- package/dist/geospatial/geospatial-utils.js +3 -2
- package/dist/geospatial/geospatial-utils.js.map +1 -1
- package/dist/geospatial/index.cjs.map +2 -2
- package/dist/gpu-a5/index.cjs.map +1 -1
- package/dist/gpu-dggs/benchmarks.cjs.map +1 -1
- package/dist/gpu-dggs/gpu-dggs-cell-projection.cjs +2 -2
- package/dist/gpu-dggs/gpu-dggs-cell-projection.js +1 -1
- package/dist/gpu-dggs/gpu-dggs-cell-projection.js.map +1 -1
- package/dist/gpu-dggs/index.cjs.map +1 -1
- package/dist/gpu-h3/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/index.cjs.map +2 -2
- package/dist/gpu-project/projection-program.cjs +2 -2
- package/dist/gpu-project/projection-program.d.ts +1 -1
- package/dist/gpu-project/projection-program.d.ts.map +1 -1
- package/dist/gpu-project/projection-program.js +1 -1
- package/dist/gpu-project/projection-program.js.map +1 -1
- package/dist/gpu-sql/lu-sql.d.ts +1 -1
- package/dist/gpu-sql/lu-sql.js +1 -1
- package/dist/gpu-tables/engine/gpu-table-shader-bindings.d.ts +1 -1
- package/dist/gpu-tables/engine/gpu-table-shader-bindings.d.ts.map +1 -1
- package/dist/gpu-vector-search/index.cjs.map +1 -1
- package/dist/utils/assemble-compute-kernel.cjs +2 -2
- package/dist/utils/assemble-compute-kernel.d.ts +2 -1
- package/dist/utils/assemble-compute-kernel.d.ts.map +1 -1
- package/dist/utils/assemble-compute-kernel.js +2 -2
- package/dist/utils/assemble-compute-kernel.js.map +1 -1
- package/package.json +19 -7
- package/src/arrow/dggs/dggs-gpu-polygons.ts +820 -0
- package/src/arrow/geoarrow/arrow-geoarrow-adapter.ts +519 -0
- package/src/arrow/geoarrow/arrow-geoarrow-conversion.ts +415 -0
- package/src/arrow/geoarrow/arrow-polygon-tessellation.ts +369 -0
- package/src/arrow/gpu/arrow-gpu-analytics-adapters.ts +474 -0
- package/src/arrow/gpu/arrow-gpu-analytics-readback.ts +294 -0
- package/src/arrow/gpu/arrow-gpu-table-adapters.ts +378 -0
- package/src/arrow/gpu/arrow-gpu-table-conversion.ts +324 -0
- package/src/arrow/gpu/arrow-input-schema.ts +98 -0
- package/src/arrow/index.ts +79 -0
- package/src/arrow/internal.ts +23 -0
- package/src/geospatial/geospatial-utils.ts +3 -7
- package/src/gpu-dggs/gpu-dggs-cell-projection.ts +1 -1
- package/src/gpu-project/projection-program.ts +1 -1
- package/src/gpu-sql/lu-sql.ts +1 -1
- package/src/gpu-tables/engine/gpu-table-shader-bindings.ts +1 -1
- package/src/utils/assemble-compute-kernel.ts +3 -7
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var arrow_gpu_analytics_adapters_exports = {};
|
|
19
|
+
__export(arrow_gpu_analytics_adapters_exports, {
|
|
20
|
+
makeGPUAnalyticsTableFromArrowTable: () => makeGPUAnalyticsTableFromArrowTable
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(arrow_gpu_analytics_adapters_exports);
|
|
23
|
+
var import_core = require("@luma.gl/core");
|
|
24
|
+
var import_gpu_data = require("@luma.gl/gpgpu/gpu-data");
|
|
25
|
+
var import_gpu_tables = require("@luma.gl/graph/gpu-tables");
|
|
26
|
+
var import_apache_arrow = require("apache-arrow");
|
|
27
|
+
var import_arrow = require("@luma.gl/gpgpu/arrow");
|
|
28
|
+
const GPU_ANALYTICS_BUFFER_USAGE = import_core.Buffer.VERTEX | import_core.Buffer.STORAGE | import_core.Buffer.COPY_DST | import_core.Buffer.COPY_SRC;
|
|
29
|
+
function makeGPUAnalyticsTableFromArrowTable(device, table, options = {}) {
|
|
30
|
+
var _a;
|
|
31
|
+
validateGPUAnalyticsBufferProps(options.bufferProps);
|
|
32
|
+
const columns = prepareGPUAnalyticsColumns(table, options.columns);
|
|
33
|
+
const requiredBufferProps = {
|
|
34
|
+
...options.bufferProps,
|
|
35
|
+
usage: (((_a = options.bufferProps) == null ? void 0 : _a.usage) ?? 0) | GPU_ANALYTICS_BUFFER_USAGE
|
|
36
|
+
};
|
|
37
|
+
const allocatedData = [];
|
|
38
|
+
const allocatedValidityData = [];
|
|
39
|
+
const validity = {};
|
|
40
|
+
const dictionaries = {};
|
|
41
|
+
const nullCounts = {};
|
|
42
|
+
let gpuTable;
|
|
43
|
+
try {
|
|
44
|
+
for (const column of columns) {
|
|
45
|
+
const columnName = column.field.name;
|
|
46
|
+
nullCounts[columnName] = Object.freeze([...column.nullCounts]);
|
|
47
|
+
if (column.dictionary) {
|
|
48
|
+
dictionaries[columnName] = column.dictionary;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
let sourceRowIndexOffset = 0;
|
|
52
|
+
const batches = table.batches.map((recordBatch, sourceBatchIndex) => {
|
|
53
|
+
const gpuData = {};
|
|
54
|
+
for (const column of columns) {
|
|
55
|
+
const sourceData = column.chunks[sourceBatchIndex];
|
|
56
|
+
const data = makeGPUAnalyticsData(device, sourceData, column.format, requiredBufferProps);
|
|
57
|
+
allocatedData.push(data);
|
|
58
|
+
gpuData[column.field.name] = data;
|
|
59
|
+
}
|
|
60
|
+
const batch = new import_gpu_tables.GPURecordBatch({
|
|
61
|
+
gpuData,
|
|
62
|
+
fields: columns.map((column) => makeGPUAnalyticsField(column)),
|
|
63
|
+
numRows: recordBatch.numRows,
|
|
64
|
+
metadata: new Map(recordBatch.schema.metadata),
|
|
65
|
+
sourceInfo: {
|
|
66
|
+
sourceBatchIndex,
|
|
67
|
+
sourceRowIndexOffset,
|
|
68
|
+
sourceRowCount: recordBatch.numRows
|
|
69
|
+
},
|
|
70
|
+
nullCount: recordBatch.nullCount
|
|
71
|
+
});
|
|
72
|
+
sourceRowIndexOffset += recordBatch.numRows;
|
|
73
|
+
return batch;
|
|
74
|
+
});
|
|
75
|
+
gpuTable = batches.length > 0 ? new import_gpu_tables.GPUTable({ batches }) : new import_gpu_tables.GPUTable({
|
|
76
|
+
schema: {
|
|
77
|
+
fields: columns.map((column) => makeGPUAnalyticsField(column)),
|
|
78
|
+
metadata: new Map(table.schema.metadata)
|
|
79
|
+
},
|
|
80
|
+
bufferLayout: columns.map((column) => ({
|
|
81
|
+
name: column.field.name,
|
|
82
|
+
format: column.format,
|
|
83
|
+
byteStride: 4
|
|
84
|
+
}))
|
|
85
|
+
});
|
|
86
|
+
if (batches.length > 0) {
|
|
87
|
+
gpuTable.schema = {
|
|
88
|
+
fields: columns.map((column) => makeGPUAnalyticsField(column)),
|
|
89
|
+
metadata: new Map(table.schema.metadata)
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
for (const column of columns) {
|
|
93
|
+
if (!column.field.nullable || batches.length === 0) {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
const chunks = column.validity.map((values) => {
|
|
97
|
+
const data = makeGPUAnalyticsValidityData(device, values, requiredBufferProps);
|
|
98
|
+
allocatedValidityData.push(data);
|
|
99
|
+
return data;
|
|
100
|
+
});
|
|
101
|
+
validity[column.field.name] = new import_gpu_data.GPUVector({
|
|
102
|
+
type: "data",
|
|
103
|
+
name: `${column.field.name}-validity`,
|
|
104
|
+
format: "uint32",
|
|
105
|
+
data: chunks,
|
|
106
|
+
ownsData: true
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
return { table: gpuTable, validity, dictionaries, nullCounts };
|
|
110
|
+
} catch (error) {
|
|
111
|
+
gpuTable == null ? void 0 : gpuTable.destroy();
|
|
112
|
+
for (const data of allocatedData) {
|
|
113
|
+
data.destroy();
|
|
114
|
+
}
|
|
115
|
+
for (const data of allocatedValidityData) {
|
|
116
|
+
data.destroy();
|
|
117
|
+
}
|
|
118
|
+
throw error;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function validateGPUAnalyticsBufferProps(bufferProps) {
|
|
122
|
+
if ((bufferProps == null ? void 0 : bufferProps.handle) !== void 0 && bufferProps.handle !== null) {
|
|
123
|
+
throw new Error("GPU analytics buffers cannot adopt an external buffer handle");
|
|
124
|
+
}
|
|
125
|
+
if (bufferProps == null ? void 0 : bufferProps._isHandleBorrowed) {
|
|
126
|
+
throw new Error("GPU analytics buffers cannot borrow an external buffer handle");
|
|
127
|
+
}
|
|
128
|
+
if (bufferProps == null ? void 0 : bufferProps.byteOffset) {
|
|
129
|
+
throw new Error("GPU analytics buffers cannot use a nonzero byte offset");
|
|
130
|
+
}
|
|
131
|
+
if ((((bufferProps == null ? void 0 : bufferProps.usage) ?? 0) & (import_core.Buffer.MAP_READ | import_core.Buffer.MAP_WRITE)) !== 0) {
|
|
132
|
+
throw new Error("GPU analytics storage buffers cannot declare mapped usage");
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function prepareGPUAnalyticsColumns(table, selectedNames) {
|
|
136
|
+
const sourceFields = /* @__PURE__ */ new Map();
|
|
137
|
+
for (const field of table.schema.fields) {
|
|
138
|
+
if (sourceFields.has(field.name)) {
|
|
139
|
+
throw new Error(`GPU analytics source contains duplicate column "${field.name}"`);
|
|
140
|
+
}
|
|
141
|
+
sourceFields.set(field.name, field);
|
|
142
|
+
}
|
|
143
|
+
const columnNames = selectedNames ?? table.schema.fields.map((field) => field.name);
|
|
144
|
+
const encounteredNames = /* @__PURE__ */ new Set();
|
|
145
|
+
return columnNames.map((columnName) => {
|
|
146
|
+
if (encounteredNames.has(columnName)) {
|
|
147
|
+
throw new Error(`GPU analytics column "${columnName}" cannot be selected more than once`);
|
|
148
|
+
}
|
|
149
|
+
encounteredNames.add(columnName);
|
|
150
|
+
const field = sourceFields.get(columnName);
|
|
151
|
+
if (!field) {
|
|
152
|
+
throw new Error(`GPU analytics column "${columnName}" does not exist`);
|
|
153
|
+
}
|
|
154
|
+
if ((0, import_gpu_tables.isGPUTableIndexColumnName)(columnName)) {
|
|
155
|
+
throw new Error(`GPU analytics column "${columnName}" is reserved for table indices`);
|
|
156
|
+
}
|
|
157
|
+
const column = {
|
|
158
|
+
field,
|
|
159
|
+
format: getGPUAnalyticsVectorFormat(field.type, columnName),
|
|
160
|
+
chunks: [],
|
|
161
|
+
validity: [],
|
|
162
|
+
nullCounts: []
|
|
163
|
+
};
|
|
164
|
+
for (const [batchIndex, batch] of table.batches.entries()) {
|
|
165
|
+
const vector = batch.getChild(columnName);
|
|
166
|
+
const data = vector == null ? void 0 : vector.data[0];
|
|
167
|
+
if (!vector || !data || vector.data.length !== 1 || data.length !== batch.numRows) {
|
|
168
|
+
throw new Error(`GPU analytics column "${columnName}" has an incompatible chunk in batch ${batchIndex}`);
|
|
169
|
+
}
|
|
170
|
+
if (getGPUAnalyticsVectorFormat(data.type, columnName) !== column.format) {
|
|
171
|
+
throw new Error(`GPU analytics column "${columnName}" changes type between batches`);
|
|
172
|
+
}
|
|
173
|
+
const validity = getGPUAnalyticsValidity(data, field.nullable, columnName);
|
|
174
|
+
if (import_apache_arrow.DataType.isDictionary(field.type)) {
|
|
175
|
+
const dictionary = getGPUAnalyticsDictionary(data, columnName);
|
|
176
|
+
if (column.dictionary && !areGPUAnalyticsDictionariesEqual(column.dictionary, dictionary)) {
|
|
177
|
+
throw new Error(`GPU analytics dictionary column "${columnName}" changes across batches`);
|
|
178
|
+
}
|
|
179
|
+
column.dictionary ??= dictionary;
|
|
180
|
+
validateGPUAnalyticsDictionaryIndices(data, dictionary, validity, columnName);
|
|
181
|
+
}
|
|
182
|
+
column.chunks.push(data);
|
|
183
|
+
column.validity.push(validity);
|
|
184
|
+
column.nullCounts.push(data.nullCount);
|
|
185
|
+
}
|
|
186
|
+
return column;
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
function getGPUAnalyticsVectorFormat(type, columnName) {
|
|
190
|
+
if (import_apache_arrow.DataType.isFloat(type) && type.precision === import_apache_arrow.Precision.SINGLE) {
|
|
191
|
+
return "float32";
|
|
192
|
+
}
|
|
193
|
+
if (import_apache_arrow.DataType.isInt(type) && type.bitWidth === 32) {
|
|
194
|
+
return type.isSigned ? "sint32" : "uint32";
|
|
195
|
+
}
|
|
196
|
+
if (import_apache_arrow.DataType.isDictionary(type) && import_apache_arrow.DataType.isUtf8(type.dictionary) && import_apache_arrow.DataType.isInt(type.indices) && type.indices.bitWidth === 32) {
|
|
197
|
+
return type.indices.isSigned ? "sint32" : "uint32";
|
|
198
|
+
}
|
|
199
|
+
throw new Error(`GPU analytics column "${columnName}" has unsupported Arrow type ${type}`);
|
|
200
|
+
}
|
|
201
|
+
function getGPUAnalyticsValidity(data, nullable, columnName) {
|
|
202
|
+
const nullCount = data.nullCount;
|
|
203
|
+
const sourceRowOffset = data.offset ?? 0;
|
|
204
|
+
if (!Number.isSafeInteger(sourceRowOffset) || sourceRowOffset < 0 || !Number.isSafeInteger(nullCount) || nullCount < 0 || nullCount > data.length) {
|
|
205
|
+
throw new Error(`GPU analytics column "${columnName}" has malformed validity metadata`);
|
|
206
|
+
}
|
|
207
|
+
if (!nullable && nullCount > 0) {
|
|
208
|
+
throw new Error(`GPU analytics non-nullable column "${columnName}" contains null values`);
|
|
209
|
+
}
|
|
210
|
+
const bitmap = data.nullBitmap;
|
|
211
|
+
if (nullCount > 0 && (!bitmap || bitmap.byteLength === 0)) {
|
|
212
|
+
throw new Error(`GPU analytics column "${columnName}" is missing its validity bitmap`);
|
|
213
|
+
}
|
|
214
|
+
if (bitmap && bitmap.byteLength > 0 && bitmap.byteLength * 8 < sourceRowOffset + data.length) {
|
|
215
|
+
throw new Error(`GPU analytics column "${columnName}" has a truncated validity bitmap`);
|
|
216
|
+
}
|
|
217
|
+
const validity = new Uint32Array(data.length);
|
|
218
|
+
let observedNullCount = 0;
|
|
219
|
+
for (let rowIndex = 0; rowIndex < data.length; rowIndex++) {
|
|
220
|
+
const sourceBitIndex = sourceRowOffset + rowIndex;
|
|
221
|
+
const valid = !bitmap || bitmap.byteLength === 0 ? true : ((bitmap[sourceBitIndex >> 3] ?? 0) & 1 << (sourceBitIndex & 7)) !== 0;
|
|
222
|
+
validity[rowIndex] = valid ? 1 : 0;
|
|
223
|
+
if (!valid) {
|
|
224
|
+
observedNullCount++;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
if (observedNullCount !== nullCount) {
|
|
228
|
+
throw new Error(`GPU analytics column "${columnName}" has inconsistent validity bitmap`);
|
|
229
|
+
}
|
|
230
|
+
return validity;
|
|
231
|
+
}
|
|
232
|
+
function getGPUAnalyticsDictionary(data, columnName) {
|
|
233
|
+
if (!(data.type instanceof import_apache_arrow.Dictionary) || !import_apache_arrow.DataType.isUtf8(data.type.dictionary)) {
|
|
234
|
+
throw new Error(`GPU analytics column "${columnName}" requires a UTF-8 dictionary`);
|
|
235
|
+
}
|
|
236
|
+
if (!data.dictionary) {
|
|
237
|
+
throw new Error(`GPU analytics dictionary column "${columnName}" has no dictionary labels`);
|
|
238
|
+
}
|
|
239
|
+
const values = [];
|
|
240
|
+
for (const value of data.dictionary) {
|
|
241
|
+
if (typeof value !== "string") {
|
|
242
|
+
throw new Error(`GPU analytics dictionary column "${columnName}" contains a null label`);
|
|
243
|
+
}
|
|
244
|
+
values.push(value);
|
|
245
|
+
}
|
|
246
|
+
return Object.freeze({ values: Object.freeze(values), ordered: data.type.isOrdered });
|
|
247
|
+
}
|
|
248
|
+
function validateGPUAnalyticsDictionaryIndices(data, dictionary, validity, columnName) {
|
|
249
|
+
const indices = data.values;
|
|
250
|
+
const sourceOffset = indices.length === data.length ? 0 : data.offset ?? 0;
|
|
251
|
+
if (sourceOffset + data.length > indices.length) {
|
|
252
|
+
throw new Error(`GPU analytics dictionary column "${columnName}" has truncated indices`);
|
|
253
|
+
}
|
|
254
|
+
for (let rowIndex = 0; rowIndex < data.length; rowIndex++) {
|
|
255
|
+
if (!validity[rowIndex]) {
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
const categoryIndex = indices[sourceOffset + rowIndex];
|
|
259
|
+
if (categoryIndex < 0 || categoryIndex >= dictionary.values.length) {
|
|
260
|
+
throw new Error(`GPU analytics dictionary column "${columnName}" has an invalid index`);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
function areGPUAnalyticsDictionariesEqual(first, second) {
|
|
265
|
+
return first.ordered === second.ordered && first.values.length === second.values.length && first.values.every((value, index) => value === second.values[index]);
|
|
266
|
+
}
|
|
267
|
+
function makeGPUAnalyticsData(device, source, format, bufferProps) {
|
|
268
|
+
if (source.length > 0) {
|
|
269
|
+
return (0, import_arrow.makeGPUDataFromArrowData)(device, source, { ...bufferProps, format });
|
|
270
|
+
}
|
|
271
|
+
const buffer = device.createBuffer({ ...bufferProps, byteLength: 4 });
|
|
272
|
+
try {
|
|
273
|
+
return new import_gpu_data.GPUData({
|
|
274
|
+
buffer,
|
|
275
|
+
format,
|
|
276
|
+
length: 0,
|
|
277
|
+
stride: 1,
|
|
278
|
+
byteStride: 4,
|
|
279
|
+
rowByteLength: 4,
|
|
280
|
+
dataType: source.type,
|
|
281
|
+
ownsBuffer: true
|
|
282
|
+
});
|
|
283
|
+
} catch (error) {
|
|
284
|
+
buffer.destroy();
|
|
285
|
+
throw error;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
function makeGPUAnalyticsValidityData(device, validity, bufferProps) {
|
|
289
|
+
const values = validity.length > 0 ? validity : new Uint32Array(1);
|
|
290
|
+
const buffer = device.createBuffer({ ...bufferProps, data: values });
|
|
291
|
+
try {
|
|
292
|
+
return new import_gpu_data.GPUData({
|
|
293
|
+
buffer,
|
|
294
|
+
format: "uint32",
|
|
295
|
+
length: validity.length,
|
|
296
|
+
ownsBuffer: true
|
|
297
|
+
});
|
|
298
|
+
} catch (error) {
|
|
299
|
+
buffer.destroy();
|
|
300
|
+
throw error;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
function makeGPUAnalyticsField(column) {
|
|
304
|
+
return {
|
|
305
|
+
name: column.field.name,
|
|
306
|
+
format: column.format,
|
|
307
|
+
nullable: column.field.nullable,
|
|
308
|
+
metadata: new Map(column.field.metadata)
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
312
|
+
0 && (module.exports = {
|
|
313
|
+
makeGPUAnalyticsTableFromArrowTable
|
|
314
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type Device } from '@luma.gl/core';
|
|
2
|
+
import { GPUVector, type GPUVectorBufferProps } from '@luma.gl/gpgpu/gpu-data';
|
|
3
|
+
import { GPUTable, type GPUTypeMap } from '@luma.gl/graph/gpu-tables';
|
|
4
|
+
import { Dictionary, type Float32, type Int32, type Table, type TypeMap, type Uint32, type Utf8 } from 'apache-arrow';
|
|
5
|
+
/** Maps a typed Arrow schema to its exact portable GPU analytics column formats. */
|
|
6
|
+
export type GPUAnalyticsTypeMapForArrow<T extends TypeMap> = {
|
|
7
|
+
[Name in keyof T & string]: T[Name] extends Float32 ? 'float32' : T[Name] extends Int32 ? 'sint32' : T[Name] extends Uint32 ? 'uint32' : T[Name] extends Dictionary<Utf8, infer IndexType> ? IndexType extends Int32 ? 'sint32' : IndexType extends Uint32 ? 'uint32' : never : never;
|
|
8
|
+
};
|
|
9
|
+
/** CPU-owned category labels associated with one GPU-resident dictionary-index column. */
|
|
10
|
+
export type GPUAnalyticsDictionary = {
|
|
11
|
+
/** Dictionary labels in the exact order referenced by uploaded integer indices. */
|
|
12
|
+
readonly values: readonly string[];
|
|
13
|
+
/** Whether the Arrow source declares these category labels ordered. */
|
|
14
|
+
readonly ordered: boolean;
|
|
15
|
+
};
|
|
16
|
+
/** Renderer-independent Arrow analytics upload options. */
|
|
17
|
+
export type GPUAnalyticsTableFromArrowTableProps<T extends GPUTypeMap = GPUTypeMap> = {
|
|
18
|
+
/** Source columns to upload, in the desired order. Defaults to all source fields. */
|
|
19
|
+
columns?: readonly (keyof T & string)[];
|
|
20
|
+
/** Additional buffer properties; required storage and copy usage are always retained. */
|
|
21
|
+
bufferProps?: GPUVectorBufferProps;
|
|
22
|
+
};
|
|
23
|
+
/** GPU table plus explicit analytical metadata retained outside generic GPU table storage. */
|
|
24
|
+
export type GPUAnalyticsTableFromArrowTableResult<T extends GPUTypeMap = GPUTypeMap> = {
|
|
25
|
+
/** Existing generic GPU table primitives, preserving every source record batch. */
|
|
26
|
+
table: GPUTable<T>;
|
|
27
|
+
/** One source-row-aligned uint32 GPU validity vector for every nullable selected field. */
|
|
28
|
+
validity: Partial<Record<keyof T & string, GPUVector<'uint32'>>>;
|
|
29
|
+
/** Explicit adapter-owned labels for selected UTF-8 dictionary columns. */
|
|
30
|
+
dictionaries: Partial<Record<keyof T & string, GPUAnalyticsDictionary>>;
|
|
31
|
+
/** Per-field Arrow null counts in source record-batch order. */
|
|
32
|
+
nullCounts: Partial<Record<keyof T & string, readonly number[]>>;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Uploads Arrow columns for GPU analytics without requiring renderer-specific shader metadata.
|
|
36
|
+
*
|
|
37
|
+
* Numeric values and dictionary indices stay in existing `GPUData`, `GPURecordBatch`, `GPUVector`,
|
|
38
|
+
* and `GPUTable` objects. Nullable rows receive separate batch-aligned uint32 validity vectors,
|
|
39
|
+
* while dictionary labels and source null counts remain explicit adapter-owned metadata.
|
|
40
|
+
*/
|
|
41
|
+
export declare function makeGPUAnalyticsTableFromArrowTable<T extends TypeMap>(device: Device, table: Table<T>, options?: GPUAnalyticsTableFromArrowTableProps<GPUAnalyticsTypeMapForArrow<T>>): GPUAnalyticsTableFromArrowTableResult<GPUAnalyticsTypeMapForArrow<T>>;
|
|
42
|
+
//# sourceMappingURL=arrow-gpu-analytics-adapters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arrow-gpu-analytics-adapters.d.ts","sourceRoot":"","sources":["../../../src/arrow/gpu/arrow-gpu-analytics-adapters.ts"],"names":[],"mappings":"AAIA,OAAO,EAAS,KAAK,MAAM,EAAC,MAAM,eAAe,CAAC;AAClD,OAAO,EAAU,SAAS,EAAE,KAAK,oBAAoB,EAAC,MAAM,yBAAyB,CAAC;AACtF,OAAO,EAEL,QAAQ,EAGR,KAAK,UAAU,EAChB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAEL,UAAU,EAIV,KAAK,OAAO,EACZ,KAAK,KAAK,EACV,KAAK,KAAK,EACV,KAAK,OAAO,EACZ,KAAK,MAAM,EACX,KAAK,IAAI,EACV,MAAM,cAAc,CAAC;AAMtB,oFAAoF;AACpF,MAAM,MAAM,2BAA2B,CAAC,CAAC,SAAS,OAAO,IAAI;KAC1D,IAAI,IAAI,MAAM,CAAC,GAAG,MAAM,GAAG,CAAC,CAAC,IAAI,CAAC,SAAS,OAAO,GAC/C,SAAS,GACT,CAAC,CAAC,IAAI,CAAC,SAAS,KAAK,GACnB,QAAQ,GACR,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,GACpB,QAAQ,GACR,CAAC,CAAC,IAAI,CAAC,SAAS,UAAU,CAAC,IAAI,EAAE,MAAM,SAAS,CAAC,GAC/C,SAAS,SAAS,KAAK,GACrB,QAAQ,GACR,SAAS,SAAS,MAAM,GACtB,QAAQ,GACR,KAAK,GACT,KAAK;CAChB,CAAC;AAEF,0FAA0F;AAC1F,MAAM,MAAM,sBAAsB,GAAG;IACnC,mFAAmF;IACnF,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,uEAAuE;IACvE,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B,CAAC;AAEF,2DAA2D;AAC3D,MAAM,MAAM,oCAAoC,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU,IAAI;IACpF,qFAAqF;IACrF,OAAO,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,EAAE,CAAC;IACxC,yFAAyF;IACzF,WAAW,CAAC,EAAE,oBAAoB,CAAC;CACpC,CAAC;AAEF,8FAA8F;AAC9F,MAAM,MAAM,qCAAqC,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU,IAAI;IACrF,mFAAmF;IACnF,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IACnB,2FAA2F;IAC3F,QAAQ,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,MAAM,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IACjE,2EAA2E;IAC3E,YAAY,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,MAAM,EAAE,sBAAsB,CAAC,CAAC,CAAC;IACxE,gEAAgE;IAChE,UAAU,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC,CAAC;CAClE,CAAC;AAeF;;;;;;GAMG;AACH,wBAAgB,mCAAmC,CAAC,CAAC,SAAS,OAAO,EACnE,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,EACf,OAAO,CAAC,EAAE,oCAAoC,CAAC,2BAA2B,CAAC,CAAC,CAAC,CAAC,GAC7E,qCAAqC,CAAC,2BAA2B,CAAC,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
import { Buffer } from '@luma.gl/core';
|
|
5
|
+
import { GPUData, GPUVector } from '@luma.gl/gpgpu/gpu-data';
|
|
6
|
+
import { GPURecordBatch, GPUTable, isGPUTableIndexColumnName } from '@luma.gl/graph/gpu-tables';
|
|
7
|
+
import { DataType, Dictionary, Precision } from 'apache-arrow';
|
|
8
|
+
import { makeGPUDataFromArrowData } from '@luma.gl/gpgpu/arrow';
|
|
9
|
+
const GPU_ANALYTICS_BUFFER_USAGE = Buffer.VERTEX | Buffer.STORAGE | Buffer.COPY_DST | Buffer.COPY_SRC;
|
|
10
|
+
export function makeGPUAnalyticsTableFromArrowTable(device, table, options = {}) {
|
|
11
|
+
validateGPUAnalyticsBufferProps(options.bufferProps);
|
|
12
|
+
const columns = prepareGPUAnalyticsColumns(table, options.columns);
|
|
13
|
+
const requiredBufferProps = {
|
|
14
|
+
...options.bufferProps,
|
|
15
|
+
usage: (options.bufferProps?.usage ?? 0) | GPU_ANALYTICS_BUFFER_USAGE
|
|
16
|
+
};
|
|
17
|
+
const allocatedData = [];
|
|
18
|
+
const allocatedValidityData = [];
|
|
19
|
+
const validity = {};
|
|
20
|
+
const dictionaries = {};
|
|
21
|
+
const nullCounts = {};
|
|
22
|
+
let gpuTable;
|
|
23
|
+
try {
|
|
24
|
+
for (const column of columns) {
|
|
25
|
+
const columnName = column.field.name;
|
|
26
|
+
nullCounts[columnName] = Object.freeze([...column.nullCounts]);
|
|
27
|
+
if (column.dictionary) {
|
|
28
|
+
dictionaries[columnName] = column.dictionary;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
let sourceRowIndexOffset = 0;
|
|
32
|
+
const batches = table.batches.map((recordBatch, sourceBatchIndex) => {
|
|
33
|
+
const gpuData = {};
|
|
34
|
+
for (const column of columns) {
|
|
35
|
+
const sourceData = column.chunks[sourceBatchIndex];
|
|
36
|
+
const data = makeGPUAnalyticsData(device, sourceData, column.format, requiredBufferProps);
|
|
37
|
+
allocatedData.push(data);
|
|
38
|
+
gpuData[column.field.name] = data;
|
|
39
|
+
}
|
|
40
|
+
const batch = new GPURecordBatch({
|
|
41
|
+
gpuData,
|
|
42
|
+
fields: columns.map(column => makeGPUAnalyticsField(column)),
|
|
43
|
+
numRows: recordBatch.numRows,
|
|
44
|
+
metadata: new Map(recordBatch.schema.metadata),
|
|
45
|
+
sourceInfo: {
|
|
46
|
+
sourceBatchIndex,
|
|
47
|
+
sourceRowIndexOffset,
|
|
48
|
+
sourceRowCount: recordBatch.numRows
|
|
49
|
+
},
|
|
50
|
+
nullCount: recordBatch.nullCount
|
|
51
|
+
});
|
|
52
|
+
sourceRowIndexOffset += recordBatch.numRows;
|
|
53
|
+
return batch;
|
|
54
|
+
});
|
|
55
|
+
gpuTable =
|
|
56
|
+
batches.length > 0
|
|
57
|
+
? new GPUTable({ batches })
|
|
58
|
+
: new GPUTable({
|
|
59
|
+
schema: {
|
|
60
|
+
fields: columns.map(column => makeGPUAnalyticsField(column)),
|
|
61
|
+
metadata: new Map(table.schema.metadata)
|
|
62
|
+
},
|
|
63
|
+
bufferLayout: columns.map(column => ({
|
|
64
|
+
name: column.field.name,
|
|
65
|
+
format: column.format,
|
|
66
|
+
byteStride: 4
|
|
67
|
+
}))
|
|
68
|
+
});
|
|
69
|
+
if (batches.length > 0) {
|
|
70
|
+
gpuTable.schema = {
|
|
71
|
+
fields: columns.map(column => makeGPUAnalyticsField(column)),
|
|
72
|
+
metadata: new Map(table.schema.metadata)
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
for (const column of columns) {
|
|
76
|
+
if (!column.field.nullable || batches.length === 0) {
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
const chunks = column.validity.map(values => {
|
|
80
|
+
const data = makeGPUAnalyticsValidityData(device, values, requiredBufferProps);
|
|
81
|
+
allocatedValidityData.push(data);
|
|
82
|
+
return data;
|
|
83
|
+
});
|
|
84
|
+
validity[column.field.name] = new GPUVector({
|
|
85
|
+
type: 'data',
|
|
86
|
+
name: `${column.field.name}-validity`,
|
|
87
|
+
format: 'uint32',
|
|
88
|
+
data: chunks,
|
|
89
|
+
ownsData: true
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
return { table: gpuTable, validity, dictionaries, nullCounts };
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
gpuTable?.destroy();
|
|
96
|
+
for (const data of allocatedData) {
|
|
97
|
+
data.destroy();
|
|
98
|
+
}
|
|
99
|
+
for (const data of allocatedValidityData) {
|
|
100
|
+
data.destroy();
|
|
101
|
+
}
|
|
102
|
+
throw error;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/** Rejects caller props that would alias owned buffers or invalidate their logical layout. */
|
|
106
|
+
function validateGPUAnalyticsBufferProps(bufferProps) {
|
|
107
|
+
if (bufferProps?.handle !== undefined && bufferProps.handle !== null) {
|
|
108
|
+
throw new Error('GPU analytics buffers cannot adopt an external buffer handle');
|
|
109
|
+
}
|
|
110
|
+
if (bufferProps?._isHandleBorrowed) {
|
|
111
|
+
throw new Error('GPU analytics buffers cannot borrow an external buffer handle');
|
|
112
|
+
}
|
|
113
|
+
if (bufferProps?.byteOffset) {
|
|
114
|
+
throw new Error('GPU analytics buffers cannot use a nonzero byte offset');
|
|
115
|
+
}
|
|
116
|
+
if (((bufferProps?.usage ?? 0) & (Buffer.MAP_READ | Buffer.MAP_WRITE)) !== 0) {
|
|
117
|
+
throw new Error('GPU analytics storage buffers cannot declare mapped usage');
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/** Validates every selected field, batch, bitmap, and dictionary before allocating GPU resources. */
|
|
121
|
+
function prepareGPUAnalyticsColumns(table, selectedNames) {
|
|
122
|
+
const sourceFields = new Map();
|
|
123
|
+
for (const field of table.schema.fields) {
|
|
124
|
+
if (sourceFields.has(field.name)) {
|
|
125
|
+
throw new Error(`GPU analytics source contains duplicate column "${field.name}"`);
|
|
126
|
+
}
|
|
127
|
+
sourceFields.set(field.name, field);
|
|
128
|
+
}
|
|
129
|
+
const columnNames = selectedNames ?? table.schema.fields.map(field => field.name);
|
|
130
|
+
const encounteredNames = new Set();
|
|
131
|
+
return columnNames.map(columnName => {
|
|
132
|
+
if (encounteredNames.has(columnName)) {
|
|
133
|
+
throw new Error(`GPU analytics column "${columnName}" cannot be selected more than once`);
|
|
134
|
+
}
|
|
135
|
+
encounteredNames.add(columnName);
|
|
136
|
+
const field = sourceFields.get(columnName);
|
|
137
|
+
if (!field) {
|
|
138
|
+
throw new Error(`GPU analytics column "${columnName}" does not exist`);
|
|
139
|
+
}
|
|
140
|
+
if (isGPUTableIndexColumnName(columnName)) {
|
|
141
|
+
throw new Error(`GPU analytics column "${columnName}" is reserved for table indices`);
|
|
142
|
+
}
|
|
143
|
+
const column = {
|
|
144
|
+
field,
|
|
145
|
+
format: getGPUAnalyticsVectorFormat(field.type, columnName),
|
|
146
|
+
chunks: [],
|
|
147
|
+
validity: [],
|
|
148
|
+
nullCounts: []
|
|
149
|
+
};
|
|
150
|
+
for (const [batchIndex, batch] of table.batches.entries()) {
|
|
151
|
+
const vector = batch.getChild(columnName);
|
|
152
|
+
const data = vector?.data[0];
|
|
153
|
+
if (!vector || !data || vector.data.length !== 1 || data.length !== batch.numRows) {
|
|
154
|
+
throw new Error(`GPU analytics column "${columnName}" has an incompatible chunk in batch ${batchIndex}`);
|
|
155
|
+
}
|
|
156
|
+
if (getGPUAnalyticsVectorFormat(data.type, columnName) !== column.format) {
|
|
157
|
+
throw new Error(`GPU analytics column "${columnName}" changes type between batches`);
|
|
158
|
+
}
|
|
159
|
+
const validity = getGPUAnalyticsValidity(data, field.nullable, columnName);
|
|
160
|
+
if (DataType.isDictionary(field.type)) {
|
|
161
|
+
const dictionary = getGPUAnalyticsDictionary(data, columnName);
|
|
162
|
+
if (column.dictionary && !areGPUAnalyticsDictionariesEqual(column.dictionary, dictionary)) {
|
|
163
|
+
throw new Error(`GPU analytics dictionary column "${columnName}" changes across batches`);
|
|
164
|
+
}
|
|
165
|
+
column.dictionary ??= dictionary;
|
|
166
|
+
validateGPUAnalyticsDictionaryIndices(data, dictionary, validity, columnName);
|
|
167
|
+
}
|
|
168
|
+
column.chunks.push(data);
|
|
169
|
+
column.validity.push(validity);
|
|
170
|
+
column.nullCounts.push(data.nullCount);
|
|
171
|
+
}
|
|
172
|
+
return column;
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
/** Maps the intentionally limited portable Arrow analytics surface to canonical GPU formats. */
|
|
176
|
+
function getGPUAnalyticsVectorFormat(type, columnName) {
|
|
177
|
+
if (DataType.isFloat(type) && type.precision === Precision.SINGLE) {
|
|
178
|
+
return 'float32';
|
|
179
|
+
}
|
|
180
|
+
if (DataType.isInt(type) && type.bitWidth === 32) {
|
|
181
|
+
return type.isSigned ? 'sint32' : 'uint32';
|
|
182
|
+
}
|
|
183
|
+
if (DataType.isDictionary(type) &&
|
|
184
|
+
DataType.isUtf8(type.dictionary) &&
|
|
185
|
+
DataType.isInt(type.indices) &&
|
|
186
|
+
type.indices.bitWidth === 32) {
|
|
187
|
+
return type.indices.isSigned ? 'sint32' : 'uint32';
|
|
188
|
+
}
|
|
189
|
+
throw new Error(`GPU analytics column "${columnName}" has unsupported Arrow type ${type}`);
|
|
190
|
+
}
|
|
191
|
+
/** Expands sliced Arrow validity bits into one 0/1 uint32 value per logical source row. */
|
|
192
|
+
function getGPUAnalyticsValidity(data, nullable, columnName) {
|
|
193
|
+
const nullCount = data.nullCount;
|
|
194
|
+
const sourceRowOffset = data.offset ?? 0;
|
|
195
|
+
if (!Number.isSafeInteger(sourceRowOffset) ||
|
|
196
|
+
sourceRowOffset < 0 ||
|
|
197
|
+
!Number.isSafeInteger(nullCount) ||
|
|
198
|
+
nullCount < 0 ||
|
|
199
|
+
nullCount > data.length) {
|
|
200
|
+
throw new Error(`GPU analytics column "${columnName}" has malformed validity metadata`);
|
|
201
|
+
}
|
|
202
|
+
if (!nullable && nullCount > 0) {
|
|
203
|
+
throw new Error(`GPU analytics non-nullable column "${columnName}" contains null values`);
|
|
204
|
+
}
|
|
205
|
+
const bitmap = data.nullBitmap;
|
|
206
|
+
if (nullCount > 0 && (!bitmap || bitmap.byteLength === 0)) {
|
|
207
|
+
throw new Error(`GPU analytics column "${columnName}" is missing its validity bitmap`);
|
|
208
|
+
}
|
|
209
|
+
if (bitmap && bitmap.byteLength > 0 && bitmap.byteLength * 8 < sourceRowOffset + data.length) {
|
|
210
|
+
throw new Error(`GPU analytics column "${columnName}" has a truncated validity bitmap`);
|
|
211
|
+
}
|
|
212
|
+
const validity = new Uint32Array(data.length);
|
|
213
|
+
let observedNullCount = 0;
|
|
214
|
+
for (let rowIndex = 0; rowIndex < data.length; rowIndex++) {
|
|
215
|
+
const sourceBitIndex = sourceRowOffset + rowIndex;
|
|
216
|
+
const valid = !bitmap || bitmap.byteLength === 0
|
|
217
|
+
? true
|
|
218
|
+
: ((bitmap[sourceBitIndex >> 3] ?? 0) & (1 << (sourceBitIndex & 7))) !== 0;
|
|
219
|
+
validity[rowIndex] = valid ? 1 : 0;
|
|
220
|
+
if (!valid) {
|
|
221
|
+
observedNullCount++;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
if (observedNullCount !== nullCount) {
|
|
225
|
+
throw new Error(`GPU analytics column "${columnName}" has inconsistent validity bitmap`);
|
|
226
|
+
}
|
|
227
|
+
return validity;
|
|
228
|
+
}
|
|
229
|
+
/** Copies dictionary labels into explicit CPU metadata without retaining the Arrow source vector. */
|
|
230
|
+
function getGPUAnalyticsDictionary(data, columnName) {
|
|
231
|
+
if (!(data.type instanceof Dictionary) || !DataType.isUtf8(data.type.dictionary)) {
|
|
232
|
+
throw new Error(`GPU analytics column "${columnName}" requires a UTF-8 dictionary`);
|
|
233
|
+
}
|
|
234
|
+
if (!data.dictionary) {
|
|
235
|
+
throw new Error(`GPU analytics dictionary column "${columnName}" has no dictionary labels`);
|
|
236
|
+
}
|
|
237
|
+
const values = [];
|
|
238
|
+
for (const value of data.dictionary) {
|
|
239
|
+
if (typeof value !== 'string') {
|
|
240
|
+
throw new Error(`GPU analytics dictionary column "${columnName}" contains a null label`);
|
|
241
|
+
}
|
|
242
|
+
values.push(value);
|
|
243
|
+
}
|
|
244
|
+
return Object.freeze({ values: Object.freeze(values), ordered: data.type.isOrdered });
|
|
245
|
+
}
|
|
246
|
+
/** Ensures every non-null dictionary row references an existing category label. */
|
|
247
|
+
function validateGPUAnalyticsDictionaryIndices(data, dictionary, validity, columnName) {
|
|
248
|
+
const indices = data.values;
|
|
249
|
+
const sourceOffset = indices.length === data.length ? 0 : (data.offset ?? 0);
|
|
250
|
+
if (sourceOffset + data.length > indices.length) {
|
|
251
|
+
throw new Error(`GPU analytics dictionary column "${columnName}" has truncated indices`);
|
|
252
|
+
}
|
|
253
|
+
for (let rowIndex = 0; rowIndex < data.length; rowIndex++) {
|
|
254
|
+
if (!validity[rowIndex]) {
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
const categoryIndex = indices[sourceOffset + rowIndex];
|
|
258
|
+
if (categoryIndex < 0 || categoryIndex >= dictionary.values.length) {
|
|
259
|
+
throw new Error(`GPU analytics dictionary column "${columnName}" has an invalid index`);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
/** Verifies independently supplied record batches use the same category encoding. */
|
|
264
|
+
function areGPUAnalyticsDictionariesEqual(first, second) {
|
|
265
|
+
return (first.ordered === second.ordered &&
|
|
266
|
+
first.values.length === second.values.length &&
|
|
267
|
+
first.values.every((value, index) => value === second.values[index]));
|
|
268
|
+
}
|
|
269
|
+
/** Reuses the existing Arrow GPU uploader while giving zero-row chunks usable storage capacity. */
|
|
270
|
+
function makeGPUAnalyticsData(device, source, format, bufferProps) {
|
|
271
|
+
if (source.length > 0) {
|
|
272
|
+
return makeGPUDataFromArrowData(device, source, { ...bufferProps, format });
|
|
273
|
+
}
|
|
274
|
+
const buffer = device.createBuffer({ ...bufferProps, byteLength: 4 });
|
|
275
|
+
try {
|
|
276
|
+
return new GPUData({
|
|
277
|
+
buffer,
|
|
278
|
+
format,
|
|
279
|
+
length: 0,
|
|
280
|
+
stride: 1,
|
|
281
|
+
byteStride: 4,
|
|
282
|
+
rowByteLength: 4,
|
|
283
|
+
dataType: source.type,
|
|
284
|
+
ownsBuffer: true
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
catch (error) {
|
|
288
|
+
buffer.destroy();
|
|
289
|
+
throw error;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
/** Stores row-aligned validity in a separate owned GPU buffer for each source record batch. */
|
|
293
|
+
function makeGPUAnalyticsValidityData(device, validity, bufferProps) {
|
|
294
|
+
const values = validity.length > 0 ? validity : new Uint32Array(1);
|
|
295
|
+
const buffer = device.createBuffer({ ...bufferProps, data: values });
|
|
296
|
+
try {
|
|
297
|
+
return new GPUData({
|
|
298
|
+
buffer,
|
|
299
|
+
format: 'uint32',
|
|
300
|
+
length: validity.length,
|
|
301
|
+
ownsBuffer: true
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
catch (error) {
|
|
305
|
+
buffer.destroy();
|
|
306
|
+
throw error;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
/** Copies source field nullability and metadata into the generic Arrow-free GPU schema. */
|
|
310
|
+
function makeGPUAnalyticsField(column) {
|
|
311
|
+
return {
|
|
312
|
+
name: column.field.name,
|
|
313
|
+
format: column.format,
|
|
314
|
+
nullable: column.field.nullable,
|
|
315
|
+
metadata: new Map(column.field.metadata)
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
//# sourceMappingURL=arrow-gpu-analytics-adapters.js.map
|