Coder Social home page Coder Social 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

Stargazers

peiqing avatar Yves M. avatar Jonathan Pugh avatar Harrys Kavan avatar Joohun, Maeng avatar Nathaniel Compton avatar Gordon avatar Elwynn Chen avatar Nikolai Novoselov avatar Fuli Wu avatar  avatar Baltazar Ortiz avatar Vitali Perchonok avatar hamlet avatar Javier avatar ludovic autin avatar  avatar Vijay Bhaskar avatar  avatar 少司命 avatar Vinicius Pereira avatar Philip Zucker avatar Cameron Martin avatar Rohan Khanna avatar 王祎 avatar Suvi-Tuuli Allan avatar Octavian Bujor avatar sm50 avatar Fabio Dias Rollo avatar Chris Slott avatar  avatar Robert Fairley avatar Viktor Kunovski avatar  avatar brian herman avatar Reginald Tan avatar Boris Cherny avatar Yutaka Takahashi avatar zeristor avatar Sean Jensen-Grey avatar J. Ryan Stinnett avatar Kevin Sullivan avatar James Edward Lewis II avatar Brian Redfern avatar

Watchers

Pete Brumm avatar Andrew avatar James Cloos avatar  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.