Easily drive GPUs from Javascript and Node.js
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples/convolutionDemo
src
tests
.gitignore
Dockerfile
Dockerfile-cpu
Dockerfile-cpu.version
Dockerfile.version
LICENSE.txt
Makefile
README.md
package.json

README.md

CL.js

Library to make GPU acceleration as seamless and easy as calling an asynchronous function call. Built on top of the low-level API provided by Node-OpenCL.

Current State

This is currently alpha quality. Many features are missing and the API is likely to change.

Quick Start

Install

The package is not yet on the npm repository. You can install it from git:

git clone https://github.com/graphistry/cljs.git
cd cljs && npm link

Test

npm run test

You should see the following output: Result is: [ 3, 3, 3 ]

Usage

Here is a minimal example:

var cl = new CLjs();
var ones = new Int32Array([1,1,1]);
var twos = new Int32Array([2,2,2]);
var numElements = 3;

// Create input and output buffers
var onesBuffer = cl.createBuffer(ones);
var twosBuffer = cl.createBuffer(twos);
var outputBuffer = cl.createBuffer(Int32Array.BYTES_PER_ELEMENT * numElements);

// Create a kernel
var argTypes = [cl.types.mem_t, cl.types.mem_t, cl.types.mem_t, cl.types.int_t];
var addKernel = cl.createKernel('tests/add.cl', 'add', argTypes);

// Run the kernel...
addKernel
	.run([256], null, [onesBuffer, twosBuffer, outputBuffer, numElements])
	.then(function (info) {
		// ... and download results
   		var result = outputBuffer.read(Int32Array);
       console.log('Result is: ', Array.prototype.slice.call(result));
    });

Going Further

Have a look at the edge detection demo in cljs/examples/convolutionDemo. You can run the demo in three steps:

  1. cd cljs/examples/convolutionDemo
  2. npm start
  3. Open localhost:3001?mode=opencl in your browser. Compare the speed with localhost:3001?mode=javascript

The meat of the code is in convolve.js and convolve.cl