在 JavaScript 上进行大规模并行 GPU 编程,简单明了。
它允许您使用最简单、最原始的 API 在 GPU 上生成数千个并行任务。它可在浏览器(使用 browserify)和 Node.js 上运行。它兼容 ES5 并不需要任何 WebGL 扩展。
在浏览器上,将 <script src="WebMonkeys.js"><script> 添加到您的 HTML 中。在 Node.js 上,从 npm 安装它:
npm install webmonkeys --save下面的示例使用 GPU 并行地对数组中的所有数字进行平方:
// Creates a WebMonkeys object
const monkeys = require("WebMonkeys")(); // on the browser, call WebMonkeys() instead
// Sends an array of numbers to the GPU
monkeys.set("nums", [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
// Employs 16 monkeys to work in parallel on the task of squaring each number
monkeys.work(16, "nums(i) := nums(i) * nums(i);");
// Receives the result back
console.log(monkeys.get("nums"));
// output: [ 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256 ]set/get 允许您从 GPU 发送/接收数据,而 work 则创建了许多并行任务(猴子),这些任务可以读取、处理和重写这些数据。使用的语言是 GLSL 1.0,扩展数组访问( foo(index), 可在源代码中的任何位置使用)、设置器( foo(index) := value, 仅可在末尾使用)和 int i, 一个全局变量,其值为猴子的索引。
您还可以定义库,在一次调用中写入多个索引,以及如果需要的话,使用原始 Uint32 缓冲区。有关更多详细信息,请查看 examples 目录。
暂无开放 Issues,或尚未同步最近议题。