Skip to content

Commit c7df01e

Browse files
fix: #514 fix and upgrade tests to detect behaviour
fix: Documentation for what types are and are not tracked fix: Added documentation for testing and building fix: Some destructuring
1 parent 045b470 commit c7df01e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+992
-486
lines changed

README.md

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,18 @@ NOTE: documentation is slightly out of date for the upcoming release of v2. We
8989
* [Cleanup](#cleanup)
9090
* [Flattened typed array support](#flattened-typed-array-support)
9191
* [Precompiled and Lighter Weight Kernels](#precompiled-and-lighter-weight-kernels)
92+
* [using JSON](#using-json)
93+
* [Exporting kernel](#exporting-kernel)
9294
* [Supported Math functions](#supported-math-functions)
9395
* [How to check what is supported](#how-to-check-what-is-supported)
9496
* [Typescript Typings](#typescript-typings)
9597
* [Dealing With Transpilation](#dealing-with-transpilation)
9698
* [Full API reference](#full-api-reference)
99+
* [How possible in node](#how-possible-in-node)
100+
* [Testing](#testing)
101+
* [Building](#building)
97102
* [Contributors](#contributors)
98103
* [Contributing](#contributing)
99-
* [How possible in node](#how-possible-in-node)
100104
* [Terms Explained](#terms-explained)
101105
* [License](#license)
102106

@@ -815,10 +819,39 @@ NOTE: There is lighter weight, pre-built, version of GPU.js to assist with seria
815819
* [dist/gpu-browser-core.js](dist/gpu-browser-core.js)
816820
* [dist/gpu-browser-core.min.js](dist/gpu-browser-core.min.js)
817821

818-
### using `kernel.toString(args...)`
822+
### Exporting kernel
819823
GPU.js supports seeing exactly how it is interacting with the graphics processor by means of the `kernel.toString(...)` method.
820-
This method, when called, creates a kernel that executes _exactly the instruction set given to the GPU_ as a function that sets up a kernel.
821-
Here is an example:
824+
This method, when called, creates a kernel that executes _exactly the instruction set given to the GPU (or CPU)_ *as a
825+
very tiny reusable function* that instantiates a kernel.
826+
827+
NOTE: When exporting a kernel and using `constants` the following constants are *not changeable*:
828+
* `Array(2)`
829+
* `Array(3)`
830+
* `Array(4)`
831+
* `Integer`
832+
* `Number`
833+
* `Float`
834+
* `Boolean`
835+
836+
Here is an example used to/from file:
837+
```
838+
import { GPU } from 'gpu.js';
839+
import * as fs from 'fs';
840+
const gpu = new GPU();
841+
const kernel = gpu.createKernel(function(v) {
842+
return this.thread.x + v + this.constants.v1;
843+
}, { output: [10], constants: { v1: 100 } });
844+
const result = kernel(1);
845+
const kernelString = kernel.toString(1);
846+
fs.writeFileSync('./my-exported-kernel.js', 'module.exports = ' + kernelString);
847+
import * as MyExportedKernel from './my-exported-kernel';
848+
import gl from 'gl';
849+
const myExportedKernel = MyExportedKernel({ context: gl(1,1), constants: { v1: 100 } });
850+
851+
```
852+
853+
854+
Here is an example for just-in-time function creation:
822855

823856
```js
824857
const gpu = new GPU();
@@ -831,10 +864,13 @@ const kernel = gpu.createKernel(function(a) {
831864
}, { output: [6] });
832865
kernel(input(a, [6, 6]));
833866
const kernelString = kernel.toString(input(a, [6, 6]));
834-
const newKernel = new Function('return ' + kernelString)()(context);
867+
const newKernel = new Function('return ' + kernelString)()({ context });
835868
newKernel(input(a, [6, 6]));
836869
```
837870

871+
#### using constants with `kernel.toString(...args)`
872+
You can assign _some_ new constants when using the function output from `.toString()`,
873+
838874
## Supported Math functions
839875

840876
Since the code running in the kernel is actually compiled to GLSL code, not all functions from the JavaScript Math module are supported.
@@ -914,6 +950,17 @@ GPU.js is written in such a way, you can introduce your own backend. Have a sug
914950
* Kernel - A function that is tightly coupled to program that runs on the Graphic Processor
915951
* Texture - A graphical artifact that is packed with data, in the case of GPU.js, bit shifted parts of a 32 bit floating point decimal
916952

953+
## Testing
954+
Testing is done (right now) manually, (help wanted (here)[https://github.com/gpujs/gpu.js/issues/515] if you can!), using the following:
955+
* For browser, setup a webserver on the root of the gpu.js project and visit htt://url/test/all.html
956+
* For node, run either of the 3 commands:
957+
* `yarn test test/features`
958+
* `yarn test test/internal`
959+
* `yarn test test/issues`
960+
961+
## Building
962+
Building isn't required on node, but is for browser. To build the browser's files, run: `yarn make`
963+
917964
# Get Involved!
918965

919966
## Contributing

0 commit comments

Comments
 (0)