gpuFilterStats = {
let count = 0;
const gpu = new GPU.GPU({ mode: 'webgl2' });
const predicate = gpu.createKernel(function(proto, startPort, endPort, isActive) {
if (
proto[this.thread.x] === 6 &&
(startPort[this.thread.x] > 0 && endPort[this.thread.x] < 200 || startPort[this.thread.x] === 49152) &&
isActive[this.thread.x] === 1
) {
return 1;
}
return 0;
})
.setOutput([policies.length])
.setPipeline(true);
const toTexture = gpu.createKernel(function(array) { return array[this.thread.x]; }, { output: [policies.length], pipeline: true });
const protosTexture = toTexture(protos);
const startPortsTexture = toTexture(startPorts);
const endPortsTexture = toTexture(endPorts);
const isActivesTexture = toTexture(isActives);
predicate.build(protosTexture, startPortsTexture, endPortsTexture, isActivesTexture);
const forceSync = gpu.createKernel(function() { return 1; }, { output: [1] });
forceSync.build();
const t1 = performance.now();
const result = predicate(protosTexture, startPortsTexture, endPortsTexture, isActivesTexture);
forceSync();
const t2 = performance.now();
return {
result: result,
count: d3.sum(result.toArray()),
ms: t2 - t1
};
}