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|
On this page
  • Tham khảo
On this page
  • Tham khảo