File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1919 "devDependencies" : {
2020 "babel-plugin-syntax-async-functions" : " ^6.5.0" ,
2121 "babel-preset-env" : " ^1.5.2" ,
22+ "benchmark" : " ^2.1.4" ,
2223 "browser-sync" : " ^2.26.3" ,
2324 "browserify" : " ^16.2.3" ,
2425 "chai" : " ^4.2.0" ,
4243 "vinyl-source-stream" : " ^2.0.0"
4344 },
4445 "scripts" : {
45- "test" : " mocha ./test" ,
46+ "test" : " mocha ./test/index " ,
4647 "setup" : " npm i -g gulp-cli" ,
4748 "build-docs" : " ./node_modules/.bin/jsdoc -c jsdoc.json src -r -d doc --debug && gulp injectCSS" ,
4849 "make" : " gulp build && gulp beautify && gulp minify"
Original file line number Diff line number Diff line change @@ -31,7 +31,9 @@ class GPU extends GPUCore {
3131 this . _canvas = settings . canvas || null ;
3232 this . _webGl = settings . webGl || null ;
3333
34- if ( ! mode || mode === 'webgl-validator' ) {
34+ if ( mode === 'cpu' ) {
35+ detectedMode = 'cpu' ;
36+ } else if ( mode === 'webgl' || mode === 'webgl-validator' ) {
3537 const context = createNodeContext ( 512 , 512 ) ;
3638 const canvas = createCanvas ( 512 , 512 ) ;
3739 detectedMode = mode || 'webgl' ;
Original file line number Diff line number Diff line change 1+ const GPU = require ( '../src/index.js' ) ;
2+ const Benchmark = require ( 'benchmark' ) ;
3+
4+ const suite = new Benchmark . Suite ;
5+
6+
7+ const gpuRunner = new GPU ( { mode : 'webgl' } ) ;
8+ const cpuRunner = new GPU ( { mode : 'cpu' } ) ;
9+
10+ const size = 200 ;
11+
12+ const myGPUFunc = gpuRunner
13+ . createKernel ( function compute ( ) {
14+ const i = this . thread . x ;
15+ const j = 0.89 ;
16+ return i + j ;
17+ } )
18+ // .setOutputToTexture(true)
19+ . setOutput ( [ size , size , size ] ) ;
20+
21+ const myCPUFunc = cpuRunner
22+ . createKernel ( function compute ( ) {
23+ const i = this . thread . x ;
24+ const j = 0.89 ;
25+ return i + j ;
26+ } )
27+ . setOutput ( [ size , size , size ] ) ;
28+
29+
30+
31+
32+ // add tests
33+ suite . add ( 'cpu' , function ( ) {
34+ myGPUFunc ( ) ;
35+ } )
36+ . add ( 'gpu' , function ( ) {
37+ myCPUFunc ( ) ;
38+ } )
39+ // add listeners
40+ . on ( 'cycle' , function ( event ) {
41+ console . log ( String ( event . target ) ) ;
42+ } )
43+ . on ( 'complete' , function ( ) {
44+ console . log ( 'Fastest is ' + this . filter ( 'fastest' ) . map ( 'name' ) ) ;
45+ } )
46+ // run async
47+ . run ( ) ;
Original file line number Diff line number Diff line change 1- const path = require ( 'path' ) ;
21const { expect } = require ( 'chai' ) ;
32
43const GPU = require ( '../src/index.js' ) ;
54
65
76describe ( 'Test Node GPU' , ( ) => {
87 it ( 'should find gpu' , ( ) => {
9- const gpu = new GPU ( ) ;
8+ const gpu = new GPU ( { mode : 'webgl' } ) ;
109
1110 const myFunc = gpu . createKernel ( function compute ( ) {
1211 const i = this . thread . x ;
1312 const j = 0.89 ;
1413 return i + j ;
15- } ) . setOutput ( [ 100 ] ) ;
14+ } ) . setOutput ( [ 1000 , 1000 ] ) ;
1615
1716 console . log ( myFunc ( ) ) ;
1817
You can’t perform that action at this time.
0 commit comments