You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
gpu.js is a single-file JavaScript library for GPGPU using WebGL. There is graceful fallback to JavaScript if WebGL is not available.
3
+
gpu.js is a single-file JavaScript library for GPGPU in the browser. gpu.js will automatically compile specially written JavaScript functions into shader language and run it on the GPU using the WebGL API. There is graceful fallback to JavaScript if WebGL is not available.
4
+
5
+
# Example
6
+
7
+
Matrix multiplication written in gpu.js:
8
+
9
+
```js
10
+
var gpu =newGPU();
11
+
12
+
// Create the GPU accelerated function from a kernel
13
+
// function that computes a single element in the
14
+
// 512 x 512 matrix (2D array). The kernel function
15
+
// is run in a parallel manner in the GPU resulting
16
+
// in very fast computations! (...sometimes)
17
+
var mat_mult =gpu.createKernel(function(A, B) {
18
+
var sum =0;
19
+
for (var i=0; i<512; i++) {
20
+
sum +=A[this.thread.y][i] *B[i][this.thread.x];
21
+
}
22
+
return sum;
23
+
}).dimensions([512, 512]);
24
+
25
+
// Perform matrix multiplication on 2 matrices of size 512 x 512
26
+
varC=mat_mult(A, B);
27
+
```
28
+
29
+
You can run a benchmark of this [here](http://gpu.rocks). Typically, it will run at 1-15x speedup depending on your hardware.
4
30
5
31
# Getting Started
6
32
@@ -21,10 +47,10 @@ var gpu = new GPU();
21
47
Depnding on your output type, specify the intended dimensions of your output. You cannot have a accelerated function that does not specify any dimensions.
0 commit comments