Skip to content

Commit

Permalink
Fix gpu aggregation tests (visgl#3932)
Browse files Browse the repository at this point in the history
* Fix GPUAggregation tests
  • Loading branch information
1chandu authored Nov 25, 2019
1 parent 3b19806 commit f7d3a55
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 29 deletions.
2 changes: 1 addition & 1 deletion test/data/grid-aggregation-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function buildAttributes(opts) {
attributeManager.add({
positions: {size: 3, accessor: 'getPosition', type: gl.DOUBLE}
});
accessorProps.getPosition = x => x.position;
accessorProps.getPosition = opts.getPosition || (x => x.position);
for (const weightId in weights) {
const accessor = `get${weightId}`;
attributeManager.add({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ import {points, GridAggregationData} from 'deck.gl-test/data';
const getPosition = d => d.COORDINATES;
const gpuGridAggregator = new GPUGridAggregator(gl);

function filterEmptyChannels(inArray) {
const outArray = [];
for (let i = 0; i < inArray.length; i += 4) {
outArray.push(inArray[i], inArray[i + 3]);
}
return outArray;
}

function compareArrays(t, name, cpu, gpu) {
t.deepEqual(filterEmptyChannels(gpu), filterEmptyChannels(cpu), name);
}

test('GridAggregationUtils#alignToCell (CPU)', t => {
t.equal(alignToCell(-3, 5), -5);
t.equal(alignToCell(3, 5), 0);
Expand All @@ -45,49 +57,40 @@ test('GridAggregationUtils#pointToDensityGridData (CPU vs GPU)', t => {
weightParams: {weight: {needMax: 1, needMin: 1, getWeight: x => 1}},
gpuGridAggregator,
aggregationFlags: {dataChanged: true},
fp64: false // true // NOTE this test fails wihtout FP64 gpu aggregation.
fp64: false // TODO: enable once FP64 extension support is resolved
};
const {attributes, vertexCount} = GridAggregationData.buildAttributes({
data: opts.data,
weights: opts.weightParams
weights: opts.weightParams,
getPosition: x => x.COORDINATES
});
const CELLSIZES = [500, 1000, 5000];
const CELLSIZES = [1000, 5000]; // cell size 500 requires 64 bit aggregation
for (const cellSizeMeters of CELLSIZES) {
opts.cellSizeMeters = cellSizeMeters;
opts.gpuAggregation = false;
const cpuResults = pointToDensityGridData(Object.assign({}, opts, {attributes, vertexCount}));
opts.gpuAggregation = true;
const gpuResults = pointToDensityGridData(Object.assign({}, opts, {attributes, vertexCount}));

const cpuCountsData = cpuResults.weights.weight.aggregationBuffer.getData();
const gpuCountsData = gpuResults.weights.weight.aggregationBuffer.getData();

t.deepEqual(
cpuCountsData,
gpuCountsData,
`Cell aggregation data should match for cellSizeMeters:${cellSizeMeters}`
);

const cpuMaxCountsData = cpuResults.weights.weight.maxBuffer.getData();
const gpuMaxCountData = gpuResults.weights.weight.maxBuffer.getData();
t.deepEqual(
cpuMaxCountsData[0],
gpuMaxCountData[0],
`Max data should match for cellSizeMeters:${cellSizeMeters}`
compareArrays(
t,
`Cell aggregation data should match for cellSizeMeters:${cellSizeMeters}`,
cpuResults.weights.weight.aggregationBuffer.getData(),
gpuResults.weights.weight.aggregationBuffer.getData()
);

const cpuMinCountsData = cpuResults.weights.weight.minBuffer.getData();
const gpuMinCountData = gpuResults.weights.weight.minBuffer.getData();
t.deepEqual(
cpuMinCountsData[0],
gpuMinCountData[0],
`Min data should match for cellSizeMeters:${cellSizeMeters}`
compareArrays(
t,
`Max data should match for cellSizeMeters:${cellSizeMeters}`,
cpuResults.weights.weight.maxBuffer.getData(),
gpuResults.weights.weight.maxBuffer.getData()
);

t.deepEqual(
cpuMaxCountsData[3],
gpuMaxCountData[3],
`Total count should match for cellSizeMeters:${cellSizeMeters}`
compareArrays(
t,
`Min data should match for cellSizeMeters:${cellSizeMeters}`,
cpuResults.weights.weight.minBuffer.getData(),
gpuResults.weights.weight.minBuffer.getData()
);
}

Expand Down

0 comments on commit f7d3a55

Please sign in to comment.