26

I'm starting a project for browsers which requires some complex data processing. The algorithm I'm using is 50-100x faster when accelerated with GPU.

I could use JavaScript, Flash or other technologies with the browser. Is there any way I can access the GPU to accelerate the processing of my math?

micho
  • 2,196
  • 2
  • 21
  • 26
  • 1
    WebGL ? That's GPU accelerated. – Raynos May 17 '11 at 19:10
  • 1
    Looks like flash GPU acceleration is handled _by flash_ - you can't send arbitrary computation requests to it. :( http://www.kaourantin.net/2008/05/what-does-gpu-acceleration-mean.html – peteorpeter May 17 '11 at 19:21
  • How about Python? It's doable to get Python running in a webpage. You could import a Python-GPU library such as Copperhead or PyCUDA and implement your algorithms in that library. – solvingPuzzles Dec 29 '12 at 05:09

4 Answers4

25

You could start experimenting with Khronos' WebCL, although that's still in its infancy. The big players like Internet Explorer, Chrome and Opera show no clear plans for support just yet, with Microsoft not even showing any plans for WebGL support.

That being said, apart from a WebGL shader based GPGPU approach, WebCL might be your best bet for computation. WebCL is in essence a set of JavaScript bindings to OpenCL. As such, developments are most likely to be closely linked to those of OpenCL.

While, as said, support for WebCL is as of this moment not yet standard nor widespread, there are currently the following resources available:

  • The Khronos group has the official website here.
  • Nokia Research reports its experiments on their dedicated site, including a WebCL extension for FireFox (Version 18 only at the moment). The developer working on this extension also has a Twitter at https://twitter.com/NokiaWebCL.
  • Samsung's experiments for WebKit tested with the Safari browser are available here.
  • Motorola has a NodeJS-based implementation of OpenCL available here.
  • Mozilla itself seems to have become active was well with their own WebCL developments, though it's exact current status is unknown to me.

I have only started to play with it myself recently, but can't yet make any recommendations beyond "quite fun".

Bart
  • 19,692
  • 7
  • 68
  • 77
4

Since this old question was a top search hit for me on this topic, I thought I'd mention that some further exploration led me to gpu.js, which wraps WebGL in utility functions.

EDIT: ...and hopping through GitHub issues etc. from there led me to weblas as well. I don't have a comparison of these two yet, converting this answer to community wiki in case someone with experience in either of these sees this and has something to add.

Dan Percival
  • 293
  • 2
  • 8
  • is there a way to calculate the inverse of a 8x8 matrix using these? I need it for implementing my own perspective transformation on the web – Ak01 Jan 26 '21 at 16:41
0

Depending on what you want to do, but I am sure it could be much easier to run the calculations on the server's gpu and get them back to the browser client

Open the way
  • 26,225
  • 51
  • 142
  • 196
0

It would be interesting to see someone pull this off with Flash and Javascript. It entirely depends how frequently you would have to do the calculations.

If you only need to perform one iteration of calculations (essentially, one "render" pass or one draw call), you may be able to setup your VertexShader3D and FragmentShader3D like you would normally for any Stage3D project in Flash, and then return the results from the BitmapData of that render:

//You probably want this to be the same dimensions as your context3D dimensions:
_context3D.drawToBitmapData(yourBitmapDataDestination);

Then you could pass the information to Javascript. I'm not sure if BitmapData can be passed directly, but I'm quite positive you will have to serialize the data first (as an Array, or String, etc.). You'll have to look at how the ExternalInterface class is used to communivate between Flash and Javascript.

Once you got your crunched numbers in JavaScript, do whatever you have to do with those values!

This exchange of information between Flash, the GPU, and JavaScript might not be optimal if you're seeking a solution for a process that needs to be executed "per frame" (like a game-loop, updating every n-frames).

Note: Sorry for the incomplete answer, but I mostly just wanted to guide you into a possible solution if you still were considering Flash as your point of access to the GPU.

chamberlainpi
  • 4,854
  • 8
  • 32
  • 63