View on GitHub

Sierra

A SIMD Extension for C++

Download this project as a .zip file Download this project as a tar.gz file

Nowadays, SIMD hardware is omnipresent in computers. Nonetheless, many software projects hardly make use of SIMD instructions: Applications are usually written in general-purpose languages like C++. However, general-purpose languages only provide poor abstractions for SIMD programming enforcing an error-prone, assembly-like programming style.

Sierra combines the full power of C++ with an intuitive and effective way to address SIMD hardware. With Sierra, the programmer can write efficient, portable and maintainable code. It is particularly easy to enhance existing code to run efficiently on SIMD machines.

Overview

Sierra's key components are vector types. The programmer can use these types via the keyword varying. Standard operators are overloaded to also work on such vectors:

SIMD

Most importantly, the programmer can explicitly trigger vectorization of code by using vectors in control-flow-dependent expressions. In the figure below, the condition v < 3 is of vector type. Thus, Sierra enters a special SIMD mode. As the condition only holds for the first and fourth element, v += 2 is only performed for the first and fourth element of v. We also say, the first and the fourth lanes are active. The other two lanes are inactive. Analogously, v -= 3 is only applied to the second and third element of v.

masking in conditional conde

Building

In order to build Sierra, we first fetch the official LLVM sources and then Sierra - which acts as drop-in replacement for clang. Additionally, we clone libsierra for supporting headers. We build everything with CMake.

Build Instructions

Debug Build

For a debug build, we do the following:

mkdir sierra
export CUR=`pwd`
cd sierra
mkdir build_debug
mkdir install_debug
git clone https://github.com/sierra-lang/libsierra.git
git clone https://github.com/sierra-lang/llvm.git -b friend_patch
cd llvm/tools
git checkout release_35
git clone https://github.com/sierra-lang/sierra.git clang
cd ../../build_debug
cmake ../llvm -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=${CUR}/sierra/install_debug/
make install -j4 # use appropriate number of threads here

Alternatively, you can use the cmake-gui tool: cmake-gui ../llvm Then,

Release Build

For a release build, setup appropriate build_release and install_release directories, and set CMAKE_BUILD_TYPE=Release.

Trying it out

You can try out the examples in libsierra/benchmark with the provided Makefile. Please make sure that clang++ points to your sierra build. Otherwise the switch -fsierra, which turns on the sierra extension, won't be available.

You may also want to checkout our wiki.

Status

Supported Control-Flow Constructs

The following constructs are currently supported in a vectorial context. They still work as normal in scalar context.

Feature Supported?
if ... else check
while check
do ... while check
for check
break check
continue check
return check
switch check
case check
goto check
expr || expr check
expr && expr check
!expr check
expr ? expr : expr check

Type System

Feature Supported?
varying primitive types check
pointers and references to varying types check
varying pointers and references check
varying structures some initial support is there

Known Issues

Publications

Roland Leißa, Immanuel Haffner, and Sebastian Hack
Sierra: A SIMD Extension for C++.
In Proceedings of the Workshop on Programming models for SIMD/Vector processing (WPMVP), 2014.

Roland Leißa, Sebastian Hack, Ingo Wald, William R. Mark and Matt Pharr
Extending C/C++ for Portable SIMD Programming.
Poster Presentation at the Intel Developer Forum (IDF), San Francisco, CA, USA, September 10-12, 2013.

Roland Leißa, Ingo Wald, and Sebastian Hack
Extending a C-like Language for Portable SIMD Programming.
In Proceedings of the Conference on Principles and Practice of Parallel Programming (PPoPP), 2012.