
const gpu = new GPU();
// 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 matMult = 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;
}).setDimensions([512, 512]);
// Perform matrix multiplication on 2 matrices of size 512 x 512
const c = matMult(a, b);
Khi chạy benchmark ở trang chủ, tùy vào cấu hình máy bạn, thường phép tính này nhanh hơn 1-15x lần.
Tham khảo
- https://github.com/gpujs/gpu.js
- http://gpu.rocks

Tôi là Duyệt