Progress On JavaScript SIMD
Written by Ian Elliot   
Friday, 31 October 2014

While most of the hot news in fast computation centers around the GPU, there are untapped possibilities in most CPUs. JavaScript is currently getting a new set of commands that give it hardware-assisted parallel processing. 




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.

In addition, C compilers support SIMD and many high performance C programs make use of it. This is a particular problem for JavaScript because the emscripten C++ to asm.js compiler can't currently cope with SIMD instructions. 

For this and other reasons, SIMD.js is being developed to allow JavaScript programmers access to the SIMD hardware on x86 with SSE and ARM with NEON - two of the most common flavours of SIMD. Intel, Google and Mozilla are working on SIMD.js and it is under consideration by the Microsoft IE team. The project is based on the Google Dart SIMD specification. A version you can try is currently in Firefox Nightly. 

If you plan on using SIMD.js then you need to be prepared for a level of programming you don't normally get in JavaScript - this is closer to the metal than usual. For example, to add two vectors of four 32-bit floats together you would use:

var a = float32x4(1.0, 2.0, 3.0, 4.0);
var b = float32x4(5.0, 6.0, 7.0, 8.0);
var c = SIMD.float32x4.add(a,b);

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.

There is also the question of whether it is a good idea to add such low level features to JavaScript which is a high level language. 




Neo4j Announces Graph Machine Learning Framework

Neo4j has announced a graph machine learning framework that the developers describe as making advanced graph-based machine learning techniques more accessible.

PyTorch Developer Day Updates

The PyTorch Virtual Developer Day is now available online with technical talks and version 1.7 release deep dives. The team also announced updates to PyTorch.

More News






or email your comment to:

Last Updated ( Friday, 31 October 2014 )