Skip to content

Instantly share code, notes, and snippets.

@Himujjal
Last active May 6, 2018 12:10
Show Gist options
  • Save Himujjal/a8e3fabd538de8bdac5299ddff4a5397 to your computer and use it in GitHub Desktop.
Save Himujjal/a8e3fabd538de8bdac5299ddff4a5397 to your computer and use it in GitHub Desktop.
Vector Addition program for node-cl ()
const CL = require("node-cl");
const context = CL.getBestContext();
const queue = CL.createCommandQueue();
function VectorAdditionGPU (array1, array2) {
const kernel = CL.createKernel({
name: "vecadd",
args: [
{ arg: "A", type: "array", prop: array1 },
{ arg: "B", type: "array", prop: array2 }
]
});
kernel.enqueueCode(`
A[gid] += B[gid];
`);
return kernel.args[0];
}
let arr1 = [3, 4, 6, 7, 8, 9, 12];
let arr2 = [5, 1, 8, 9, 2, 14, 2];
console.log( VectorAdditionGPU( arr1, arr2 ) );
// => [8, 5, 14, 16, 10, 23, 14]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment