WebMonkeys: parallel GPU programming in JavaScript

https://news.ycombinator.com/rss Hits: 13
Summary

WebMonkeys Allows you to spawn thousands of parallel tasks on the GPU with the simplest, dumbest API possible. It works on the browser (with browserify) and on Node.js. It is ES5-compatible and doesn't require any WebGL extension. Usage On the browser, add <script src="WebMonkeys.js"><script> to your HTML. On Node.js, install it from npm: npm install webmonkeys --save The example below uses the GPU to square all numbers in an array in parallel: // 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 allow you to send/receive data from the GPU, and work creates a number of parallel tasks (monkeys) that can read, process and rewrite that data. The language used is GLSL 1.0, extended array access ( foo(index) , usable anywhere on the source), setters ( foo(index) := value , usable on the end only), and int i , a global variable with the index of the monkey. More examples More elaborate algorithms can be developed with GLSL. Vector multiplication: monkeys . set ( "a" , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 ] ) ; monkeys . set ( "b" , [ 1 , 1 , 1 , 1 , 2 , 2 , 2 , 2 , 3 , 3 , 3 , 3 , 4 , 4 , 4 , 4 ] ) ; monkeys . set ( "c" , 16 ) ; // use a number to just alloc an array monkeys . work ( 16 , "c(i) := a(i) * b(i);" ) ; console . log ( monkeys . get ( "c" ) ) ; Crypto-currency mining: monkeys . set ( "blockhash" , [ blockhash ] ) ; monkeys . set ( "monkeyNonce" , monkeyNonce ) ; monkeys . set ( "result" , [ 0 ] ) ; monkeys . work ( totalMon...

First seen: 2025-05-07 08:04

Last seen: 2025-05-07 20:06