Skip to content

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.

[Bug] fall back to CPU when shared filter GPU channels are full (#3880)

Igor Dykhta627a40c3aa78
diff --git a/src/table/src/gpu-filter-utils.ts b/src/table/src/gpu-filter-utils.ts
index a370c1814..7a6028165 100644
--- a/src/table/src/gpu-filter-utils.ts
+++ b/src/table/src/gpu-filter-utils.ts
@@ -77,7 +77,7 @@ export function assignGpuChannel(filter: Filter, filters: Filter[]) {
return filter;
}
- const gpuChannel = filter.gpuChannel || [];
+ const gpuChannel = [...(filter.gpuChannel || [])];
filter.dataId.forEach((dataId, datasetIdx) => {
const findGpuChannel = channel => f =>
@@ -100,11 +100,13 @@ export function assignGpuChannel(filter: Filter, filters: Filter[]) {
}
i++;
}
+
+ gpuChannel[datasetIdx] = undefined as unknown as number;
});
// if cannot find channel for all dataid, set gpu back to false
// TODO: refactor filter to handle same filter different gpu mode
- if (!gpuChannel.length || !gpuChannel.every(Number.isFinite)) {
+ if (!gpuChannel.length || !filter.dataId.every((_, idx) => Number.isFinite(gpuChannel[idx]))) {
return {
...filter,
gpu: false
diff --git a/test/node/reducers/vis-state-test.js b/test/node/reducers/vis-state-test.js
index 455af6d4a..4af3a2542 100644
--- a/test/node/reducers/vis-state-test.js
+++ b/test/node/reducers/vis-state-test.js
@@ -3103,6 +3103,65 @@ test('#visStateReducer -> SET_FILTER.dataId falls back to CPU when GPU channels
t.end();
});
+test('#visStateReducer -> SET_FILTER shares a filter with a dataset whose GPU channels are full', async t => {
+ const createDataset = id =>
+ createNewDataEntryMock({
+ info: {id, label: id},
+ data: {
+ fields: [{name: 'value', type: ALL_FIELD_TYPES.integer}],
+ rows: [[10], [20]]
+ }
+ });
+ let state = {
+ ...INITIAL_VIS_STATE,
+ datasets: {...(await createDataset('first')), ...(await createDataset('second'))}
+ };
+
+ state = reducer(state, VisStateActions.addFilter('first'));
+ state = reducer(state, VisStateActions.setFilter(0, 'name', 'value'));
+ state = reducer(state, VisStateActions.setFilter(0, 'value', [10, 10]));
+ for (let i = 0; i < MAX_GPU_FILTERS; i++) {
+ state = reducer(state, VisStateActions.addFilter('second'));
+ state = reducer(state, VisStateActions.setFilter(i + 1, 'name', 'value'));
+ }
+ t.deepEqual(
+ state.filters.slice(1).map(filter => filter.gpuChannel[0]),
+ [0, 1, 2, 3],
+ 'the target dataset has four occupied GPU channels'
+ );
+
+ state = reducer(state, VisStateActions.setFilter(0, ['dataId', 'name'], ['second', 'value'], 1));
+
+ t.equal(state.filters[0].gpu, false, 'falls back to CPU for the whole shared filter');
+ for (const dataId of ['first', 'second']) {
+ const dataset = state.datasets[dataId];
+ const {filterRange, filterValueAccessor} = dataset.gpuFilter;
+ const getFilterValue = filterValueAccessor(dataset.dataContainer)();
+ const visibleRows = dataset.filteredIndex.filter(index =>
+ getFilterValue({index}).every(
+ (value, channel) => value >= filterRange[channel][0] && value <= filterRange[channel][1]
+ )
+ );
+ t.deepEqual(visibleRows, [0], `${dataId}: only row 10 remains visible`);
+ t.ok(
+ dataset.filterRecord.cpu.some(filter => filter.id === state.filters[0].id),
+ `${dataId}: records the shared filter on CPU`
+ );
+ t.deepEqual(dataset.filteredIndex, [0], `${dataId}: updates the cached CPU row indexes`);
+ const cpuDataset = copyTableAndUpdate(dataset).filterTableCPU(state.filters, state.layers);
+ t.deepEqual(visibleRows, cpuDataset.filteredIdxCPU, `${dataId}: matches CPU-only filtering`);
+ }
+
+ state = reducer(state, VisStateActions.setFilter(0, 'value', [20, 20]));
+ t.deepEqual(
+ state.datasets.first.filteredIndex,
+ [1],
+ 'updates the original dataset after fallback'
+ );
+ t.deepEqual(state.datasets.second.filteredIndex, [1], 'updates the added dataset after fallback');
+ t.end();
+});
+
test('#visStateReducer -> SET_FILTER synced', t => {
const initialState = StateWSyncedTimeFilter.visState;
const oldFilter = {...initialState.filters[0]};
diff --git a/test/node/utils/gpu-filter-utils-test.js b/test/node/utils/gpu-filter-utils-test.js
index 102acd687..0f297e3e4 100644
--- a/test/node/utils/gpu-filter-utils-test.js
+++ b/test/node/utils/gpu-filter-utils-test.js
@@ -121,6 +121,36 @@ test('gpuFilterUtils -> assignGpuChannel', t => {
t.end();
});
+test('gpuFilterUtils -> assignGpuChannel requires a free channel for every shared dataset', t => {
+ const occupied = [0, 1, 2, 3].map(channel => ({
+ id: `occupied-${channel}`,
+ dataId: ['full'],
+ gpu: true,
+ gpuChannel: [channel]
+ }));
+ const cases = [
+ {dataId: ['available', 'full'], gpuChannel: [0]},
+ {dataId: ['full', 'available'], gpuChannel: []},
+ {dataId: ['available', 'full'], gpuChannel: [0, 0]}
+ ];
+
+ cases.forEach(({dataId, gpuChannel}) => {
+ const filter = {id: 'shared', dataId, gpu: true, gpuChannel};
+ const originalChannels = gpuChannel.slice();
+ const result = assignGpuChannel(filter, occupied);
+ t.equal(result.gpu, false, 'falls back for a missing, sparse, or conflicting channel');
+ t.deepEqual(filter.gpuChannel, originalChannels, 'preserves the input filter channels');
+ });
+
+ const available = assignGpuChannel(
+ {id: 'shared', dataId: ['available', 'full'], gpu: true, gpuChannel: [0]},
+ occupied.slice(0, 3)
+ );
+ t.equal(available.gpu, true, 'keeps GPU filtering when every dataset has room');
+ t.deepEqual(available.gpuChannel, [0, 3], 'uses the remaining channel in the second dataset');
+ t.end();
+});
+
test('gpuFilterUtils -> assignGpuChannels', t => {
const testCases = [
{