Monday 11 July 2011

New hardware power for Web apps?

Web applications such as image editors and advanced games could get a new performance boost from a graphics chip's processing power through a technology called WebCL.
Hardware acceleration is all the rage right now among browser makers: it can speed up everything from animating graphics to laying out all the elements of a Web page. Tapping directly into the hardware at a low level not only speeds things up, it saves precious battery power, too.
Now several companies are hard at work on a new interface called WebCL through the auspices of the Khronos Group standards body. WebCL is a browser-specific offshoot of a movement called GPGPU--general-purpose graphics processing unit.
Backers of WebCL aren't afraid to raise expectations.
"Providing millions of Web developers access to high-performance graphics and parallel computation will unleash a wave of creativity that will result in amazingly innovative Web applications that we haven't even imagined yet," said Neil Trevett, vice president of mobile content at graphics chipmaker Nvidia and the Khronos Group's president.
But WebCL advocates still have some persuading to do.
"We don't have plans to integrate WebCL at this point," said Mike Shaver, vice president of technical strategy at Mozilla, which has worked for years to make browsers a better foundation for more powerful Web applications. Its caution is notable given that one of its projects is WebGL, a close cousin of WebCL that's confined just to hardware-accelerated 3D graphics.
"WebGL reflects OpenGL, which is a well-understood and widely used graphics technology with a long history of interoperability," Shaver said. WebGL is based on a very mature Khronos graphics interface standard called OpenGL, but WebCL is based on the much younger OpenCL. "It's much, much earlier in OpenCL's life, and that makes it harder to say whether WebCL will let people write important new kinds of Web apps," Shaver said.
What it offers
The technology--if it comes to fruition, as appears likely for at least some browsers--won't accelerate everything under the sun. It's best suited to mathematical chores that can be broken down into independent pieces running in parallel.
Some examples of what it can offer: image processing algorithms, video game engines to simulate real-world physics, and even mining bitcoin virtual currency. Because such applications come from the Web, they arrive in a browser when you click a link--no downloading an installation file--and don't require programmers to worry about what operating system the browser is running on.
WebCL is part of a bigger trend, showing how the browser world is working hard to match what operating systems can do. That means, in short, that Web apps can be a more viable competitor to native apps. That's a particularly hot competition for developer attention when it comes to how to program apps for smartphones.
WebCL is not just an idea kicking around a standards group.
This Samsung WebCL demonstration of a transparent and reflective deformed blobs in a 3D world shows the vastly faster performance of WebCL. It yielded more than 87 frames per second for WebCL vs. 1 or 2 for unaided JavaScript.
This Samsung WebCL demonstration of transparent and reflective deformed blobs in a 3D world shows the vastly faster performance of WebCL. It yielded more than 87 frames per second for WebCL vs. 1 or 2 for unaided JavaScript.
(Credit: screenshot by Stephen Shankland/CNET)
The first proposal for the work came from Nokia, which developed a WebCL add-on for Firefox.
And earlier in July, Samsung contributed WebCL features to the open-source WebKit project that provides a foundation for many browsers, notably desktop and mobile browsers from Apple and Google. It's not clear yet which WebKit browsers if any will add WebCL support, but one possibility is the browser in Samsung's Bada operating system, which also is based on WebKit.
The work so far is still a long way from widespread availability--and the standardization process isn't done yet, either. And even when WebCL arrives in browsers, programmers will have to learn how to use it. So don't expect an immediate effect. When it does, though, it'll be useful, Trevett argues.
"Typical use cases would include accelerating a physics engine for a 3D game in a browser using WebGL for the graphics. Or accelerating editing HD photos or videos--smoothly and interactively, right in the browser," Trevett said.
In the cases where WebCL is useful, he predicts a significant help to battery life.
"Using a GPU instead of the CPU for image and computationally intensive tasks that can be highly parallelized can often deliver between 5 and 100 times performance increase," Trevett said. "A GPU is typically also far more efficient at highly parallel computation than general-purpose CPUs--and can deliver the same workload with a tenth of the battery consumption."
How much of that battery-life savings will actually be visible isn't yet clear--especially because game programmers have a tendency to write software that fully exploits the hardware rather than does what yesterday's games do with less power consumption.
How it works
GPUs are designed to accelerate visual tasks, for example by running programs called shaders involved in 3D graphics or converting videos into the color scheme used by a monitor. The work typically involves many similar operations proceeding in parallel.
As graphics chips grew more powerful, chipmakers such as Nvidia and AMD jumped on the idea of letting them perform more work than just graphics.
There are complications--for example, moving data into and out of the graphics chip's separate memory into the memory used by the main processor--but the idea has gained currency in programming circles.
Early attempts to use the technology were difficult, but it's become easier as higher-level interfaces arrived: Nvidia's CUDA (Compute Unified Device Architecture), Microsoft's DirectCompute, and the Khronos Group's OpenCL (Open Computing Language), an interface available in in Mac OS X.
WebCL is an OpenCL derivative that takes the form of a JavaScript "binding," which means it offers a way to utilize OpenCL using the JavaScript language used for Web programming.
WebCL dovetails with the WebGL project for the more limited job of 3D graphics in the browser.
"The performance of JavaScript Web applications will not match highly optimized AAA [top-notch] native games--but the recent optimizations in JavaScript, and the fact that both WebGL and WebCL can be driven very efficiently form JavaScript, enable surprisingly high levels of performance," Trevett said.
WebCL, being an element of JavaScript, also can plug into another mechanism to improve Web-app programming called Web Workers. This lets programmers move some computing work to background processing tasks that don't bog down the user interface, for example, and they're becoming more important as Internet Explorer 10 joins the list of browsers with Web Workers support.
Security matters
Granting software downloaded from the Web access to low-level hardware adds new risks, though.
An illustration: security firm Context Information Security uncovered a WebGL vulnerability, and Khronos allies quickly updated the specification to disable the feature that led to the hole, requiring programmers who'd used it to rewrite their software. Mozilla backed out the WebGL feature with Firefox 5 to sidestep the problem, and Google, which prides itself on Chrome security, is doing the same with Chrome 13. Meanwhile, Microsoft declared WebGL too unsafe to use.
Security is "job one," Trevett said, and its backers are working with hardware companies to make sure their drivers--the software that enables operating systems to use their graphics hardware--are hardened against vulnerabilities. And the Web interfaces have limits not present in their native equivalents.
"WebGL has simplifications and restrictions compared to 'raw' OpenGL ES to enable secure operation. WebCL will go through the same exercise and expose a secure subset of OpenCL to JavaScript," he said.
Don't expect Microsoft to jump aboard, though, given its expressed reservations--and its competing interfaces--DirectCompute and Direct3D for Windows and the new version of its Silverlight browser plug-in. And as Mozilla and 3D expert Gregg Tavares have observed, Silverlight and the Molehill 3D interface in the upcoming version of Flash Player expose the same low-level hardware to downloaded software.
Missing Microsoft support is a problem: when Web developers can't count on a feature being present in all browsers, they must either write different versions of their applications to adjust, or omit support for a particular browser in the first place. The first option is time-consuming, the second is limiting and potentially unpleasant for users.
There's another wrinkle here: Google has its own project, called Native Client, that's geared to let Web applications run with the speed of native software. Thus far, though, Google seems content to support WebGL even though Native Client has a 3D acceleration component, too. In fact, WebCL can even run on a regular CPU, something Khronos says is faster than ordinary JavaScript. WebCL also can tap into multicore processor abilities for work that can be done in parallel tasks.
One possible scenario is that Web programmers familiar with JavaScript prefer WebCL and WebGL, while those from the C and C++ programming camp go with Native Client--if Google can encourage programmers and other browser makers to adopt it.
Sure, it's a bit of a muddle. But given how many parties are collectively developing the future of the Web as a programming platform, a little chaos is to be expected.

No comments:

Post a Comment

what is Juice Jacking SCAM

  Juice Jacking is a cybersecurity threat that occurs when cybercriminals manipulate public charging stations, such as USB charging ports in...