GithubHelp home page GithubHelp logo

gpgpu.js's Introduction

gpgpu.js

This is a toy utility for this blog post. It is designed to abstract away WebGL as a graphics technology and make it behave more like a general-purpose computing technology, like CUDA or OpenCL.

I will probably not be expanding on this utility unless there is substantial interest.

Benchmarks

Running the following kernel on 100M floats:

  • CPU Kernel: (num) -> num + Math.tan(Math.cos(Math.sin(num * num)))
  • GPU Kernel: dst = src + tan(cos(sin(src * src)));
CPU: 6851.25ms
GPU Total: 1449.29ms
GPU Execution: 30.64ms
GPU IO: 1418.65ms
Theoretical Speedup: 223.59x
Actual Speedup: 4.73x

Basic Usage

root = $("#gpgpu")
engine = getEngine root

kernel = "dst = src + tan(cos(sin(src * src)));"
inputs = new Float32Array [1, 2, 3, 4, 5]

outputs = engine.execute kernel, inputs

User-defined functions

root = $("#gpgpu")
engine = getEngine root

inputs = new Float32Array [1, 2, 3, 4, 5]
preamble = """
float cube(float v) {
    return v * v * v;
}
"""
kernel = "dst = cube(src);"
outputs = engine.execute inputs, kernel, preamble

Uniforms

inputData = new Float32Array [1, 2, 3, 4, 5]
inputs = Storage.fromData engine, inputData

kernel = "dst = src * float(num);"
preamble = "uniform int num;"

comp = engine.createComputation inputData.length, kernel, preamble
outputs = comp.execute inputs, {num:["1i", 3]}

gpgpu.js's People

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.