#JC (JS CUDA) ##What is JC? JC is a NodeJs module for doing linear algebra (which mainly consists of vector and matrix operations) based on CUDA.
It means you can easily use Javascript to bring your GPU down computing linear problems in parallel. In my experience, JC is 5 - 1000 times faster than traditional CPU method thanks to huge development of modern GPU, and JC doesn't merely binding the CUDA ToolKit for using, it hides the relatively uncomprehensive BLAS routine or solvers' routine(in development) under the hood.
And most important one is: User can quickly deploy JC with very little effort instead of learning enormous and complicate API provided by CUDA Toolkit which is writen in C++.
##What JC can do?
-
Level-1
- arbitrary dimension vector add
- arbitrary dimension vector dot product
- arbitrary dimension vector Euclidean Norm
- arbitrary dimension vector multiply scalar
-
Level-2
- arbitrary dimension vector tensor product
- arbitrary dimension matrix add
- arbitrary dimension matrix multiply scalar
- arbitrary dimension matrix multiply vector
-
Level-3
- arbitrary dimension matrix multiply matrix
- arbitrary dimension matrix multiply matrix ( Batched )
-
Solvers
- quick dense n x n matrix inverse, n is less than 32 ( Batched )
- dense n x n matrix LU decomposition & solve linear system & matrix inverse ( Batched )
- dense n x n matrix QR decomposition & solve linear system & matrix inverse ( Batched ) Coming soon
- Sparse matrix solvers Coming soon
##Requirements
- Make sure your graphic card support CUDA v7.5 and compute capability is higher than 2.0, if you are not sure please refer to [https://developer.nvidia.com/cuda-gpus]
- Have Nodejs v6.2.X installed
##How to install? ###Pre-build copy files in git ./Pre-build to any directory you like for example E:/Example/
- jc.node // NodeJs module
- JSCUDA.dll // C++ binding part
- JC.js // Javascript part
###Build from source
##Usage After copied related files to your module directory, all you have to do is require 'JC.js' as regular Node module.
Javascript:
var JC = require( ${path_of_JC.js} )
Coffeescript:
JC = require( ${path_of_JC.js} )
Attension: If you ignore the extension '.js', Node will require 'jc.node' instead, and 'jc.node' is Node's C++ binding part which offer basic data structures as well as basic linear functions supporting 'JC.js'. If you only want to use JC, please add '.js' explicitly.
Then you can use it like this
Coffeescript:
#@@@ You can understand Host as CPU part, Device as GPU part)
JC = require( ${path_of_JC.js} )
testLength = 100
JC.cudaDeviceInit() # Preface
vAh = new Float32Array( ( Math.random() for num in [0...len] ) ) # Host memory
vAd = new JC.VectorD( vAh.length, vAh ) # Assign vAh value to Device memory
vBd = new JC.VectorD( vAh.length, vAh ) # Assgin same value to vBd
vAd.add( vBd ) # vAd = vAd + vBd
vAd.copyTo( vAd.length, vAh ) # Copy value to Host from Device memory
# Although Device memory will be freed automatically,
# it is recommanded to 'destroy' it explicitly,
# give back device memory to GPU for better performance
vAd.destroy()
console.log( #{ vAh } ) # output the result
JC.cudaDeviceReset() # Before program exits
##Unit test
If you want to do unit tests, or take them as examples, please goto "./Pre-build" folder and copy whole "unit_test" folder into your module directory which contains ["JC.js", "jc.node", "JSCUDA.dll"].
Then open the terminal in module's directory and input
E:\expamles>npm install
to install dependencies:
- mocha ^2.5.3 ( JavaScript test framework )
- colors ^1.1.2 ( Color and style outputs in node.js console )
( It's totally OK to install them globally as npm package by
npm install mocha -g
andnpm install colors -g
)
And now you can run test:
E:\expamles>mocha ${testname}.js
Output is something like this:
##API Reference & Guide [https://github.com/CallmeNezha/JSCUDA/wiki/]