|
1 | 1 | [](http://gpu.rocks/)
|
2 | 2 |
|
3 | 3 |
|
4 |
| -# gpu.js |
5 |
| -gpu.js is a JavaScript Acceleration library for GPGPU (General purpose computing on GPUs) in JavaScript. gpu.js will automatically compile simple JavaScript functions into shader language and run them on the GPU. In case a GPU is not available, the functions will still run in regular JavaScript. |
| 4 | +# GPU.js |
| 5 | +GPU.js is a JavaScript Acceleration library for GPGPU (General purpose computing on GPUs) in JavaScript. GPU.js will automatically compile simple JavaScript functions into shader language and run them on the GPU. In case a GPU is not available, the functions will still run in regular JavaScript. |
6 | 6 |
|
7 | 7 |
|
8 | 8 | [](https://gitter.im/gpujs/gpu.js?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
9 | 9 | [](https://slack.bri.im)
|
10 | 10 |
|
11 | 11 | # What is this sorcery?
|
12 | 12 |
|
13 |
| -Matrix multiplication written in gpu.js: |
| 13 | +Matrix multiplication written in GPU.js: |
14 | 14 |
|
15 | 15 | ```js
|
16 | 16 | const gpu = new GPU();
|
@@ -50,6 +50,7 @@ Or alternatively you can experiment around with the [kernel playground here](htt
|
50 | 50 | * [Adding Custom Functions Directly to Kernel](#adding-custom-functions-directly-to-kernel)
|
51 | 51 | * [Loops](#loops)
|
52 | 52 | * [Pipelining](#pipelining)
|
| 53 | +* [Offscreen Canvas](#offscreen-canvas) |
53 | 54 | * [Cleanup](#cleanup)
|
54 | 55 | * [Flattened typed array support](#flattened-typed-array-support)
|
55 | 56 | * [Supported Math functions](#supported-math-functions)
|
@@ -78,7 +79,7 @@ yarn add gpu.js
|
78 | 79 |
|
79 | 80 | ### Browser
|
80 | 81 |
|
81 |
| -Download the latest version of gpu.js and include the files in your HTML page using the following tags: |
| 82 | +Download the latest version of GPU.js and include the files in your HTML page using the following tags: |
82 | 83 |
|
83 | 84 | ```html
|
84 | 85 | <script src="/path/to/js/gpu.min.js"></script>
|
@@ -405,12 +406,46 @@ const matMult = gpu.createKernel(function(a, b) {
|
405 | 406 | [Pipeline](https://en.wikipedia.org/wiki/Pipeline_(computing)) is a feature where values are sent directly from kernel to kernel via a texture.
|
406 | 407 | This results in extremely fast computing. This is achieved with the kernel option `outputToTexture: boolean` option or by calling `kernel.setOutputToTexture(true)`
|
407 | 408 |
|
| 409 | +## Offscreen Canvas |
| 410 | +GPU.js supports offscreen canvas where available. Here is an example of how to use it with two files, `gpu-worker.js`, and `index.js`: |
| 411 | + |
| 412 | +file: `gpu-worker.js` |
| 413 | +```js |
| 414 | +importScripts('path/to/gpu.js'); |
| 415 | +onmessage = function() { |
| 416 | + // define gpu instance |
| 417 | + const gpu = new GPU(); |
| 418 | + |
| 419 | + // input values |
| 420 | + const a = [1,2,3]; |
| 421 | + const b = [3,2,1]; |
| 422 | + |
| 423 | + // setup kernel |
| 424 | + const kernel = gpu.createKernel(function(a, b) { |
| 425 | + return a[this.thread.x] - b[this.thread.x]; |
| 426 | + }) |
| 427 | + .setOutput([3]); |
| 428 | + |
| 429 | + // output some results! |
| 430 | + postMessage(kernel(a, b)); |
| 431 | +}; |
| 432 | +``` |
| 433 | + |
| 434 | +file: `index.js` |
| 435 | +```js |
| 436 | +var worker = new Worker('gpu-worker.js'); |
| 437 | +worker.onmessage = function(e) { |
| 438 | + var result = e.data; |
| 439 | + console.log(result); |
| 440 | +}; |
| 441 | +``` |
| 442 | + |
408 | 443 | ## Cleanup
|
409 | 444 | * for instances of `GPU` use the `destroy` method. Example: `gpu.destroy()`
|
410 | 445 | * for instances of `Kernel` use the `destroy` method. Example: `kernel.destroy()`
|
411 | 446 |
|
412 | 447 | ## Flattened typed array support
|
413 |
| -To use the useful `x`, `y`, `z` `thread` lookup api inside of gpu.js, and yet use flattened arrays, there is the `Input` type. |
| 448 | +To use the useful `x`, `y`, `z` `thread` lookup api inside of GPU.js, and yet use flattened arrays, there is the `Input` type. |
414 | 449 | This is generally much faster for when sending values to the gpu, especially with larger data sets. Usage example:
|
415 | 450 | ```js
|
416 | 451 | import GPU, { input } from 'gpu.js';
|
@@ -490,7 +525,7 @@ We promise never to pass off your code as ours.
|
490 | 525 |
|
491 | 526 | The MIT License
|
492 | 527 |
|
493 |
| -Copyright (c) 2017 gpu.js Team |
| 528 | +Copyright (c) 2018 GPU.js Team |
494 | 529 |
|
495 | 530 | Permission is hereby granted, free of charge, to any person obtaining a copy
|
496 | 531 | of this software and associated documentation files (the "Software"), to deal
|
|
0 commit comments