Currently includes hundreds of unit tests, which verify correctness on hundreds of millions of data points.
Our focus is on numerical operations useful for neural networks and machine learning. So far, we've got 32-bit versions of each of these:
- sscal - Matrix (and Vector) Scale (with addition)
- sgemm - Matrix Multiply
- sdwns - Matrix (and Image) Downsample (for Max Pooling)
- sclmp - Matrix clamp (for ReLU)
First, include the
weblas.js file (from a release or the
Then use it like this.
Pipeline mode gives (sometimes very large) increases in performance by leaving data in GPU memory. A demo illustrating performance on a deep neural net can be found here.
Here's a basic example:
// create Tensor containers for interacting directly with GPU memoryvar t0 = weblaspipeline;// second matrix must be transposedvar t1 = weblaspipeline;var t2 = weblaspipeline;var alpha = 10;var beta = 05;/* NOTE: pipeline.sgemm takes a transpose matrix in thesecond slot (t1 here)(this requirement allows for improved performance)*/var t3 = weblaspipeline;// result is a Float32Arrayvar result = t3;
More information can be found on the wiki Pipeline page.
Unit tests and benchmarks both require
npm install -g browserify npm install -g testling
All operations have unit test coverage. Unit tests use data generated outside
the browser (to verify correctness). Generating the data requires
the modules in
pip installed run:
pip install -r requirements.txt
Then, to generate the data, run:
npm run data
Then, run the unit tests with:
If the tests won't run, try this (it restores the default npm browser setting)
npm config set browser open
npm config set browser xdg-open
npm config set browser start
testling, run the benchmarks with:
npm run benchmark
TAP version 13 ok 1 128x128 . 128x128 # 316 ops/sec ±4.80% n = 51 µ = 3ms ok 2 128x256 . 256x128 # 280 ops/sec ±6.15% n = 40 µ = 4ms ok 3 256x256 . 256x256 # 171 ops/sec ±14.79% n = 47 µ = 6ms ok 4 512x256 . 256x512 # 101 ops/sec ±6.68% n = 50 µ = 10ms ok 5 256x512 . 512x256 # 139 ops/sec ±3.64% n = 49 µ = 7ms ok 6 512x512 . 512x512 # 61.61 ops/sec ±3.14% n = 42 µ = 16ms ok 7 513x513 . 513x513 # 52.92 ops/sec ±8.82% n = 49 µ = 19ms ok 8 1024x512 . 512x1024 # 34.99 ops/sec ±4.86% n = 38 µ = 29ms ok 9 512x1024 . 1024x512 # 52.03 ops/sec ±2.66% n = 47 µ = 19ms ok 10 1024x1024 . 1024x1024 # 23.27 ops/sec ±12.70% n = 34 µ = 43ms ok 11 2048x2048 . 2048x2048 # 4.89 ops/sec ±1.82% n = 17 µ = 204ms 1..11 # tests 11 # pass 11 # ok
more information about benchmarks (including test configuration) can be found on the wiki.
Want to see more happen here? Contribute on