@@ -89,14 +89,18 @@ NOTE: documentation is slightly out of date for the upcoming release of v2. We
89
89
* [ Cleanup] ( #cleanup )
90
90
* [ Flattened typed array support] ( #flattened-typed-array-support )
91
91
* [ Precompiled and Lighter Weight Kernels] ( #precompiled-and-lighter-weight-kernels )
92
+ * [ using JSON] ( #using-json )
93
+ * [ Exporting kernel] ( #exporting-kernel )
92
94
* [ Supported Math functions] ( #supported-math-functions )
93
95
* [ How to check what is supported] ( #how-to-check-what-is-supported )
94
96
* [ Typescript Typings] ( #typescript-typings )
95
97
* [ Dealing With Transpilation] ( #dealing-with-transpilation )
96
98
* [ Full API reference] ( #full-api-reference )
99
+ * [ How possible in node] ( #how-possible-in-node )
100
+ * [ Testing] ( #testing )
101
+ * [ Building] ( #building )
97
102
* [ Contributors] ( #contributors )
98
103
* [ Contributing] ( #contributing )
99
- * [ How possible in node] ( #how-possible-in-node )
100
104
* [ Terms Explained] ( #terms-explained )
101
105
* [ License] ( #license )
102
106
@@ -815,10 +819,38 @@ NOTE: There is lighter weight, pre-built, version of GPU.js to assist with seria
815
819
* [ dist/gpu-browser-core.js] ( dist/gpu-browser-core.js )
816
820
* [ dist/gpu-browser-core.min.js] ( dist/gpu-browser-core.min.js )
817
821
818
- ### using ` kernel.toString(args...) `
822
+ ### Exporting kernel
819
823
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
+ ``` js
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
+ Here is an example for just-in-time function creation:
822
854
823
855
``` js
824
856
const gpu = new GPU ();
@@ -831,10 +863,13 @@ const kernel = gpu.createKernel(function(a) {
831
863
}, { output: [6 ] });
832
864
kernel (input (a, [6 , 6 ]));
833
865
const kernelString = kernel .toString (input (a, [6 , 6 ]));
834
- const newKernel = new Function (' return ' + kernelString)()(context);
866
+ const newKernel = new Function (' return ' + kernelString)()({ context } );
835
867
newKernel (input (a, [6 , 6 ]));
836
868
```
837
869
870
+ #### using constants with ` kernel.toString(...args) `
871
+ You can assign _ some_ new constants when using the function output from ` .toString() ` ,
872
+
838
873
## Supported Math functions
839
874
840
875
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 +949,17 @@ GPU.js is written in such a way, you can introduce your own backend. Have a sug
914
949
* Kernel - A function that is tightly coupled to program that runs on the Graphic Processor
915
950
* 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
916
951
952
+ ## Testing
953
+ Testing is done (right now) manually, (help wanted (here)[ https://github.com/gpujs/gpu.js/issues/515 ] if you can!), using the following:
954
+ * For browser, setup a webserver on the root of the gpu.js project and visit htt://url/test/all.html
955
+ * For node, run either of the 3 commands:
956
+ * ` yarn test test/features `
957
+ * ` yarn test test/internal `
958
+ * ` yarn test test/issues `
959
+
960
+ ## Building
961
+ Building isn't required on node, but is for browser. To build the browser's files, run: ` yarn make `
962
+
917
963
# Get Involved!
918
964
919
965
## Contributing
0 commit comments