Tuesday, January 26th, 2010

JavaScript running on the GPU

>I love programmers like Alex Miltsev. He won the Jetpack 0.5 content by prototyping access to the GPU from JavaScript!

Alex’s work is an alpha-prototype that shows the feasibility of the project and it requires a custom build of Firefox to use — it’s not easy to demo. However, the code sample below shows how the technology works. In this example, we are transposing a matrix at lightening speed:

javascript
< view plain text >
  1. jetpack.statusBar.append({
  2.   html: "Transpose!",
  3.   onReady: function(widget){
  4.     $(widget).click(function(){
  5.       var myStorage = jetpack.cuda-storage;
  6.       var matrix = new Array();
  7.       var size = 32;
  8.       for(var i=0; i<size *size; ++i)
  9.         array[i] = i;
  10.       var transposedMatrix = myStorage.transpose(size, matrix);
  11.       transposedMatrix.forEach(function (v) { console.log( v ); })
  12.     });
  13. });

Alex discussed why this matters:

People are using the internet to collaborate more than ever before. Collaboration on the internet has been evolving at a rapid pace, and the applications and technology that will drive the next wave of internet collaboration will require even greater technical complexity and more significant computing resources than is currently available through the browser environment today. While text documents, videos, music, and image-base forms of collaboration are now common place, there are many needs require a level of compute performace beyond the web platform as it exists today, such as:

  • consumption of high-quality digital video or music streams,
  • complex image or speech recognition,
  • manipulation and processing large pictures of nature or space,
  • processing large sets of tabular data locally in the browser,
  • complex animations with DOM elements (via DirectX or OpenGL),
  • exploring 3D worlds, such as SecondLife or an OpenSim Grid,
  • real-time audio and video editing,
  • having an integrated development environment that runs entirely in the browser

There are endless examples of such complex uses of the internet platform that are just not feasible with the status quo web platform. Developers have tried to overcome such barriers in the past with client-side enhancements like ActiveX, Netscape Plugins, Java Applets, but each in its own way was flawed and failed to gain mass adoption. It is possible that the Native Client project will change all this, but standardization of such initiatives across the browser landscape is a lengthy endeavor. For the near future the tools that the developer uses to provide a rich user experience remain JavaScript and ActionScript, plug-ins, such as the ones previously mentioned, are significantly limited by the architectural mismatch of performance requirements they place on the CPU.

Ben tends to get a little giddy when he hears about GPU access :)

Posted by Dion Almaer at 12:07 pm
15 Comments

++++-
4.6 rating from 29 votes

15 Comments »

Comments feed TrackBack URI

Isn’t this a syntax error?

jetpack.cuda-storage

Comment by eyelidlessness — January 26, 2010

Yeah that’ll tell you storage is undefined, should be jetpack['cuda-storage']

Comment by Jadet — January 26, 2010

Any chance of getting a webkit build with this into webOS any time soon?

Comment by sos — January 26, 2010

Hi!

To eyelidlessness:

“Isn’t this a syntax error? jetpack.cuda-storage”

jetpack.cuda-storage isn’t syntax error. jetpack class is extended with C++.

To sos:

“Any chance of getting a webkit build with this into webOS any time soon?”

I’m not sure what do you exactly mean by “webOS”. Could you comment? It is Open Source movement. So if community needs it and it is possible to build then it will be! You may be interested in these articles: http://mozillalabs.com/blog/2010/01/the-future-of-add-ons/ and http://mozillalabs.com/blog/2010/01/elevating-javascript-performance-through-gpu-power/ .

Regards,
Alex Miltsev
http://malexander.wordpress.com/

Comment by sanya — January 26, 2010

sanya,

Excluse me, not a syntax error; a reference error. But ECMA-262 syntax does not allow dot access to object members with hyphens (nor unquoted declaration of those members in object literal syntax; this would be a syntax error). jetpack.cuda-storage would try to subtract the variable storage from the member cuda of the object jetpack.

Run from the Firebug console:
var jetpack = { 'cuda-storage': 'foo' };
jetpack.cuda-storage; // ReferenceError: storage is not defined

I don’t really understand your answer to me. Jetpack, as I understand it, is a web technology (HTML/CSS/JS) API for extending Mozilla applications. The APIs target C++ classes (obviously), but that shouldn’t change the syntax rules of Javascript—so there must be something else going on. I’ve found no evidence that Javascript in Jetpack has different syntax rules than Javascript in other Mozilla technologies. Can you please clarify?

Comment by eyelidlessness — January 26, 2010

GPU in the browser. Nummers.

So does this mean we can install custom shaders to apply effects directly to the contents of the Canvas object, or does that require more integration with the browser?

Comment by joshmarinacci — January 26, 2010

eyelidlessness,

bull’s eye :)! This is code misprint. Originally (you can see sourse on groups.google) the jetpack.storage was extended with transpose method. Then for the article it was renamed to cuda-storage. And misprint was made. Thanks for noticing!

By the way, in the end of “Elevating Performance” there are few words about JS syntax extending. (I don’t mean hyphen objects call ;)) What do you think about new JS syntax features for parallelizing? For start it could be provided by Jetpack environment.

Regards

Comment by sanya — January 27, 2010

joshmarinacci,

CUDA environment installation is required. Additional integration with browser is still needed. In Jetpack-to-CUDA project additional C++ code was written to extend jetpack.storage to make it possible to transpose on GPU. Answers to your question?

Regards

Comment by sanya — January 27, 2010

Anyone have Alex’s contact information? I’d love to talk to him further about JS.

http://www.apture.com <–one of the most impressive javascript applications currently available.

Comment by pelechati — January 27, 2010

Hi Alex,

webOS is the operating system that runs on the Palm Pre & Pixi smartphones. Ben and Dion who run this blog are the tech leads of that project. All applications in webOS run in a webkit browser, and the phone has a very powerful GPU, but it is not accessible from the browser.

Bridging the gap between the browser and the GPU could be a massive gain for webOS.

Comment by sos — January 27, 2010

I don’t all the in’s-and-out’s, I must admit, but wouldn’t it make more sense to use OpenCL instead of CUDA?

Comment by mdmadph — January 27, 2010

pelechati,
you could find my contact information in my CV: http://malexander.wordpress.com/2009/11/16/cirriculum-vitae/

Comment by sanya — January 27, 2010

sos,
I’m not sure about GPGPU on webOS. I read only about plans. Do you have information? The idea of webkit GPU acceleration on webOS is excellent from my point of view.

Alex

Comment by sanya — January 27, 2010

mdmadph,
what advantages of using OpenCL instead of CUDA do you see? I had more experience in CUDA than in OpenCL.
Alex

Comment by sanya — January 27, 2010

I think OpenCL if not yet… will be able to run on a wider spectrum of GPUs. Especially because NVIDIA is working on a OpenCL layer on top of CUDA, also besides articles like this… “Why Won’t ATI Support CUDA and PhysX?”
http://www.extremetech.com/article2/0,2845,2324555,00.asp
I think OpenCL will work as smaller GPUs like my phone’s (Nokia N900) Graphics Card… and this is precisely the place where I would love some JavaScript acceleration.
Ideally what I envision… though have no clue how feasible it is… is FireFox mobile having some kind of an accelerator layer above their JS engine… that could take various JavaScript threads (especially the calculation intensive ones) and throw them into an OpenCL app that runs the calculations on the GPU and returns a value back to the CPU… I imagine this could take a load off the 600mhz CPU and make for a much smoother web browsing experience. As more and more cellphones are adding simple graphic chips to speed up the GUI, Games, Video… it would be nice to speed up the cellphone web browser these technologies.

Comment by sentry360 — February 1, 2010

Leave a comment

You must be logged in to post a comment.