Code Monkey home page Code Monkey logo

cljs's Introduction

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

cljs's People

Contributors

lsb avatar quinnhj avatar thibaudh avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.