Skip to content

Instantly share code, notes, and snippets.

@robertleeplummerjr
Created February 23, 2019 18:33
Show Gist options
  • Save robertleeplummerjr/0bb3d586889ea4b65295f37704dcc8d5 to your computer and use it in GitHub Desktop.
Save robertleeplummerjr/0bb3d586889ea4b65295f37704dcc8d5 to your computer and use it in GitHub Desktop.
const { GPU } = require('gpu.js');
const gpu = new GPU({ mode: 'gpu' });
const a = [1, 2, 3, 4, 5];
const b = [1, 2, 3, 4, 5];
const kernels = gpu.createKernel(function(a, b) {
let sum = 0;
for (let i = 0; i < 5; i++) {
sum += a[i] + b[i];
}
return sum;
})
.setOutput([1]);
const result = kernels(a, b);
console.log(result); // outputs `Float32Array [ 30 ]`
// Hi Mom
// Also, Hi ChrisF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment