Perform massively parallel GPGPU computations using GPU.
Graceful pure JavaScript fallback when GPU is not available.
Create the GPU accelerated function from a kernel function that computes a single element in the 512 x 512 matrix (2D array). The kernel function is run in a parallel manner in the GPU resulting in very fast computations! (...sometimes)
const gpu = new GPU();
const multiplyMatrix = gpu.createKernel(function(a, b) {
var sum = 0;
for (var i = 0; i < 512; i++) {
sum += a[this.thread.y][i] * b[i][this.thread.x];
}
return sum;
}).setOutput([512, 512]);
Performs matrix multiplication on 2 matrices of size 512 x 512
const c = multiplyMatrix(a, b);
gpu.js relies on the assumption that the kernel function is using only a subset of legal JavaScript syntax:
function
s+
, +=
, -
, *
, /
, %
)Math.floor()
and etc.)if
and else
statementsconst
and let
Here is a chart representing the performance of a 512x512 matrix multiplication throughout our development (lower is better).
Last Updated: 2017-07-23
This is the legacy version for backward compatiblity with the demos made using the "hackathon" API.
DownloadMade under 24 hours for a NUS Hackers hackathon, out of 68 competing projects.