|Written by Ian Elliot|
|Friday, 31 October 2014|
Long before GPUs became the focus of attention for parallel computing, most CPUs acquired a set of low level instructions that allowed multiple items of data to be operated on in a single instruction. SIMD - or Single Instruction Multiple Data - is one of the simplest and easiest parallel processing mechanisms.
Essentially what it comes down to is packing multiple values into a single register and then perform the operation as if it was a single value. Of course, there are some overheads - you have to pack and unpack the data - but in most cases these can be minimized.
SIMD instructions are great for vector arithmetic, and it can be used to speed up tasks like matrix operations and media decoding. If you have a codec that doesn't quite work in real time then modifying it to make use of the processor's SIMD instructions can make it real time. Of course, for embarrassingly parallel tasks, such as image manipulation and a lot of graphics, in general you can't do better than the GPU which has the capability to do many more operations in parallel than the SIMD hardware. The advantage of SIMD is that you don't have to ship the data off to the GPU and it is a lot easier to understand.
Note you have constructors for the new SIMD data types and the operations are provided as methods of a new SIMD object. The four 32-bit floats are packed into vectors and then added in one operation.
At the moment, SIMD.js supports float32x4 and int32x4 and introduces two new typed arrays that allow access to the individual values and to provide aliasing with other typed arrays to convert the data.
You can see the sort of speedup that results from using SIMD.js in Firefox:
As SIMD.js is low level, it is assumed that other libraries will be built on top of it to provide a higher level view:
"SIMD.js will accelerate a wide range of demanding applications today, including games, video and audio manipulation, scientific simulations, and more, on the web. Applications will be able to use the SIMD.js API directly, libraries will be able to use SIMD.js to expose higher-level interfaces that applications can use, and Emscripten will compile C++ with popular SIMD idioms onto optimized SIMD.js code."
This all good and it should make asm.js even more essential to the web, but there are many who will ask if this is at all sensible. Perhaps the best thing to do would be to take another route. Things would be much simpler if all browsers came with a well-designed byte code VM.
To be informed about new articles on I Programmer, install the I Programmer Toolbar, subscribe to the RSS feed, follow us on, Twitter, Facebook, Google+ or Linkedin, or sign up for our weekly newsletter.
or email your comment to: email@example.com
|Last Updated ( Friday, 31 October 2014 )|