LogoDuyệtSr. Data Engineer
HomeAboutPhotosInsightsCV

Footer

Logo

Resources

  • Rust Tiếng Việt
  • /archives
  • /series
  • /tags
  • Status

me@duyet.net

  • About
  • LinkedIn
  • Resume
  • Projects

© 2026 duyet.net | Sr. Data Engineer

gpu.js - Tăng tốc Javascript với GPU

Note: This post is over 9 years old. The information may be outdated.

Mình lướt github và vô tình thấy thư viện gpu.js này. gpu.js tự động compile mã Javascript thành một ngôn ngữ ánh xạ khác, và chạy trên GPU nhờ vào WebGL API. Nếu máy trình duyệt không có GPU, mã JS vẫn được thực thi bình thường.

Ví dụ về phép nhân ma trận 512x512 trên gpu.js

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
Jul 26, 2017·9 years ago
|Web|
JavascriptJavascript Framework
|Edit|

Related Posts

Javascript Shorthands Tips

These Javascript shorthand tips will make your code look more cool and clean.

Oct 20, 2019·6 years ago
Read more

5 bí quyết viết JS conditionals tốt hơn

Trong Javascript, chúng ta phải sử dụng nhiều loại lệnh điều kiện (if ... else ...) khác nhau, sau đây là 5 bí quyết để viết lệnh if else nhanh hơn và chuyên nghiệp hơn.

Sep 20, 2018·7 years ago
Read more

Signale - Hackable console logger for Nodejs

Signale là một thư viện thay thế console logger trong Nodejs, cho kết quả đẹp, sexy hơn và nhiều chức năng.

Jul 19, 2018·8 years ago
Read more

Gio.js - 3D Globe Data Visualization

Gio.js là thư viện nguồn mở để visualization 3D globe, xây dựng dựa trên thư viện **Three.js**. Gio.js cực kỳ dễ sử dụng và dễ customize.

Jul 1, 2018·8 years ago
Read more
On this page
  • Tham khảo
On this page
  • Tham khảo